]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/authenticate.c
Add new files
[bacula/bacula] / bacula / src / dird / authenticate.c
index 456004df8b6b509b82d58b3a9de6c5bdff2e1b78..81c638c97cc5b1299e5c314cbf4be3d7c788a762 100644 (file)
@@ -55,28 +55,32 @@ static char Dir_sorry[]  = N_("1999 You are not authorized.\n");
 int authenticate_storage_daemon(JCR *jcr)
 {
    BSOCK *sd = jcr->store_bsock;
+   char dirname[MAX_NAME_LENGTH];
+   int ssl_need = BNET_SSL_NONE;
 
    /* 
     * Send my name to the Storage daemon then do authentication
     */
-   if (!bnet_fsend(sd, hello, director->hdr.name)) {
+   strcpy(dirname, director->hdr.name);
+   bash_spaces(dirname);
+   if (!bnet_fsend(sd, hello, dirname)) {
       Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
       return 0;
    }
-   if (!cram_md5_get_auth(sd, jcr->store->password) || 
-       !cram_md5_auth(sd, jcr->store->password)) {
+   if (!cram_md5_get_auth(sd, jcr->store->password, ssl_need) || 
+       !cram_md5_auth(sd, jcr->store->password, ssl_need)) {
       Jmsg0(jcr, M_FATAL, 0, _("Director and Storage daemon passwords not the same.\n"));
       return 0;
    }
    Dmsg1(116, ">stored: %s", sd->msg);
    if (bnet_recv(sd) <= 0) {
-      Emsg1(M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
+      Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
         bnet_strerror(sd));
       return 0;
    }
    Dmsg1(110, "<stored: %s", sd->msg);
    if (strncmp(sd->msg, OKhello, sizeof(OKhello)) != 0) {
-      Emsg0(M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
+      Jmsg0(jcr, M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
       return 0;
    }
    return 1;
@@ -88,22 +92,26 @@ int authenticate_storage_daemon(JCR *jcr)
 int authenticate_file_daemon(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
+   char dirname[MAX_NAME_LENGTH];
+   int ssl_need = BNET_SSL_NONE;
 
    /* 
     * Send my name to the File daemon then do authentication
     */
-   if (!bnet_fsend(fd, hello, director->hdr.name)) {
+   strcpy(dirname, director->hdr.name);
+   bash_spaces(dirname);
+   if (!bnet_fsend(fd, hello, dirname)) {
       Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
       return 0;
    }
-   if (!cram_md5_get_auth(fd, jcr->client->password) || 
-       !cram_md5_auth(fd, jcr->client->password)) {
+   if (!cram_md5_get_auth(fd, jcr->client->password, ssl_need) || 
+       !cram_md5_auth(fd, jcr->client->password, ssl_need)) {
       Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords not the same.\n"));
       return 0;
    }
    Dmsg1(116, ">filed: %s", fd->msg);
    if (bnet_recv(fd) <= 0) {
-      Jmsg(jcr, M_FATAL, 0, _("bdird<filed: bad response to Hello command: ERR=%s\n"),
+      Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
         bnet_strerror(fd));
       return 0;
    }
@@ -120,24 +128,33 @@ int authenticate_file_daemon(JCR *jcr)
  */
 int authenticate_user_agent(BSOCK *ua)
 {
-   char name[128];
-   int ok = 0;
+   char name[MAXSTRING];
+   int ssl_need = BNET_SSL_NONE;
+   int ok;    
 
+   if (ua->msglen < 16 || ua->msglen >= MAXSTRING-1) {
+      Emsg2(M_ERROR, 0, _("UA Hello from %s is invalid. Len=%d\n"), ua->who, 
+           ua->msglen);
+      return 0;
+   }
 
    if (sscanf(ua->msg, "Hello %127s calling\n", name) != 1) {
-      Emsg1(M_FATAL, 0, _("Authentication failure: %s"), ua->msg);
+      ua->msg[100] = 0;              /* terminate string */
+      Emsg2(M_ERROR, 0, _("UA Hello from %s is invalid. Got: %s\n"), ua->who,
+           ua->msg);
       return 0;
    }
 
-   ok = cram_md5_auth(ua, director->password) &&
-       cram_md5_get_auth(ua, director->password);
+   ok = cram_md5_auth(ua, director->password, ssl_need) &&
+       cram_md5_get_auth(ua, director->password, ssl_need);
 
    if (!ok) {
       bnet_fsend(ua, "%s", _(Dir_sorry));
-      Emsg0(M_WARNING, 0, _("Unable to authenticate User Agent\n"));
+      Emsg1(M_WARNING, 0, _("Unable to authenticate User Agent at %s.\n"),
+           ua->who);
       sleep(5);
       return 0;
    }
-   bnet_fsend(ua, "1000 OK: %s Version: " VERSION " (" DATE ")\n", my_name);
+   bnet_fsend(ua, "1000 OK: %s Version: " VERSION " (" BDATE ")\n", my_name);
    return 1;
 }