]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tray-monitor/authenticate.c
f6afcf4a2106b1e6f610a2273f304ff1cc467b54
[bacula/bacula] / bacula / src / tray-monitor / authenticate.c
1 /*
2  *
3  *   Bacula UA authentication. Provides authentication with
4  *     the Director.
5  *
6  *     Kern Sibbald, June MMI
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) 2001-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 Storage daemon and File daemon and received
40  *  from the User Agent */
41 static char hello[]    = "Hello Director %s calling\n";
42
43 /* Response from FD */
44 static char FDOKhello[] = "2000 OK Hello\n";
45
46 /* Forward referenced functions */
47
48 /*
49  * Authenticate File daemon connection
50  */
51 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
52 {
53    BSOCK *fd = jcr->file_bsock;
54    char dirname[MAX_NAME_LENGTH];
55    int ssl_need = BNET_SSL_NONE;
56
57    /* 
58     * Send my name to the File daemon then do authentication
59     */
60    bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
61    bash_spaces(dirname);
62    /* Timeout Hello after 5 mins */
63    btimer_t *tid = start_bsock_timer(fd, 60 * 5);
64    if (!bnet_fsend(fd, hello, dirname)) {
65       stop_bsock_timer(tid);
66       Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
67       return 0;
68    }
69    if (!cram_md5_get_auth(fd, client->password, ssl_need) || 
70        !cram_md5_auth(fd, client->password, ssl_need)) {
71       stop_bsock_timer(tid);
72       Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"   
73        "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
74       return 0;
75    }
76    Dmsg1(116, ">filed: %s", fd->msg);
77    if (bnet_recv(fd) <= 0) {
78       stop_bsock_timer(tid);
79       Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
80          bnet_strerror(fd));
81       return 0;
82    }
83    Dmsg1(110, "<stored: %s", fd->msg);
84    stop_bsock_timer(tid);
85    if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)) != 0) {
86       Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));
87       return 0;
88    }
89    return 1;
90 }