]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/MDSAuthCaps: move allows() into MDSCapSpec
authorSage Weil <sage@redhat.com>
Thu, 28 May 2015 04:52:27 +0000 (00:52 -0400)
committerSage Weil <sage@redhat.com>
Thu, 1 Oct 2015 13:39:29 +0000 (09:39 -0400)
Also, fix this so that 'any' implies that we can read or write.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mds/MDSAuthCaps.cc
src/mds/MDSAuthCaps.h

index 9aa65c5f43663a634d71e4b5c74a7179e9788ade..4f78db7ac0853788d677fdf2ac5855ce4c538801 100644 (file)
@@ -97,16 +97,13 @@ struct MDSCapParser : qi::grammar<Iterator, MDSAuthCaps()>
  * requested path + op.
  *
  */
-bool MDSAuthCaps::is_capable(const std::string &path, int uid, bool may_read, bool may_write) const
+bool MDSAuthCaps::is_capable(const std::string &path, int uid,
+                            bool may_read, bool may_write) const
 {
   for (std::vector<MDSCapGrant>::const_iterator i = grants.begin(); i != grants.end(); ++i) {
-    if (i->match.match(path, uid)) {
-      if ((may_read && !i->spec.read) ||
-          (may_write && !i->spec.write)) {
-        continue;
-      } else {
-        return true;
-      }
+    if (i->match.match(path, uid) &&
+       i->spec.allows(may_read, may_write)) {
+      return true;
     }
   }
 
index c243ef424caf44e326a203e68e45529c236ecb38..13cdc29e3583ea4804b393fe0b2b5b8346ea4607 100644 (file)
@@ -32,6 +32,15 @@ struct MDSCapSpec {
   bool allow_all() const {
     return any;
   }
+  bool allows(bool r, bool w) const {
+    if (any)
+      return true;
+    if (r && !read)
+      return false;
+    if (w && !write)
+      return false;
+    return true;
+  }
 };
 
 // conditions before we are allowed to do it