]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: future-proof AUTH_MODE_* a bit in case we need to change the encoding byte
authorSage Weil <sage@redhat.com>
Fri, 1 Feb 2019 18:14:08 +0000 (12:14 -0600)
committerSage Weil <sage@redhat.com>
Thu, 7 Feb 2019 18:10:34 +0000 (12:10 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/auth/Auth.h
src/mon/MonClient.cc
src/mon/Monitor.cc

index 5e8e375fdf337bd759543b082bc1b7c43a55676f..59370e25dc70cdfc4fcb9f0c72d807755fa48c0e 100644 (file)
 #include "Crypto.h"
 #include "common/entity_name.h"
 
+// The _MAX values are a bit wonky here because we are overloading the first
+// byte of the auth payload to identify both the type of authentication to be
+// used *and* the encoding version for the authenticator.  So, we define a
+// range.
 enum {
   AUTH_MODE_NONE = 0,
   AUTH_MODE_AUTHORIZER = 1,
-  AUTH_MODE_MON = 100,
+  AUTH_MODE_AUTHORIZER_MAX = 9,
+  AUTH_MODE_MON = 10,
+  AUTH_MODE_MON_MAX = 19,
 };
 
 class Cond;
@@ -160,7 +166,7 @@ struct AuthConnectionMeta {
   /// client: initial empty, but populated if server said bad method
   std::vector<uint32_t> allowed_methods;
 
-  int auth_mode = 0;  ///< AUTH_MODE_*
+  int auth_mode = AUTH_MODE_NONE;  ///< AUTH_MODE_*
 
   int con_mode = 0;  ///< negotiated mode
 
index 74a1891b0b2bc895779e17830aec5a28a7118d3c..fd149192c8be1acf7a1d9722c58eac678f6b54e3 100644 (file)
@@ -1402,7 +1402,8 @@ int MonClient::handle_auth_request(
   bufferlist *reply)
 {
   auth_meta->auth_mode = payload[0];
-  if (auth_meta->auth_mode != AUTH_MODE_AUTHORIZER) {
+  if (auth_meta->auth_mode < AUTH_MODE_AUTHORIZER ||
+      auth_meta->auth_mode > AUTH_MODE_AUTHORIZER_MAX) {
     return -EACCES;
   }
   AuthAuthorizeHandler *ah = get_auth_authorize_handler(con->get_peer_type(),
index c9e433059900aca7b7219646b0b72cb2b540247e..7f271e8e37728dc966dd81a81677b44fb3674eea 100644 (file)
@@ -6053,7 +6053,8 @@ int Monitor::handle_auth_request(
     auth_meta->auth_mode = payload[0];
   }
 
-  if (auth_meta->auth_mode == AUTH_MODE_AUTHORIZER) {
+  if (auth_meta->auth_mode >= AUTH_MODE_AUTHORIZER &&
+      auth_meta->auth_mode <= AUTH_MODE_AUTHORIZER_MAX) {
     AuthAuthorizeHandler *ah = get_auth_authorize_handler(con->get_peer_type(),
                                                          auth_method);
     if (!ah) {
@@ -6083,7 +6084,8 @@ int Monitor::handle_auth_request(
     }
     dout(10) << __func__ << " bad authorizer on " << con << dendl;
     return -EACCES;
-  } else if (auth_meta->auth_mode != AUTH_MODE_MON) {
+  } else if (auth_meta->auth_mode < AUTH_MODE_MON &&
+            auth_meta->auth_mode > AUTH_MODE_MON_MAX) {
     derr << __func__ << " unrecognized auth mode " << auth_meta->auth_mode
         << dendl;
     return -EACCES;
@@ -6118,7 +6120,7 @@ int Monitor::handle_auth_request(
     EntityName entity_name;
 
     decode(mode, p);
-    assert(mode == AUTH_MODE_MON);
+    assert(mode >= AUTH_MODE_MON && mode <= AUTH_MODE_MON_MAX);
     decode(entity_name, p);
     decode(con->peer_global_id, p);