641db73a86
Merge in DNS/adguard-home from 2231-autoupdate to master Updates #2231. Squashed commit of the following: commit 4ee9148ee7a38f2759898302a2109aa982fb4ee9 Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 30 19:08:14 2020 +0300 sysutil: provide os-independent interface commit 778097c5fdeb1dec94f4cfc6443d08f92d9db0ba Author: Eugene Burkov <e.burkov@adguard.com> Date: Mon Nov 30 16:40:33 2020 +0300 all: add sysutil package
43 lines
793 B
Go
43 lines
793 B
Go
//+build windows
|
|
|
|
package sysutil
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func canBindPrivilegedPorts() (can bool, err error) {
|
|
return HaveAdminRights()
|
|
}
|
|
|
|
func setRlimit(val uint) {
|
|
}
|
|
|
|
func haveAdminRights() (bool, error) {
|
|
var token windows.Token
|
|
h := windows.CurrentProcess()
|
|
err := windows.OpenProcessToken(h, windows.TOKEN_QUERY, &token)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
info := make([]byte, 4)
|
|
var returnedLen uint32
|
|
err = windows.GetTokenInformation(token, windows.TokenElevation, &info[0], uint32(len(info)), &returnedLen)
|
|
token.Close()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if info[0] == 0 {
|
|
return false, nil
|
|
}
|
|
return true, nil
|
|
}
|
|
|
|
func sendProcessSignal(pid int, sig syscall.Signal) error {
|
|
return fmt.Errorf("not supported on Windows")
|
|
}
|