Hello,
I’m making a program the place I need to use the LogonUserA operate from the home windows API however I’m not capable of finding this operate within the golang.org/x/sys/home windows package deal. Any recommendation can be very useful.
Along with Jeff’s suggestion, you may as well get away with not utilizing Cgo right here and as a substitute use syscall.NewLazySystemDLL
and (*syscall.LazyDLL).NewProc
. I haven’t examined this; I simply wrote it within the reply field right here, so it won’t even compile, however I feel it must be near what you’re on the lookout for.
package deal predominant
var logonUserW = syscall.NewLazySystemDLL("advapi32.dll").NewProc("LogonUserW")
func LogonUser(username, area, password string, logonType LogonType, logonProvider LogonProvider) (home windows.Token, error) {
pUsername := home windows.UTF16PtrFromString(username)
pDomain := home windows.UTF16PtrFromString(area)
pPassword := home windows.UTF16PtrFromString(password)
hToken := uintptr(0)
res, _, err := logonUserW.Name(
uintptr(unsafe.Pointer(pUsername)),
uintptr(unsafe.Pointer(pDomain)),
uintptr(unsafe.Pointer(pPassword)),
uintptr(logonType),
uintptr(logonProvider),
uintptr(unsafe.Pointer(&hToken)),
)
if res != 0 {
return home windows.Token(hToken), nil
}
return 0, err
}
kind LogonType int32
const (
// LOGON32_LOGON_BATCH is meant for batch servers, the place
// processes could also be executing on behalf of a person with out their
// direct intervention. This kind can be for greater efficiency
// servers that course of many plaintext authentication makes an attempt at a
// time, reminiscent of mail or net servers.
LOGON32_LOGON_BATCH LogonType = 4
// LOGON32_LOGON_INTERACTIVE is meant for customers who might be
// interactively utilizing the pc, reminiscent of a person being logged on
// by a terminal server, distant shell, or comparable course of. This
// logon kind has the extra expense of caching logon
// data for disconnected operations; due to this fact, it's
// inappropriate for some shopper/server functions, reminiscent of a
// mail server.
LOGON32_LOGON_INTERACTIVE LogonType = 2
// LOGON32_LOGON_NETWORK is meant for prime efficiency servers to
// authenticate plaintext passwords. The LogonUser operate doesn't
// cache credentials for this logon kind.
LOGON32_LOGON_NETWORK LogonType = 3
// LOGON32_LOGON_NETWORK_CLEARTEXT preserves the title and password
// within the authentication package deal, which permits the server to make
// connections to different community servers whereas impersonating the
// shopper. A server can settle for plaintext credentials from a shopper,
// name LogonUser, confirm that the person can entry the system throughout
// the community, and nonetheless talk with different servers.
LOGON32_LOGON_NETWORK_CLEARTEXT LogonType = 8
// LOGON32_LOGON_NEW_CREDENTIALS permits the caller to clone its
// present token and specify new credentials for outbound
// connections. The brand new logon session has the identical native identifier
// however makes use of totally different credentials for different community connections.
//
// This logon kind is supported solely by the LOGON32_PROVIDER_WINNT50
// logon supplier.
LOGON32_LOGON_NEW_CREDENTIALS LogonType = 9
// LOGON32_LOGON_SERVICE signifies a service-type logon. The account
// offered should have the service privilege enabled.
LOGON32_LOGON_SERVICE LogonType = 5
// LOGON32_LOGON_UNLOCK GINAs are now not supported.
//
// Home windows Server 2003 and Home windows XP: This logon kind is for GINA
// DLLs that go surfing customers who might be interactively utilizing the
// pc. This logon kind can generate a singular audit document that
// reveals when the workstation was unlocked.
//LOGON32_LOGON_UNLOCK LogonType = 7
)
// Copied from MS documentation:
kind LogonProvider int32
const (
// LOGON32_PROVIDER_DEFAULT makes use of the usual logon supplier for the
// system. The default safety supplier is negotiate, until you
// cross NULL for the area title and the person title is just not in UPN
// format. On this case, the default supplier is NTLM.
LOGON32_PROVIDER_DEFAULT LogonProvider = 0
// LOGON32_PROVIDER_WINNT40 makes use of the NTLM logon supplier.
//LOGON32_PROVIDER_WINNT40 LogonProvider = 1
// LOGON32_PROVIDER_WINNT40 makes use of the NTLM logon supplier.
//LOGON32_PROVIDER_WINNT40 LogonProvider = 2
// LOGON32_PROVIDER_WINNT50 makes use of the negotiate logon supplier.
LOGON32_PROVIDER_WINNT50 LogonProvider = 3
)
EDIT: Forgot to place definitions of LogonType and LogonProvider
2 Likes
Cool, that appears heaps simpler than making Cgo work.
This subject was mechanically closed 90 days after the final reply. New replies are now not allowed.