aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/winpipe/sd.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-23 14:53:44 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-23 15:16:02 +0200
commita74a29bc937cf75c1af4166e746df49ef53b2fc2 (patch)
tree1d9c3ad1ca48fa370fd25b3a86007ec70466be4e /ipc/winpipe/sd.go
parentsetupapi: trim "Get" from getters (diff)
downloadwireguard-go-a74a29bc937cf75c1af4166e746df49ef53b2fc2.tar.xz
wireguard-go-a74a29bc937cf75c1af4166e746df49ef53b2fc2.zip
ipc: use simplified fork of winio
Diffstat (limited to 'ipc/winpipe/sd.go')
-rw-r--r--ipc/winpipe/sd.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/ipc/winpipe/sd.go b/ipc/winpipe/sd.go
new file mode 100644
index 0000000..5f99a32
--- /dev/null
+++ b/ipc/winpipe/sd.go
@@ -0,0 +1,29 @@
+// +build windows
+
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2005 Microsoft
+ * Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package winpipe
+
+import (
+ "unsafe"
+)
+
+//sys convertStringSecurityDescriptorToSecurityDescriptor(str string, revision uint32, sd *uintptr, size *uint32) (err error) = advapi32.ConvertStringSecurityDescriptorToSecurityDescriptorW
+//sys localFree(mem uintptr) = LocalFree
+//sys getSecurityDescriptorLength(sd uintptr) (len uint32) = advapi32.GetSecurityDescriptorLength
+
+func SddlToSecurityDescriptor(sddl string) ([]byte, error) {
+ var sdBuffer uintptr
+ err := convertStringSecurityDescriptorToSecurityDescriptor(sddl, 1, &sdBuffer, nil)
+ if err != nil {
+ return nil, err
+ }
+ defer localFree(sdBuffer)
+ sd := make([]byte, getSecurityDescriptorLength(sdBuffer))
+ copy(sd, (*[0xffff]byte)(unsafe.Pointer(sdBuffer))[:len(sd)])
+ return sd, nil
+} \ No newline at end of file