]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/tray-monitor/authenticate.c
- Add spin button to set refresh interval.
[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 ssl_need = BNET_SSL_NONE;
63    char bashed_name[MAX_NAME_LENGTH];
64    char *password;
65
66    bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name));
67    bash_spaces(bashed_name);
68    password = mon->password;
69    
70    /* Timeout Hello after 5 mins */
71    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
72    bnet_fsend(dir, DIRhello, bashed_name);
73
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"));
80       return 0;
81    }
82
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"),
87          bnet_strerror(dir));
88       return 0;
89    }
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"));
94       return 0;
95    } else {
96       Jmsg0(jcr, M_FATAL, 0, dir->msg);
97    }
98    return 1;
99 }
100
101 /*
102  * Authenticate Storage daemon connection
103  */
104 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
105 {
106    BSOCK *sd = jcr->store_bsock;
107    char dirname[MAX_NAME_LENGTH];
108    int ssl_need = BNET_SSL_NONE;
109
110    /* 
111     * Send my name to the Storage daemon then do authentication
112     */
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));
120       return 0;
121    }
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"));
127       return 0;
128    }
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"),
133          bnet_strerror(sd));
134       return 0;
135    }
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"));
140       return 0;
141    }
142    return 1;
143 }
144
145 /*
146  * Authenticate File daemon connection
147  */
148 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client)
149 {
150    BSOCK *fd = jcr->file_bsock;
151    char dirname[MAX_NAME_LENGTH];
152    int ssl_need = BNET_SSL_NONE;
153
154    /* 
155     * Send my name to the File daemon then do authentication
156     */
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));
164       return 0;
165    }
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"));
171       return 0;
172    }
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"),
177          bnet_strerror(fd));
178       return 0;
179    }
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"));
184       return 0;
185    }
186    return 1;
187 }