fusefronted: preserve owner for device nodes and sockets
https://github.com/rfjakob/gocryptfs/issues/64
This commit is contained in:
parent
a66440c668
commit
e3c5e3f1c8
|
@ -195,36 +195,43 @@ func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context)
|
||||||
if fs.isFiltered(path) {
|
if fs.isFiltered(path) {
|
||||||
return fuse.EPERM
|
return fuse.EPERM
|
||||||
}
|
}
|
||||||
cPath, err := fs.encryptPath(path)
|
cPath, err := fs.getBackingPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
// Create ".name" file to store long file name
|
||||||
// Handle long file name
|
|
||||||
cName := filepath.Base(cPath)
|
cName := filepath.Base(cPath)
|
||||||
if nametransform.IsLongContent(cName) {
|
if nametransform.IsLongContent(cName) {
|
||||||
dirfd, err := os.Open(filepath.Dir(cPath))
|
var dirfd *os.File
|
||||||
|
dirfd, err = os.Open(filepath.Dir(cPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
defer dirfd.Close()
|
defer dirfd.Close()
|
||||||
|
|
||||||
// Create ".name"
|
|
||||||
err = fs.nameTransform.WriteLongName(dirfd, cName, path)
|
err = fs.nameTransform.WriteLongName(dirfd, cName, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
// Create "gocryptfs.longfile." device node
|
||||||
// Create device node
|
err = syscallcompat.Mknodat(int(dirfd.Fd()), cName, mode, int(dev))
|
||||||
err = syscallcompat.Mknodat(int(dirfd.Fd()), cName, uint32(mode), int(dev))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nametransform.DeleteLongName(dirfd, cName)
|
nametransform.DeleteLongName(dirfd, cName)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Create regular device node
|
||||||
|
err = syscall.Mknod(cPath, mode, int(dev))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
// Set owner
|
||||||
return fs.FileSystem.Mknod(cPath, mode, dev, context)
|
if fs.args.PreserveOwner {
|
||||||
|
err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
|
||||||
|
if err != nil {
|
||||||
|
tlog.Warn.Printf("Mknod: Lchown failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fuse.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truncate implements pathfs.Filesystem.
|
// Truncate implements pathfs.Filesystem.
|
||||||
|
|
|
@ -57,7 +57,8 @@ func NameType(cName string) int {
|
||||||
return LongNameContent
|
return LongNameContent
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLongContent returns true if "cName" is the content store of a long name file.
|
// IsLongContent returns true if "cName" is the content store of a long name
|
||||||
|
// file (looks like "gocryptfs.longname.[sha256]").
|
||||||
func IsLongContent(cName string) bool {
|
func IsLongContent(cName string) bool {
|
||||||
return NameType(cName) == LongNameContent
|
return NameType(cName) == LongNameContent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue