]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/MDSAuthCaps: add cct for debug context
authorSage Weil <sage@redhat.com>
Wed, 8 Jul 2015 19:47:00 +0000 (15:47 -0400)
committerSage Weil <sage@redhat.com>
Thu, 1 Oct 2015 13:39:30 +0000 (09:39 -0400)
signed-off-by: Nishtha Rai <nishtha3rai@gmail.com>
Signed-off-by: Sage Weil <sage@redhat.com>
src/mds/MDSAuthCaps.cc
src/mds/MDSAuthCaps.h
src/mds/MDSDaemon.cc
src/mds/SessionMap.h
src/test/mds/TestMDSAuthCaps.cc

index b5b3c09454eccd7f4ac1469c765eee3061630d52..3febc2cb408a73d332e7f98c7744f43497141b81 100644 (file)
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix.hpp>
 
+#include "common/debug.h"
 #include "MDSAuthCaps.h"
 
+#define dout_subsys ceph_subsys_mds
+
+#undef dout_prefix
+#define dout_prefix *_dout << "nish-debug "
+
 using std::ostream;
 using std::string;
 namespace qi = boost::spirit::qi;
@@ -157,7 +163,7 @@ void MDSAuthCaps::set_allow_all()
     grants.push_back(MDSCapGrant(MDSCapSpec(true, true, true), MDSCapMatch()));
 }
 
-bool MDSAuthCaps::parse(const std::string& str, ostream *err)
+bool MDSAuthCaps::parse(CephContext *c, const std::string& str, ostream *err)
 {
   // Special case for legacy caps
   if (str == "allow") {
@@ -171,6 +177,7 @@ bool MDSAuthCaps::parse(const std::string& str, ostream *err)
   std::string::const_iterator end = str.end();
 
   bool r = qi::phrase_parse(iter, end, g, ascii::space, *this);
+  cct = c;  // set after parser self-assignment
   if (r && iter == end) {
     return true;
   } else {
index 89337227c2912aca08f16c33165da8cc342c20e0..31941780d39532dac3c446ab0d850c856880ba7b 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <sstream>
 #include "include/types.h"
+#include "common/debug.h"
 
 // unix-style capabilities
 enum {
@@ -28,6 +29,8 @@ enum {
   MAY_EXECUTE = 4,
 };
 
+class CephContext;
+
 // what we can do
 struct MDSCapSpec {
   bool read, write, any;
@@ -88,14 +91,19 @@ struct MDSCapGrant {
 
 class MDSAuthCaps
 {
+  CephContext *cct;
   std::vector<MDSCapGrant> grants;
 
 public:
-  MDSAuthCaps() {}
-  MDSAuthCaps(const std::vector<MDSCapGrant> &grants_) : grants(grants_) {}
+  MDSAuthCaps(CephContext *cct_=NULL)
+    : cct(cct_) { }
+
+  // this ctor is used by spirit/phoenix; doesn't need cct.
+  MDSAuthCaps(const std::vector<MDSCapGrant> &grants_)
+    : cct(NULL), grants(grants_) { }
 
   void set_allow_all();
-  bool parse(const std::string &str, std::ostream *err);
+  bool parse(CephContext *cct, const std::string &str, std::ostream *err);
 
   bool allow_all() const;
   bool is_capable(const std::string &inode_path,
index 8fb0a76a36a1f033bb7dd209c810e44d69abffc3..4ac020169014544467f79be3bd84f4f1dca494e0 100644 (file)
@@ -1292,7 +1292,7 @@ bool MDSDaemon::ms_verify_authorizer(Connection *con, int peer_type,
 
       dout(10) << __func__ << ": parsing auth_cap_str='" << auth_cap_str << "'" << dendl;
       std::ostringstream errstr;
-      if (!s->auth_caps.parse(auth_cap_str, &errstr)) {
+      if (!s->auth_caps.parse(g_ceph_context, auth_cap_str, &errstr)) {
         dout(1) << __func__ << ": auth cap parse error: " << errstr.str()
           << " parsing '" << auth_cap_str << "'" << dendl;
       }
index cfcfa04a6fa802a9ded78f72f7ae97926c40b66c..a4fdb3d8c1fe16e6f2f98a1cf90dcc17e5ea4b96 100644 (file)
@@ -305,6 +305,7 @@ public:
   Session() : 
     state(STATE_CLOSED), state_seq(0), importing_count(0),
     recalled_at(), recall_count(0), recall_release_count(0),
+    auth_caps(g_ceph_context),
     connection(NULL), item_session_list(this),
     requests(0),  // member_offset passed to front() manually
     cap_push_seq(0),
index 3c644d7ebcb850390ecae6fb062271e36d9dde56..bf3a1aca7c8cda407ee0efb010162d1985ffb825 100644 (file)
@@ -42,7 +42,7 @@ TEST(MDSAuthCaps, ParseGood) {
     string str = parse_good[i];
     MDSAuthCaps cap;
     std::cout << "Testing good input: '" << str << "'" << std::endl;
-    ASSERT_TRUE(cap.parse(str, &cout));
+    ASSERT_TRUE(cap.parse(g_ceph_context, str, &cout));
   }
 }
 
@@ -81,7 +81,7 @@ TEST(MDSAuthCaps, ParseBad) {
     string str = parse_bad[i];
     MDSAuthCaps cap;
     std::cout << "Testing bad input: '" << str << "'" << std::endl;
-    ASSERT_FALSE(cap.parse(str, &cout));
+    ASSERT_FALSE(cap.parse(g_ceph_context, str, &cout));
   }
 }
 
@@ -89,26 +89,26 @@ TEST(MDSAuthCaps, AllowAll) {
   MDSAuthCaps cap;
   ASSERT_FALSE(cap.allow_all());
 
-  ASSERT_TRUE(cap.parse("allow r", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow r", NULL));
   ASSERT_FALSE(cap.allow_all());
   cap = MDSAuthCaps();
 
-  ASSERT_TRUE(cap.parse("allow rw", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow rw", NULL));
   ASSERT_FALSE(cap.allow_all());
   cap = MDSAuthCaps();
 
-  ASSERT_TRUE(cap.parse("allow", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow", NULL));
   ASSERT_FALSE(cap.allow_all());
   cap = MDSAuthCaps();
 
-  ASSERT_TRUE(cap.parse("allow *", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow *", NULL));
   ASSERT_TRUE(cap.allow_all());
   ASSERT_TRUE(cap.is_capable("/foo/bar", 0, 0, 0777, 0, MAY_READ | MAY_WRITE));
 }
 
 TEST(MDSAuthCaps, AllowUid) {
   MDSAuthCaps cap;
-  ASSERT_TRUE(cap.parse("allow * uid=10", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow * uid=10", NULL));
   ASSERT_FALSE(cap.allow_all());
   ASSERT_TRUE(cap.is_capable("/foo", 0, 0, 0777, 10, MAY_READ | MAY_WRITE));
   ASSERT_FALSE(cap.is_capable("/foo", 0, 0, 0777, -1, MAY_READ | MAY_WRITE));
@@ -117,7 +117,7 @@ TEST(MDSAuthCaps, AllowUid) {
 
 TEST(MDSAuthCaps, AllowPath) {
   MDSAuthCaps cap;
-  ASSERT_TRUE(cap.parse("allow * path=/sandbox", NULL));
+  ASSERT_TRUE(cap.parse(g_ceph_context, "allow * path=/sandbox", NULL));
   ASSERT_FALSE(cap.allow_all());
   ASSERT_TRUE(cap.is_capable("/sandbox/foo", 0, 0, 0777, 0, MAY_READ | MAY_WRITE));
   ASSERT_TRUE(cap.is_capable("/sandbox", 0, 0, 0777, 0, MAY_READ | MAY_WRITE));
@@ -158,7 +158,7 @@ TEST(MDSAuthCaps, OutputParsed) {
   for (size_t i = 0; i < num_tests; ++i) {
     MDSAuthCaps cap;
     std::cout << "Testing input '" << test_values[i].input << "'" << std::endl;
-    ASSERT_TRUE(cap.parse(test_values[i].input, &cout));
+    ASSERT_TRUE(cap.parse(g_ceph_context, test_values[i].input, &cout));
     ASSERT_EQ(test_values[i].output, stringify(cap));
   }
 }