]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/auth/KeyRing.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / auth / KeyRing.cc
index b946a298b48bbe130d3e0dca69d6524272bc830a..7f207d8fa538ed229e31ec7daa7012bcb78be58e 100644 (file)
@@ -18,6 +18,7 @@
 #include <sstream>
 #include <algorithm>
 #include "auth/KeyRing.h"
+#include "common/ceph_context.h"
 #include "common/config.h"
 #include "common/debug.h"
 #include "common/errno.h"
 #undef dout_prefix
 #define dout_prefix *_dout << "auth: "
 
-using namespace std;
-
 int KeyRing::from_ceph_context(CephContext *cct)
 {
-  const md_config_t *conf = cct->_conf;
+  const auto& conf = cct->_conf;
   string filename;
 
   int ret = ceph_resolve_file_search(conf->keyring, filename);
@@ -88,7 +87,10 @@ KeyRing *KeyRing::create_empty()
   return new KeyRing();
 }
 
-int KeyRing::set_modifier(const char *type, const char *val, EntityName& name, map<string, bufferlist>& caps)
+int KeyRing::set_modifier(const char *type,
+                         const char *val,
+                         EntityName& name,
+                         map<string, bufferlist>& caps)
 {
   if (!val)
     return -EINVAL;
@@ -108,12 +110,11 @@ int KeyRing::set_modifier(const char *type, const char *val, EntityName& name, m
       return -EINVAL;
     string l(val);
     bufferlist bl;
-    ::encode(l, bl);
+    encode(l, bl);
     caps[caps_entity] = bl;
     set_caps(name, caps);
   } else if (strcmp(type, "auid") == 0) {
-    uint64_t auid = strtoull(val, NULL, 0);
-    set_uid(name, auid);
+    // just ignore it so we can still decode "old" keyrings that have an auid
   } else
     return -EINVAL;
 
@@ -130,7 +131,6 @@ void KeyRing::encode_plaintext(bufferlist& bl)
 
 void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
 {
-  std::ostringstream(os);
   f->open_array_section(label.c_str());
   for (map<EntityName, EntityAuth>::iterator p = keys.begin();
        p != keys.end();
@@ -141,15 +141,14 @@ void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
     std::ostringstream keyss;
     keyss << p->second.key;
     f->dump_string("key", keyss.str());
-    if (p->second.auid != CEPH_AUTH_UID_DEFAULT)
-      f->dump_int("auid", p->second.auid);
     f->open_object_section("caps");
     for (map<string, bufferlist>::iterator q = p->second.caps.begin();
-        q != p->second.caps.end();
+        q != p->second.caps.end();
         ++q) {
-      bufferlist::iterator dataiter = q->second.begin();
+      auto dataiter = q->second.cbegin();
       string caps;
-      ::decode(caps, dataiter);
+      using ceph::decode;
+      decode(caps, dataiter);
       f->dump_string(q->first.c_str(), caps);
     }
     f->close_section();        /* caps */
@@ -159,7 +158,7 @@ void KeyRing::encode_formatted(string label, Formatter *f, bufferlist& bl)
   f->flush(bl);
 }
 
-void KeyRing::decode_plaintext(bufferlist::iterator& bli)
+void KeyRing::decode_plaintext(bufferlist::const_iterator& bli)
 {
   int ret;
   bufferlist bl;
@@ -202,12 +201,13 @@ void KeyRing::decode_plaintext(bufferlist::iterator& bli)
   }
 }
 
-void KeyRing::decode(bufferlist::iterator& bl) {
+void KeyRing::decode(bufferlist::const_iterator& bl) {
   __u8 struct_v;
-  bufferlist::iterator start_pos = bl;
+  auto start_pos = bl;
   try {
-    ::decode(struct_v, bl);
-    ::decode(keys, bl);
+    using ceph::decode;
+    decode(struct_v, bl);
+    decode(keys, bl);
   } catch (buffer::error& err) {
     keys.clear();
     decode_plaintext(start_pos);
@@ -228,11 +228,11 @@ int KeyRing::load(CephContext *cct, const std::string &filename)
   }
 
   try {
-    bufferlist::iterator iter = bl.begin();
+    auto iter = bl.cbegin();
     decode(iter);
   }
   catch (const buffer::error& err) {
-    lderr(cct) << "error parsing file " << filename << dendl;
+    lderr(cct) << "error parsing file " << filename << ": " << err.what() << dendl;
     return -EIO;
   }
 
@@ -247,15 +247,14 @@ void KeyRing::print(ostream& out)
        ++p) {
     out << "[" << p->first << "]" << std::endl;
     out << "\tkey = " << p->second.key << std::endl;
-    if (p->second.auid != CEPH_AUTH_UID_DEFAULT)
-      out << "\tauid = " << p->second.auid << std::endl;
 
     for (map<string, bufferlist>::iterator q = p->second.caps.begin();
         q != p->second.caps.end();
         ++q) {
-      bufferlist::iterator dataiter = q->second.begin();
+      auto dataiter = q->second.cbegin();
       string caps;
-      ::decode(caps, dataiter);
+      using ceph::decode;
+      decode(caps, dataiter);
       out << "\tcaps " << q->first << " = \"" << caps << '"' << std::endl;
     }
   }