+/*
+ * Authenticate Director
+ */
+int authenticate_director(JCR *jcr, MONITOR *mon, DIRRES *director)
+{
+ BSOCK *dir = jcr->dir_bsock;
+ int tls_local_need = BNET_TLS_NONE;
+ int tls_remote_need = BNET_TLS_NONE;
+ int compatible = true;
+ char bashed_name[MAX_NAME_LENGTH];
+ char *password;
+
+ bstrncpy(bashed_name, mon->hdr.name, sizeof(bashed_name));
+ bash_spaces(bashed_name);
+ password = mon->password;
+
+ /* Timeout Hello after 5 mins */
+ btimer_t *tid = start_bsock_timer(dir, 60 * 5);
+ dir->fsend(DIRhello, bashed_name);
+
+ if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
+ !cram_md5_challenge(dir, password, tls_local_need, compatible)) {
+ stop_bsock_timer(tid);
+ Jmsg0(jcr, M_FATAL, 0, _("Director authorization problem.\n"
+ "Most likely the passwords do not agree.\n"
+ "Please see http://www.bacula.org/en/rel-manual/Bacula_Freque_Asked_Questi.html#SECTION003760000000000000000 for help.\n"));
+ return 0;
+ }
+
+ Dmsg1(6, ">dird: %s", dir->msg);
+ if (dir->recv() <= 0) {
+ stop_bsock_timer(tid);
+ Jmsg1(jcr, M_FATAL, 0, _("Bad response to Hello command: ERR=%s\n"),
+ dir->bstrerror());
+ return 0;
+ }
+ Dmsg1(10, "<dird: %s", dir->msg);
+ stop_bsock_timer(tid);
+ if (strncmp(dir->msg, DIROKhello, sizeof(DIROKhello)-1) != 0) {
+ Jmsg0(jcr, M_FATAL, 0, _("Director rejected Hello command\n"));
+ return 0;
+ } else {
+ Jmsg0(jcr, M_INFO, 0, dir->msg);
+ }
+ return 1;
+}
+
+/*
+ * Authenticate Storage daemon connection
+ */
+int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store)
+{
+ BSOCK *sd = jcr->store_bsock;
+ char dirname[MAX_NAME_LENGTH];
+ int tls_local_need = BNET_TLS_NONE;
+ int tls_remote_need = BNET_TLS_NONE;
+ int compatible = true;
+
+ /*
+ * Send my name to the Storage daemon then do authentication
+ */
+ bstrncpy(dirname, monitor->hdr.name, sizeof(dirname));
+ bash_spaces(dirname);
+ /* Timeout Hello after 5 mins */
+ btimer_t *tid = start_bsock_timer(sd, 60 * 5);
+ if (!sd->fsend(SDFDhello, dirname)) {
+ stop_bsock_timer(tid);
+ Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to Storage daemon. ERR=%s\n"), bnet_strerror(sd));
+ return 0;
+ }
+ if (!cram_md5_respond(sd, store->password, &tls_remote_need, &compatible) ||
+ !cram_md5_challenge(sd, store->password, tls_local_need, compatible)) {
+ stop_bsock_timer(tid);
+ Jmsg0(jcr, M_FATAL, 0, _("Director and Storage daemon passwords or names not the same.\n"
+ "Please see http://www.bacula.org/en/rel-manual/Bacula_Freque_Asked_Questi.html#SECTION003760000000000000000 for help.\n"));
+ return 0;
+ }
+ Dmsg1(116, ">stored: %s", sd->msg);
+ if (sd->recv() <= 0) {
+ stop_bsock_timer(tid);
+ Jmsg1(jcr, M_FATAL, 0, _("bdird<stored: bad response to Hello command: ERR=%s\n"),
+ sd->bstrerror());
+ return 0;
+ }
+ Dmsg1(110, "<stored: %s", sd->msg);
+ stop_bsock_timer(tid);
+ if (strncmp(sd->msg, SDOKhello, sizeof(SDOKhello)) != 0) {
+ Jmsg0(jcr, M_FATAL, 0, _("Storage daemon rejected Hello command\n"));
+ return 0;
+ }
+ return 1;
+}
+