]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/authenticate.c
Restore all/done updates
[bacula/bacula] / bacula / src / console / authenticate.c
index 819b93ab19ce0b803a3f61bb46c579529a8c203d..5f5be7bfca5bdc704081e23a64132afb8176be5d 100644 (file)
@@ -33,6 +33,9 @@
 #include "jcr.h"
 
 
+void senditf(char *fmt, ...);
+void sendit(char *buf); 
+
 /* Commands sent to Director */
 static char hello[]    = "Hello %s calling\n";
 
@@ -44,35 +47,50 @@ static char OKhello[]   = "1000 OK:";
 /*
  * Authenticate Director
  */
-int authenticate_director(JCR *jcr, DIRRES *director)
+int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
 {
    BSOCK *dir = jcr->dir_bsock;
+   int ssl_need = BNET_SSL_NONE;
+   char bashed_name[MAX_NAME_LENGTH];
+   char *password;
 
    /* 
     * Send my name to the Director then do authentication
     */
-   bnet_fsend(dir, hello, "UserAgent");
+   if (cons) {
+      bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
+      bash_spaces(bashed_name);
+      password = cons->password;
+   } else {
+      bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
+      password = director->password;
+   }
+   /* Timeout Hello after 5 mins */
+   btimer_t *tid = start_bsock_timer(dir, 60 * 5);
+   bnet_fsend(dir, hello, bashed_name);
 
-   if (!cram_md5_get_auth(dir, director->password) || 
-       !cram_md5_auth(dir, director->password)) {
-      Dmsg0(-1, _("Director authorization problem.\n"
+   if (!cram_md5_get_auth(dir, password, ssl_need) || 
+       !cram_md5_auth(dir, password, ssl_need)) {
+      stop_bsock_timer(tid);
+      sendit( _("Director authorization problem.\n"
             "Most likely the passwords do not agree.\n"));  
       return 0;
    }
 
    Dmsg1(6, ">dird: %s", dir->msg);
    if (bnet_recv(dir) <= 0) {
-      Dmsg1(-1, "Bad response to Hello command: ERR=%s\n",
+      stop_bsock_timer(tid);
+      senditf(_("Bad response to Hello command: ERR=%s\n"),
         bnet_strerror(dir));
-      Dmsg0(-1, "The Director is probably not running.\n");
       return 0;
    }
    Dmsg1(10, "<dird: %s", dir->msg);
+   stop_bsock_timer(tid);
    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
-      Dmsg0(-1, "Director rejected Hello command\n");
+      sendit(_("Director rejected Hello command\n"));
       return 0;
    } else {
-      Dmsg1(-1, "%s", dir->msg);
+      sendit(dir->msg);
    }
    return 1;
 }