4 * Kern Sibbald, October 2000
10 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 static char Dir_sorry[] = "3999 No go\n";
33 static char OK_hello[] = "3000 OK Hello\n";
36 /*********************************************************************
40 static int authenticate(int rcode, BSOCK *bs, JCR* jcr)
43 DIRRES *director = NULL;
44 int ssl_need = BNET_SSL_NONE;
46 if (rcode != R_DIRECTOR) {
47 Emsg1(M_FATAL, 0, _("I only authenticate Directors, not %d\n"), rcode);
50 if (bs->msglen < 25 || bs->msglen > 200) {
51 Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
55 dirname = get_pool_memory(PM_MESSAGE);
56 dirname = check_pool_memory_size(dirname, bs->msglen);
58 if (sscanf(bs->msg, "Hello Director %127s calling\n", dirname) != 1) {
60 Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
65 unbash_spaces(dirname);
67 while ((director=(DIRRES *)GetNextRes(rcode, (RES *)director))) {
68 if (strcmp(director->hdr.name, dirname) == 0)
73 Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"
74 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
76 free_pool_memory(dirname);
80 /* Timeout Hello after 10 mins */
81 btimer_t *tid = start_bsock_timer(bs, 60 * 10);
82 if (!cram_md5_auth(bs, director->password, ssl_need) ||
83 !cram_md5_get_auth(bs, director->password, ssl_need)) {
84 stop_bsock_timer(tid);
85 Emsg0(M_FATAL, 0, _("Incorrect password given by Director.\n"
86 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"));
87 free_pool_memory(dirname);
90 stop_bsock_timer(tid);
91 free_pool_memory(dirname);
92 jcr->director = director;
97 * Inititiate the message channel with the Director.
98 * He has made a connection to our server.
100 * Basic tasks done here:
101 * Assume the Hello message is already in the input
102 * buffer. We then authenticate him.
103 * Get device, media, and pool information from Director
105 * This is the channel across which we will send error
106 * messages and job status information.
108 int authenticate_director(JCR *jcr)
110 BSOCK *dir = jcr->dir_bsock;
112 if (!authenticate(R_DIRECTOR, dir, jcr)) {
113 bnet_fsend(dir, "%s", Dir_sorry);
114 Emsg1(M_ERROR, 0, _("Unable to authenticate Director at %s.\n"), dir->who);
118 return bnet_fsend(dir, "%s", OK_hello);
121 int authenticate_filed(JCR *jcr)
123 BSOCK *fd = jcr->file_bsock;
124 int ssl_need = BNET_SSL_NONE;
126 /* Timeout Hello after 5 mins */
127 btimer_t *tid = start_bsock_timer(fd, 60 * 10);
128 if (cram_md5_auth(fd, jcr->sd_auth_key, ssl_need) &&
129 cram_md5_get_auth(fd, jcr->sd_auth_key, ssl_need)) {
130 jcr->authenticated = true;
132 stop_bsock_timer(tid);
133 if (!jcr->authenticated) {
134 Jmsg(jcr, M_FATAL, 0, _("Incorrect authorization key from File daemon at %s rejected.\n"
135 "Please see http://www.bacula.org/html-manual/faq.html#AuthorizationErrors for help.\n"),
138 return jcr->authenticated;