From 4f4afb7de8738fee51104f5c4f3f3cc1ded45067 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Fri, 12 Oct 2018 14:36:41 +0800 Subject: [PATCH] windows: Login with system username and password for web Signed-off-by: Jianhui Zhao --- build.sh | 1 - conf/rttys.ini | 3 --- login_windows.go | 24 +++++++++++++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 conf/rttys.ini diff --git a/build.sh b/build.sh index 85ea553..92be48e 100755 --- a/build.sh +++ b/build.sh @@ -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" } diff --git a/conf/rttys.ini b/conf/rttys.ini deleted file mode 100644 index 41b9c45..0000000 --- a/conf/rttys.ini +++ /dev/null @@ -1,3 +0,0 @@ -[login] -username = rttys -password = rttys diff --git a/login_windows.go b/login_windows.go index 4056d4e..70c08dc 100644 --- a/login_windows.go +++ b/login_windows.go @@ -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 }