aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-26 19:18:13 +0200
committerJakob Unterwurzacher2016-06-26 19:18:13 +0200
commit23cc0657f43c21a4f249594a5dcc660b2d5fb77a (patch)
tree1c98faa5188adcbc05d2ff573842fbac295308f5
parent38767ab5278f6fe62dcf70fc151e8a56cfffcfe4 (diff)
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.
-rw-r--r--internal/fusefrontend/args.go3
-rw-r--r--internal/fusefrontend/fs.go7
-rw-r--r--main.go5
3 files changed, 14 insertions, 1 deletions
diff --git a/internal/fusefrontend/args.go b/internal/fusefrontend/args.go
index b3fa665..78b9b5b 100644
--- a/internal/fusefrontend/args.go
+++ b/internal/fusefrontend/args.go
@@ -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
}
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go
index 640c45d..9ae57fa 100644
--- a/internal/fusefrontend/fs.go
+++ b/internal/fusefrontend/fs.go
@@ -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)
}
diff --git a/main.go b/main.go
index b7ff97d..c87cc87 100644
--- a/main.go
+++ b/main.go
@@ -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))