]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/console/authenticate.c
Add this for symmetry
[bacula/bacula] / bacula / src / 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) 2000, 2001 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
36 /* Commands sent to Director */
37 static char hello[]    = "Hello %s calling\n";
38
39 /* Response from Director */
40 static char OKhello[]   = "1000 OK:";
41
42 /* Forward referenced functions */
43
44 /*
45  * Authenticate Director
46  */
47 int authenticate_director(JCR *jcr, DIRRES *director)
48 {
49    BSOCK *dir = jcr->dir_bsock;
50    int ssl_need = BNET_SSL_NONE;
51
52    /* 
53     * Send my name to the Director then do authentication
54     */
55    bnet_fsend(dir, hello, "UserAgent");
56
57    if (!cram_md5_get_auth(dir, director->password, ssl_need) || 
58        !cram_md5_auth(dir, director->password, ssl_need)) {
59       Pmsg0(-1, _("Director authorization problem.\n"
60             "Most likely the passwords do not agree.\n"));  
61       return 0;
62    }
63
64    Dmsg1(6, ">dird: %s", dir->msg);
65    if (bnet_recv(dir) <= 0) {
66       Pmsg1(-1, "Bad response to Hello command: ERR=%s\n",
67          bnet_strerror(dir));
68       Pmsg0(-1, "The Director is probably not running.\n");
69       return 0;
70    }
71    Dmsg1(10, "<dird: %s", dir->msg);
72    if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
73       Pmsg0(-1, "Director rejected Hello command\n");
74       return 0;
75    } else {
76       Pmsg1(-1, "%s", dir->msg);
77    }
78    return 1;
79 }