From ac9ed33a075e1464cfc954f0069f0a7fb97e54f6 Mon Sep 17 00:00:00 2001 From: Andras Elso Date: Wed, 27 Feb 2013 00:20:39 +0100 Subject: [PATCH] client: allow change file owner or group only Signed-off-by: Andras Elso --- src/client/Client.cc | 21 +++++++++++++++------ src/client/Client.h | 6 +++--- src/include/cephfs/libcephfs.h | 6 +++--- src/libcephfs.cc | 6 +++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 71bb5d92143fa..eee7fdd6c1fb5 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4435,7 +4435,7 @@ int Client::fchmod(int fd, mode_t mode) return _setattr(f->inode, &attr, CEPH_SETATTR_MODE); } -int Client::chown(const char *relpath, uid_t uid, gid_t gid) +int Client::chown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "chown" << std::endl; @@ -4450,10 +4450,13 @@ int Client::chown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } -int Client::fchown(int fd, uid_t uid, gid_t gid) +int Client::fchown(int fd, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "fchown" << std::endl; @@ -4466,10 +4469,13 @@ int Client::fchown(int fd, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(f->inode, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(f->inode, &attr, mask); } -int Client::lchown(const char *relpath, uid_t uid, gid_t gid) +int Client::lchown(const char *relpath, int uid, int gid) { Mutex::Locker lock(client_lock); tout(cct) << "lchown" << std::endl; @@ -4485,7 +4491,10 @@ int Client::lchown(const char *relpath, uid_t uid, gid_t gid) struct stat attr; attr.st_uid = uid; attr.st_gid = gid; - return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID); + int mask = 0; + if (uid != -1) mask |= CEPH_SETATTR_UID; + if (gid != -1) mask |= CEPH_SETATTR_GID; + return _setattr(in, &attr, mask); } int Client::utime(const char *relpath, struct utimbuf *buf) diff --git a/src/client/Client.h b/src/client/Client.h index 3fcdf481ad179..3ebf27fd0a9ad 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -622,9 +622,9 @@ public: int setattr(const char *relpath, struct stat *attr, int mask); int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); - int chown(const char *path, uid_t uid, gid_t gid); - int fchown(int fd, uid_t uid, gid_t gid); - int lchown(const char *path, uid_t uid, gid_t gid); + int chown(const char *path, int uid, int gid); + int fchown(int fd, int uid, int gid); + int lchown(const char *path, int uid, int gid); int utime(const char *path, struct utimbuf *buf); int truncate(const char *path, loff_t size); diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index adcdb39e6007a..abfd25cfd7e9d 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -530,7 +530,7 @@ int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_chown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change the ownership of a file from an open file descriptor. @@ -541,7 +541,7 @@ int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_ * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); +int ceph_fchown(struct ceph_mount_info *cmount, int fd, int uid, int gid); /** * Change the ownership of a file/directory, don't follow symlinks. @@ -552,7 +552,7 @@ int ceph_fchown(struct ceph_mount_info *cmount, int fd, uid_t uid, gid_t gid); * @param gid the group id to set on the file/directory. * @returns 0 on success or negative error code on failure. */ -int ceph_lchown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid); +int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int gid); /** * Change file/directory last access and modification times. diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 75937586cb074..d2fe0dac861b0 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -574,21 +574,21 @@ extern "C" int ceph_fchmod(struct ceph_mount_info *cmount, int fd, mode_t mode) return cmount->get_client()->fchmod(fd, mode); } extern "C" int ceph_chown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->chown(path, uid, gid); } extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; return cmount->get_client()->fchown(fd, uid, gid); } extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path, - uid_t uid, gid_t gid) + int uid, int gid) { if (!cmount->is_mounted()) return -ENOTCONN; -- 2.39.5