Documentation
¶
Index ¶
- Constants
- Variables
- func AddAccessAllowedAce(acl *Acl, revision, mask uint32, sid *syscall.SID) error
- func AddAccessAllowedAceEx(acl *Acl, revision, flags, mask uint32, sid *syscall.SID) error
- func AddAceToDesktop(desk Hdesk, sid *syscall.SID) error
- func AddAceToWindowStation(winsta Hwinsta, sid *syscall.SID) error
- func AlignedBuffer(size, offset int) []byte
- func CloseHandle(handle syscall.Handle) (err error)
- func CoTaskMemFree(pv uintptr)
- func CreateEnvironment(env *[]string, hUser syscall.Token) (mergedEnv *[]string, err error)
- func CreateEnvironmentBlock(lpEnvironment *uintptr, hToken syscall.Token, bInherit bool) (err error)
- func CreateSecurityDescriptor(length int) ([]byte, error)
- func DestroyEnvironmentBlock(lpEnvironment uintptr) (err error)
- func GetCurrentThreadId() uint32
- func GetFolder(hUser syscall.Token, folder *syscall.GUID, dwFlags uint32) (value string, err error)
- func GetLinkedToken(hToken syscall.Token) (syscall.Token, error)
- func GetProfilesDirectory(lpProfilesDir *uint16, lpcchSize *uint32) (err error)
- func GetTokenInformation(tokenHandle syscall.Token, tokenInformationClass TOKEN_INFORMATION_CLASS, ...) (err error)
- func GetTokenSessionID(hToken syscall.Token) (uint32, error)
- func GetTokenUIAccess(hToken syscall.Token) (uint32, error)
- func GetUserObjectInformation(obj syscall.Handle, index int, info unsafe.Pointer, length uint32) (uint32, error)
- func GetUserObjectName(obj syscall.Handle) (string, error)
- func GetUserProfileDirectory(hToken syscall.Token, lpProfileDir *uint16, lpcchSize *uint32) (err error)
- func ImpersonateLoggedOnUser(hToken syscall.Token) (err error)
- func InitializeAcl(acl *Acl, length, revision uint32) error
- func InitializeSecurityDescriptor(sd []byte) error
- func InteractiveUserToken(timeout time.Duration) (hToken syscall.Token, err error)
- func IsWindows8OrGreater() bool
- func LoadUserProfile(token syscall.Token, pinfo *ProfileInfo) error
- func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, ...) (token syscall.Token, err error)
- func MergeEnvLists(envLists ...*[]string) (*[]string, error)
- func ProfileDirectory(hToken syscall.Token) (string, error)
- func ProfilesDirectory() string
- func RevertToSelf() (err error)
- func SHGetKnownFolderPath(rfid *syscall.GUID, dwFlags uint32, hToken syscall.Token, pszPath *uintptr) (err error)
- func SHSetKnownFolderPath(rfid *syscall.GUID, dwFlags uint32, hToken syscall.Token, pszPath *uint16) (err error)
- func SetAclTo(obj syscall.Handle, acl *Acl) error
- func SetAndCreateFolder(hUser syscall.Token, folder *syscall.GUID, value string) (err error)
- func SetFolder(hUser syscall.Token, folder *syscall.GUID, value string) (err error)
- func SetSecurityDescriptorDacl(sd []byte, present bool, acl *Acl, defaulted bool) error
- func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass TOKEN_INFORMATION_CLASS, ...) (err error)
- func SetUserObjectSecurity(obj syscall.Handle, sid uint32, desc []byte) error
- func UnloadUserProfile(token syscall.Token, profile syscall.Handle) error
- func VerSetConditionMask(lConditionMask uint64, typeBitMask uint32, conditionMask uint8) uint64
- func VerifyWindowsInfoW(vi OSVersionInfoEx, typeMask uint32, conditionMask uint64) (bool, error)
- func WTSGetActiveConsoleSessionId() (sessionId uint32, err error)
- func WTSQueryUserToken(sessionId uint32, phToken *syscall.Token) (err error)
- type Ace
- type AceHeader
- type Acl
- type Hdesk
- type Hwinsta
- type LUID
- type LazyDLLWrapper
- type LazyProcWrapper
- type OSVersionInfoEx
- type ProfileInfo
- type TOKEN_INFORMATION_CLASS
- type TOKEN_LINKED_TOKEN
Examples ¶
Constants ¶
const ( LOGON32_PROVIDER_DEFAULT = 0 LOGON32_LOGON_INTERACTIVE = 2 PI_NOUI = 1 KF_FLAG_CREATE uint32 = 0x00008000 CREATE_BREAKAWAY_FROM_JOB = 0x01000000 CREATE_NEW_CONSOLE = 0x00000010 CREATE_NEW_PROCESS_GROUP = 0x00000200 VER_MAJORVERSION = 0x0000002 VER_MINORVERSION = 0x0000001 VER_SERVICEPACKMAJOR = 0x0000020 VER_SERVICEPACKMINOR = 0x0000010 VER_GREATER_EQUAL = 3 ERROR_OLD_WIN_VERSION syscall.Errno = 1150 // https://msdn.microsoft.com/en-us/library/windows/hardware/ff556838(v=vs.85).aspx // TOKEN_INFORMATION_CLASS enumeration TokenUser TOKEN_INFORMATION_CLASS = 1 TokenGroups TOKEN_INFORMATION_CLASS = 2 TokenPrivileges TOKEN_INFORMATION_CLASS = 3 TokenOwner TOKEN_INFORMATION_CLASS = 4 TokenPrimaryGroup TOKEN_INFORMATION_CLASS = 5 TokenDefaultDacl TOKEN_INFORMATION_CLASS = 6 TokenSourceX TOKEN_INFORMATION_CLASS = 7 TokenType TOKEN_INFORMATION_CLASS = 8 TokenImpersonationLevel TOKEN_INFORMATION_CLASS = 9 TokenStatistics TOKEN_INFORMATION_CLASS = 10 TokenRestrictedSids TOKEN_INFORMATION_CLASS = 11 TokenSessionId TOKEN_INFORMATION_CLASS = 12 TokenGroupsAndPrivileges TOKEN_INFORMATION_CLASS = 13 TokenSessionReference TOKEN_INFORMATION_CLASS = 14 TokenSandBoxInert TOKEN_INFORMATION_CLASS = 15 TokenAuditPolicy TOKEN_INFORMATION_CLASS = 16 TokenOrigin TOKEN_INFORMATION_CLASS = 17 TokenElevationType TOKEN_INFORMATION_CLASS = 18 TokenLinkedToken TOKEN_INFORMATION_CLASS = 19 TokenElevation TOKEN_INFORMATION_CLASS = 20 TokenHasRestrictions TOKEN_INFORMATION_CLASS = 21 TokenAccessInformation TOKEN_INFORMATION_CLASS = 22 TokenVirtualizationAllowed TOKEN_INFORMATION_CLASS = 23 TokenVirtualizationEnabled TOKEN_INFORMATION_CLASS = 24 TokenIntegrityLevel TOKEN_INFORMATION_CLASS = 25 TokenUIAccess TOKEN_INFORMATION_CLASS = 26 TokenMandatoryPolicy TOKEN_INFORMATION_CLASS = 27 TokenLogonSid TOKEN_INFORMATION_CLASS = 28 TokenIsAppContainer TOKEN_INFORMATION_CLASS = 29 TokenCapabilities TOKEN_INFORMATION_CLASS = 30 TokenAppContainerSid TOKEN_INFORMATION_CLASS = 31 TokenAppContainerNumber TOKEN_INFORMATION_CLASS = 32 TokenUserClaimAttributes TOKEN_INFORMATION_CLASS = 33 TokenDeviceClaimAttributes TOKEN_INFORMATION_CLASS = 34 TokenRestrictedUserClaimAttributes TOKEN_INFORMATION_CLASS = 35 TokenRestrictedDeviceClaimAttributes TOKEN_INFORMATION_CLASS = 36 TokenDeviceGroups TOKEN_INFORMATION_CLASS = 37 TokenRestrictedDeviceGroups TOKEN_INFORMATION_CLASS = 38 TokenSecurityAttributes TOKEN_INFORMATION_CLASS = 39 TokenIsRestricted TOKEN_INFORMATION_CLASS = 40 TokenProcessTrustLevel TOKEN_INFORMATION_CLASS = 41 MaxTokenInfoClass TOKEN_INFORMATION_CLASS = 42 )
const ( DACL_SECURITY_INFORMATION = 0x00000004 SECURITY_DESCRIPTOR_REVISION = 1 ACL_REVISION = 2 DESKTOP_CREATEMENU = 0x4 DESKTOP_CREATEWINDOW = 0x2 DESKTOP_ENUMERATE = 0x40 DESKTOP_HOOKCONTROL = 0x8 DESKTOP_JOURNALPLAYBACK = 0x20 DESKTOP_JOURNALRECORD = 0x10 DESKTOP_READOBJECTS = 0x1 DESKTOP_SWITCHDESKTOP = 0x100 DESKTOP_WRITEOBJECTS = 0x80 STANDARD_RIGHTS_REQUIRED = 0x000F0000 READ_CONTROL = 0x00020000 DESKTOP_ALL = DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALPLAYBACK | DESKTOP_JOURNALRECORD | DESKTOP_READOBJECTS | DESKTOP_SWITCHDESKTOP | DESKTOP_WRITEOBJECTS | READ_CONTROL WINSTA_ALL_ACCESS = 0x37F WINSTA_ALL = WINSTA_ALL_ACCESS | READ_CONTROL CONTAINER_INHERIT_ACE = 2 INHERIT_ONLY_ACE = 8 OBJECT_INHERIT_ACE = 1 NO_PROPAGATE_INHERIT_ACE = 4 )
const (
UOI_NAME = 2
)
Variables ¶
var ( FOLDERID_LocalAppData = syscall.GUID{Data1: 0xF1B32785, Data2: 0x6FBA, Data3: 0x4FCF, Data4: [8]byte{0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91}} FOLDERID_RoamingAppData = syscall.GUID{Data1: 0x3EB685DB, Data2: 0x65F9, Data3: 0x4CF6, Data4: [8]byte{0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D}} )
Functions ¶
func AddAccessAllowedAce ¶
func AddAccessAllowedAceEx ¶
func AlignedBuffer ¶
Return byte slice of given size, aligned at given offset.
func CloseHandle ¶
func CoTaskMemFree ¶
func CoTaskMemFree(pv uintptr)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680722(v=vs.85).aspx Note: the system call returns no value, so we can't check for an error
func CreateEnvironment ¶
CreateEnvironment returns an environment block, suitable for use with the CreateProcessAsUser system call. The default environment variables of hUser are overlayed with values in env.
func CreateEnvironmentBlock ¶
func CreateEnvironmentBlock( lpEnvironment *uintptr, hToken syscall.Token, bInherit bool, ) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762270(v=vs.85).aspx
func DestroyEnvironmentBlock ¶
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762274(v=vs.85).aspx
func GetCurrentThreadId ¶
func GetCurrentThreadId() uint32
func GetProfilesDirectory ¶
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762278(v=vs.85).aspx BOOL WINAPI GetProfilesDirectory(
_Out_ LPTSTR lpProfilesDir, _Inout_ LPDWORD lpcchSize
);
func GetTokenInformation ¶
func GetTokenInformation( tokenHandle syscall.Token, tokenInformationClass TOKEN_INFORMATION_CLASS, tokenInformation uintptr, tokenInformationLength uintptr, returnLength *uintptr, ) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/aa446671(v=vs.85).aspx BOOL WINAPI GetTokenInformation(
_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _Out_opt_ LPVOID TokenInformation, _In_ DWORD TokenInformationLength, _Out_ PDWORD ReturnLength
);
func GetUserProfileDirectory ¶
func GetUserProfileDirectory( hToken syscall.Token, lpProfileDir *uint16, lpcchSize *uint32, ) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx BOOL WINAPI GetUserProfileDirectory(
_In_ HANDLE hToken, _Out_opt_ LPTSTR lpProfileDir, _Inout_ LPDWORD lpcchSize
);
func ImpersonateLoggedOnUser ¶
https://msdn.microsoft.com/en-us/library/Aa378612(v=VS.85).aspx BOOL WINAPI ImpersonateLoggedOnUser(
_In_ HANDLE hToken
);
func InitializeAcl ¶
func InteractiveUserToken ¶
InteractiveUserToken returns a user token (security context) for the interactive desktop session attached to the default console (i.e. what would be seen on a display connected directly to the computer, rather than a remote RDP session). It must be called from a process which is running under LocalSystem account in order to have the necessary privileges (typically a Windows service). Since the service might be running before a local logon occurs, a timeout can be specified for waiting for a successful logon (via winlogon) to occur. The returned token can be used in e.g. CreateProcessAsUser system call, which allows e.g. a Windows service to run a process in the interactive desktop session, as if the logged in user had executed the process directly. The function additionally waits for the user profile directory to exist, before returning.
func IsWindows8OrGreater ¶
func IsWindows8OrGreater() bool
func LoadUserProfile ¶
func LoadUserProfile(token syscall.Token, pinfo *ProfileInfo) error
func MergeEnvLists ¶
Example ¶
package main
import (
"fmt"
"log"
"github.com/taskcluster/generic-worker/win32"
)
func main() {
lists := []*[]string{
{
"a=dog",
"Pete=man",
"x=ray",
}, {
"food=good",
"PETE=person",
},
}
res, err := win32.MergeEnvLists(lists...)
if err != nil {
log.Fatalf("Hit error: %v", err)
}
fmt.Println(*res)
}
Output: [a=dog food=good Pete=person x=ray]
func ProfileDirectory ¶
ProfileDirectory returns the profile directory of the user represented by the given user handle
func ProfilesDirectory ¶
func ProfilesDirectory() string
ProfilesDirectory returns the folder where user profiles get created, typically `C:\Users`
func RevertToSelf ¶
func RevertToSelf() (err error)
https://msdn.microsoft.com/en-us/library/aa379317(v=vs.85).aspx BOOL WINAPI RevertToSelf(void);
func SHGetKnownFolderPath ¶
func SHGetKnownFolderPath(rfid *syscall.GUID, dwFlags uint32, hToken syscall.Token, pszPath *uintptr) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188(v=vs.85).aspx
func SHSetKnownFolderPath ¶
func SHSetKnownFolderPath( rfid *syscall.GUID, dwFlags uint32, hToken syscall.Token, pszPath *uint16, ) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762249(v=vs.85).aspx
func SetAndCreateFolder ¶
func SetTokenInformation ¶
func SetTokenInformation( tokenHandle syscall.Token, tokenInformationClass TOKEN_INFORMATION_CLASS, tokenInformation uintptr, tokenInformationLength uintptr, ) (err error)
https://msdn.microsoft.com/en-us/library/windows/desktop/aa379591(v=vs.85).aspx BOOL WINAPI SetTokenInformation(
_In_ HANDLE TokenHandle, _In_ TOKEN_INFORMATION_CLASS TokenInformationClass, _In_ LPVOID TokenInformation, _In_ DWORD TokenInformationLength
);
func SetUserObjectSecurity ¶
func UnloadUserProfile ¶
https://docs.microsoft.com/en-us/windows/desktop/api/userenv/nf-userenv-unloaduserprofile
func VerSetConditionMask ¶
func VerifyWindowsInfoW ¶
func VerifyWindowsInfoW(vi OSVersionInfoEx, typeMask uint32, conditionMask uint64) (bool, error)
func WTSGetActiveConsoleSessionId ¶
https://msdn.microsoft.com/en-us/library/aa383835(VS.85).aspx DWORD WTSGetActiveConsoleSessionId(void);
func WTSQueryUserToken ¶
https://msdn.microsoft.com/en-us/library/aa383840(VS.85).aspx BOOL WTSQueryUserToken(
_In_ ULONG SessionId, _Out_ PHANDLE phToken
);
Types ¶
type LazyDLLWrapper ¶
These wrappers are used to be able to intercept system calls, and log what is being called...
func NewLazyDLL ¶
func NewLazyDLL(name string) *LazyDLLWrapper
func (*LazyDLLWrapper) NewProc ¶
func (l *LazyDLLWrapper) NewProc(name string) *LazyProcWrapper
type LazyProcWrapper ¶
These wrappers are used to be able to intercept system calls, and log what is being called...
type OSVersionInfoEx ¶
type ProfileInfo ¶
type TOKEN_INFORMATION_CLASS ¶
type TOKEN_INFORMATION_CLASS uint32
type TOKEN_LINKED_TOKEN ¶
https://msdn.microsoft.com/en-us/library/windows/desktop/bb530719(v=vs.85).aspx
typedef struct _TOKEN_LINKED_TOKEN {
HANDLE LinkedToken;
} TOKEN_LINKED_TOKEN, *PTOKEN_LINKED_TOKEN;