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 tls_local_need = BNET_TLS_NONE;
63 int tls_remote_need = BNET_TLS_NONE;
64 char bashed_name[MAX_NAME_LENGTH];
67 bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name));
68 bash_spaces(bashed_name);
69 password = mon->password;
71 /* Timeout Hello after 5 mins */
72 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
73 bnet_fsend(dir, DIRhello, bashed_name);
75 if (!cram_md5_get_auth(dir, password, &tls_remote_need) ||
76 !cram_md5_auth(dir, password, tls_local_need)) {
77 stop_bsock_timer(tid);
78 Jmsg0(jcr, M_FATAL, 0, _("Director authorization problem.\n"
79 "Most likely the passwords do not agree.\n"
80 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
84 Dmsg1(6, ">dird: %s", dir->msg);
85 if (bnet_recv(dir) <= 0) {
86 stop_bsock_timer(tid);
87 Jmsg1(jcr, M_FATAL, 0, _("Bad response to Hello command: ERR=%s\n"),
91 Dmsg1(10, "<dird: %s", dir->msg);
92 stop_bsock_timer(tid);
93 if (strncmp(dir->msg, DIROKhello, sizeof(DIROKhello)-1) != 0) {
94 Jmsg0(jcr, M_FATAL, 0, _("Director rejected Hello command\n"));
97 Jmsg0(jcr, M_FATAL, 0, dir->msg);
103 * Authenticate Storage daemon connection
105 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
107 BSOCK *sd = jcr->store_bsock;
108 char dirname[MAX_NAME_LENGTH];
109 int tls_local_need = BNET_TLS_NONE;
110 int tls_remote_need = BNET_TLS_NONE;
113 * Send my name to the Storage daemon then do authentication
115 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
116 bash_spaces(dirname);
117 /* Timeout Hello after 5 mins */
118 btimer_t *tid = start_bsock_timer(sd, 60 * 5);
119 if (!bnet_fsend(sd, SDFDhello, dirname)) {
120 stop_bsock_timer(tid);
121 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
124 if (!cram_md5_get_auth(sd, store->password, &tls_remote_need) ||
125 !cram_md5_auth(sd, store->password, tls_local_need)) {
126 stop_bsock_timer(tid);
127 Jmsg0(jcr, M_FATAL, 0, _("Director and Storage daemon passwords or names not the same.\n"
128 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
131 Dmsg1(116, ">stored: %s", sd->msg);
132 if (bnet_recv(sd) <= 0) {
133 stop_bsock_timer(tid);
134 Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
138 Dmsg1(110, "<stored: %s", sd->msg);
139 stop_bsock_timer(tid);
140 if (strncmp(sd->msg, SDOKhello, sizeof(SDOKhello)) != 0) {
141 Jmsg0(jcr, M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
148 * Authenticate File daemon connection
150 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
152 BSOCK *fd = jcr->file_bsock;
153 char dirname[MAX_NAME_LENGTH];
154 int tls_local_need = BNET_TLS_NONE;
155 int tls_remote_need = BNET_TLS_NONE;
158 * Send my name to the File daemon then do authentication
160 bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
161 bash_spaces(dirname);
162 /* Timeout Hello after 5 mins */
163 btimer_t *tid = start_bsock_timer(fd, 60 * 5);
164 if (!bnet_fsend(fd, SDFDhello, dirname)) {
165 stop_bsock_timer(tid);
166 Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
169 if (!cram_md5_get_auth(fd, client->password, &tls_remote_need) ||
170 !cram_md5_auth(fd, client->password, tls_local_need)) {
171 stop_bsock_timer(tid);
172 Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"
173 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
176 Dmsg1(116, ">filed: %s", fd->msg);
177 if (bnet_recv(fd) <= 0) {
178 stop_bsock_timer(tid);
179 Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
183 Dmsg1(110, "<stored: %s", fd->msg);
184 stop_bsock_timer(tid);
185 if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) {
186 Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));