github.com/Serizao/go-winio@v0.0.0-20230906082528-f02f7f4ad6e8/pkg/security/zsyscall_windows.go (about) 1 //go:build windows 2 3 // Code generated by 'go generate' using "github.com/Serizao/go-winio/tools/mkwinsyscall"; DO NOT EDIT. 4 5 package security 6 7 import ( 8 "syscall" 9 "unsafe" 10 11 "golang.org/x/sys/windows" 12 ) 13 14 var _ unsafe.Pointer 15 16 // Do the interface allocations only once for common 17 // Errno values. 18 const ( 19 errnoERROR_IO_PENDING = 997 20 ) 21 22 var ( 23 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) 24 errERROR_EINVAL error = syscall.EINVAL 25 ) 26 27 // errnoErr returns common boxed Errno values, to prevent 28 // allocations at runtime. 29 func errnoErr(e syscall.Errno) error { 30 switch e { 31 case 0: 32 return errERROR_EINVAL 33 case errnoERROR_IO_PENDING: 34 return errERROR_IO_PENDING 35 } 36 // TODO: add more here, after collecting data on the common 37 // error values see on Windows. (perhaps when running 38 // all.bat?) 39 return e 40 } 41 42 var ( 43 modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") 44 45 procGetSecurityInfo = modadvapi32.NewProc("GetSecurityInfo") 46 procSetEntriesInAclW = modadvapi32.NewProc("SetEntriesInAclW") 47 procSetSecurityInfo = modadvapi32.NewProc("SetSecurityInfo") 48 ) 49 50 func getSecurityInfo(handle windows.Handle, objectType uint32, si uint32, ppsidOwner **uintptr, ppsidGroup **uintptr, ppDacl *uintptr, ppSacl *uintptr, ppSecurityDescriptor *uintptr) (win32err error) { 51 r0, _, _ := syscall.Syscall9(procGetSecurityInfo.Addr(), 8, uintptr(handle), uintptr(objectType), uintptr(si), uintptr(unsafe.Pointer(ppsidOwner)), uintptr(unsafe.Pointer(ppsidGroup)), uintptr(unsafe.Pointer(ppDacl)), uintptr(unsafe.Pointer(ppSacl)), uintptr(unsafe.Pointer(ppSecurityDescriptor)), 0) 52 if r0 != 0 { 53 win32err = syscall.Errno(r0) 54 } 55 return 56 } 57 58 func setEntriesInAcl(count uintptr, pListOfEEs uintptr, oldAcl uintptr, newAcl *uintptr) (win32err error) { 59 r0, _, _ := syscall.Syscall6(procSetEntriesInAclW.Addr(), 4, uintptr(count), uintptr(pListOfEEs), uintptr(oldAcl), uintptr(unsafe.Pointer(newAcl)), 0, 0) 60 if r0 != 0 { 61 win32err = syscall.Errno(r0) 62 } 63 return 64 } 65 66 func setSecurityInfo(handle windows.Handle, objectType uint32, si uint32, psidOwner uintptr, psidGroup uintptr, pDacl uintptr, pSacl uintptr) (win32err error) { 67 r0, _, _ := syscall.Syscall9(procSetSecurityInfo.Addr(), 7, uintptr(handle), uintptr(objectType), uintptr(si), uintptr(psidOwner), uintptr(psidGroup), uintptr(pDacl), uintptr(pSacl), 0, 0) 68 if r0 != 0 { 69 win32err = syscall.Errno(r0) 70 } 71 return 72 }