]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/authenticate.cpp
Add qt-console configuration
[bacula/bacula] / bacula / src / qt-console / authenticate.cpp
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-2007 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 plus additions
25    that are listed 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 John Walker.
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 "mainwindow.h"
44 #include "bacula.h"
45 #include "console_conf.h"
46 #include "jcr.h"
47
48
49 /* Commands sent to Director */
50 static char hello[]    = "Hello %s calling\n";
51
52 /* Response from Director */
53 static char OKhello[]   = "1000 OK:";
54
55 /* Forward referenced functions */
56
57 /*
58  * Authenticate Director
59  */
60 int authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons)
61 {
62    BSOCK *dir = jcr->dir_bsock;
63    int tls_local_need = BNET_TLS_NONE;
64    int tls_remote_need = BNET_TLS_NONE;
65    int compatible = true;
66    char bashed_name[MAX_NAME_LENGTH];
67    char *password;
68
69    /*
70     * Send my name to the Director then do authentication
71     */
72    if (cons) {
73       bstrncpy(bashed_name, cons->hdr.name, sizeof(bashed_name));
74       bash_spaces(bashed_name);
75       password = cons->password;
76    } else {
77       bstrncpy(bashed_name, "*UserAgent*", sizeof(bashed_name));
78       password = director->password;
79    }
80    /* Timeout Hello after 5 mins */
81    btimer_t *tid = start_bsock_timer(dir, 60 * 5);
82    bnet_fsend(dir, hello, bashed_name);
83
84    /* respond to Dir challenge */
85    if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
86        /* Now challenge dir */
87        !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
88       stop_bsock_timer(tid);
89       printf(_("%s: Director authorization problem.\n"), my_name);
90       set_text(_("Director authorization problem.\n"));    
91       set_text(_(
92        "Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"));
93       return 0;
94    }
95
96    Dmsg1(6, ">dird: %s", dir->msg);
97    if (bnet_recv(dir) <= 0) {
98       stop_bsock_timer(tid);
99       set_textf(_("Bad response to Hello command: ERR=%s\n"),
100          bnet_strerror(dir));
101       printf(_("%s: Bad response to Hello command: ERR=%s\n"),
102          my_name, bnet_strerror(dir));
103       set_text(_("The Director is probably not running.\n"));
104       return 0;
105    }
106   stop_bsock_timer(tid);
107    Dmsg1(10, "<dird: %s", dir->msg);
108    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
109       set_text(_("Director rejected Hello command\n"));    
110       return 0;
111    } else {
112       set_text(dir->msg);
113    }
114    return 1;
115 }