win32

package
v11.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Rendered for windows/amd64

Index

Examples

Constants

View Source
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
)
View Source
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
)
View Source
const (
	UOI_NAME = 2
)

Variables

View Source
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 AddAccessAllowedAce(acl *Acl, revision, mask uint32, sid *syscall.SID) error

func AddAccessAllowedAceEx

func AddAccessAllowedAceEx(acl *Acl, revision, flags, mask uint32, sid *syscall.SID) error

func AddAceToDesktop

func AddAceToDesktop(desk Hdesk, sid *syscall.SID) error

func AddAceToWindowStation

func AddAceToWindowStation(winsta Hwinsta, sid *syscall.SID) error

func AlignedBuffer

func AlignedBuffer(size, offset int) []byte

Return byte slice of given size, aligned at given offset.

func CloseHandle

func CloseHandle(handle syscall.Handle) (err error)

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

func CreateEnvironment(env *[]string, hUser syscall.Token) (mergedEnv *[]string, err error)

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 CreateSecurityDescriptor

func CreateSecurityDescriptor(length int) ([]byte, error)

func GetCurrentThreadId

func GetCurrentThreadId() uint32

func GetFolder

func GetFolder(hUser syscall.Token, folder *syscall.GUID, dwFlags uint32) (value string, err error)

func GetLinkedToken

func GetLinkedToken(hToken syscall.Token) (syscall.Token, error)

func GetProfilesDirectory

func GetProfilesDirectory(
	lpProfilesDir *uint16,
	lpcchSize *uint32,
) (err error)

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 GetTokenSessionID

func GetTokenSessionID(hToken syscall.Token) (uint32, error)

func GetTokenUIAccess

func GetTokenUIAccess(hToken syscall.Token) (uint32, error)

func GetUserObjectInformation

func GetUserObjectInformation(obj syscall.Handle, index int, info unsafe.Pointer, length uint32) (uint32, error)

func GetUserObjectName

func GetUserObjectName(obj syscall.Handle) (string, error)

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

func ImpersonateLoggedOnUser(hToken syscall.Token) (err error)

https://msdn.microsoft.com/en-us/library/Aa378612(v=VS.85).aspx BOOL WINAPI ImpersonateLoggedOnUser(

_In_ HANDLE hToken

);

func InitializeAcl

func InitializeAcl(acl *Acl, length, revision uint32) error

func InitializeSecurityDescriptor

func InitializeSecurityDescriptor(sd []byte) error

func InteractiveUserToken

func InteractiveUserToken(timeout time.Duration) (hToken syscall.Token, err error)

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 LogonUser

func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32) (token syscall.Token, err error)

func MergeEnvLists

func MergeEnvLists(envLists ...*[]string) (*[]string, error)
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

func ProfileDirectory(hToken syscall.Token) (string, error)

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 SetAclTo

func SetAclTo(obj syscall.Handle, acl *Acl) error

func SetAndCreateFolder

func SetAndCreateFolder(hUser syscall.Token, folder *syscall.GUID, value string) (err error)

func SetFolder

func SetFolder(hUser syscall.Token, folder *syscall.GUID, value string) (err error)

func SetSecurityDescriptorDacl

func SetSecurityDescriptorDacl(sd []byte, present bool, acl *Acl, defaulted bool) error

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 SetUserObjectSecurity(obj syscall.Handle, sid uint32, desc []byte) error

func VerSetConditionMask

func VerSetConditionMask(lConditionMask uint64, typeBitMask uint32, conditionMask uint8) uint64

func VerifyWindowsInfoW

func VerifyWindowsInfoW(vi OSVersionInfoEx, typeMask uint32, conditionMask uint64) (bool, error)

func WTSGetActiveConsoleSessionId

func WTSGetActiveConsoleSessionId() (sessionId uint32, err error)

https://msdn.microsoft.com/en-us/library/aa383835(VS.85).aspx DWORD WTSGetActiveConsoleSessionId(void);

func WTSQueryUserToken

func WTSQueryUserToken(
	sessionId uint32,
	phToken *syscall.Token,
) (err error)

https://msdn.microsoft.com/en-us/library/aa383840(VS.85).aspx BOOL WTSQueryUserToken(

_In_  ULONG   SessionId,
_Out_ PHANDLE phToken

);

Types

type Ace

type Ace struct{}

type AceHeader

type AceHeader struct {
	AceType  byte
	AceFlags byte
	AceSize  uint16
}

type Acl

type Acl struct{}

func CreateDesktopAllowAcl

func CreateDesktopAllowAcl(sid *syscall.SID) (*Acl, error)

func CreateNewAcl

func CreateNewAcl(length int) (*Acl, error)

func CreateWinstaAllowAcl

func CreateWinstaAllowAcl(sid *syscall.SID) (*Acl, error)

type Hdesk

type Hdesk uintptr

func GetThreadDesktop

func GetThreadDesktop(threadId uint32) (Hdesk, error)

type Hwinsta

type Hwinsta uintptr

func GetProcessWindowStation

func GetProcessWindowStation() (Hwinsta, error)

type LUID

type LUID struct {
	LowPart  uint32 // DWORD
	HighPart int32  // LONG
}

https://msdn.microsoft.com/en-us/library/windows/desktop/aa379261(v=vs.85).aspx

type LazyDLLWrapper

type LazyDLLWrapper struct {
	LazyDLL *syscall.LazyDLL
}

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

type LazyProcWrapper struct {
	LazyProc *syscall.LazyProc
}

These wrappers are used to be able to intercept system calls, and log what is being called...

func (*LazyProcWrapper) Call

func (p *LazyProcWrapper) Call(a ...uintptr) (r1, r2 uintptr, lastErr error)

type OSVersionInfoEx

type OSVersionInfoEx struct {
	OSVersionInfoSize uint32
	MajorVersion      uint32
	MinorVersion      uint32
	BuildNumber       uint32
	PlatformId        uint32
	CSDVersion        [128]uint16
	ServicePackMajor  uint16
	ServicePackMinor  uint16
	SuiteMask         uint16
	ProductType       byte
	Reserve           byte
}

type ProfileInfo

type ProfileInfo struct {
	Size        uint32
	Flags       uint32
	Username    *uint16
	ProfilePath *uint16
	DefaultPath *uint16
	ServerName  *uint16
	PolicyPath  *uint16
	Profile     syscall.Handle
}

type TOKEN_INFORMATION_CLASS

type TOKEN_INFORMATION_CLASS uint32

type TOKEN_LINKED_TOKEN

type TOKEN_LINKED_TOKEN struct {
	LinkedToken syscall.Token // HANDLE
}

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;

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL