From 57c72346c71dbcb82be80f34884029c8034d5a01 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 14 Jan 2019 16:13:53 -0600 Subject: [PATCH] auth: clean up AuthServiceHandler::start_session() - return error code, not type (which never changes) - take const ref for input args - pointers for output args Signed-off-by: Sage Weil --- src/auth/AuthServiceHandler.h | 4 +++- src/auth/cephx/CephxServiceHandler.cc | 11 +++++++---- src/auth/cephx/CephxServiceHandler.h | 4 +++- src/auth/krb/KrbServiceHandler.cpp | 9 ++++----- src/auth/krb/KrbServiceHandler.hpp | 7 +++---- src/auth/none/AuthNoneServiceHandler.h | 8 +++++--- src/auth/unknown/AuthUnknownServiceHandler.h | 6 ++++-- src/mon/AuthMonitor.cc | 5 +++-- 8 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/auth/AuthServiceHandler.h b/src/auth/AuthServiceHandler.h index 2230c75c71f..1aa1bcc7ea3 100644 --- a/src/auth/AuthServiceHandler.h +++ b/src/auth/AuthServiceHandler.h @@ -35,7 +35,9 @@ public: virtual ~AuthServiceHandler() { } - virtual int start_session(EntityName& name, bufferlist::const_iterator& indata, bufferlist& result, AuthCapsInfo& caps) = 0; + virtual int start_session(const EntityName& name, + bufferlist *result, + AuthCapsInfo *caps) = 0; virtual int handle_request(bufferlist::const_iterator& indata, bufferlist& result, uint64_t& global_id, AuthCapsInfo& caps) = 0; EntityName& get_entity_name() { return entity_name; } diff --git a/src/auth/cephx/CephxServiceHandler.cc b/src/auth/cephx/CephxServiceHandler.cc index 4bd197ae5a7..ae0b2bb5e11 100644 --- a/src/auth/cephx/CephxServiceHandler.cc +++ b/src/auth/cephx/CephxServiceHandler.cc @@ -27,19 +27,22 @@ #undef dout_prefix #define dout_prefix *_dout << "cephx server " << entity_name << ": " -int CephxServiceHandler::start_session(EntityName& name, bufferlist::const_iterator& indata, bufferlist& result_bl, AuthCapsInfo& caps) +int CephxServiceHandler::start_session(const EntityName& name, + bufferlist *result_bl, + AuthCapsInfo *caps) { entity_name = name; uint64_t min = 1; // always non-zero uint64_t max = std::numeric_limits::max(); server_challenge = ceph::util::generate_random_number(min, max); - ldout(cct, 10) << "start_session server_challenge " << hex << server_challenge << dec << dendl; + ldout(cct, 10) << "start_session server_challenge " + << hex << server_challenge << dec << dendl; CephXServerChallenge ch; ch.server_challenge = server_challenge; - encode(ch, result_bl); - return CEPH_AUTH_CEPHX; + encode(ch, *result_bl); + return 0; } int CephxServiceHandler::handle_request(bufferlist::const_iterator& indata, bufferlist& result_bl, uint64_t& global_id, AuthCapsInfo& caps) diff --git a/src/auth/cephx/CephxServiceHandler.h b/src/auth/cephx/CephxServiceHandler.h index e961e38814e..4d8804d559d 100644 --- a/src/auth/cephx/CephxServiceHandler.h +++ b/src/auth/cephx/CephxServiceHandler.h @@ -29,7 +29,9 @@ public: : AuthServiceHandler(cct_), key_server(ks), server_challenge(0) {} ~CephxServiceHandler() override {} - int start_session(EntityName& name, bufferlist::const_iterator& indata, bufferlist& result_bl, AuthCapsInfo& caps) override; + int start_session(const EntityName& name, + bufferlist *result_bl, + AuthCapsInfo *caps) override; int handle_request(bufferlist::const_iterator& indata, bufferlist& result_bl, uint64_t& global_id, AuthCapsInfo& caps) override; void build_cephx_response_header(int request_type, int status, bufferlist& bl); }; diff --git a/src/auth/krb/KrbServiceHandler.cpp b/src/auth/krb/KrbServiceHandler.cpp index 52ebd0a5681..f896c3fd777 100644 --- a/src/auth/krb/KrbServiceHandler.cpp +++ b/src/auth/krb/KrbServiceHandler.cpp @@ -148,10 +148,9 @@ int KrbServiceHandler::handle_request(bufferlist::const_iterator& indata, return result; } -int KrbServiceHandler::start_session(EntityName& name, - bufferlist::const_iterator& indata, - bufferlist& buff_list, - AuthCapsInfo& caps) +int KrbServiceHandler::start_session(const EntityName& name, + bufferlist *buff_list, + AuthCapsInfo *caps) { gss_buffer_desc gss_buffer_in = {0, nullptr}; gss_OID gss_object_id = GSS_C_NT_HOSTBASED_SERVICE; @@ -206,7 +205,7 @@ int KrbServiceHandler::start_session(EntityName& name, static_cast(GSSAuthenticationRequest::GSS_MUTUAL); using ceph::encode; - encode(krb_response, buff_list); + encode(krb_response, *buff_list); return (CEPH_AUTH_GSS); } } diff --git a/src/auth/krb/KrbServiceHandler.hpp b/src/auth/krb/KrbServiceHandler.hpp index 692a7ebd06a..649c5f38887 100644 --- a/src/auth/krb/KrbServiceHandler.hpp +++ b/src/auth/krb/KrbServiceHandler.hpp @@ -42,10 +42,9 @@ class KrbServiceHandler : public AuthServiceHandler { uint64_t& global_id, AuthCapsInfo& caps) override; - int start_session(EntityName& name, - bufferlist::const_iterator& indata, - bufferlist& buff_list, - AuthCapsInfo& caps) override; + int start_session(const EntityName& name, + bufferlist *buff_list, + AuthCapsInfo *caps) override; private: gss_buffer_desc m_gss_buffer_out; diff --git a/src/auth/none/AuthNoneServiceHandler.h b/src/auth/none/AuthNoneServiceHandler.h index 44914389492..0f90a840252 100644 --- a/src/auth/none/AuthNoneServiceHandler.h +++ b/src/auth/none/AuthNoneServiceHandler.h @@ -26,10 +26,12 @@ public: : AuthServiceHandler(cct_) {} ~AuthNoneServiceHandler() override {} - int start_session(EntityName& name, bufferlist::const_iterator& indata, bufferlist& result_bl, AuthCapsInfo& caps) override { + int start_session(const EntityName& name, + bufferlist *result_bl, + AuthCapsInfo *caps) override { entity_name = name; - caps.allow_all = true; - return CEPH_AUTH_NONE; + caps->allow_all = true; + return 0; } int handle_request(bufferlist::const_iterator& indata, bufferlist& result_bl, uint64_t& global_id, AuthCapsInfo& caps) override { return 0; diff --git a/src/auth/unknown/AuthUnknownServiceHandler.h b/src/auth/unknown/AuthUnknownServiceHandler.h index f89174d9aa1..a7856093e7c 100644 --- a/src/auth/unknown/AuthUnknownServiceHandler.h +++ b/src/auth/unknown/AuthUnknownServiceHandler.h @@ -26,8 +26,10 @@ public: : AuthServiceHandler(cct_) {} ~AuthUnknownServiceHandler() {} - int start_session(EntityName& name, bufferlist::iterator& indata, bufferlist& result_bl, AuthCapsInfo& caps) { - return CEPH_AUTH_UNKNOWN; + int start_session(const EntityName& name, + bufferlist *result_bl, + AuthCapsInfo *caps) { + return 0; } int handle_request(bufferlist::iterator& indata, bufferlist& result_bl, uint64_t& global_id, AuthCapsInfo& caps) { ceph_abort(); // shouldn't get called diff --git a/src/mon/AuthMonitor.cc b/src/mon/AuthMonitor.cc index 871b246ddcb..6f2e676edaa 100644 --- a/src/mon/AuthMonitor.cc +++ b/src/mon/AuthMonitor.cc @@ -599,6 +599,7 @@ bool AuthMonitor::prep_auth(MonOpRequestRef op, bool paxos_writable) goto reply; } start = true; + proto = type; } else if (!s->auth_handler) { dout(10) << "protocol specified but no s->auth_handler" << dendl; ret = -EINVAL; @@ -639,8 +640,8 @@ bool AuthMonitor::prep_auth(MonOpRequestRef op, bool paxos_writable) try { if (start) { // new session - proto = s->auth_handler->start_session(entity_name, indata, response_bl, - s->con->peer_caps_info); + s->auth_handler->start_session(entity_name, &response_bl, + &s->con->peer_caps_info); ret = 0; } else { // request -- 2.39.5