]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/console/authenticate.c
Add extra safety for readdir buffer
[bacula/bacula] / bacula / src / console / authenticate.c
index 2297943b98ff948935728c461a1bf7d452191162..4eb781447754c4f871d6e2385e3971302a18b3ef 100644 (file)
@@ -1,29 +1,20 @@
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   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., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of Kern Sibbald.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2017 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 /*
  *
 
 #include "bacula.h"
 #include "console_conf.h"
-#include "jcr.h"
 
+/*
+ * Version at end of Hello
+ *   prior to 06Aug13 no version
+ *   100  14Feb17 - added comm line compression
+ */
+#define UA_VERSION 100
 
 void senditf(const char *fmt, ...);
 void sendit(const char *buf);
 
 /* Commands sent to Director */
-static char hello[]    = "Hello %s calling\n";
+static char hello[]    = "Hello %s calling %d\n";
 
 /* Response from Director */
-static char OKhello[]   = "1000 OK:";
+static char oldOKhello[]   = "1000 OK:";
+static char newOKhello[]   = "1000 OK: %d";
+static char FDOKhello[]    = "2000 OK Hello %d";
 
 /* Forward referenced functions */
 
 /*
  * Authenticate Director
  */
-int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
+int authenticate_director(BSOCK *dir, DIRRES *director, CONRES *cons)
 {
-   BSOCK *dir = jcr->dir_bsock;
    int tls_local_need = BNET_TLS_NONE;
    int tls_remote_need = BNET_TLS_NONE;
-   bool tls_needed;
    bool tls_authenticate;
    int compatible = true;
+   int dir_version = 0;
+   int fd_version = 0;
    char bashed_name[MAX_NAME_LENGTH];
    char *password;
    TLS_CONTEXT *tls_ctx = NULL;
-
+            
    /*
     * Send my name to the Director then do authentication
     */
@@ -88,7 +86,6 @@ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
          tls_local_need = BNET_TLS_REQUIRED;
       }
       tls_authenticate = cons->tls_authenticate;
-      tls_needed = cons->tls_enable || cons->tls_authenticate;
       tls_ctx = cons->tls_ctx;
    } else {
       bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
@@ -106,14 +103,13 @@ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
          tls_local_need = BNET_TLS_REQUIRED;
       }
       tls_authenticate = director->tls_authenticate;
-      tls_needed = director->tls_enable || director->tls_authenticate;
       tls_ctx = director->tls_ctx;
    }
 
-   
-   /* Timeout Hello after 5 mins */
-   btimer_t *tid = start_bsock_timer(dir, 60 * 5);
-   dir->fsend(hello, bashed_name);
+
+   /* Timeout Hello after 15 secs */
+   btimer_t *tid = start_bsock_timer(dir, 15);
+   dir->fsend(hello, bashed_name, UA_VERSION);
 
    if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
        !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
@@ -158,12 +154,24 @@ int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
    }
 
    Dmsg1(10, "<dird: %s", dir->msg);
-   if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
+   if (strncmp(dir->msg, oldOKhello, sizeof(oldOKhello)-1) == 0) {
+      /* If Dir version exists, get it */
+      sscanf(dir->msg, newOKhello, &dir_version);
+      sendit(dir->msg);
+   /* Check for hello from FD */
+   } else if (sscanf(dir->msg, FDOKhello, &fd_version) == 1) {
+      sendit(dir->msg);
+   } else {
       sendit(_("Director rejected Hello command\n"));
       goto bail_out;
+   }
+   /* Turn on compression for newer Directors */
+   if (dir_version >= 103 && (!cons || cons->comm_compression)) {
+      dir->set_compress();
    } else {
-      sendit(dir->msg);
+      dir->clear_compress();
    }
+   /* ***FIXME*** should turn on compression for FD if possible */
    stop_bsock_timer(tid);
    return 1;
 
@@ -172,6 +180,6 @@ bail_out:
    sendit( _("Director authorization problem.\n"
              "Most likely the passwords do not agree.\n"
              "If you are using TLS, there may have been a certificate validation error during the TLS handshake.\n"
-             "Please see http://www.bacula.org/en/rel-manual/Bacula_Freque_Asked_Questi.html#SECTION003760000000000000000 for help.\n"));
+             "For help, please see " MANUAL_AUTH_URL "\n"));
    return 0;
 }