]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tray-monitor/authenticate.c
added VSS toggling by enable_vss
[bacula/bacula] / bacula / src / tray-monitor / authenticate.c
1 /*
2  *
3  *   Bacula authentication. Provides authentication with
4  *     File and Storage daemons.
5  *
6  *     Nicolas Boichat, August MMIV
7  *
8  *    This routine runs as a thread and must be thread reentrant.
9  *
10  *  Basic tasks done here:
11  *
12  */
13 /*
14    Copyright (C) 2004 Kern Sibbald and John Walker
15
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.
20
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.
25
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,
29    MA 02111-1307, USA.
30  */
31
32 #include "bacula.h"
33 #include "tray-monitor.h"
34 #include "jcr.h"
35
36 void senditf(const char *fmt, ...);
37 void sendit(const char *buf);
38
39 /* Commands sent to Director */
40 static char DIRhello[]    = "Hello %s calling\n";
41
42 /* Response from Director */
43 static char DIROKhello[]   = "1000 OK:";
44
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";
48
49 /* Response from SD */
50 static char SDOKhello[]   = "3000 OK Hello\n";
51 /* Response from FD */
52 static char FDOKhello[] = "2000 OK Hello\n";
53
54 /* Forward referenced functions */
55
56 /*
57  * Authenticate Director
58  */
59 int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director)
60 {
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];
65    char *password;
66
67    bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name));
68    bash_spaces(bashed_name);
69    password = mon->password;
70
71    /* Timeout Hello after 5 mins */
72    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
73    bnet_fsend(dir, DIRhello, bashed_name);
74
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"));
81       return 0;
82    }
83
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"),
88          bnet_strerror(dir));
89       return 0;
90    }
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"));
95       return 0;
96    } else {
97       Jmsg0(jcr, M_FATAL, 0, dir->msg);
98    }
99    return 1;
100 }
101
102 /*
103  * Authenticate Storage daemon connection
104  */
105 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
106 {
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;
111
112    /*
113     * Send my name to the Storage daemon then do authentication
114     */
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));
122       return 0;
123    }
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"));
129       return 0;
130    }
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"),
135          bnet_strerror(sd));
136       return 0;
137    }
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"));
142       return 0;
143    }
144    return 1;
145 }
146
147 /*
148  * Authenticate File daemon connection
149  */
150 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
151 {
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;
156
157    /*
158     * Send my name to the File daemon then do authentication
159     */
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));
167       return 0;
168    }
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"));
174       return 0;
175    }
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"),
180          bnet_strerror(fd));
181       return 0;
182    }
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"));
187       return 0;
188    }
189    return 1;
190 }