mirror of
https://github.com/octoleo/restic.git
synced 2024-11-16 10:05:25 +00:00
Merge pull request #375 from restic/fix-suid
Backup and restore setuid/setgid/sticky bits
This commit is contained in:
commit
3abff7928c
3
node.go
3
node.go
@ -67,10 +67,11 @@ func (node Node) Tree() *Tree {
|
|||||||
|
|
||||||
// NodeFromFileInfo returns a new node from the given path and FileInfo.
|
// NodeFromFileInfo returns a new node from the given path and FileInfo.
|
||||||
func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
|
func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
|
||||||
|
mask := os.ModePerm | os.ModeType | os.ModeSetuid | os.ModeSetgid | os.ModeSticky
|
||||||
node := &Node{
|
node := &Node{
|
||||||
path: path,
|
path: path,
|
||||||
Name: fi.Name(),
|
Name: fi.Name(),
|
||||||
Mode: fi.Mode() & (os.ModePerm | os.ModeType),
|
Mode: fi.Mode() & mask,
|
||||||
ModTime: fi.ModTime(),
|
ModTime: fi.ModTime(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
node_test.go
39
node_test.go
@ -83,13 +83,46 @@ var nodeTests = []restic.Node{
|
|||||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
},
|
},
|
||||||
|
restic.Node{
|
||||||
|
Name: "testSuidFile",
|
||||||
|
Type: "file",
|
||||||
|
Content: []backend.ID{},
|
||||||
|
UID: uint32(os.Getuid()),
|
||||||
|
GID: uint32(os.Getgid()),
|
||||||
|
Mode: 0755 | os.ModeSetuid,
|
||||||
|
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||||
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
|
},
|
||||||
|
restic.Node{
|
||||||
|
Name: "testSuidFile2",
|
||||||
|
Type: "file",
|
||||||
|
Content: []backend.ID{},
|
||||||
|
UID: uint32(os.Getuid()),
|
||||||
|
GID: uint32(os.Getgid()),
|
||||||
|
Mode: 0755 | os.ModeSetgid,
|
||||||
|
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||||
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
|
},
|
||||||
|
restic.Node{
|
||||||
|
Name: "testSticky",
|
||||||
|
Type: "file",
|
||||||
|
Content: []backend.ID{},
|
||||||
|
UID: uint32(os.Getuid()),
|
||||||
|
GID: uint32(os.Getgid()),
|
||||||
|
Mode: 0755 | os.ModeSticky,
|
||||||
|
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||||
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
|
},
|
||||||
restic.Node{
|
restic.Node{
|
||||||
Name: "testDir",
|
Name: "testDir",
|
||||||
Type: "dir",
|
Type: "dir",
|
||||||
Subtree: nil,
|
Subtree: nil,
|
||||||
UID: uint32(os.Getuid()),
|
UID: uint32(os.Getuid()),
|
||||||
GID: uint32(os.Getgid()),
|
GID: uint32(os.Getgid()),
|
||||||
Mode: 020000000750,
|
Mode: 0750 | os.ModeDir,
|
||||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
@ -100,7 +133,7 @@ var nodeTests = []restic.Node{
|
|||||||
LinkTarget: "invalid",
|
LinkTarget: "invalid",
|
||||||
UID: uint32(os.Getuid()),
|
UID: uint32(os.Getuid()),
|
||||||
GID: uint32(os.Getgid()),
|
GID: uint32(os.Getgid()),
|
||||||
Mode: 01000000777,
|
Mode: 0777 | os.ModeSymlink,
|
||||||
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
ModTime: parseTime("2015-05-14 21:07:23.111"),
|
||||||
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
AccessTime: parseTime("2015-05-14 21:07:24.222"),
|
||||||
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
ChangeTime: parseTime("2015-05-14 21:07:25.333"),
|
||||||
@ -150,7 +183,7 @@ func TestNodeRestoreAt(t *testing.T) {
|
|||||||
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
"%v: GID doesn't match (%v != %v)", test.Type, test.GID, n2.GID)
|
||||||
if test.Type != "symlink" {
|
if test.Type != "symlink" {
|
||||||
Assert(t, test.Mode == n2.Mode,
|
Assert(t, test.Mode == n2.Mode,
|
||||||
"%v: mode doesn't match (%v != %v)", test.Type, test.Mode, n2.Mode)
|
"%v: mode doesn't match (0%o != 0%o)", test.Type, test.Mode, n2.Mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ func (env *TravisEnvironment) Prepare() {
|
|||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
// install the libraries necessary for fuse
|
// install the libraries necessary for fuse
|
||||||
|
run("brew", "update")
|
||||||
run("brew", "install", "caskroom/cask/brew-cask")
|
run("brew", "install", "caskroom/cask/brew-cask")
|
||||||
run("brew", "cask", "install", "osxfuse")
|
run("brew", "cask", "install", "osxfuse")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user