]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: get caller's uid/gid on every libcephfs operation 11526/head
authorYan, Zheng <zyan@redhat.com>
Tue, 18 Oct 2016 09:44:31 +0000 (17:44 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 18 Oct 2016 09:44:31 +0000 (17:44 +0800)
Fixes: http://tracker.ceph.com/issues/17591
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/client/Client.h
src/client/UserPerm.h

index 91863ff4932004b3f4d715a1afc5bb3f6a08e038..d544e927558f25218dd75742d412473aecba7199 100644 (file)
@@ -292,14 +292,14 @@ public:
   void tick();
 
   UserPerm pick_my_perms() {
-    uid_t uid = user_id >= 0 ? user_id : ::geteuid();
-    gid_t gid = group_id >= 0 ? group_id : ::getegid();
+    uid_t uid = user_id >= 0 ? user_id : -1;
+    gid_t gid = group_id >= 0 ? group_id : -1;
     return UserPerm(uid, gid);
   }
 
   static UserPerm pick_my_perms(CephContext *c) {
-    uid_t uid = c->_conf->client_mount_uid >= 0 ? c->_conf->client_mount_uid : ::geteuid();
-    gid_t gid = c->_conf->client_mount_gid >= 0 ? c->_conf->client_mount_gid : ::getegid();
+    uid_t uid = c->_conf->client_mount_uid >= 0 ? c->_conf->client_mount_uid : -1;
+    gid_t gid = c->_conf->client_mount_gid >= 0 ? c->_conf->client_mount_gid : -1;
     return UserPerm(uid, gid);
   }
 protected:
index 71775b00334e8c6514e5efc55060d3f6ad4dcfc0..9ce510412077ddb28b8829c7fd6bfccdd03b157a 100644 (file)
@@ -65,8 +65,8 @@ public:
     return *this;
   }
 
-  uid_t uid() const { return m_uid; }
-  gid_t gid() const { return m_gid; }
+  uid_t uid() const { return m_uid != (uid_t)-1 ? m_uid : ::geteuid(); }
+  gid_t gid() const { return m_gid != (gid_t)-1 ? m_gid : ::getegid(); }
   bool gid_in_groups(gid_t gid) const {
     if (gid == m_gid) return true;
     for (int i = 0; i < gid_count; ++i) {