Remove use of SDDL in tar headers

Switching to using straight binary instead of SDDL in tar headers to avoid failures in converting domain SIDs into/out of SDDL.

Fixes https://github.com/Microsoft/go-winio/issues/19
This commit is contained in:
Stefan J. Wernli
2016-05-11 17:05:17 -07:00
parent 3b8b3c98b2
commit 0ab2de7e65
+18 -8
View File
@@ -1,6 +1,7 @@
package backuptar package backuptar
import ( import (
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@@ -31,6 +32,7 @@ const (
const ( const (
hdrFileAttributes = "fileattr" hdrFileAttributes = "fileattr"
hdrSecurityDescriptor = "sd" hdrSecurityDescriptor = "sd"
hdrRawSecurityDescriptor = "rawsd"
hdrMountPoint = "mountpoint" hdrMountPoint = "mountpoint"
) )
@@ -108,7 +110,7 @@ func BasicInfoHeader(name string, size int64, fileInfo *winio.FileBasicInfo) *ta
// //
// MSWINDOWS.fileattr: The Win32 file attributes, as a decimal value // MSWINDOWS.fileattr: The Win32 file attributes, as a decimal value
// //
// MSWINDOWS.sd: The Win32 security descriptor, in SDDL (string) format // MSWINDOWS.rawsd: The Win32 security descriptor, in raw binary format
// //
// MSWINDOWS.mountpoint: If present, this is a mount point and not a symlink, even though the type is '2' (symlink) // MSWINDOWS.mountpoint: If present, this is a mount point and not a symlink, even though the type is '2' (symlink)
func WriteTarFileFromBackupStream(t *tar.Writer, r io.Reader, name string, size int64, fileInfo *winio.FileBasicInfo) error { func WriteTarFileFromBackupStream(t *tar.Writer, r io.Reader, name string, size int64, fileInfo *winio.FileBasicInfo) error {
@@ -133,11 +135,7 @@ func WriteTarFileFromBackupStream(t *tar.Writer, r io.Reader, name string, size
if err != nil { if err != nil {
return err return err
} }
sddl, err := winio.SecurityDescriptorToSddl(sd) hdr.Winheaders[hdrRawSecurityDescriptor] = base64.StdEncoding.EncodeToString(sd)
if err != nil {
return err
}
hdr.Winheaders[hdrSecurityDescriptor] = sddl
case winio.BackupReparseData: case winio.BackupReparseData:
hdr.Mode |= c_ISLNK hdr.Mode |= c_ISLNK
@@ -263,16 +261,28 @@ func FileInfoFromHeader(hdr *tar.Header) (name string, size int64, fileInfo *win
// tar file that was not processed, or io.EOF is there are no more. // tar file that was not processed, or io.EOF is there are no more.
func WriteBackupStreamFromTarFile(w io.Writer, t *tar.Reader, hdr *tar.Header) (*tar.Header, error) { func WriteBackupStreamFromTarFile(w io.Writer, t *tar.Reader, hdr *tar.Header) (*tar.Header, error) {
bw := winio.NewBackupStreamWriter(w) bw := winio.NewBackupStreamWriter(w)
var sd []byte
var err error
// Maintaining old SDDL-based behavior for backward compatibility. All new tar headers written
// by this library will have raw binary for the security descriptor.
if sddl, ok := hdr.Winheaders[hdrSecurityDescriptor]; ok { if sddl, ok := hdr.Winheaders[hdrSecurityDescriptor]; ok {
sd, err := winio.SddlToSecurityDescriptor(sddl) sd, err = winio.SddlToSecurityDescriptor(sddl)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
if sdraw, ok := hdr.Winheaders[hdrRawSecurityDescriptor]; ok {
sd, err = base64.StdEncoding.DecodeString(sdraw)
if err != nil {
return nil, err
}
}
if len(sd) != 0 {
bhdr := winio.BackupHeader{ bhdr := winio.BackupHeader{
Id: winio.BackupSecurity, Id: winio.BackupSecurity,
Size: int64(len(sd)), Size: int64(len(sd)),
} }
err = bw.WriteHeader(&bhdr) err := bw.WriteHeader(&bhdr)
if err != nil { if err != nil {
return nil, err return nil, err
} }