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 "tray-monitor.h"
36 void senditf(const char *fmt, ...);
37 void sendit(const char *buf);
39 /* Commands sent to Storage daemon and File daemon and received
40 * from the User Agent */
41 static char hello[] = "Hello Director %s calling\n";
43 /* Response from FD */
44 static char FDOKhello[] = "2000 OK Hello\n";
46 /* Forward referenced functions */
49 * Authenticate File daemon connection
51 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
53 BSOCK *fd = jcr->file_bsock;
54 char dirname[MAX_NAME_LENGTH];
55 int ssl_need = BNET_SSL_NONE;
58 * Send my name to the File daemon then do authentication
60 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
62 /* Timeout Hello after 5 mins */
63 btimer_t *tid = start_bsock_timer(fd, 60 * 5);
64 if (!bnet_fsend(fd, hello, dirname)) {
65 stop_bsock_timer(tid);
66 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
69 if (!cram_md5_get_auth(fd, client->password, ssl_need) ||
70 !cram_md5_auth(fd, client->password, ssl_need)) {
71 stop_bsock_timer(tid);
72 Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"
73 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
76 Dmsg1(116, ">filed: %s", fd->msg);
77 if (bnet_recv(fd) <= 0) {
78 stop_bsock_timer(tid);
79 Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
83 Dmsg1(110, "<stored: %s", fd->msg);
84 stop_bsock_timer(tid);
85 if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) {
86 Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));