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 }