]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add an inspection to the field of type when assigning user caps 6051/head
authorclever215 <wu.kongming@h3c.com>
Wed, 25 Nov 2015 16:31:48 +0000 (11:31 -0500)
committerclever215 <wu.kongming@h3c.com>
Wed, 25 Nov 2015 16:33:09 +0000 (11:33 -0500)
Bug #13096

This modification adds the check to the field of type of a user's capality while previous versions set it any value. i.e. we limit the option of types to the 9 certain values, which are "users|buckets|metadata|usage|zone|bilog|mdlog|datalog|ops These 9 choosens are found in ceph documents and in source codes.

Signed-off-by: Kongming Wu <wu.kongming@h3c.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index 132fd9e809f88f61fc0ffdefdb97c3fd8dee2b9b..7a82648fdd169e70197af32bb66c06c6c8487e48 100644 (file)
@@ -965,7 +965,7 @@ int RGWUserCaps::get_cap(const string& cap, string& type, uint32_t *pperm)
     trim_whitespace(cap.substr(0, pos), type);
   }
 
-  if (type.size() == 0)
+  if (!is_valid_cap_type(type))
     return -EINVAL;
 
   string cap_perm;
@@ -1125,6 +1125,26 @@ int RGWUserCaps::check_cap(const string& cap, uint32_t perm)
   return 0;
 }
 
+bool RGWUserCaps::is_valid_cap_type(const string& tp)
+{
+  static const char *cap_type[] = { "users",
+                                    "buckets",
+                                    "metadata",
+                                    "usage",
+                                    "zone",
+                                    "bilog",
+                                    "mdlog",
+                                    "datalog",
+                                    "opstate" };
+
+  for (unsigned int i = 0; i < sizeof(cap_type) / sizeof(char *); ++i) {
+    if (tp.compare(cap_type[i]) == 0) {
+      return true;
+    }
+  }
+
+  return false;
+}
 
 static struct rgw_name_to_flag op_type_mapping[] = { {"*",  RGW_OP_TYPE_ALL},
                   {"read",  RGW_OP_TYPE_READ},
index 8426057a61150dbd7a8fdbc164f2fc5216d71ddd..c41e4d64d404d323f00f6c73d65ab5fe4506f000 100644 (file)
@@ -431,6 +431,7 @@ public:
      DECODE_FINISH(bl);
   }
   int check_cap(const string& cap, uint32_t perm);
+  bool is_valid_cap_type(const string& tp);
   void dump(Formatter *f) const;
   void dump(Formatter *f, const char *name) const;