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 Bacula® - The Network Backup Solution
16 Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
18 The main author of Bacula is Kern Sibbald, with contributions from
19 many others, a complete list can be found in the file AUTHORS.
20 This program is Free Software; you can redistribute it and/or
21 modify it under the terms of version three of the GNU Affero General Public
22 License as published by the Free Software Foundation plus additions
23 that are listed in the file LICENSE.
25 This program is distributed in the hope that it will be useful, but
26 WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received a copy of the GNU Affero General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 Bacula® is a registered trademark of John Walker.
36 The licensor of Bacula is the Free Software Foundation Europe
37 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
38 Switzerland, email:ftf@fsfeurope.org.
42 #include "check_bacula.h"
44 void senditf(const char *fmt, ...);
45 void sendit(const char *buf);
47 /* Commands sent to Director */
48 static char DIRhello[] = "Hello %s calling\n";
50 /* Response from Director */
51 static char DIROKhello[] = "1000 OK:";
53 /* Commands sent to Storage daemon and File daemon and received
54 * from the User Agent */
55 static char SDFDhello[] = "Hello Director %s calling\n";
57 /* Response from SD */
58 static char SDOKhello[] = "3000 OK Hello\n";
59 /* Response from FD */
60 static char FDOKhello[] = "2000 OK Hello";
62 /* Forward referenced functions */
65 * Authenticate Director
67 int authenticate_director(BSOCK *dir, char *dirname, char *password)
69 int tls_local_need = BNET_TLS_NONE;
70 int tls_remote_need = BNET_TLS_NONE;
71 int compatible = true;
72 char bashed_name[MAX_NAME_LENGTH];
74 bstrncpy(bashed_name, dirname, sizeof(bashed_name));
75 bash_spaces(bashed_name);
77 /* Timeout Hello after 5 mins */
78 btimer_t *tid = start_bsock_timer(dir, 60 * 5);
79 bnet_fsend(dir, DIRhello, bashed_name);
81 if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
82 !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
83 stop_bsock_timer(tid);
87 Dmsg1(6, ">dird: %s", dir->msg);
88 if (bnet_recv(dir) <= 0) {
89 stop_bsock_timer(tid);
92 Dmsg1(10, "<dird: %s", dir->msg);
93 stop_bsock_timer(tid);
94 if (strncmp(dir->msg, DIROKhello, sizeof(DIROKhello)-1) != 0) {
101 * Authenticate Storage daemon connection
103 int authenticate_storage_daemon(BSOCK *sd, char *sdname, char* password)
105 char dirname[MAX_NAME_LENGTH];
106 int tls_local_need = BNET_TLS_NONE;
107 int tls_remote_need = BNET_TLS_NONE;
108 int compatible = true;
111 * Send my name to the Storage daemon then do authentication
113 bstrncpy(dirname, sdname, 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);
121 if (!cram_md5_respond(sd, password, &tls_remote_need, &compatible) ||
122 !cram_md5_challenge(sd, password, tls_local_need, compatible)) {
123 stop_bsock_timer(tid);
126 Dmsg1(116, ">stored: %s", sd->msg);
127 if (bnet_recv(sd) <= 0) {
128 stop_bsock_timer(tid);
131 Dmsg1(110, "<stored: %s", sd->msg);
132 stop_bsock_timer(tid);
133 if (strncmp(sd->msg, SDOKhello, sizeof(SDOKhello)) != 0) {
140 * Authenticate File daemon connection
142 int authenticate_file_daemon(BSOCK *fd, char *fdname, char *password)
144 char dirname[MAX_NAME_LENGTH];
145 int tls_local_need = BNET_TLS_NONE;
146 int tls_remote_need = BNET_TLS_NONE;
147 int compatible = true;
150 * Send my name to the File daemon then do authentication
152 bstrncpy(dirname, fdname, sizeof(dirname));
153 bash_spaces(dirname);
154 /* Timeout Hello after 5 mins */
155 btimer_t *tid = start_bsock_timer(fd, 60 * 5);
156 if (!bnet_fsend(fd, SDFDhello, dirname)) {
157 stop_bsock_timer(tid);
160 if (!cram_md5_respond(fd, password, &tls_remote_need, &compatible) ||
161 !cram_md5_challenge(fd, password, tls_local_need, compatible)) {
162 stop_bsock_timer(tid);
165 Dmsg1(116, ">filed: %s", fd->msg);
166 if (bnet_recv(fd) <= 0) {
167 stop_bsock_timer(tid);
170 Dmsg1(110, "<stored: %s", fd->msg);
171 stop_bsock_timer(tid);
172 if ((strncmp(fd->msg, FDOKhello, strlen(FDOKhello)) != 0)) {