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 Director */
40 static char DIRhello[] = "Hello %s calling\n";
42 /* Response from Director */
43 static char DIROKhello[] = "1000 OK:";
45 /* Commands sent to Storage daemon and File daemon and received
46 * from the User Agent */
47 static char SDFDhello[] = "Hello Director %s calling\n";
49 /* Response from SD */
50 static char SDOKhello[] = "3000 OK Hello\n";
51 /* Response from FD */
52 static char FDOKhello[] = "2000 OK Hello\n";
54 /* Forward referenced functions */
57 * Authenticate Director
59 int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director)
61 BSOCK *dir = jcr->dir_bsock;
62 int ssl_need = BNET_SSL_NONE;
63 char bashed_name[MAX_NAME_LENGTH];
66 bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name));
67 bash_spaces(bashed_name);
68 password = mon->password;
70 /* Timeout Hello after 5 mins */
71 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
72 bnet_fsend(dir, DIRhello, bashed_name);
74 if (!cram_md5_get_auth(dir, password, ssl_need) ||
75 !cram_md5_auth(dir, password, ssl_need)) {
76 stop_bsock_timer(tid);
77 Jmsg0(jcr, M_FATAL, 0, _("Director authorization problem.\n"
78 "Most likely the passwords do not agree.\n"
79 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
83 Dmsg1(6, ">dird: %s", dir->msg);
84 if (bnet_recv(dir) <= 0) {
85 stop_bsock_timer(tid);
86 Jmsg1(jcr, M_FATAL, 0, _("Bad response to Hello command: ERR=%s\n"),
90 Dmsg1(10, "<dird: %s", dir->msg);
91 stop_bsock_timer(tid);
92 if (strncmp(dir->msg, DIROKhello, sizeof(DIROKhello)-1) != 0) {
93 Jmsg0(jcr, M_FATAL, 0, _("Director rejected Hello command\n"));
96 Jmsg0(jcr, M_FATAL, 0, dir->msg);
102 * Authenticate Storage daemon connection
104 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
106 BSOCK *sd = jcr->store_bsock;
107 char dirname[MAX_NAME_LENGTH];
108 int ssl_need = BNET_SSL_NONE;
111 * Send my name to the Storage daemon then do authentication
113 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
114 bash_spaces(dirname);
115 /* Timeout Hello after 5 mins */
116 btimer_t *tid = start_bsock_timer(sd, 60 * 5);
117 if (!bnet_fsend(sd, SDFDhello, dirname)) {
118 stop_bsock_timer(tid);
119 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
122 if (!cram_md5_get_auth(sd, store->password, ssl_need) ||
123 !cram_md5_auth(sd, store->password, ssl_need)) {
124 stop_bsock_timer(tid);
125 Jmsg0(jcr, M_FATAL, 0, _("Director and Storage daemon passwords or names not the same.\n"
126 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
129 Dmsg1(116, ">stored: %s", sd->msg);
130 if (bnet_recv(sd) <= 0) {
131 stop_bsock_timer(tid);
132 Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
136 Dmsg1(110, "<stored: %s", sd->msg);
137 stop_bsock_timer(tid);
138 if (strncmp(sd->msg, SDOKhello, sizeof(SDOKhello)) != 0) {
139 Jmsg0(jcr, M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
146 * Authenticate File daemon connection
148 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
150 BSOCK *fd = jcr->file_bsock;
151 char dirname[MAX_NAME_LENGTH];
152 int ssl_need = BNET_SSL_NONE;
155 * Send my name to the File daemon then do authentication
157 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
158 bash_spaces(dirname);
159 /* Timeout Hello after 5 mins */
160 btimer_t *tid = start_bsock_timer(fd, 60 * 5);
161 if (!bnet_fsend(fd, SDFDhello, dirname)) {
162 stop_bsock_timer(tid);
163 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
166 if (!cram_md5_get_auth(fd, client->password, ssl_need) ||
167 !cram_md5_auth(fd, client->password, ssl_need)) {
168 stop_bsock_timer(tid);
169 Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"
170 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
173 Dmsg1(116, ">filed: %s", fd->msg);
174 if (bnet_recv(fd) <= 0) {
175 stop_bsock_timer(tid);
176 Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
180 Dmsg1(110, "<stored: %s", fd->msg);
181 stop_bsock_timer(tid);
182 if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) {
183 Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));