return _setattr(in, &attr, CEPH_SETATTR_MODE, perms);
}
-int Client::chown(const char *relpath, int uid, int gid)
+int Client::chown(const char *relpath, uid_t new_uid, gid_t new_gid,
+ const UserPerm& perms)
{
Mutex::Locker lock(client_lock);
tout(cct) << "chown" << std::endl;
tout(cct) << relpath << std::endl;
- tout(cct) << uid << std::endl;
- tout(cct) << gid << std::endl;
+ tout(cct) << new_uid << std::endl;
+ tout(cct) << new_gid << std::endl;
filepath path(relpath);
InodeRef in;
- int r = path_walk(path, &in);
+ int r = path_walk(path, &in, perms);
if (r < 0)
return r;
struct stat attr;
- attr.st_uid = uid;
- attr.st_gid = gid;
+ attr.st_uid = new_uid;
+ attr.st_gid = new_gid;
int mask = 0;
- if (uid != -1) mask |= CEPH_SETATTR_UID;
- if (gid != -1) mask |= CEPH_SETATTR_GID;
- return _setattr(in, &attr, mask);
+ if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+ if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+ return _setattr(in, &attr, mask, perms);
}
-int Client::fchown(int fd, int uid, int gid)
+int Client::fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms)
{
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;
+ tout(cct) << new_uid << std::endl;
+ tout(cct) << new_gid << std::endl;
Fh *f = get_filehandle(fd);
if (!f)
return -EBADF;
return -EBADF;
#endif
struct stat attr;
- attr.st_uid = uid;
- attr.st_gid = gid;
+ attr.st_uid = new_uid;
+ attr.st_gid = new_gid;
int mask = 0;
- if (uid != -1) mask |= CEPH_SETATTR_UID;
- if (gid != -1) mask |= CEPH_SETATTR_GID;
- return _setattr(f->inode, &attr, mask);
+ if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+ if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+ return _setattr(f->inode, &attr, mask, perms);
}
-int Client::lchown(const char *relpath, int uid, int gid)
+int Client::lchown(const char *relpath, uid_t new_uid, gid_t new_gid,
+ const UserPerm& perms)
{
Mutex::Locker lock(client_lock);
tout(cct) << "lchown" << std::endl;
tout(cct) << relpath << std::endl;
- tout(cct) << uid << std::endl;
- tout(cct) << gid << std::endl;
+ tout(cct) << new_uid << std::endl;
+ tout(cct) << new_gid << std::endl;
filepath path(relpath);
InodeRef in;
// don't follow symlinks
- int r = path_walk(path, &in, false);
+ int r = path_walk(path, &in, perms, false);
if (r < 0)
return r;
struct stat attr;
- attr.st_uid = uid;
- attr.st_gid = gid;
+ attr.st_uid = new_uid;
+ attr.st_gid = new_gid;
int mask = 0;
- if (uid != -1) mask |= CEPH_SETATTR_UID;
- if (gid != -1) mask |= CEPH_SETATTR_GID;
- return _setattr(in, &attr, mask);
+ if (new_uid != static_cast<uid_t>(-1)) mask |= CEPH_SETATTR_UID;
+ if (new_gid != static_cast<gid_t>(-1)) mask |= CEPH_SETATTR_GID;
+ return _setattr(in, &attr, mask, perms);
}
int Client::utime(const char *relpath, struct utimbuf *buf)
int chmod(const char *path, mode_t mode, const UserPerm& perms);
int fchmod(int fd, mode_t mode, const UserPerm& perms);
int lchmod(const char *path, mode_t mode, const UserPerm& perms);
- 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 chown(const char *path, uid_t new_uid, gid_t new_gid,
+ const UserPerm& perms);
+ int fchown(int fd, uid_t new_uid, gid_t new_gid, const UserPerm& perms);
+ int lchown(const char *path, uid_t new_uid, gid_t new_gid,
+ const UserPerm& perms);
int utime(const char *path, struct utimbuf *buf);
int lutime(const char *path, struct utimbuf *buf);
int flock(int fd, int operation, uint64_t owner);
const char *a = t.get_string(buf, p);
int64_t b = t.get_int();
int64_t c = t.get_int();
- client->chown(a, b, c);
+ client->chown(a, b, c, perms);
} else if (strcmp(op, "utime") == 0) {
const char *a = t.get_string(buf, p);
int64_t b = t.get_int();
}
if (op == CEPH_MDS_OP_CHOWN) {
- if (contents.empty()) r = client->chown( cwd.c_str(), rand(), rand() );
+ if (contents.empty()) r = client->chown(cwd.c_str(), rand(), rand(), perms);
else
- r = client->chown( get_random_sub(), rand(), rand() );
+ r = client->chown(get_random_sub(), rand(), rand(), perms);
}
if (op == CEPH_MDS_OP_UTIME) {
*
*/
+ UserPerm process_perms = client->pick_my_perms();
+
if (base[0] != '-')
- client->mkdir(base, 0755, client->pick_my_perms());
+ client->mkdir(base, 0755, process_perms);
ifstream f(find);
assert(f.is_open());
}
client->close(fd);
- //client->chmod(f.c_str(), mode & 0777, perms);
- client->chown(f.c_str(), uid, gid);
+ //client->chmod(f.c_str(), mode & 0777, perms, process_perms);
+ client->chown(f.c_str(), uid, gid, process_perms);
struct utimbuf ut;
ut.modtime = mtime;
{
if (!cmount->is_mounted())
return -ENOTCONN;
- return cmount->get_client()->chown(path, uid, gid);
+ UserPerm perms = cmount->get_client()->pick_my_perms();
+ return cmount->get_client()->chown(path, uid, gid, perms);
}
extern "C" int ceph_fchown(struct ceph_mount_info *cmount, int fd,
int uid, int gid)
{
if (!cmount->is_mounted())
return -ENOTCONN;
- return cmount->get_client()->fchown(fd, uid, gid);
+ UserPerm perms = cmount->get_client()->pick_my_perms();
+ return cmount->get_client()->fchown(fd, uid, gid, perms);
}
extern "C" int ceph_lchown(struct ceph_mount_info *cmount, const char *path,
int uid, int gid)
{
if (!cmount->is_mounted())
return -ENOTCONN;
- return cmount->get_client()->lchown(path, uid, gid);
+ UserPerm perms = cmount->get_client()->pick_my_perms();
+ return cmount->get_client()->lchown(path, uid, gid, perms);
}