]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/authenticate.c
- Apply all of Preben's patches, but revert to old backup.c
[bacula/bacula] / bacula / src / filed / authenticate.c
index ec3acb05e8ef4022d43e8556153fb6afdf4a6dcc..a5728416a76f850556c9b8ce3885eba883b52556 100644 (file)
@@ -4,10 +4,10 @@
  *   Kern Sibbald, October 2000
  *
  *   Version $Id$
- * 
+ *
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -25,7 +25,7 @@
    MA 02111-1307, USA.
 
  */
-  
+
 #include "bacula.h"
 #include "filed.h"
 
@@ -33,21 +33,25 @@ static char OK_hello[]  = "2000 OK Hello\n";
 static char Dir_sorry[] = "2999 No go\n";
 
 
-/********************************************************************* 
+/*********************************************************************
  *
  */
-static int authenticate(int rcode, BSOCK *bs)
+static int authenticate(int rcode, BSOCK *bs, JCR* jcr)
 {
    POOLMEM *dirname;
    DIRRES *director;
    int ssl_need = BNET_SSL_NONE;
+   bool auth, get_auth = false;
 
    if (rcode != R_DIRECTOR) {
+      Dmsg1(50, _("I only authenticate directors, not %d\n"), rcode);
       Emsg1(M_FATAL, 0, _("I only authenticate directors, not %d\n"), rcode);
       return 0;
    }
    if (bs->msglen < 25 || bs->msglen > 200) {
-      Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"), 
+      Dmsg2(50, _("Bad Hello command from Director at %s. Len=%d.\n"),
+           bs->who, bs->msglen);
+      Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
            bs->who, bs->msglen);
       return 0;
    }
@@ -57,7 +61,9 @@ static int authenticate(int rcode, BSOCK *bs)
    if (sscanf(bs->msg, "Hello Director %s calling\n", dirname) != 1) {
       free_pool_memory(dirname);
       bs->msg[100] = 0;
-      Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"), 
+      Dmsg2(50, _("Bad Hello command from Director at %s: %s\n"),
+           bs->who, bs->msg);
+      Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
            bs->who, bs->msg);
       return 0;
    }
@@ -69,29 +75,40 @@ static int authenticate(int rcode, BSOCK *bs)
    }
    UnlockRes();
    if (!director) {
-      Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"   
-       "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"), 
+      Dmsg2(50, _("Connection from unknown Director %s at %s rejected.\n"),
+           dirname, bs->who);
+      Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
+       "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
            dirname, bs->who);
       free_pool_memory(dirname);
       return 0;
    }
-   btimer_t *tid = start_bsock_timer(bs, 60 * 5);
-   if (!cram_md5_auth(bs, director->password, ssl_need) ||
-       !cram_md5_get_auth(bs, director->password, ssl_need)) {
-      Emsg1(M_FATAL, 0, _("Incorrect password given by Director at %s.\n"  
-       "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"), 
+   btimer_t *tid = start_bsock_timer(bs, AUTH_TIMEOUT);
+   auth = cram_md5_auth(bs, director->password, ssl_need);
+   if (auth) {
+      get_auth = cram_md5_get_auth(bs, director->password, ssl_need);
+      if (!get_auth) {
+        Dmsg1(50, "cram_get_auth failed for %s\n", bs->who);
+      }
+   } else {
+      Dmsg1(50, "cram_auth failed for %s\n", bs->who);
+   }
+   if (!auth || !get_auth) {
+      Emsg1(M_FATAL, 0, _("Incorrect password given by Director at %s.\n"
+       "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
            bs->who);
       director = NULL;
    }
    stop_bsock_timer(tid);
    free_pool_memory(dirname);
+   jcr->director = director;
    return (director != NULL);
 }
 
 /*
  * Inititiate the communications with the Director.
  * He has made a connection to our server.
- * 
+ *
  * Basic tasks done here:
  *   We read Director's initial message and authorize him.
  *
@@ -100,7 +117,7 @@ int authenticate_director(JCR *jcr)
 {
    BSOCK *dir = jcr->dir_bsock;
 
-   if (!authenticate(R_DIRECTOR, dir)) {
+   if (!authenticate(R_DIRECTOR, dir, jcr)) {
       bnet_fsend(dir, "%s", Dir_sorry);
       Emsg0(M_FATAL, 0, _("Unable to authenticate Director\n"));
       bmicrosleep(5, 0);
@@ -116,17 +133,24 @@ int authenticate_director(JCR *jcr)
 int authenticate_storagedaemon(JCR *jcr)
 {
    BSOCK *sd = jcr->store_bsock;
-   int stat;
    int ssl_need = BNET_SSL_NONE;
+   bool get_auth, auth = false;
 
-   btimer_t *tid = start_bsock_timer(sd, 60 * 5);
-   stat = cram_md5_get_auth(sd, jcr->sd_auth_key, ssl_need) &&
-         cram_md5_auth(sd, jcr->sd_auth_key, ssl_need);
+   btimer_t *tid = start_bsock_timer(sd, AUTH_TIMEOUT);
+   get_auth = cram_md5_get_auth(sd, jcr->sd_auth_key, ssl_need);
+   if (!get_auth) {
+      Dmsg1(50, "cram_get_auth failed for %s\n", sd->who);
+   } else {
+      auth = cram_md5_auth(sd, jcr->sd_auth_key, ssl_need);
+      if (!auth) {
+        Dmsg1(50, "cram_auth failed for %s\n", sd->who);
+      }
+   }
    stop_bsock_timer(tid);
    memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
-   if (!stat) {
-      Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"   
+   if (!get_auth || !auth) {
+      Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"
        "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
    }
-   return stat;
+   return get_auth && auth;
 }