]> git.proxmox.com Git - pve-cluster.git/blobdiff - data/src/pmxcfs.c
fix file permission check in chmod
[pve-cluster.git] / data / src / pmxcfs.c
index 26cbc30483062fbee2ef719d66a3a03b2bda88f2..8fa3bccad5bf65f095104d2d75654c2b5e576120 100644 (file)
@@ -186,6 +186,41 @@ ret:
        return ret;
 }
 
+static int cfs_fuse_chmod(const char *path, mode_t mode)
+{
+       int ret = -EPERM;
+
+       cfs_debug("enter cfs_fuse_chmod %s", path);
+
+       mode_t allowed_mode = (S_IRUSR | S_IWUSR);
+       if (!path_is_private(path))
+               allowed_mode |= (S_IRGRP);
+
+       // allow only setting our supported modes (0600 for priv, 0640 for rest)
+       // mode has additional bits set, which we ignore; see stat(2)
+       if ((mode & ALLPERMS) == allowed_mode)
+               ret = 0;
+
+       cfs_debug("leave cfs_fuse_chmod %s (%d) mode: %o", path, ret, (int)mode);
+
+       return ret;
+}
+
+static int cfs_fuse_chown(const char *path, uid_t user, gid_t group)
+{
+       int ret = -EPERM;
+
+       cfs_debug("enter cfs_fuse_chown %s", path);
+
+       // we get -1 if no change should be made
+       if ((user == 0 || user == -1) && (group == cfs.gid || group == -1))
+               ret = 0;
+
+       cfs_debug("leave cfs_fuse_chown %s (%d) (uid: %d; gid: %d)", path, ret, user, group);
+
+       return ret;
+}
+
 static int cfs_fuse_mkdir(const char *path, mode_t mode)
 {
        cfs_debug("enter cfs_fuse_mkdir %s", path);
@@ -295,7 +330,7 @@ static int cfs_fuse_read(const char *path, char *buf, size_t size, off_t offset,
 {
        (void) fi;
 
-       cfs_debug("enter cfs_fuse_read %s %lu %ld", path, size, offset);
+       cfs_debug("enter cfs_fuse_read %s %zu %jd", path, size, offset);
 
        int ret = -EACCES;
 
@@ -320,7 +355,7 @@ static int cfs_fuse_write(const char *path, const char *buf, size_t size,
 {
        (void) fi;
 
-       cfs_debug("enter cfs_fuse_write %s %lu %ld", path, size, offset);
+       cfs_debug("enter cfs_fuse_write %s %zu %jd", path, size, offset);
 
        int ret = -EACCES;
 
@@ -343,7 +378,7 @@ static int cfs_fuse_write(const char *path, const char *buf, size_t size,
 
 static int cfs_fuse_truncate(const char *path, off_t size)
 {
-       cfs_debug("enter cfs_fuse_truncate %s %ld", path, size);
+       cfs_debug("enter cfs_fuse_truncate %s %jd", path, size);
 
        int ret = -EACCES;
 
@@ -488,7 +523,9 @@ static struct fuse_operations fuse_ops = {
        .readlink = cfs_fuse_readlink,
        .utimens = cfs_fuse_utimens,
        .statfs = cfs_fuse_statfs,
-       .init = cfs_fuse_init
+       .init = cfs_fuse_init,
+       .chown = cfs_fuse_chown,
+       .chmod = cfs_fuse_chmod
 };
 
 static char *
@@ -800,9 +837,9 @@ int main(int argc, char *argv[])
                exit (-1);
        }
 
-       for (int i=0; i < sizeof(utsname.nodename); i++) {
-               if (utsname.nodename[i] =='.') utsname.nodename[i] = 0;
-       }
+       char *dot = strchr(utsname.nodename, '.');
+       if (dot)
+               *dot = 0;
 
        cfs.nodename = g_strdup(utsname.nodename);