X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fconsole%2Fauthenticate.c;h=2297943b98ff948935728c461a1bf7d452191162;hb=ed8b34d3e172f009a02fb5b17b1ab237e36554f9;hp=b378a0976f84a6b1f544a8ad0f9dce563568d67a;hpb=b30de1ea0de78714829a08fce5f31dbd382a903e;p=bacula%2Fbacula diff --git a/bacula/src/console/authenticate.c b/bacula/src/console/authenticate.c index b378a0976f..2297943b98 100644 --- a/bacula/src/console/authenticate.c +++ b/bacula/src/console/authenticate.c @@ -1,3 +1,30 @@ +/* + 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 UA authentication. Provides authentication with @@ -10,29 +37,15 @@ * Basic tasks done here: * */ -/* - Copyright (C) 2000, 2001 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 published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - 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. - */ #include "bacula.h" #include "console_conf.h" #include "jcr.h" +void senditf(const char *fmt, ...); +void sendit(const char *buf); + /* Commands sent to Director */ static char hello[] = "Hello %s calling\n"; @@ -44,36 +57,121 @@ 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; + int tls_local_need = BNET_TLS_NONE; + int tls_remote_need = BNET_TLS_NONE; + bool tls_needed; + bool tls_authenticate; + int compatible = true; + char bashed_name[MAX_NAME_LENGTH]; + char *password; + TLS_CONTEXT *tls_ctx = NULL; - /* + /* * 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; + /* TLS Requirement */ + if (cons->tls_enable) { + if (cons->tls_require) { + tls_local_need = BNET_TLS_REQUIRED; + } else { + tls_local_need = BNET_TLS_OK; + } + } + if (cons->tls_authenticate) { + 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)); + password = director->password; + /* TLS Requirement */ + if (director->tls_enable) { + if (director->tls_require) { + tls_local_need = BNET_TLS_REQUIRED; + } else { + tls_local_need = BNET_TLS_OK; + } + } + + if (director->tls_authenticate) { + 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); + + if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) || + !cram_md5_challenge(dir, password, tls_local_need, compatible)) { + goto bail_out; + } - if (!cram_md5_get_auth(dir, director->password, ssl_need) || - !cram_md5_auth(dir, director->password, ssl_need)) { - Pmsg0(-1, _("Director authorization problem.\n" - "Most likely the passwords do not agree.\n")); - return 0; + /* Verify that the remote host is willing to meet our TLS requirements */ + if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) { + sendit(_("Authorization problem:" + " Remote server did not advertise required TLS support.\n")); + goto bail_out; } + /* Verify that we are willing to meet the remote host's requirements */ + if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) { + sendit(_("Authorization problem:" + " Remote server requires TLS.\n")); + goto bail_out; + } + + /* 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(tls_ctx, dir, NULL)) { + sendit(_("TLS negotiation failed\n")); + goto bail_out; + } + if (tls_authenticate) { /* Authenticate only? */ + dir->free_tls(); /* yes, shutdown tls */ + } + } + + /* + * It's possible that the TLS connection will + * be dropped here if an invalid client certificate was presented + */ Dmsg1(6, ">dird: %s", dir->msg); - if (bnet_recv(dir) <= 0) { - Pmsg1(-1, "Bad response to Hello command: ERR=%s\n", - bnet_strerror(dir)); - Pmsg0(-1, "The Director is probably not running.\n"); - return 0; + if (dir->recv() <= 0) { + senditf(_("Bad response to Hello command: ERR=%s\n"), + dir->bstrerror()); + goto bail_out; } + Dmsg1(10, "msg); if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) { - Pmsg0(-1, "Director rejected Hello command\n"); - return 0; + sendit(_("Director rejected Hello command\n")); + goto bail_out; } else { - Pmsg1(-1, "%s", dir->msg); + sendit(dir->msg); } + stop_bsock_timer(tid); return 1; + +bail_out: + stop_bsock_timer(tid); + 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")); + return 0; }