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)
43 int ssl_need = BNET_SSL_NONE;
45 if (rcode != R_DIRECTOR) {
46 Emsg1(M_FATAL, 0, _("I only authenticate directors, not %d\n"), rcode);
49 if (bs->msglen < 25 || bs->msglen > 200) {
50 Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s. Len=%d.\n"),
54 dirname = get_pool_memory(PM_MESSAGE);
55 dirname = check_pool_memory_size(dirname, bs->msglen);
57 if (sscanf(bs->msg, "Hello Director %s calling\n", dirname) != 1) {
58 free_pool_memory(dirname);
60 Emsg2(M_FATAL, 0, _("Bad Hello command from Director at %s: %s\n"),
64 unbash_spaces(dirname);
66 foreach_res(director, R_DIRECTOR) {
67 if (strcmp(director->hdr.name, dirname) == 0)
72 Emsg2(M_FATAL, 0, _("Connection from unknown Director %s at %s rejected.\n"),
74 free_pool_memory(dirname);
77 btimer_t *tid = start_bsock_timer(bs, 60 * 5);
78 if (!cram_md5_auth(bs, director->password, ssl_need) ||
79 !cram_md5_get_auth(bs, director->password, ssl_need)) {
80 Emsg1(M_FATAL, 0, _("Incorrect password given by Director at %s.\n"),
84 stop_bsock_timer(tid);
85 free_pool_memory(dirname);
86 return (director != NULL);
90 * Inititiate the communications with the Director.
91 * He has made a connection to our server.
93 * Basic tasks done here:
94 * We read Director's initial message and authorize him.
97 int authenticate_director(JCR *jcr)
99 BSOCK *dir = jcr->dir_bsock;
101 if (!authenticate(R_DIRECTOR, dir)) {
102 bnet_fsend(dir, "%s", Dir_sorry);
103 Emsg0(M_FATAL, 0, _("Unable to authenticate Director\n"));
107 return bnet_fsend(dir, "%s", OK_hello);
111 * First prove our identity to the Storage daemon, then
112 * make him prove his identity.
114 int authenticate_storagedaemon(JCR *jcr)
116 BSOCK *sd = jcr->store_bsock;
118 int ssl_need = BNET_SSL_NONE;
120 btimer_t *tid = start_bsock_timer(sd, 60 * 5);
121 stat = cram_md5_get_auth(sd, jcr->sd_auth_key, ssl_need) &&
122 cram_md5_auth(sd, jcr->sd_auth_key, ssl_need);
123 stop_bsock_timer(tid);
124 memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
126 Jmsg(jcr, M_FATAL, 0, _("Authorization key rejected by Storage daemon.\n"));