3 * Bacula UA authentication. Provides authentication with
6 * Kern Sibbald, June MMI
8 * This routine runs as a thread and must be thread reentrant.
10 * Basic tasks done here:
14 Copyright (C) 2001-2004 Kern Sibbald and John Walker
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public
27 License along with this program; if not, write to the Free
28 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33 #include "console_conf.h"
37 void senditf(const char *fmt, ...);
38 void sendit(const char *buf);
40 /* Commands sent to Director */
41 static char hello[] = "Hello %s calling\n";
43 /* Response from Director */
44 static char OKhello[] = "1000 OK:";
46 /* Forward referenced functions */
49 * Authenticate Director
51 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
53 BSOCK *dir = jcr->dir_bsock;
54 int tls_local_need = BNET_TLS_NONE;
55 int tls_remote_need = BNET_TLS_NONE;
56 char bashed_name[MAX_NAME_LENGTH];
58 TLS_CONTEXT *tls_ctx = NULL;
61 * Send my name to the Director then do authentication
64 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
65 bash_spaces(bashed_name);
66 password = cons->password;
68 if (cons->tls_enable) {
69 if (cons->tls_require) {
70 tls_local_need = BNET_TLS_REQUIRED;
72 tls_local_need = BNET_TLS_OK;
76 tls_ctx = cons->tls_ctx;
78 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
79 password = director->password;
81 if (director->tls_enable) {
82 if (director->tls_require) {
83 tls_local_need = BNET_TLS_REQUIRED;
85 tls_local_need = BNET_TLS_OK;
89 tls_ctx = director->tls_ctx;
93 /* Timeout Hello after 5 mins */
94 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
95 bnet_fsend(dir, hello, bashed_name);
97 if (!cram_md5_get_auth(dir, password, &tls_remote_need) ||
98 !cram_md5_auth(dir, password, tls_local_need)) {
102 /* Verify that the remote host is willing to meet our TLS requirements */
103 if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
104 sendit(_("Authorization problem:"
105 " Remote server did not advertise required TLS support.\n"));
109 /* Verify that we are willing to meet the remote host's requirements */
110 if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
111 sendit(_("Authorization problem:"
112 " Remote server requires TLS.\n"));
116 /* Is TLS Enabled? */
118 if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
119 /* Engage TLS! Full Speed Ahead! */
120 if (!bnet_tls_client(tls_ctx, dir)) {
121 sendit(_("TLS negotiation failed\n"));
128 * It's possible that the TLS connection will
129 * be dropped here if an invalid client certificate was presented
131 Dmsg1(6, ">dird: %s", dir->msg);
132 if (bnet_recv(dir) <= 0) {
133 senditf(_("Bad response to Hello command: ERR=%s\n"),
138 Dmsg1(10, "<dird: %s", dir->msg);
139 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
140 sendit(_("Director rejected Hello command\n"));
145 stop_bsock_timer(tid);
149 stop_bsock_timer(tid);
150 sendit( _("Director authorization problem.\n"
151 "Most likely the passwords do not agree.\n"
152 "If you are using TLS, there may have been a certificate validation error during the TLS handshake.\n"
153 "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));