2 Bacula® - The Network Backup Solution
4 Copyright (C) 2001-2009 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
31 * Bacula UA authentication. Provides authentication with
34 * Kern Sibbald, June MMI adapted to bat, Jan MMVI
44 /* Commands sent to Director */
45 static char hello[] = "Hello %s calling\n";
47 /* Response from Director */
48 static char OKhello[] = "1000 OK:";
50 /* Forward referenced functions */
53 * Authenticate Director
55 bool DirComm::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons,
56 char *errmsg, int errmsg_len)
58 BSOCK *dir = jcr->dir_bsock;
59 int tls_local_need = BNET_TLS_NONE;
60 int tls_remote_need = BNET_TLS_NONE;
61 bool tls_authenticate;
62 int compatible = true;
63 char bashed_name[MAX_NAME_LENGTH];
65 TLS_CONTEXT *tls_ctx = NULL;
69 * Send my name to the Director then do authentication
72 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
73 bash_spaces(bashed_name);
74 password = cons->password;
76 if (cons->tls_enable) {
77 if (cons->tls_require) {
78 tls_local_need = BNET_TLS_REQUIRED;
80 tls_local_need = BNET_TLS_OK;
83 tls_authenticate = cons->tls_authenticate;
84 tls_ctx = cons->tls_ctx;
86 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
87 password = director->password;
89 if (director->tls_enable) {
90 if (director->tls_require) {
91 tls_local_need = BNET_TLS_REQUIRED;
93 tls_local_need = BNET_TLS_OK;
97 tls_authenticate = director->tls_authenticate;
98 tls_ctx = director->tls_ctx;
100 if (tls_authenticate) {
101 tls_local_need = BNET_TLS_REQUIRED;
104 /* Timeout Hello after 15 secs */
105 // Temp turn this off until we workout how to make sigusr2 work with Qt
106 // dir->start_timer(15);
107 dir->fsend(hello, bashed_name);
109 /* respond to Dir challenge */
110 if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
111 /* Now challenge dir */
112 !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
113 bsnprintf(errmsg, errmsg_len, _("Director authorization problem at \"%s:%d\"\n"),
114 dir->host(), dir->port());
118 /* Verify that the remote host is willing to meet our TLS requirements */
119 if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
120 bsnprintf(errmsg, errmsg_len, _("Authorization problem:"
121 " Remote server at \"%s:%d\" did not advertise required TLS support.\n"),
122 dir->host(), dir->port());
126 /* Verify that we are willing to meet the remote host's requirements */
127 if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
128 bsnprintf(errmsg, errmsg_len, _("Authorization problem with Director at \"%s:%d\":"
129 " Remote server requires TLS.\n"),
130 dir->host(), dir->port());
135 /* Is TLS Enabled? */
136 if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
137 /* Engage TLS! Full Speed Ahead! */
138 if (!bnet_tls_client(tls_ctx, dir, NULL)) {
139 bsnprintf(errmsg, errmsg_len, _("TLS negotiation failed with Director at \"%s:%d\"\n"),
140 dir->host(), dir->port());
143 if (tls_authenticate) { /* authenticate only? */
144 dir->free_tls(); /* Yes, shutdown tls */
148 Dmsg1(6, ">dird: %s", dir->msg);
149 if (dir->recv() <= 0) {
151 bsnprintf(errmsg, errmsg_len, _("Bad response to Hello command: ERR=%s\n"
152 "The Director at \"%s:%d\" is probably not running.\n"),
153 dir->bstrerror(), dir->host(), dir->port());
158 Dmsg1(10, "<dird: %s", dir->msg);
159 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
160 bsnprintf(errmsg, errmsg_len, _("Director at \"%s:%d\" rejected Hello command\n"),
161 dir->host(), dir->port());
164 bsnprintf(errmsg, errmsg_len, "%s", dir->msg);
170 bsnprintf(errmsg, errmsg_len, _("Authorization problem with Director at \"%s:%d\"\n"
171 "Most likely the passwords do not agree.\n"
172 "If you are using TLS, there may have been a certificate validation error during the TLS handshake.\n"
173 "Please see http://www.bacula.org/en/rel-manual/Bacula_Freque_Asked_Questi.html#SECTION003760000000000000000 for help.\n"),
174 dir->host(), dir->port());