]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/authenticate.c
- Add more documentation to mtx-changer.in
[bacula/bacula] / bacula / src / wx-console / 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 License
27    along with this program; if not, write to the Free Software
28    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29  */
30
31 #include "bacula.h"
32 #include "console_conf.h"
33 #include "jcr.h"
34
35 #include "csprint.h"
36
37 void senditf(char *fmt, ...);
38 void sendit(char *buf);
39
40 /* Commands sent to Director */
41 static char hello[]    = "Hello %s calling\n";
42
43 /* Response from Director */
44 static char OKhello[]   = "1000 OK:";
45
46 /* Forward referenced functions */
47
48 /*
49  * Authenticate Director
50  */
51 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
52 {
53    BSOCK *dir = jcr->dir_bsock;
54    int tls_local_need = BNET_TLS_NONE;
55    int tls_remote_need = BNET_TLS_NONE;
56    char bashed_name[MAX_NAME_LENGTH];
57    char *password;
58
59    /*
60     * Send my name to the Director then do authentication
61     */
62    if (cons) {
63       bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
64       bash_spaces(bashed_name);
65       password = cons->password;
66    } else {
67       bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
68       password = director->password;
69    }
70    /* Timeout Hello after 5 mins */
71    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
72    bnet_fsend(dir, hello, bashed_name);
73
74    if (!cram_md5_get_auth(dir, password, &tls_remote_need) ||
75        !cram_md5_auth(dir, password, tls_local_need)) {
76       stop_bsock_timer(tid);
77       csprint("Director authorization problem.\nMost likely the passwords do not agree.\n", CS_DATA);
78       csprint(
79        "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n", CS_DATA);
80       return 0;
81    }
82
83    Dmsg1(6, ">dird: %s", dir->msg);
84    if (bnet_recv(dir) <= 0) {
85       stop_bsock_timer(tid);
86       csprint("Bad response to Hello command: ERR=", CS_DATA);
87       csprint(bnet_strerror(dir), CS_DATA);
88       csprint("\n", CS_DATA);
89       return 0;
90    }
91    Dmsg1(10, "<dird: %s", dir->msg);
92    stop_bsock_timer(tid);
93    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
94       csprint("Director rejected Hello command\n", CS_DATA);
95       return 0;
96    } else {
97       csprint(dir->msg, CS_DATA);
98    }
99    return 1;
100 }