]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/gnome2-console/authenticate.c
kes Change Bacula trademark owner from John Walker to Kern Sibbald
[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    Bacula® - The Network Backup Solution
17
18    Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
19
20    The main author of Bacula is Kern Sibbald, with contributions from
21    many others, a complete list can be found in the file AUTHORS.
22    This program is Free Software; you can redistribute it and/or
23    modify it under the terms of version two of the GNU General Public
24    License as published by the Free Software Foundation and included
25    in the file LICENSE.
26
27    This program is distributed in the hope that it will be useful, but
28    WITHOUT ANY WARRANTY; without even the implied warranty of
29    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30    General Public License for more details.
31
32    You should have received a copy of the GNU General Public License
33    along with this program; if not, write to the Free Software
34    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35    02110-1301, USA.
36
37    Bacula® is a registered trademark of Kern Sibbald.
38    The licensor of Bacula is the Free Software Foundation Europe
39    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
40    Switzerland, email:ftf@fsfeurope.org.
41 */
42
43 #include "bacula.h"
44 #include "console.h"
45
46
47 /* Commands sent to Director */
48 static char hello[]    = "Hello %s calling\n";
49
50 /* Response from Director */
51 static char OKhello[]   = "1000 OK:";
52
53 /* Forward referenced functions */
54
55 /*
56  * Authenticate Director
57  */
58 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
59 {
60    BSOCK *dir = jcr->dir_bsock;
61    int tls_local_need = BNET_TLS_NONE;
62    int tls_remote_need = BNET_TLS_NONE;
63    int compatible = true;
64    char bashed_name[MAX_NAME_LENGTH];
65    char *password;
66
67    /*
68     * Send my name to the Director then do authentication
69     */
70    if (cons) {
71       bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
72       bash_spaces(bashed_name);
73       password = cons->password;
74    } else {
75       bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
76       password = director->password;
77    }
78    /* Timeout Hello after 5 mins */
79    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
80    bnet_fsend(dir, hello, bashed_name);
81
82    /* respond to Dir challenge */
83    if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
84        /* Now challenge dir */
85        !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
86       stop_bsock_timer(tid);
87       printf(_("%s: Director authorization problem.\n"), my_name);
88       set_text(_("Director authorization problem.\n"), -1);
89       set_text(_(
90        "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"),
91         -1);
92       return 0;
93    }
94
95    Dmsg1(6, ">dird: %s", dir->msg);
96    if (bnet_recv(dir) <= 0) {
97       stop_bsock_timer(tid);
98       set_textf(_("Bad response to Hello command: ERR=%s\n"),
99          bnet_strerror(dir));
100       printf(_("%s: Bad response to Hello command: ERR=%s\n"),
101          my_name, bnet_strerror(dir));
102       set_text(_("The Director is probably not running.\n"), -1);
103       return 0;
104    }
105   stop_bsock_timer(tid);
106    Dmsg1(10, "<dird: %s", dir->msg);
107    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
108       set_text(_("Director rejected Hello command\n"), -1);
109       return 0;
110    } else {
111       set_text(dir->msg, dir->msglen);
112    }
113    return 1;
114 }