From 4551808fa00b812fee6e0c196fd333eca0b06de9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 22 May 2012 18:54:10 -0700 Subject: [PATCH] mon: add 'auth get-or-create' variant that outputs a keyring This is more convenient when you're creating daemons, since you want to write out a keyring file for them. This lets you do it in a single command. Signed-off-by: Sage Weil --- src/auth/KeyRing.h | 5 +++++ src/mon/AuthMonitor.cc | 24 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/auth/KeyRing.h b/src/auth/KeyRing.h index 26f41ab3e5526..26358003766fe 100644 --- a/src/auth/KeyRing.h +++ b/src/auth/KeyRing.h @@ -74,6 +74,11 @@ public: void add(const EntityName& name, EntityAuth &a) { keys[name] = a; } + void add(const EntityName& name, CryptoKey &k) { + EntityAuth a; + a.key = k; + keys[name] = a; + } void remove(const EntityName& name) { keys.erase(name); } diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index df7ce5532204b..d9b698aefd5e3 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -431,6 +431,7 @@ bool AuthMonitor::preprocess_command(MMonCommand *m) if (m->cmd.size() > 1) { if (m->cmd[1] == "add" || m->cmd[1] == "del" || + m->cmd[1] == "get-or-create" || m->cmd[1] == "get-or-create-key" || m->cmd[1] == "caps") { return false; @@ -628,7 +629,9 @@ bool AuthMonitor::prepare_command(MMonCommand *m) paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); return true; } - else if (m->cmd[1] == "get-or-create-key" && m->cmd.size() >= 3) { + else if ((m->cmd[1] == "get-or-create-key" || + m->cmd[1] == "get-or-create") && + m->cmd.size() >= 3) { // auth get-or-create [mon osdcapa osd osdcapb ...] EntityName entity; if (!entity.from_str(m->cmd[2])) { @@ -652,7 +655,13 @@ bool AuthMonitor::prepare_command(MMonCommand *m) } } - ss << entity_auth.key; + if (m->cmd[1] == "get-or-create-key") { + ss << entity_auth.key; + } else { + KeyRing kr; + kr.add(entity, entity_auth.key); + kr.encode_plaintext(rdata); + } err = 0; goto done; } @@ -683,9 +692,16 @@ bool AuthMonitor::prepare_command(MMonCommand *m) push_cephx_inc(auth_inc); - ss << auth_inc.auth.key; + if (m->cmd[1] == "get-or-create-key") { + ss << auth_inc.auth.key; + } else { + KeyRing kr; + kr.add(entity, auth_inc.auth.key); + kr.encode_plaintext(rdata); + } + getline(ss, rs); - paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, paxos->get_version())); + paxos->wait_for_commit(new Monitor::C_Command(mon, m, 0, rs, rdata, paxos->get_version())); return true; } else if (m->cmd[1] == "caps" && m->cmd.size() >= 3) { -- 2.39.5