windows: Login with system username and password for web

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
Jianhui Zhao
2018-10-12 14:36:41 +08:00
parent 037aaf59ab
commit 4f4afb7de8
3 changed files with 15 additions and 13 deletions
-1
View File
@@ -10,7 +10,6 @@ generate() {
cp conf/rttys.crt conf/rttys.key output/$dir
[ "$os" = "windows" ] && {
cp conf/rttys.ini output/$dir
bin="rttys.exe"
}
-3
View File
@@ -1,3 +0,0 @@
[login]
username = rttys
password = rttys
+15 -9
View File
@@ -1,7 +1,8 @@
package main
import (
"github.com/robfig/config"
"syscall"
"unsafe"
)
func checkUser() bool {
@@ -9,14 +10,19 @@ func checkUser() bool {
}
func login(username, password string) bool {
c, err := config.ReadDefault("rttys.ini")
mod := syscall.NewLazyDLL("Advapi32.dll")
LOGON32_LOGON_INTERACTIVE := 2
LOGON32_PROVIDER_DEFAULT := 0
var token syscall.Handle
if err != nil {
return true
}
proc := mod.NewProc("LogonUserW")
ret, _, err := proc.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(username))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("."))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(password))),
uintptr(LOGON32_LOGON_INTERACTIVE),
uintptr(LOGON32_PROVIDER_DEFAULT),
uintptr(unsafe.Pointer(&token)))
u, _ := c.String("login", "username")
p, _ := c.String("login", "password")
return username == u && password == p
return ret == 1 || err.(syscall.Errno) == 1327
}