From: Greg Farnum Date: Wed, 27 Jul 2016 21:31:56 +0000 (-0700) Subject: client: always pass a UserPerm to getxattr variants X-Git-Tag: v11.0.1~36^2~85 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=16cc0e6814aad28ebcb8a728485ddad115bab46e;p=ceph.git client: always pass a UserPerm to getxattr variants Signed-off-by: Greg Farnum --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 8ac2a98ef541..73db672830c7 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9740,33 +9740,36 @@ int Client::ll_setattr(Inode *in, struct stat *attr, int mask, // ---------- // xattrs -int Client::getxattr(const char *path, const char *name, void *value, size_t size) +int Client::getxattr(const char *path, const char *name, void *value, size_t size, + const UserPerm& perms) { Mutex::Locker lock(client_lock); InodeRef in; - int r = Client::path_walk(path, &in, true); + int r = Client::path_walk(path, &in, perms, true); if (r < 0) return r; - return _getxattr(in, name, value, size); + return _getxattr(in, name, value, size, perms); } -int Client::lgetxattr(const char *path, const char *name, void *value, size_t size) +int Client::lgetxattr(const char *path, const char *name, void *value, size_t size, + const UserPerm& perms) { Mutex::Locker lock(client_lock); InodeRef in; - int r = Client::path_walk(path, &in, false); + int r = Client::path_walk(path, &in, perms, false); if (r < 0) return r; - return _getxattr(in, name, value, size); + return _getxattr(in, name, value, size, perms); } -int Client::fgetxattr(int fd, const char *name, void *value, size_t size) +int Client::fgetxattr(int fd, const char *name, void *value, size_t size, + const UserPerm& perms) { Mutex::Locker lock(client_lock); Fh *f = get_filehandle(fd); if (!f) return -EBADF; - return _getxattr(f->inode, name, value, size); + return _getxattr(f->inode, name, value, size, perms); } int Client::listxattr(const char *path, char *list, size_t size) @@ -9857,7 +9860,7 @@ int Client::fsetxattr(int fd, const char *name, const void *value, size_t size, } int Client::_getxattr(Inode *in, const char *name, void *value, size_t size, - int uid, int gid) + const UserPerm& perms) { int r; @@ -9885,11 +9888,11 @@ int Client::_getxattr(Inode *in, const char *name, void *value, size_t size, goto out; } - r = _getattr(in, CEPH_STAT_CAP_XATTR, uid, gid, in->xattr_version == 0); + r = _getattr(in, CEPH_STAT_CAP_XATTR, perms, in->xattr_version == 0); if (r == 0) { string n(name); r = -ENODATA; - if (in->xattrs.count(n)) { + if (in->xattrs.count(n)) { r = in->xattrs[n].length(); if (r > 0 && size != 0) { if (size >= (unsigned)r) @@ -9904,14 +9907,14 @@ int Client::_getxattr(Inode *in, const char *name, void *value, size_t size, return r; } -int Client::_getxattr(InodeRef &in, const char *name, void *value, size_t size) +int Client::_getxattr(InodeRef &in, const char *name, void *value, size_t size, + const UserPerm& perms) { if (cct->_conf->client_permissions) { int r = xattr_permission(in.get(), name, MAY_READ); if (r < 0) return r; } - UserPerm perms(0, 0); // FIXME return _getxattr(in.get(), name, value, size, perms); } diff --git a/src/client/Client.h b/src/client/Client.h index 79c403dd452f..78a228775f77 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -815,12 +815,9 @@ private: } int _readlink(Inode *in, char *buf, size_t size); int _getxattr(Inode *in, const char *name, void *value, size_t len, - int uid=-1, int gid=-1); - int _getxattr(InodeRef &in, const char *name, void *value, size_t len); - int _getxattr(Inode *in, const char *name, void *value, size_t len, - const UserPerm& perms) { - return _getxattr(in, name, value, len, perms.uid(), perms.gid()); - } + const UserPerm& perms); + int _getxattr(InodeRef &in, const char *name, void *value, size_t len, + const UserPerm& perms); int _listxattr(Inode *in, char *names, size_t len, int uid=-1, int gid=-1); int _listxattr(Inode *in, char *names, size_t len, const UserPerm& perms) { return _listxattr(in, names, len, perms.uid(), perms.gid()); @@ -1107,9 +1104,12 @@ public: int fallocate(int fd, int mode, loff_t offset, loff_t length); // full path xattr ops - int getxattr(const char *path, const char *name, void *value, size_t size); - int lgetxattr(const char *path, const char *name, void *value, size_t size); - int fgetxattr(int fd, const char *name, void *value, size_t size); + int getxattr(const char *path, const char *name, void *value, size_t size, + const UserPerm& perms); + int lgetxattr(const char *path, const char *name, void *value, size_t size, + const UserPerm& perms); + int fgetxattr(int fd, const char *name, void *value, size_t size, + const UserPerm& perms); int listxattr(const char *path, char *list, size_t size); int llistxattr(const char *path, char *list, size_t size); int flistxattr(int fd, char *list, size_t size); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index eb1a8811d3e3..fc3dfcaaed34 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -636,21 +636,25 @@ extern "C" int ceph_getxattr(struct ceph_mount_info *cmount, const char *path, c { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->getxattr(path, name, value, size); + + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->getxattr(path, name, value, size, perms); } extern "C" int ceph_lgetxattr(struct ceph_mount_info *cmount, const char *path, const char *name, void *value, size_t size) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->lgetxattr(path, name, value, size); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->lgetxattr(path, name, value, size, perms); } extern "C" int ceph_fgetxattr(struct ceph_mount_info *cmount, int fd, const char *name, void *value, size_t size) { if (!cmount->is_mounted()) return -ENOTCONN; - return cmount->get_client()->fgetxattr(fd, name, value, size); + UserPerm perms = cmount->get_client()->pick_my_perms(); + return cmount->get_client()->fgetxattr(fd, name, value, size, perms); }