fusefronted: preserve owner if running as root

If allow_other is set and we run as root, try to give newly created files to
the right user.
This commit is contained in:
Jakob Unterwurzacher 2016-06-26 19:18:13 +02:00
parent 38767ab527
commit 23cc0657f4
3 changed files with 14 additions and 1 deletions

View File

@ -7,4 +7,7 @@ type Args struct {
OpenSSL bool
PlaintextNames bool
LongNames bool
// Should we chown a file after it has been created?
// This only makes sense if (1) allow_other is set and (2) we run as root.
PreserveOwner bool
}

View File

@ -145,7 +145,12 @@ func (fs *FS) Create(path string, flags uint32, mode uint32, context *fuse.Conte
return nil, fuse.ToStatus(err)
}
}
if fs.args.PreserveOwner {
err = fd.Chown(int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
tlog.Warn.Printf("PreserveOwner: Chown failed: %v", err)
}
}
return NewFile(fd, writeOnly, fs.contentEnc)
}

View File

@ -374,6 +374,11 @@ func initFuseFrontend(key []byte, args argContainer, confFile *configfile.ConfFi
// Settings from the config file override command line args
frontendArgs.PlaintextNames = confFile.IsFeatureFlagSet(configfile.FlagPlaintextNames)
}
// If allow_other is set and we run as root, try to give newly created files to
// the right user.
if args.allow_other && os.Getuid() == 0 {
frontendArgs.PreserveOwner = true
}
jsonBytes, _ := json.MarshalIndent(frontendArgs, "", "\t")
tlog.Debug.Printf("frontendArgs: %s", string(jsonBytes))