return _setattr(in, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID);
}
+int Client::fchown(int fd, uid_t uid, gid_t gid)
+{
+ Mutex::Locker lock(client_lock);
+ tout(cct) << "fchown" << std::endl;
+ tout(cct) << fd << std::endl;
+ tout(cct) << uid << std::endl;
+ tout(cct) << gid << std::endl;
+ assert(fd_map.count(fd));
+ Fh *f = fd_map[fd];
+ struct stat attr;
+ attr.st_uid = uid;
+ attr.st_gid = gid;
+ return _setattr(f->inode, &attr, CEPH_SETATTR_UID|CEPH_SETATTR_GID);
+}
+
int Client::lchown(const char *relpath, uid_t uid, gid_t gid)
{
Mutex::Locker lock(client_lock);
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 utime(const char *path, struct utimbuf *buf);
int truncate(const char *path, loff_t size);
*/
int ceph_chown(struct ceph_mount_info *cmount, const char *path, uid_t uid, gid_t gid);
+/**
+ * Change the ownership of a file from an open file descriptor.
+ *
+ * @param cmount the ceph mount handle to use for performing the chown.
+ * @param path the path of the file/directory to change the ownership of.
+ * @param uid the user id to set on the file/directory.
+ * @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);
+
/**
* Change the ownership of a file/directory, don't follow symlinks.
*
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)
+{
+ 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)
{
ceph_shutdown(cmount);
}
+TEST(LibCephFS, Fchown) {
+ struct ceph_mount_info *cmount;
+ ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+ ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+ ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+ char test_file[256];
+ sprintf(test_file, "test_fchown_%d", getpid());
+
+ int fd = ceph_open(cmount, test_file, O_CREAT|O_RDWR, 0666);
+ ASSERT_GT(fd, 0);
+
+ // set perms to readable and writeable only by owner
+ ASSERT_EQ(ceph_fchmod(cmount, fd, 0600), 0);
+
+ // change ownership to nobody -- we assume nobody exists and id is always 65534
+ ASSERT_EQ(ceph_fchown(cmount, fd, 65534, 65534), 0);
+
+ ceph_close(cmount, fd);
+
+ fd = ceph_open(cmount, test_file, O_RDWR, 0);
+ ASSERT_EQ(fd, -EACCES);
+ ceph_shutdown(cmount);
+}
+
TEST(LibCephFS, Symlinks) {
struct ceph_mount_info *cmount;
ASSERT_EQ(ceph_create(&cmount, NULL), 0);