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 Copyright (C) 2001-2006 Kern Sibbald
18 This program is free software; you can redistribute it and/or
19 modify it under the terms of the GNU General Public License
20 version 2 as amended with additional clauses defined in the
21 file LICENSE in the main source directory.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 the file LICENSE for additional details.
34 /* Commands sent to Director */
35 static char hello[] = "Hello %s calling\n";
37 /* Response from Director */
38 static char OKhello[] = "1000 OK:";
40 /* Forward referenced functions */
43 * Authenticate Director
45 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
47 BSOCK *dir = jcr->dir_bsock;
48 int tls_local_need = BNET_TLS_NONE;
49 int tls_remote_need = BNET_TLS_NONE;
50 int compatible = true;
51 char bashed_name[MAX_NAME_LENGTH];
55 * Send my name to the Director then do authentication
58 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
59 bash_spaces(bashed_name);
60 password = cons->password;
62 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
63 password = director->password;
65 /* Timeout Hello after 5 mins */
66 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
67 bnet_fsend(dir, hello, bashed_name);
69 /* respond to Dir challenge */
70 if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
71 /* Now challenge dir */
72 !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
73 stop_bsock_timer(tid);
74 printf(_("%s: Director authorization problem.\n"), my_name);
75 set_text(_("Director authorization problem.\n"), -1);
77 "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"),
82 Dmsg1(6, ">dird: %s", dir->msg);
83 if (bnet_recv(dir) <= 0) {
84 stop_bsock_timer(tid);
85 set_textf(_("Bad response to Hello command: ERR=%s\n"),
87 printf(_("%s: Bad response to Hello command: ERR=%s\n"),
88 my_name, bnet_strerror(dir));
89 set_text(_("The Director is probably not running.\n"), -1);
92 stop_bsock_timer(tid);
93 Dmsg1(10, "<dird: %s", dir->msg);
94 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
95 set_text(_("Director rejected Hello command\n"), -1);
98 set_text(dir->msg, dir->msglen);