3 * Bacula authentication. Provides authentication with
4 * File and Storage daemons.
6 * Nicolas Boichat, August MMIV
8 * This routine runs as a thread and must be thread reentrant.
10 * Basic tasks done here:
14 Copyright (C) 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 SD */
44 static char OKhello[] = "3000 OK Hello\n";
45 /* Response from FD */
46 static char FDOKhello[] = "2000 OK Hello\n";
48 /* Forward referenced functions */
51 * Authenticate Storage daemon connection
53 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
55 BSOCK *sd = jcr->store_bsock;
56 char dirname[MAX_NAME_LENGTH];
57 int ssl_need = BNET_SSL_NONE;
60 * Send my name to the Storage daemon then do authentication
62 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
64 /* Timeout Hello after 5 mins */
65 btimer_t *tid = start_bsock_timer(sd, 60 * 5);
66 if (!bnet_fsend(sd, hello, dirname)) {
67 stop_bsock_timer(tid);
68 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
71 if (!cram_md5_get_auth(sd, store->password, ssl_need) ||
72 !cram_md5_auth(sd, store->password, ssl_need)) {
73 stop_bsock_timer(tid);
74 Jmsg0(jcr, M_FATAL, 0, _("Director and Storage daemon passwords or names not the same.\n"
75 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
78 Dmsg1(116, ">stored: %s", sd->msg);
79 if (bnet_recv(sd) <= 0) {
80 stop_bsock_timer(tid);
81 Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
85 Dmsg1(110, "<stored: %s", sd->msg);
86 stop_bsock_timer(tid);
87 if (strncmp(sd->msg, OKhello, sizeof(OKhello)) != 0) {
88 Jmsg0(jcr, M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
95 * Authenticate File daemon connection
97 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
99 BSOCK *fd = jcr->file_bsock;
100 char dirname[MAX_NAME_LENGTH];
101 int ssl_need = BNET_SSL_NONE;
104 * Send my name to the File daemon then do authentication
106 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
107 bash_spaces(dirname);
108 /* Timeout Hello after 5 mins */
109 btimer_t *tid = start_bsock_timer(fd, 60 * 5);
110 if (!bnet_fsend(fd, hello, dirname)) {
111 stop_bsock_timer(tid);
112 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
115 if (!cram_md5_get_auth(fd, client->password, ssl_need) ||
116 !cram_md5_auth(fd, client->password, ssl_need)) {
117 stop_bsock_timer(tid);
118 Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"
119 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
122 Dmsg1(116, ">filed: %s", fd->msg);
123 if (bnet_recv(fd) <= 0) {
124 stop_bsock_timer(tid);
125 Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
129 Dmsg1(110, "<stored: %s", fd->msg);
130 stop_bsock_timer(tid);
131 if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) {
132 Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));