mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-03 23:57:38 -04:00
Merge pull request #21 from Microsoft/sjw/sddl-fix
Remove use of SDDL in tar headers
This commit is contained in:
+21
-11
@@ -1,6 +1,7 @@
|
|||||||
package backuptar
|
package backuptar
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -29,9 +30,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hdrFileAttributes = "fileattr"
|
hdrFileAttributes = "fileattr"
|
||||||
hdrSecurityDescriptor = "sd"
|
hdrSecurityDescriptor = "sd"
|
||||||
hdrMountPoint = "mountpoint"
|
hdrRawSecurityDescriptor = "rawsd"
|
||||||
|
hdrMountPoint = "mountpoint"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeZeroes(w io.Writer, count int64) error {
|
func writeZeroes(w io.Writer, count int64) error {
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user