]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Actually handle gid lists in UserPerm
authorGreg Farnum <gfarnum@redhat.com>
Wed, 3 Aug 2016 22:48:01 +0000 (15:48 -0700)
committerGreg Farnum <gfarnum@redhat.com>
Wed, 21 Sep 2016 23:33:56 +0000 (16:33 -0700)
Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/client/UserPerm.h

index de4513f1223f1953e264611fee0c85e150f884b0..45364c2f2b9ba041780ea54386f030356ce8e5c2 100644 (file)
@@ -20,14 +20,45 @@ struct UserPerm
 private:
   uid_t m_uid;
   gid_t m_gid;
+  int gid_count;
+  gid_t *gids;
+  bool alloced_gids;
 public:
-  UserPerm() : m_uid(-1), m_gid(-1) {}
-  UserPerm(int uid, int gid) : m_uid(uid), m_gid(gid) {}
-  // the readdir code relies on UserPerm copy-constructor being a deep copy!
+  UserPerm() : m_uid(-1), m_gid(-1), gid_count(0),
+              gids(NULL), alloced_gids(false) {}
+  UserPerm(int uid, int gid) : m_uid(uid), m_gid(gid), gid_count(0),
+                              gids(NULL), alloced_gids(false) {}
+  UserPerm(const UserPerm& o) {
+    m_uid = o.m_uid;
+    m_gid = o.m_gid;
+    gid_count = o.gid_count;
+    gids = new gid_t[gid_count];
+    alloced_gids = true;
+    for (int i = 0; i < gid_count; ++i) {
+      gids[i] = o.gids[i];
+    }
+  }
+  ~UserPerm() {
+    if (alloced_gids)
+      delete gids;
+  }
+  // FIXME: stop doing a deep-copy all the time. We need it on stuff
+  // that lasts longer than a single "syscall", but not for MetaRequests et al
   uid_t uid() const { return m_uid; }
   gid_t gid() const { return m_gid; }
-  bool gid_in_groups(gid_t gid) const { return gid == m_gid; }
-  int get_gids(const gid_t **gids) const { return 0; }
+  bool gid_in_groups(gid_t gid) const {
+    if (gid == m_gid) return true;
+    for (int i = 0; i < gid_count; ++i) {
+      if (gid == gids[i]) return true;
+    }
+    return false;
+  }
+  int get_gids(const gid_t **_gids) const { *_gids = gids; return gid_count; }
+  void init_gids(gid_t* _gids, int count) {
+    gids = _gids;
+    gid_count = count;
+  }
+  void take_gids() { alloced_gids = true; }
 };