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