From: Greg Farnum Date: Wed, 27 Jul 2016 22:26:07 +0000 (-0700) Subject: client: always pass a UserPerm to public setattr variants X-Git-Tag: v11.0.1~36^2~81 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d9a7f156ce015f01f3af1d64ba83613e8ceae21c;p=ceph.git client: always pass a UserPerm to public setattr variants We also recast our private _setattr() stuff to be implemented in terms of UserPerm instead of uid/gid, and translate the other direction. Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 28209010f259..3311311d3d7c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6560,11 +6560,9 @@ force_request: return res; } -int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid, - InodeRef *inp) +int Client::_setattr(Inode *in, struct stat *attr, int mask, + const UserPerm& perms, InodeRef *inp) { - // FIXME - UserPerm perms(uid, gid); int ret = _do_setattr(in, attr, mask, perms, inp); if (ret < 0) return ret; @@ -6573,21 +6571,23 @@ int Client::_setattr(Inode *in, struct stat *attr, int mask, int uid, int gid, return ret; } -int Client::_setattr(InodeRef &in, struct stat *attr, int mask) +int Client::_setattr(InodeRef &in, struct stat *attr, int mask, + const UserPerm& perms) { mask &= (CEPH_SETATTR_MODE | CEPH_SETATTR_UID | CEPH_SETATTR_GID | CEPH_SETATTR_MTIME | CEPH_SETATTR_ATIME | CEPH_SETATTR_SIZE | CEPH_SETATTR_CTIME); if (cct->_conf->client_permissions) { - int r = may_setattr(in.get(), attr, mask); + int r = may_setattr(in.get(), attr, mask, perms); if (r < 0) return r; } - return _setattr(in.get(), attr, mask); + return _setattr(in.get(), attr, mask, perms); } -int Client::setattr(const char *relpath, struct stat *attr, int mask) +int Client::setattr(const char *relpath, struct stat *attr, int mask, + const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "setattr" << std::endl; @@ -6596,13 +6596,14 @@ int Client::setattr(const char *relpath, struct stat *attr, int mask) filepath path(relpath); InodeRef in; - int r = path_walk(path, &in); + int r = path_walk(path, &in, perms); if (r < 0) return r; - return _setattr(in, attr, mask); + return _setattr(in, attr, mask, perms); } -int Client::fsetattr(int fd, struct stat *attr, int mask) +int Client::fsetattr(int fd, struct stat *attr, int mask, + const UserPerm& perms) { Mutex::Locker lock(client_lock); tout(cct) << "fsetattr" << std::endl; @@ -6616,7 +6617,7 @@ int Client::fsetattr(int fd, struct stat *attr, int mask) if (f->flags & O_PATH) return -EBADF; #endif - return _setattr(f->inode, attr, mask); + return _setattr(f->inode, attr, mask, perms); } int Client::stat(const char *relpath, struct stat *stbuf, @@ -8705,7 +8706,9 @@ int Client::truncate(const char *relpath, loff_t length) { struct stat attr; attr.st_size = length; - return setattr(relpath, &attr, CEPH_SETATTR_SIZE); + // FIXME + UserPerm perms(get_uid(), get_gid()); + return setattr(relpath, &attr, CEPH_SETATTR_SIZE, perms); } int Client::ftruncate(int fd, loff_t length) diff --git a/src/client/Client.h b/src/client/Client.h index c43ff714ed09..4db706f5e48f 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -798,12 +798,19 @@ private: const UserPerm& perms, InodeRef *inp = 0); int _do_setattr(Inode *in, struct stat *attr, int mask, const UserPerm& perms, InodeRef *inp); - int _setattr(Inode *in, struct stat *attr, int mask, int uid=-1, int gid=-1, InodeRef *inp = 0); int _setattr(Inode *in, struct stat *attr, int mask, const UserPerm& perms, + InodeRef *inp = 0); + int _setattr(Inode *in, struct stat *attr, int mask, int uid=-1, int gid=-1, InodeRef *inp = 0) { - return _setattr(in, attr, mask, perms.uid(), perms.gid(), inp); + UserPerm perms(uid, gid); + return _setattr(in, attr, mask, perms, inp); + } + int _setattr(InodeRef &in, struct stat *attr, int mask, + const UserPerm& perms); + int _setattr(InodeRef &in, struct stat *attr, int mask) { + UserPerm perms(get_uid(), get_gid()); + return _setattr(in, attr, mask, perms); } - int _setattr(InodeRef &in, struct stat *attr, int mask); int _getattr(Inode *in, int mask, int uid=-1, int gid=-1, bool force=false); int _getattr(InodeRef &in, int mask, int uid=-1, int gid=-1, bool force=false) { return _getattr(in.get(), mask, uid, gid, force); @@ -1063,8 +1070,8 @@ public: int lstat(const char *path, struct stat *stbuf, frag_info_t *dirstat=0, int mask=CEPH_STAT_CAP_INODE_ALL); int lstatlite(const char *path, struct statlite *buf); - int setattr(const char *relpath, struct stat *attr, int mask); - int fsetattr(int fd, struct stat *attr, int mask); + int setattr(const char *relpath, struct stat *attr, int mask, const UserPerm& perms); + int fsetattr(int fd, struct stat *attr, int mask, const UserPerm& perms); int chmod(const char *path, mode_t mode); int fchmod(int fd, mode_t mode); int lchmod(const char *path, mode_t mode); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index f72b6db3a3f8..c996e8db0aeb 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -628,7 +628,8 @@ extern "C" int ceph_setattr(struct ceph_mount_info *cmount, const char *relpath, { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->setattr(relpath, attr, mask); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->setattr(relpath, attr, mask, perms); } // *xattr() calls supporting samba/vfs