3 * Bacula UA authentication. Provides authentication with
6 * Kern Sibbald, June MMI
10 * This routine runs as a thread and must be thread reentrant.
12 * Basic tasks done here:
16 Bacula® - The Network Backup Solution
18 Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
20 The main author of Bacula is Kern Sibbald, with contributions from
21 many others, a complete list can be found in the file AUTHORS.
22 This program is Free Software; you can redistribute it and/or
23 modify it under the terms of version two of the GNU General Public
24 License as published by the Free Software Foundation and included
27 This program is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 Bacula® is a registered trademark of John Walker.
38 The licensor of Bacula is the Free Software Foundation Europe
39 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
40 Switzerland, email:ftf@fsfeurope.org.
47 /* Commands sent to Director */
48 static char hello[] = "Hello %s calling\n";
50 /* Response from Director */
51 static char OKhello[] = "1000 OK:";
53 /* Forward referenced functions */
56 * Authenticate Director
58 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
60 BSOCK *dir = jcr->dir_bsock;
61 int tls_local_need = BNET_TLS_NONE;
62 int tls_remote_need = BNET_TLS_NONE;
63 int compatible = true;
64 char bashed_name[MAX_NAME_LENGTH];
68 * Send my name to the Director then do authentication
71 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
72 bash_spaces(bashed_name);
73 password = cons->password;
75 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
76 password = director->password;
78 /* Timeout Hello after 5 mins */
79 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
80 bnet_fsend(dir, hello, bashed_name);
82 /* respond to Dir challenge */
83 if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
84 /* Now challenge dir */
85 !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
86 stop_bsock_timer(tid);
87 printf(_("%s: Director authorization problem.\n"), my_name);
88 set_text(_("Director authorization problem.\n"), -1);
90 "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"),
95 Dmsg1(6, ">dird: %s", dir->msg);
96 if (bnet_recv(dir) <= 0) {
97 stop_bsock_timer(tid);
98 set_textf(_("Bad response to Hello command: ERR=%s\n"),
100 printf(_("%s: Bad response to Hello command: ERR=%s\n"),
101 my_name, bnet_strerror(dir));
102 set_text(_("The Director is probably not running.\n"), -1);
105 stop_bsock_timer(tid);
106 Dmsg1(10, "<dird: %s", dir->msg);
107 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
108 set_text(_("Director rejected Hello command\n"), -1);
111 set_text(dir->msg, dir->msglen);