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 ssl_need = BNET_SSL_NONE;
55 char bashed_name[MAX_NAME_LENGTH];
59 * Send my name to the Director then do authentication
62 bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
63 bash_spaces(bashed_name);
64 password = cons->password;
66 bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
67 password = director->password;
69 /* Timeout Hello after 5 mins */
70 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
71 bnet_fsend(dir, hello, bashed_name);
73 if (!cram_md5_get_auth(dir, password, ssl_need) ||
74 !cram_md5_auth(dir, password, ssl_need)) {
75 stop_bsock_timer(tid);
76 sendit( _("Director authorization problem.\n"
77 "Most likely the passwords do not agree.\n"
78 "Please see http://www.bacula.org/html-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 senditf(_("Bad response to Hello command: ERR=%s\n"),
89 Dmsg1(10, "<dird: %s", dir->msg);
90 stop_bsock_timer(tid);
91 if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
92 sendit(_("Director rejected Hello command\n"));