]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Update error handling in BPAM framework.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Tue, 13 Oct 2020 11:49:27 +0000 (13:49 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:58 +0000 (09:02 +0100)
bacula/src/console/authenticate.c
bacula/src/dird/authenticate.c
bacula/src/dird/dir_authplugin.c

index 4157a2a63cf9ed7c1fe00965df1182772a21f07b..0e2cb7700ad01a1de454c2733bd41d6eb72c7b44 100644 (file)
@@ -146,6 +146,12 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password)
                return false;
             }
 
+            // early check if auth interaction finish
+            if (dir->msg[0] == UA_AUTH_INTERACTIVE_FINISH){
+               // break the loop
+               break;
+            }
+
             pm_strcpy(msg, NULL);
             pm_strcpy(msg, dir->msg + 1);
             strip_trailing_junk(msg.c_str());
@@ -167,7 +173,7 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password)
 
                   // now we should return it to director
                   strip_trailing_junk(buf.c_str());
-                  dir->fsend("%s", buf.c_str());
+                  dir->fsend("%c%s", UA_AUTH_INTERACTIVE_RESPONSE, buf.c_str());
                   break;
 
                case UA_AUTH_INTERACTIVE_HIDDEN:
@@ -184,7 +190,7 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password)
                   bstrncpy(buf.c_str(), passwd, buf.size());
 #endif
                   // now we should get a hidden response at `buf` class, return it to director
-                  dir->fsend("%s", buf.c_str());
+                  dir->fsend("%c%s", UA_AUTH_INTERACTIVE_RESPONSE, buf.c_str());
                   break;
 
                case UA_AUTH_INTERACTIVE_MESSAGE:
@@ -193,13 +199,28 @@ bool ConsoleAuthenticate::ClientAuthenticate(CONRES *cons, const char *password)
                   break;
 
                case UA_AUTH_INTERACTIVE_FINISH:
-                  return true;
+                  // well it is not possible that we will reach this code, so report insanity
+                  return false;
 
                default:
                   bmicrosleep(5, 0); // original cram_md5_respond() wait for 5s here
                   return false;
             }
          }
+
+         // now check if authorized
+         if (bsock->wait_data(180) <= 0 || bsock->recv() <= 0) {
+            Dmsg1(1, "Receive auth confirmation failed. ERR=%s\n", bsock->bstrerror());
+            bmicrosleep(5, 0);
+            return false;
+         }
+         if (strcmp(bsock->msg, "1000 OK auth\n") == 0) {
+            // authorization ok
+            return true;
+         }
+         Dmsg1(1, "Received bad response: %s\n", bsock->msg);
+         bmicrosleep(5, 0);
+         return false;
       }
    }
 
@@ -239,7 +260,7 @@ int ConsoleAuthenticate::authenticate_director(DIRRES *director, CONRES *cons)
    }
 
    /* Timeout Hello after 15 secs */
-   StartAuthTimeout(15);
+   StartAuthTimeout(1500);
 
    dir->fsend(hello, bashed_name, UA_VERSION, tlspsk_local_need);
 
index e40fdf49b2380fe03ec810403f3e8800165ad58f..27a62470f07bf0d2a3ccd581e388ccfbcdef7e5d 100644 (file)
@@ -336,6 +336,7 @@ int UAAuthenticate::authenticate_user_agent()
          legacy_auth = false;
          Dmsg1(dbglvl, "authenticate with Plugin=%s\n", cons->authenticationplugin);
          if (ua_version < UA_VERSION_PLUGINAUTH || !authenticate_with_plugin(cons)){
+            auth_success = false;
             goto auth_done;
          }
       }
@@ -429,8 +430,11 @@ bool UAAuthenticate::authenticate_with_plugin(CONRES * cons)
    }
 
    if (dir_authplugin_authenticate(uac->jcr, bsock, authData->name) != bRC_OK){
+      bsock->fsend(_("1999 Authorization failed !!!.\n"));
+      bmicrosleep(5, 0);
       return false;
    }
 
+   bsock->fsend("1000 OK auth\n");
    return true;
 }
\ No newline at end of file
index 105c52514f884d8711cc865bda803681d27d6605..72c725b05b6ad6bb7fd1b95f1b2f683c27bb8338 100644 (file)
@@ -233,9 +233,16 @@ static bRC dir_authplugin_handle_response(JCR *jcr, BSOCK *bsock, const char *pl
       return bRC_Error;
    }
 
+   // check if it is a response packet
+   if (bsock->msg[0] != UA_AUTH_INTERACTIVE_RESPONSE){
+      Dmsg1(dbglvl, "Receive auth response packet error. Sig=%d\n", (int)bsock->msg[0]);
+      bmicrosleep(5, 0);
+      return bRC_Error;
+   }
+
    // forward response to plugin
    value.seqdata = seqdata;
-   value.response = bsock->msg;
+   value.response = bsock->msg + 1;    // we have to omit a first character which is a packet mark
    return dir_authplugin_generate_plugin_event(jcr, pluginname, bDirEventAuthenticationResponse, (void*)&value);
 }