]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/authenticate.c
Minor tweaks to Migration
[bacula/bacula] / bacula / src / dird / authenticate.c
index c778966fa166c668824dbc19c94190d1b7f42b00..383e78ae57c3a7b4ea32d3483d6a7b94780bc359 100644 (file)
  *
  */
 /*
-   Copyright (C) 2001-2004 Kern Sibbald and John Walker
+   Copyright (C) 2001-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as amended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -34,7 +29,6 @@
 #include "dird.h"
 
 extern DIRRES *director;
-extern char my_name[];
 
 /* Commands sent to Storage daemon and File daemon and received
  *  from the User Agent */
@@ -58,6 +52,7 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store)
    char dirname[MAX_NAME_LENGTH];
    int tls_local_need = BNET_TLS_NONE;
    int tls_remote_need = BNET_TLS_NONE;
+   int compatible = true;
    bool auth_success = false;
 
    /*
@@ -74,36 +69,34 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store)
       return 0;
    }
 
-#ifdef HAVE_TLS
    /* TLS Requirement */
    if (store->tls_enable) {
      if (store->tls_require) {
-       tls_local_need = BNET_TLS_REQUIRED;
+        tls_local_need = BNET_TLS_REQUIRED;
      } else {
-       tls_local_need = BNET_TLS_OK;
+        tls_local_need = BNET_TLS_OK;
      }
    }
-#endif
 
-   auth_success = cram_md5_get_auth(sd, store->password, &tls_remote_need);
+   auth_success = cram_md5_respond(sd, store->password, &tls_remote_need, &compatible);
    if (auth_success) {
-      auth_success = cram_md5_auth(sd, store->password, tls_local_need);
+      auth_success = cram_md5_challenge(sd, store->password, tls_local_need, compatible);
       if (!auth_success) {
-        Dmsg1(50, "cram_auth failed for %s\n", sd->who);
+         Dmsg1(50, "cram_challenge failed for %s\n", sd->who);
       }
    } else {
-      Dmsg1(50, "cram_get_auth failed for %s\n", sd->who);
+      Dmsg1(50, "cram_respond failed for %s\n", sd->who);
    }
 
    if (!auth_success) {
       stop_bsock_timer(tid);
       Dmsg0(50, _("Director and Storage daemon passwords or names not the same.\n"));
       Jmsg0(jcr, M_FATAL, 0,
-           _("Unable to authenticate with Storage daemon. Possible causes:\n"
-           "Passwords or names not the same or\n"
-           "Maximum Concurrent Jobs exceeded on the SD or\n"
-           "SD networking messed up (restart daemon).\n"
-           "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
+            _("Director unable to authenticate with Storage daemon. Possible causes:\n"
+            "Passwords or names not the same or\n"
+            "Maximum Concurrent Jobs exceeded on the SD or\n"
+            "SD networking messed up (restart daemon).\n"
+            "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
       return 0;
    }
 
@@ -121,23 +114,21 @@ bool authenticate_storage_daemon(JCR *jcr, STORE *store)
       return 0;
    }
 
-#ifdef HAVE_TLS
    /* Is TLS Enabled? */
    if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
       /* Engage TLS! Full Speed Ahead! */
       if (!bnet_tls_client(store->tls_ctx, sd)) {
-        stop_bsock_timer(tid);
-        Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed.\n"));
-        return 0;
+         stop_bsock_timer(tid);
+         Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed.\n"));
+         return 0;
       }
    }
-#endif
 
    Dmsg1(116, ">stored: %s", sd->msg);
    if (bnet_recv(sd) <= 0) {
       stop_bsock_timer(tid);
       Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
-        bnet_strerror(sd));
+         bnet_strerror(sd));
       return 0;
    }
    Dmsg1(110, "<stored: %s", sd->msg);
@@ -160,6 +151,7 @@ int authenticate_file_daemon(JCR *jcr)
    char dirname[MAX_NAME_LENGTH];
    int tls_local_need = BNET_TLS_NONE;
    int tls_remote_need = BNET_TLS_NONE;
+   int compatible = true;
    bool auth_success = false;
 
    /*
@@ -174,23 +166,22 @@ int authenticate_file_daemon(JCR *jcr)
       Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
       return 0;
    }
+   Dmsg1(50, "Sent: %s", fd->msg);
 
-#ifdef HAVE_TLS
    /* TLS Requirement */
    if (client->tls_enable) {
      if (client->tls_require) {
-       tls_local_need = BNET_TLS_REQUIRED;
+        tls_local_need = BNET_TLS_REQUIRED;
      } else {
-       tls_local_need = BNET_TLS_OK;
+        tls_local_need = BNET_TLS_OK;
      }
    }
-#endif
 
-   auth_success = cram_md5_get_auth(fd, client->password, &tls_remote_need);
+   auth_success = cram_md5_respond(fd, client->password, &tls_remote_need, &compatible);
    if (auth_success) {
-      auth_success = cram_md5_auth(fd, client->password, tls_local_need);
+      auth_success = cram_md5_challenge(fd, client->password, tls_local_need, compatible);
       if (!auth_success) {
-        Dmsg1(50, "cram_auth failed for %s\n", fd->who);
+         Dmsg1(50, "cram_auth failed for %s\n", fd->who);
       }
    } else {
       Dmsg1(50, "cram_get_auth failed for %s\n", fd->who);
@@ -199,11 +190,11 @@ int authenticate_file_daemon(JCR *jcr)
       stop_bsock_timer(tid);
       Dmsg0(50, _("Director and File daemon passwords or names not the same.\n"));
       Jmsg(jcr, M_FATAL, 0,
-           _("Unable to authenticate with File daemon. Possible causes:\n"
-           "Passwords or names not the same or\n"
-           "Maximum Concurrent Jobs exceeded on the FD or\n"
-           "FD networking messed up (restart daemon).\n"
-           "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
+            _("Unable to authenticate with File daemon. Possible causes:\n"
+            "Passwords or names not the same or\n"
+            "Maximum Concurrent Jobs exceeded on the FD or\n"
+            "FD networking messed up (restart daemon).\n"
+            "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
       return 0;
    }
 
@@ -221,25 +212,23 @@ int authenticate_file_daemon(JCR *jcr)
       return 0;
    }
 
-#ifdef HAVE_TLS
    /* Is TLS Enabled? */
    if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
       /* Engage TLS! Full Speed Ahead! */
       if (!bnet_tls_client(client->tls_ctx, fd)) {
-        stop_bsock_timer(tid);
-        Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed.\n"));
-        return 0;
+         stop_bsock_timer(tid);
+         Jmsg(jcr, M_FATAL, 0, _("TLS negotiation failed.\n"));
+         return 0;
       }
    }
-#endif
 
    Dmsg1(116, ">filed: %s", fd->msg);
    if (bnet_recv(fd) <= 0) {
       stop_bsock_timer(tid);
       Dmsg1(50, _("Bad response from File daemon to Hello command: ERR=%s\n"),
-        bnet_strerror(fd));
+         bnet_strerror(fd));
       Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
-        bnet_strerror(fd));
+         bnet_strerror(fd));
       return 0;
    }
    Dmsg1(110, "<stored: %s", fd->msg);
@@ -260,77 +249,74 @@ int authenticate_user_agent(UAContext *uac)
    char name[MAX_NAME_LENGTH];
    int tls_local_need = BNET_TLS_NONE;
    int tls_remote_need = BNET_TLS_NONE;
+   int compatible = true;
    CONRES *cons = NULL;
    BSOCK *ua = uac->UA_sock;
    bool auth_success = false;
-#ifdef HAVE_TLS
    TLS_CONTEXT *tls_ctx = NULL;
    alist *verify_list = NULL;
-#endif /* HAVE_TLS */
  
 
 //  Emsg4(M_INFO, 0, _("UA Hello from %s:%s:%d is invalid. Len=%d\n"), ua->who,
-//         ua->host, ua->port, ua->msglen);
+//          ua->host, ua->port, ua->msglen);
    if (ua->msglen < 16 || ua->msglen >= MAX_NAME_LENGTH + 15) {
       Emsg4(M_ERROR, 0, _("UA Hello from %s:%s:%d is invalid. Len=%d\n"), ua->who,
-           ua->host, ua->port, ua->msglen);
+            ua->host, ua->port, ua->msglen);
       return 0;
    }
 
    if (sscanf(ua->msg, "Hello %127s calling\n", name) != 1) {
-      ua->msg[100] = 0;              /* terminate string */
+      ua->msg[100] = 0;               /* terminate string */
       Emsg4(M_ERROR, 0, _("UA Hello from %s:%s:%d is invalid. Got: %s\n"), ua->who,
-           ua->host, ua->port, ua->msg);
+            ua->host, ua->port, ua->msg);
       return 0;
    }
 
-   name[sizeof(name)-1] = 0;            /* terminate name */
+   name[sizeof(name)-1] = 0;             /* terminate name */
    if (strcmp(name, "*UserAgent*") == 0) {  /* default console */
-#ifdef HAVE_TLS
       /* TLS Requirement */
       if (director->tls_enable) {
          if (director->tls_require) {
             tls_local_need = BNET_TLS_REQUIRED;
          } else {
-           tls_local_need = BNET_TLS_OK;
+            tls_local_need = BNET_TLS_OK;
          }
       }
 
       if (director->tls_verify_peer) {
          verify_list = director->tls_allowed_cns;
       }
-#endif /* HAVE_TLS */
 
-      auth_success = cram_md5_auth(ua, director->password, tls_local_need) &&
-          cram_md5_get_auth(ua, director->password, &tls_remote_need);
+      auth_success = cram_md5_challenge(ua, director->password, tls_local_need,
+                                        compatible) &&
+                     cram_md5_respond(ua, director->password, &tls_remote_need, &compatible);
    } else {
       unbash_spaces(name);
       cons = (CONRES *)GetResWithName(R_CONSOLE, name);
       if (cons) {
-#ifdef HAVE_TLS
-        /* TLS Requirement */
+         /* TLS Requirement */
          if (cons->tls_enable) {
             if (cons->tls_require) {
-              tls_local_need = BNET_TLS_REQUIRED;
+               tls_local_need = BNET_TLS_REQUIRED;
             } else {
-              tls_local_need = BNET_TLS_OK;
+               tls_local_need = BNET_TLS_OK;
             }
          }
 
-        if (cons->tls_verify_peer) {
+         if (cons->tls_verify_peer) {
             verify_list = cons->tls_allowed_cns;
-        }
-#endif /* HAVE_TLS */
+         }
 
-        auth_success = cram_md5_auth(ua, cons->password, tls_local_need) &&
-             cram_md5_get_auth(ua, cons->password, &tls_remote_need);
+         auth_success = cram_md5_challenge(ua, cons->password, tls_local_need,
+                                           compatible) &&
+                     cram_md5_respond(ua, cons->password, &tls_remote_need, &compatible);
 
-        if (auth_success) {
-           uac->cons = cons;         /* save console resource pointer */
-        }
+         if (auth_success) {
+            uac->cons = cons;         /* save console resource pointer */
+         }
       } else {
-        auth_success = false;
-        goto auth_done;
+         auth_success = false;
+         goto auth_done;
       }
    }
 
@@ -350,22 +336,20 @@ int authenticate_user_agent(UAContext *uac)
       goto auth_done;
    }
 
-#ifdef HAVE_TLS
    if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
       if (cons) {
-        tls_ctx = cons->tls_ctx;
+         tls_ctx = cons->tls_ctx;
       } else {
-        tls_ctx = director->tls_ctx;
+         tls_ctx = director->tls_ctx;
       }
 
       /* Engage TLS! Full Speed Ahead! */
       if (!bnet_tls_server(tls_ctx, ua, verify_list)) {
-        Emsg0(M_ERROR, 0, "TLS negotiation failed.\n");
-        auth_success = false;
-        goto auth_done;
+         Emsg0(M_ERROR, 0, _("TLS negotiation failed.\n"));
+         auth_success = false;
+         goto auth_done;
       }
    }
-#endif /* HAVE_TLS */
 
 
 /* Authorization Completed */
@@ -373,10 +357,10 @@ auth_done:
    if (!auth_success) {
       bnet_fsend(ua, "%s", _(Dir_sorry));
       Emsg4(M_ERROR, 0, _("Unable to authenticate console \"%s\" at %s:%s:%d.\n"),
-           name, ua->who, ua->host, ua->port);
+            name, ua->who, ua->host, ua->port);
       sleep(5);
       return 0;
    }
-   bnet_fsend(ua, "1000 OK: %s Version: " VERSION " (" BDATE ")\n", my_name);
+   bnet_fsend(ua, _("1000 OK: %s Version: %s (%s)\n"), my_name, VERSION, BDATE);
    return 1;
 }