]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: KeyRing, RotatingKeyRing: deglobalize
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 15 Jun 2011 18:34:55 +0000 (11:34 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 20 Jun 2011 23:35:18 +0000 (16:35 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/auth/KeyRing.cc
src/auth/KeyRing.h
src/auth/RotatingKeyRing.cc
src/auth/RotatingKeyRing.h
src/cauthtool.cc
src/mon/AuthMonitor.cc
src/mon/MonClient.cc

index 5f21a1d3e3a6027ae7d2e4a2f144f79c15b97e87..71caef42743a4f473349a4401a2280369551001d 100644 (file)
@@ -33,23 +33,24 @@ using std::auto_ptr;
 using namespace std;
 
 KeyRing *KeyRing::
-from_ceph_conf(const md_config_t *conf)
+from_ceph_context(CephContext *cct)
 {
+  const md_config_t *conf = cct->_conf;
   bool found_key = false;
   auto_ptr < KeyRing > keyring(new KeyRing());
 
   if (!is_supported_auth(CEPH_AUTH_CEPHX)) {
-    dout(2) << "KeyRing::from_ceph_conf: CephX auth is not supported." << dendl;
+    ldout(cct, 2) << "KeyRing::from_ceph_context: CephX auth is not supported." << dendl;
     return keyring.release();
   }
 
   int ret = 0;
   string filename;
   if (ceph_resolve_file_search(conf->keyring, filename)) {
-    ret = keyring->load(filename);
+    ret = keyring->load(cct, filename);
     if (ret) {
-      derr << "KeyRing::from_ceph_conf: failed to load " << filename
-          << ": error " << ret << dendl;
+      lderr(cct) << "KeyRing::from_ceph_context: failed to load " << filename
+                << ": error " << ret << dendl;
     }
     else {
       found_key = true;
@@ -70,8 +71,8 @@ from_ceph_conf(const md_config_t *conf)
       int res = fread(buf, 1, sizeof(buf) - 1, fp);
       if (res < 0) {
        res = ferror(fp);
-       derr << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
-            << "'" << dendl;
+       lderr(cct) << "KeyRing::from_ceph_conf: failed to read '" << conf->keyfile
+                  << "'" << dendl;
       }
       else {
        string k = buf;
@@ -143,8 +144,7 @@ void KeyRing::decode_plaintext(bufferlist::iterator& bli)
   ConfFile cf;
   std::deque<std::string> parse_errors;
   if (cf.parse_bufferlist(&bl, &parse_errors) != 0) {
-    derr << "cannot parse buffer" << dendl;
-    throw buffer::error();
+    throw buffer::malformed_input("cannot parse buffer");
   }
 
   for (ConfFile::const_section_iter_t s = cf.sections_begin();
@@ -156,8 +156,9 @@ void KeyRing::decode_plaintext(bufferlist::iterator& bli)
     EntityName ename;
     map<string, bufferlist> caps;
     if (!ename.from_str(name)) {
-      derr << "bad entity name: " << name << dendl;
-      throw buffer::error();
+      ostringstream oss;
+      oss << "bad entity name: " << name;
+      throw buffer::malformed_input(oss.str().c_str());
     }
 
     for (ConfSection::const_line_iter_t l = s->second.lines.begin();
@@ -168,9 +169,10 @@ void KeyRing::decode_plaintext(bufferlist::iterator& bli)
       std::replace(k.begin(), k.end(), '_', ' ');
       ret = set_modifier(k.c_str(), l->val.c_str(), ename, caps);
       if (ret < 0) {
-        derr << "error setting modifier for [" << name << "] type=" << k
-            << " val=" << l->val << dendl;
-       throw buffer::error();
+       ostringstream oss;
+       oss << "error setting modifier for [" << name << "] type=" << k
+           << " val=" << l->val;
+       throw buffer::malformed_input(oss.str().c_str());
       }
     }
   }
@@ -188,7 +190,7 @@ void KeyRing::decode(bufferlist::iterator& bl) {
   }
 }
 
-int KeyRing::load(const std::string &filename)
+int KeyRing::load(CephContext *cct, const std::string &filename)
 {
   if (filename.empty())
     return -EINVAL;
@@ -209,7 +211,7 @@ int KeyRing::load(const std::string &filename)
     derr << "error parsing file " << filename << dendl;
   }
 
-  dout(2) << "KeyRing::load: loaded key file " << filename << dendl;
+  ldout(cct, 2) << "KeyRing::load: loaded key file " << filename << dendl;
   return 0;
 }
 
@@ -233,12 +235,12 @@ void KeyRing::print(ostream& out)
   }
 }
 
-void KeyRing::import(KeyRing& other)
+void KeyRing::import(CephContext *cct, KeyRing& other)
 {
   for (map<EntityName, EntityAuth>::iterator p = other.keys.begin();
        p != other.keys.end();
        ++p) {
-    dout(10) << " importing " << p->first << " " << p->second << dendl;
+    ldout(cct, 10) << " importing " << p->first << " " << p->second << dendl;
     keys[p->first] = p->second;
   }
 }
index b02a9c664d5913ee80c784d6307ce9f3e5a2b1f8..08b6d8bb038290129500a8d00c16276cd79a3ab2 100644 (file)
@@ -28,14 +28,15 @@ class KeyRing {
   int set_modifier(const char *type, const char *val, EntityName& name, map<string, bufferlist>& caps);
   void decode_plaintext(bufferlist::iterator& bl);
 public:
-  /* Create a KeyRing from a Ceph configuration */
-  static KeyRing *from_ceph_conf(const md_config_t *conf);
+  /* Create a KeyRing from a Ceph context.
+   * We will use the configuration stored inside the context. */
+  static KeyRing *from_ceph_context(CephContext *cct);
   /* Create an empty KeyRing */
   static KeyRing *create_empty();
 
   map<EntityName, EntityAuth>& get_keys() { return keys; }  // yuck
 
-  int load(const std::string &filename);
+  int load(CephContext *cct, const std::string &filename);
   void print(ostream& out);
 
   // accessors
@@ -70,7 +71,7 @@ public:
   void set_key(EntityName& ename, CryptoKey& key) {
     keys[ename].key = key;
   }
-  void import(KeyRing& other);
+  void import(CephContext *cct, KeyRing& other);
 
   // encoders
   void encode(bufferlist& bl) const {
index d00a7d601daa89b401b7ad2a938427fdaa452fbc..9ded2901c9d50a2d4cd46dde8a29da7c564a4cdd 100644 (file)
@@ -34,11 +34,11 @@ void RotatingKeyRing::set_secrets(RotatingSecrets& s)
 
 void RotatingKeyRing::dump_rotating() const
 {
-  dout(10) << "dump_rotating:" << dendl;
+  ldout(cct, 10) << "dump_rotating:" << dendl;
   for (map<uint64_t, ExpiringCryptoKey>::const_iterator iter = secrets.secrets.begin();
        iter != secrets.secrets.end();
        ++iter)
-    dout(10) << " id " << iter->first << " " << iter->second << dendl;
+    ldout(cct, 10) << " id " << iter->first << " " << iter->second << dendl;
 }
 
 bool RotatingKeyRing::get_secret(const EntityName& name, CryptoKey& secret) const
@@ -53,7 +53,7 @@ bool RotatingKeyRing::get_service_secret(uint32_t service_id_, uint64_t secret_i
   Mutex::Locker l(lock);
 
   if (service_id_ != this->service_id) {
-    dout(0) << "do not have service " << ceph_entity_type_name(service_id_)
+    ldout(cct, 0) << "do not have service " << ceph_entity_type_name(service_id_)
            << ", i am " << ceph_entity_type_name(this->service_id) << dendl;
     return false;
   }
@@ -61,7 +61,7 @@ bool RotatingKeyRing::get_service_secret(uint32_t service_id_, uint64_t secret_i
   map<uint64_t, ExpiringCryptoKey>::const_iterator iter =
     secrets.secrets.find(secret_id);
   if (iter == secrets.secrets.end()) {
-    dout(0) << "could not find secret_id=" << secret_id << dendl;
+    ldout(cct, 0) << "could not find secret_id=" << secret_id << dendl;
     dump_rotating();
     return false;
   }
index a088d995d0a9dae22915b0979f213662a427bda0..efcb6382c7fbcd55ccb6805a664e6f699f657d35 100644 (file)
 class KeyRing;
 
 class RotatingKeyRing : public KeyStore {
+  CephContext *cct;
   uint32_t service_id;
   RotatingSecrets secrets;
   KeyRing *keyring;
   mutable Mutex lock;
 
 public:
-  RotatingKeyRing(uint32_t s, KeyRing *kr) :
+  RotatingKeyRing(CephContext *cct_, uint32_t s, KeyRing *kr) :
+    cct(cct_),
     service_id(s),
     keyring(kr),
     lock("RotatingKeyRing::lock") {}
index 0ea02cfec2add5a740f0cd1523acdfee705c2c9c..333f8812dec4663f616eb7f86fe2c86c31a75611 100644 (file)
@@ -178,7 +178,7 @@ int main(int argc, const char **argv)
       
       cout << "importing contents of " << import_keyring << " into " << fn << std::endl;
       //other.print(cout);
-      keyring.import(other);
+      keyring.import(&g_ceph_context, other);
       modified = true;
     } else {
       cerr << "can't open " << import_keyring << ": " << err << std::endl;
index 5a0b88ebcb9086f30fec716f3d24b9e7fb3011e7..0a64440e4be8c36953f62df8c932909e29674e3e 100644 (file)
@@ -94,7 +94,7 @@ void AuthMonitor::create_initial(bufferlist& bl)
   dout(10) << "create_initial -- creating initial map" << dendl;
 
   KeyRing keyring;
-  if (keyring.load(g_conf->keyring) == 0) {
+  if (keyring.load(&g_ceph_context, g_conf->keyring) == 0) {
     import_keyring(keyring);
   }
 
index 792d9a8b7b4bd3688cecf54cfc01be68a59dcfd7..3d44b876bbc798d6ead57b7828616e4ba58efcd7 100644 (file)
@@ -345,12 +345,12 @@ int MonClient::init()
 
   messenger->add_dispatcher_head(this);
 
-  keyring = KeyRing::from_ceph_conf(cct->_conf);
+  keyring = KeyRing::from_ceph_context(cct);
   if (!keyring) {
     derr << "MonClient::init(): Failed to create keyring" << dendl;
     return -EDOM;
   }
-  rotating_secrets = new RotatingKeyRing(cct->get_module_type(), keyring);
+  rotating_secrets = new RotatingKeyRing(cct, cct->get_module_type(), keyring);
 
   entity_name = g_conf->name;