Skip to content

Commit 0a74186

Browse files
author
Kathryn Baldauf
committed
Update to use upstream sddl/SecurityAttribute but retain old exported functions
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
1 parent 3fe6c52 commit 0a74186

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

backuptar/tar.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import (
1313
"strings"
1414
"syscall"
1515
"time"
16+
"unsafe"
1617

1718
"github.com/Microsoft/go-winio"
1819
"github.com/Microsoft/go-winio/archive/tar" // until archive/tar supports pax extensions in its interface
20+
"golang.org/x/sys/windows"
1921
)
2022

2123
const (
@@ -317,32 +319,34 @@ func FileInfoFromHeader(hdr *tar.Header) (name string, size int64, fileInfo *win
317319
// tar file that was not processed, or io.EOF is there are no more.
318320
func WriteBackupStreamFromTarFile(w io.Writer, t *tar.Reader, hdr *tar.Header) (*tar.Header, error) {
319321
bw := winio.NewBackupStreamWriter(w)
320-
var sd []byte
322+
var sd *windows.SECURITY_DESCRIPTOR
321323
var err error
322324
// Maintaining old SDDL-based behavior for backward compatibility. All new tar headers written
323325
// by this library will have raw binary for the security descriptor.
324326
if sddl, ok := hdr.Winheaders[hdrSecurityDescriptor]; ok {
325-
sd, err = winio.SddlToSecurityDescriptor(sddl)
327+
sd, err = windows.SecurityDescriptorFromString(sddl)
326328
if err != nil {
327329
return nil, err
328330
}
329331
}
330332
if sdraw, ok := hdr.Winheaders[hdrRawSecurityDescriptor]; ok {
331-
sd, err = base64.StdEncoding.DecodeString(sdraw)
333+
sdbytes, err := base64.StdEncoding.DecodeString(sdraw)
334+
sd = (*windows.SECURITY_DESCRIPTOR)(unsafe.Pointer(&sdbytes[0]))
332335
if err != nil {
333336
return nil, err
334337
}
335338
}
336-
if len(sd) != 0 {
339+
sdLen := sd.Length()
340+
if sdLen != 0 {
337341
bhdr := winio.BackupHeader{
338342
Id: winio.BackupSecurity,
339-
Size: int64(len(sd)),
343+
Size: int64(sdLen),
340344
}
341345
err := bw.WriteHeader(&bhdr)
342346
if err != nil {
343347
return nil, err
344348
}
345-
_, err = bw.Write(sd)
349+
_, err = bw.Write((*[0xffff]byte)(unsafe.Pointer(sd))[:sdLen])
346350
if err != nil {
347351
return nil, err
348352
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.12
55
require (
66
github.com/pkg/errors v0.8.1
77
github.com/sirupsen/logrus v1.4.1
8-
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3
8+
golang.org/x/sys v0.0.0-20200523222454-059865788121
99
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qd
1616
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1717
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3 h1:7TYNF4UdlohbFwpNH04CoPMp1cHUZgO1Ebq5r2hIjfo=
1818
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
20+
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

pipe.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"syscall"
1414
"time"
1515
"unsafe"
16+
17+
"golang.org/x/sys/windows"
1618
)
1719

1820
//sys connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) = ConnectNamedPipe
@@ -273,7 +275,7 @@ type win32PipeListener struct {
273275
doneCh chan int
274276
}
275277

276-
func makeServerPipeHandle(path string, sd []byte, c *PipeConfig, first bool) (syscall.Handle, error) {
278+
func makeServerPipeHandle(path string, sd *windows.SECURITY_DESCRIPTOR, c *PipeConfig, first bool) (syscall.Handle, error) {
277279
path16, err := syscall.UTF16FromString(path)
278280
if err != nil {
279281
return 0, &os.PathError{Op: "open", Path: path, Err: err}
@@ -286,24 +288,24 @@ func makeServerPipeHandle(path string, sd []byte, c *PipeConfig, first bool) (sy
286288
if err := rtlDosPathNameToNtPathName(&path16[0], &ntPath, 0, 0).Err(); err != nil {
287289
return 0, &os.PathError{Op: "open", Path: path, Err: err}
288290
}
289-
defer localFree(ntPath.Buffer)
291+
defer windows.LocalFree(windows.Handle(ntPath.Buffer))
290292
oa.ObjectName = &ntPath
291293

292294
// The security descriptor is only needed for the first pipe.
293295
if first {
294296
if sd != nil {
295-
len := uint32(len(sd))
297+
len := sd.Length()
296298
sdb := localAlloc(0, len)
297-
defer localFree(sdb)
298-
copy((*[0xffff]byte)(unsafe.Pointer(sdb))[:], sd)
299+
defer windows.LocalFree(windows.Handle(sdb))
300+
copy((*[0xffff]byte)(unsafe.Pointer(sdb))[:len], (*[0xffff]byte)(unsafe.Pointer(sd))[:len])
299301
oa.SecurityDescriptor = (*securityDescriptor)(unsafe.Pointer(sdb))
300302
} else {
301303
// Construct the default named pipe security descriptor.
302304
var dacl uintptr
303305
if err := rtlDefaultNpAcl(&dacl).Err(); err != nil {
304306
return 0, fmt.Errorf("getting default named pipe ACL: %s", err)
305307
}
306-
defer localFree(dacl)
308+
defer windows.LocalFree(windows.Handle(dacl))
307309

308310
sdb := &securityDescriptor{
309311
Revision: 1,
@@ -440,14 +442,14 @@ type PipeConfig struct {
440442
// The pipe must not already exist.
441443
func ListenPipe(path string, c *PipeConfig) (net.Listener, error) {
442444
var (
443-
sd []byte
445+
sd *windows.SECURITY_DESCRIPTOR
444446
err error
445447
)
446448
if c == nil {
447449
c = &PipeConfig{}
448450
}
449451
if c.SecurityDescriptor != "" {
450-
sd, err = SddlToSecurityDescriptor(c.SecurityDescriptor)
452+
sd, err = windows.SecurityDescriptorFromString(c.SecurityDescriptor)
451453
if err != nil {
452454
return nil, err
453455
}

0 commit comments

Comments
 (0)