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-2005 Kern Sibbald
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 version 2 as amended with additional clauses defined in the
19 file LICENSE in the main source directory.
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 the file LICENSE for additional details.
28 /* _("...") macro returns a wxChar*, so if we need a char*, we need to convert it with:
29 * wxString(_("...")).mb_str(*wxConvCurrent) */
34 #include "console_conf.h"
39 void senditf(char *fmt, ...);
40 void sendit(char *buf);
42 /* Commands sent to Director */
43 static char hello[] = "Hello %s calling\n";
45 /* Response from Director */
46 static char OKhello[] = "1000 OK:";
48 /* Forward referenced functions */
51 * Authenticate Director
53 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
55 BSOCK *dir = jcr->dir_bsock;
56 int tls_local_need = BNET_TLS_NONE;
57 int tls_remote_need = BNET_TLS_NONE;
58 char bashed_name[MAX_NAME_LENGTH];
60 TLS_CONTEXT *tls_ctx = NULL;
63 * Send my name to the Director then do authentication
66 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
67 bash_spaces(bashed_name);
68 password = cons->password;
70 if (cons->tls_enable) {
71 if (cons->tls_require) {
72 tls_local_need = BNET_TLS_REQUIRED;
74 tls_local_need = BNET_TLS_OK;
78 tls_ctx = cons->tls_ctx;
80 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
81 password = director->password;
83 if (director->tls_enable) {
84 if (director->tls_require) {
85 tls_local_need = BNET_TLS_REQUIRED;
87 tls_local_need = BNET_TLS_OK;
91 tls_ctx = director->tls_ctx;
95 /* Timeout Hello after 5 mins */
96 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
97 bnet_fsend(dir, hello, bashed_name);
99 if (!cram_md5_get_auth(dir, password, &tls_remote_need) ||
100 !cram_md5_auth(dir, password, tls_local_need)) {
104 /* Verify that the remote host is willing to meet our TLS requirements */
105 if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
106 csprint(_("Authorization problem:"
107 " Remote server did not advertise required TLS support.\n"));
111 /* Verify that we are willing to meet the remote host's requirements */
112 if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
113 csprint(_("Authorization problem:"
114 " Remote server requires TLS.\n"));
118 /* Is TLS Enabled? */
120 if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
121 /* Engage TLS! Full Speed Ahead! */
122 if (!bnet_tls_client(tls_ctx, dir)) {
123 csprint(_("TLS negotiation failed\n"));
129 Dmsg1(6, ">dird: %s", dir->msg);
130 if (bnet_recv(dir) <= 0) {
131 csprint(_("Bad response to Hello command: ERR="), CS_DATA);
132 csprint(bnet_strerror(dir), CS_DATA);
133 csprint("\n", CS_DATA);
136 Dmsg1(10, "<dird: %s", dir->msg);
137 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
138 csprint(_("Director rejected Hello command\n"), CS_DATA);
141 csprint(dir->msg, CS_DATA);
143 stop_bsock_timer(tid);
147 stop_bsock_timer(tid);
148 csprint( _("Director authorization problem.\nMost likely the passwords do not agree.\nIf you are using TLS, there may have been a certificate validation error during the TLS handshake.\nPlease see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));