]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/gnome2-console/authenticate.c
======================= Warning ==========================
[bacula/bacula] / bacula / src / gnome2-console / authenticate.c
1 /*
2  *
3  *   Bacula UA authentication. Provides authentication with
4  *     the Director.
5  *
6  *     Kern Sibbald, June MMI
7  *
8  *     Version $Id$
9  *
10  *    This routine runs as a thread and must be thread reentrant.
11  *
12  *  Basic tasks done here:
13  *
14  */
15 /*
16    Copyright (C) 2000, 2001 Kern Sibbald and John Walker
17
18    This program is free software; you can redistribute it and/or
19    modify it under the terms of the GNU General Public License
20    as published by the Free Software Foundation; either version 2
21    of the License, or (at your option) any later version.
22
23    This program is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26    GNU General Public License for more details.
27
28    You should have received a copy of the GNU General Public License
29    along with this program; if not, write to the Free Software
30    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31  */
32
33 #include "bacula.h"
34 #include "console.h"
35
36
37 /* Commands sent to Director */
38 static char hello[]    = "Hello %s calling\n";
39
40 /* Response from Director */
41 static char OKhello[]   = "1000 OK:";
42
43 /* Forward referenced functions */
44
45 /*
46  * Authenticate Director
47  */
48 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
49 {
50    BSOCK *dir = jcr->dir_bsock;
51    int tls_local_need = BNET_TLS_NONE;
52    int tls_remote_need = BNET_TLS_NONE;
53    int compatible = true;
54    char bashed_name[MAX_NAME_LENGTH];
55    char *password;
56
57    /*
58     * Send my name to the Director then do authentication
59     */
60    if (cons) {
61       bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
62       bash_spaces(bashed_name);
63       password = cons->password;
64    } else {
65       bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
66       password = director->password;
67    }
68    /* Timeout Hello after 5 mins */
69    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
70    bnet_fsend(dir, hello, bashed_name);
71
72    /* respond to Dir challenge */
73    if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
74        /* Now challenge dir */
75        !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
76       stop_bsock_timer(tid);
77       printf(_("%s: Director authorization problem.\n"), my_name);
78       set_text(_("Director authorization problem.\n"), -1);
79       set_text(_(
80        "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"),
81         -1);
82       return 0;
83    }
84
85    Dmsg1(6, ">dird: %s", dir->msg);
86    if (bnet_recv(dir) <= 0) {
87       stop_bsock_timer(tid);
88       set_textf(_("Bad response to Hello command: ERR=%s\n"),
89          bnet_strerror(dir));
90       printf(_("%s: Bad response to Hello command: ERR=%s\n"),
91          my_name, bnet_strerror(dir));
92       set_text(_("The Director is probably not running.\n"), -1);
93       return 0;
94    }
95   stop_bsock_timer(tid);
96    Dmsg1(10, "<dird: %s", dir->msg);
97    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
98       set_text(_("Director rejected Hello command\n"), -1);
99       return 0;
100    } else {
101       set_text(dir->msg, dir->msglen);
102    }
103    return 1;
104 }