2 * Authenticate Director who is attempting to connect.
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 OK_hello[] = "2000 OK Hello\n";
33 static char Dir_sorry[] = "2999 No go\n";
36 /*********************************************************************
39 static int authenticate(int rcode, BSOCK *bs)
44 if (rcode != R_DIRECTOR) {
45 Emsg1(M_FATAL, 0, _("I only authenticate directors, not %d\n"), rcode);
48 name = (char *) get_pool_memory(PM_MESSAGE);
49 name = (char *) check_pool_memory_size(name, bs->msglen);
51 if (sscanf(bs->msg, "Hello Director %s calling\n", name) != 1) {
52 free_pool_memory(name);
53 Emsg1(M_FATAL, 0, _("Bad Hello command from Director: %s"), bs->msg);
58 while ((director=(DIRRES *)GetNextRes(rcode, (RES *)director))) {
59 if (strcmp(director->hdr.name, name) == 0)
64 Emsg1(M_FATAL, 0, _("Connection from unknown Director %s rejected.\n"), name);
65 free_pool_memory(name);
68 if (!cram_md5_auth(bs, director->password) ||
69 !cram_md5_get_auth(bs, director->password)) {
70 Emsg0(M_FATAL, 0, _("Incorrect password given by Director.\n"));
73 free_pool_memory(name);
74 return (director != NULL);
78 * Inititiate the communications with the Director.
79 * He has made a connection to our server.
81 * Basic tasks done here:
82 * We read Director's initial message and authorize him.
85 int authenticate_director(JCR *jcr)
87 BSOCK *dir = jcr->dir_bsock;
89 if (!authenticate(R_DIRECTOR, dir)) {
90 bnet_fsend(dir, "%s", Dir_sorry);
91 Emsg0(M_FATAL, 0, _("Unable to authenticate Director\n"));
95 return bnet_fsend(dir, "%s", OK_hello);
99 * First prove our identity to the Storage daemon, then
100 * make him prove his identity.
102 int authenticate_storagedaemon(JCR *jcr)
104 BSOCK *sd = jcr->store_bsock;
107 stat = cram_md5_get_auth(sd, jcr->sd_auth_key) &&
108 cram_md5_auth(sd, jcr->sd_auth_key);
110 Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"));