]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: fix auth get-or-create output 5965/head
authorJohn Spray <john.spray@redhat.com>
Thu, 17 Sep 2015 14:51:20 +0000 (15:51 +0100)
committerJohn Spray <john.spray@redhat.com>
Fri, 18 Sep 2015 17:46:05 +0000 (18:46 +0100)
Previously the caps were omitted from the
output: they should be present for this
to fulfil the 'get' part of get-or-create.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mon/AuthMonitor.cc

index c948680840bbc2295beee9f6878fd8e6a89ce889..730410e8c50822cfba7944aa5af413a14c31dda6 100644 (file)
@@ -864,17 +864,25 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
       goto done;
     }
 
+    // Parse the list of caps into a map
+    std::map<std::string, bufferlist> wanted_caps;
+    for (vector<string>::const_iterator it = caps_vec.begin();
+        it != caps_vec.end() && (it + 1) != caps_vec.end();
+        it += 2) {
+      const std::string &sys = *it;
+      bufferlist cap;
+      ::encode(*(it+1), cap);
+      wanted_caps[sys] = cap;
+    }
+
     // do we have it?
     EntityAuth entity_auth;
     if (mon->key_server.get_auth(entity, entity_auth)) {
-      for (vector<string>::iterator it = caps_vec.begin();
-          it != caps_vec.end(); it += 2) {
-       string sys = *it;
-       bufferlist cap;
-       ::encode(*(it+1), cap);
-       if (entity_auth.caps.count(sys) == 0 ||
-           !entity_auth.caps[sys].contents_equal(cap)) {
-         ss << "key for " << entity << " exists but cap " << sys << " does not match";
+      for (const auto &sys_cap : wanted_caps) {
+       if (entity_auth.caps.count(sys_cap.first) == 0 ||
+           !entity_auth.caps[sys_cap.first].contents_equal(sys_cap.second)) {
+         ss << "key for " << entity << " exists but cap " << sys_cap.first
+            << " does not match";
          err = -EINVAL;
          goto done;
        }
@@ -890,6 +898,7 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
        KeyRing kr;
        kr.add(entity, entity_auth.key);
         if (f) {
+          kr.set_caps(entity, entity_auth.caps);
           kr.encode_formatted("auth", f.get(), rdata);
         } else {
           kr.encode_plaintext(rdata);
@@ -921,9 +930,7 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
     auth_inc.op = KeyServerData::AUTH_INC_ADD;
     auth_inc.name = entity;
     auth_inc.auth.key.create(g_ceph_context, CEPH_CRYPTO_AES);
-    for (vector<string>::iterator it = caps_vec.begin();
-        it != caps_vec.end(); it += 2)
-      ::encode(*(it+1), auth_inc.auth.caps[*it]);
+    auth_inc.auth.caps = wanted_caps;
 
     push_cephx_inc(auth_inc);
 
@@ -937,6 +944,7 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
       KeyRing kr;
       kr.add(entity, auth_inc.auth.key);
       if (f) {
+        kr.set_caps(entity, wanted_caps);
         kr.encode_formatted("auth", f.get(), rdata);
       } else {
         kr.encode_plaintext(rdata);