4 * Kern Sibbald, October 2000
8 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public
21 License along with this program; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 static char Dir_sorry[] = "3999 No go\n";
31 static char OK_hello[] = "3000 OK Hello\n";
34 /*********************************************************************
38 static int authenticate(int rcode, BSOCK *bs)
43 if (rcode != R_DIRECTOR) {
44 Emsg1(M_FATAL, 0, _("I only authenticate Directors, not %d\n"), rcode);
47 name = (char *) get_pool_memory(PM_MESSAGE);
48 name = (char *) check_pool_memory_size(name, bs->msglen);
50 if (sscanf(bs->msg, "Hello Director %127s calling\n", name) != 1) {
51 free_pool_memory(name);
52 Emsg1(M_FATAL, 0, _("Authentication failure: %s\n"), bs->msg);
57 while ((director=(DIRRES *)GetNextRes(rcode, (RES *)director))) {
58 if (strcmp(director->hdr.name, name) == 0)
62 if (director && (!cram_md5_auth(bs, director->password) ||
63 !cram_md5_get_auth(bs, director->password))) {
66 free_pool_memory(name);
67 return (director != NULL);
71 * Inititiate the message channel with the Director.
72 * He has made a connection to our server.
74 * Basic tasks done here:
75 * Assume the Hello message is already in the input
76 * buffer. We then authenticate him.
77 * Get device, media, and pool information from Director
79 * This is the channel across which we will send error
80 * messages and job status information.
82 int authenticate_director(JCR *jcr)
84 BSOCK *dir = jcr->dir_bsock;
86 if (!authenticate(R_DIRECTOR, dir)) {
87 bnet_fsend(dir, "%s", Dir_sorry);
88 Emsg0(M_ERROR, 0, _("Unable to authenticate Director\n"));
91 return bnet_fsend(dir, "%s", OK_hello);
94 int authenticate_filed(JCR *jcr)
96 BSOCK *fd = jcr->file_bsock;
98 if (cram_md5_auth(fd, jcr->sd_auth_key) &&
99 cram_md5_get_auth(fd, jcr->sd_auth_key)) {
100 jcr->authenticated = TRUE;
102 return jcr->authenticated;