-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to use upstream sddl/SecurityAttribute but retain old exported functions #172
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ import ( | |
"syscall" | ||
"time" | ||
"unsafe" | ||
|
||
"golang.org/x/sys/windows" | ||
) | ||
|
||
//sys connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) = ConnectNamedPipe | ||
|
@@ -35,7 +37,7 @@ type objectAttributes struct { | |
RootDirectory uintptr | ||
ObjectName *unicodeString | ||
Attributes uintptr | ||
SecurityDescriptor *securityDescriptor | ||
SecurityDescriptor *windows.SECURITY_DESCRIPTOR | ||
SecurityQoS uintptr | ||
} | ||
|
||
|
@@ -45,16 +47,6 @@ type unicodeString struct { | |
Buffer uintptr | ||
} | ||
|
||
type securityDescriptor struct { | ||
Revision byte | ||
Sbz1 byte | ||
Control uint16 | ||
Owner uintptr | ||
Group uintptr | ||
Sacl uintptr | ||
Dacl uintptr | ||
} | ||
|
||
type ntstatus int32 | ||
|
||
func (status ntstatus) Err() error { | ||
|
@@ -82,8 +74,6 @@ const ( | |
|
||
cFILE_PIPE_MESSAGE_TYPE = 1 | ||
cFILE_PIPE_REJECT_REMOTE_CLIENTS = 2 | ||
|
||
cSE_DACL_PRESENT = 4 | ||
) | ||
|
||
var ( | ||
|
@@ -273,7 +263,7 @@ type win32PipeListener struct { | |
doneCh chan int | ||
} | ||
|
||
func makeServerPipeHandle(path string, sd []byte, c *PipeConfig, first bool) (syscall.Handle, error) { | ||
func makeServerPipeHandle(path string, sd *windows.SECURITY_DESCRIPTOR, c *PipeConfig, first bool) (syscall.Handle, error) { | ||
path16, err := syscall.UTF16FromString(path) | ||
if err != nil { | ||
return 0, &os.PathError{Op: "open", Path: path, Err: err} | ||
|
@@ -286,29 +276,25 @@ func makeServerPipeHandle(path string, sd []byte, c *PipeConfig, first bool) (sy | |
if err := rtlDosPathNameToNtPathName(&path16[0], &ntPath, 0, 0).Err(); err != nil { | ||
return 0, &os.PathError{Op: "open", Path: path, Err: err} | ||
} | ||
defer localFree(ntPath.Buffer) | ||
defer windows.LocalFree(windows.Handle(ntPath.Buffer)) | ||
oa.ObjectName = &ntPath | ||
|
||
// The security descriptor is only needed for the first pipe. | ||
if first { | ||
if sd != nil { | ||
len := uint32(len(sd)) | ||
sdb := localAlloc(0, len) | ||
defer localFree(sdb) | ||
copy((*[0xffff]byte)(unsafe.Pointer(sdb))[:], sd) | ||
oa.SecurityDescriptor = (*securityDescriptor)(unsafe.Pointer(sdb)) | ||
oa.SecurityDescriptor = sd | ||
} else { | ||
// Construct the default named pipe security descriptor. | ||
var dacl uintptr | ||
if err := rtlDefaultNpAcl(&dacl).Err(); err != nil { | ||
dacl := &windows.ACL{} | ||
if err := windows.RtlDefaultNpAcl(&dacl); err != nil { | ||
return 0, fmt.Errorf("getting default named pipe ACL: %s", err) | ||
} | ||
defer localFree(dacl) | ||
|
||
sdb := &securityDescriptor{ | ||
Revision: 1, | ||
Control: cSE_DACL_PRESENT, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to set |
||
Dacl: dacl, | ||
sdb, err := windows.NewSecurityDescriptor() | ||
if err != nil { | ||
return 0, err | ||
} | ||
if err := sdb.SetDACL(dacl, true, true); err != nil { | ||
return 0, err | ||
} | ||
oa.SecurityDescriptor = sdb | ||
} | ||
|
@@ -440,14 +426,14 @@ type PipeConfig struct { | |
// The pipe must not already exist. | ||
func ListenPipe(path string, c *PipeConfig) (net.Listener, error) { | ||
var ( | ||
sd []byte | ||
sd *windows.SECURITY_DESCRIPTOR | ||
err error | ||
) | ||
if c == nil { | ||
c = &PipeConfig{} | ||
} | ||
if c.SecurityDescriptor != "" { | ||
sd, err = SddlToSecurityDescriptor(c.SecurityDescriptor) | ||
sd, err = windows.SecurityDescriptorFromString(c.SecurityDescriptor) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ import ( | |
|
||
//go:generate go run mksyscall_windows.go -output zvhd_windows.go vhd.go | ||
|
||
//sys createVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *uintptr, createVirtualDiskFlags uint32, providerSpecificFlags uint32, parameters *CreateVirtualDiskParameters, overlapped *syscall.Overlapped, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.CreateVirtualDisk | ||
//sys createVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, securityDescriptor *windows.SECURITY_DESCRIPTOR, createVirtualDiskFlags uint32, providerSpecificFlags uint32, parameters *CreateVirtualDiskParameters, overlapped *syscall.Overlapped, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.CreateVirtualDisk | ||
//sys openVirtualDisk(virtualStorageType *VirtualStorageType, path string, virtualDiskAccessMask uint32, openVirtualDiskFlags uint32, parameters *OpenVirtualDiskParameters, handle *syscall.Handle) (err error) [failretval != 0] = virtdisk.OpenVirtualDisk | ||
//sys attachVirtualDisk(handle syscall.Handle, securityDescriptor *uintptr, attachVirtualDiskFlag uint32, providerSpecificFlags uint32, parameters *AttachVirtualDiskParameters, overlapped *syscall.Overlapped) (err error) [failretval != 0] = virtdisk.AttachVirtualDisk | ||
//sys attachVirtualDisk(handle syscall.Handle, securityDescriptor *windows.SECURITY_DESCRIPTOR, attachVirtualDiskFlag uint32, providerSpecificFlags uint32, parameters *AttachVirtualDiskParameters, overlapped *syscall.Overlapped) (err error) [failretval != 0] = virtdisk.AttachVirtualDisk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TBBle The signature for these is changing in this PR anyways so let's make sure we get in the other /x/sys/windows'ify PR shortly after and we can cut a release. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I did a quick review previously, and the conflicts are textual-only. i.e. on this line I changed the type of So assuming this lands first, rebasing #197 should only take a few minutes, mostly compile-checking everything. |
||
//sys detachVirtualDisk(handle syscall.Handle, detachVirtualDiskFlags uint32, providerSpecificFlags uint32) (err error) [failretval != 0] = virtdisk.DetachVirtualDisk | ||
//sys getVirtualDiskPhysicalPath(handle syscall.Handle, diskPathSizeInBytes *uint32, buffer *uint16) (err error) [failretval != 0] = virtdisk.GetVirtualDiskPhysicalPath | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This idiom fails
-gcflags=all=-d=checkptr
as of Go 1.14. In this case, it's just being moved from elsewhere, so it's not an objection to this change, but a reminder that we need to do a pass over the code-base withcheckptr
(orrace
enabled, which includes it) with Go 1.15 or later, and fix occurrences of this.The fix itself is pretty simple, I did the same pass for hcsshim in microsoft/hcsshim#926, see
Uint16BufferToSlice
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! It just occurred to me now that there's no CI running in this repository (other than the
license/cla
check); should we add a basic github-action?