* Authenticate Director
*/
bool Console::authenticate_director(JCR *jcr, DIRRES *director, CONRES *cons,
- char *msg, int msglen)
+ char *errmsg, int errmsglen)
{
BSOCK *dir = jcr->dir_bsock;
int tls_local_need = BNET_TLS_NONE;
char *password;
TLS_CONTEXT *tls_ctx = NULL;
- msg[0] = 0;
+ errmsg[0] = 0;
/*
* Send my name to the Director then do authentication
*/
if (!cram_md5_respond(dir, password, &tls_remote_need, &compatible) ||
/* Now challenge dir */
!cram_md5_challenge(dir, password, tls_local_need, compatible)) {
- bsnprintf(msg, msglen, _("Director authorization problem at \"%s:%d\"\n"),
+ bsnprintf(errmsg, errmsglen, _("Director authorization problem at \"%s:%d\"\n"),
dir->host(), dir->port());
goto bail_out;
}
/* Verify that the remote host is willing to meet our TLS requirements */
if (tls_remote_need < tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
- bsnprintf(msg, msglen, _("Authorization problem:"
+ bsnprintf(errmsg, errmsglen, _("Authorization problem:"
" Remote server at \"%s:%d\" did not advertise required TLS support.\n"),
dir->host(), dir->port());
goto bail_out;
/* Verify that we are willing to meet the remote host's requirements */
if (tls_remote_need > tls_local_need && tls_local_need != BNET_TLS_OK && tls_remote_need != BNET_TLS_OK) {
- bsnprintf(msg, msglen, _("Authorization problem with Director at \"%s:%d\":"
+ bsnprintf(errmsg, errmsglen, _("Authorization problem with Director at \"%s:%d\":"
" Remote server requires TLS.\n"),
dir->host(), dir->port());
if (tls_local_need >= BNET_TLS_OK && tls_remote_need >= BNET_TLS_OK) {
/* Engage TLS! Full Speed Ahead! */
if (!bnet_tls_client(tls_ctx, dir, NULL)) {
- bsnprintf(msg, msglen, _("TLS negotiation failed with Director at \"%s:%d\"\n"),
+ bsnprintf(errmsg, errmsglen, _("TLS negotiation failed with Director at \"%s:%d\"\n"),
dir->host(), dir->port());
goto bail_out;
}
Dmsg1(6, ">dird: %s", dir->msg);
if (dir->recv() <= 0) {
dir->stop_timer();
- bsnprintf(msg, msglen, _("Bad response to Hello command: ERR=%s\n"
+ bsnprintf(errmsg, errmsglen, _("Bad response to Hello command: ERR=%s\n"
"The Director at \"%s:%d\" is probably not running.\n"),
dir->bstrerror(), dir->host(), dir->port());
return false;
dir->stop_timer();
Dmsg1(10, "<dird: %s", dir->msg);
if (strncmp(dir->msg, OKhello, sizeof(OKhello)-1) != 0) {
- bsnprintf(msg, msglen, _("Director at \"%s:%d\" rejected Hello command\n"),
+ bsnprintf(errmsg, errmsglen, _("Director at \"%s:%d\" rejected Hello command\n"),
dir->host(), dir->port());
return false;
} else {
- bsnprintf(msg, msglen, "%s", dir->msg);
+ bsnprintf(errmsg, errmsglen, "%s", dir->errmsg);
}
return true;
bail_out:
dir->stop_timer();
- bsnprintf(msg, msglen, _("Authorization problem with Director at \"%s:%d\"\n"
+ bsnprintf(errmsg, errmsglen, _("Authorization problem with Director at \"%s:%d\"\n"
"Most likely the passwords do not agree.\n"
"If you are using TLS, there may have been a certificate validation error during the TLS handshake.\n"
"Please see http://www.bacula.org/rel-manual/faq.html#AuthorizationErrors for help.\n"),
*/
void Console::connect_dir()
{
- JCR jcr;
+ JCR *jcr = new JCR;
utime_t heart_beat;
char buf[1024];
+ CONRES *cons;
m_textEdit = textEdit; /* our console screen */
if (!m_dir) {
mainWin->set_status("No Director found.");
- return;
+ goto bail_out;
}
if (m_sock) {
mainWin->set_status("Already connected.");
- return;
+ goto bail_out;
}
- memset(&jcr, 0, sizeof(jcr));
+ memset(jcr, 0, sizeof(JCR));
mainWin->set_statusf(_("Connecting to Director %s:%d"), m_dir->address, m_dir->DIRport);
display_textf(_("Connecting to Director %s:%d\n\n"), m_dir->address, m_dir->DIRport);
LockRes();
/* If cons==NULL, default console will be used */
- CONRES *cons = (CONRES *)GetNextRes(R_CONSOLE, NULL);
+ cons = (CONRES *)GetNextRes(R_CONSOLE, NULL);
UnlockRes();
/* Initialize Console TLS context once */
if (!cons->tls_ctx) {
display_textf(_("Failed to initialize TLS context for Console \"%s\".\n"),
m_dir->name());
- return;
+ goto bail_out;
}
}
display_textf(_("Failed to initialize TLS context for Director \"%s\".\n"),
m_dir->name());
mainWin->set_status("Connection failed");
- return;
+ goto bail_out;
}
}
NULL, m_dir->DIRport, 0);
if (m_sock == NULL) {
mainWin->set_status("Connection failed");
- return;
+ goto bail_out;
} else {
/* Update page selector to green to indicate that Console is connected */
mainWin->actionConnect->setIcon(QIcon(":images/connected.png"));
item->setForeground(0, greenBrush);
}
- jcr.dir_bsock = m_sock;
+ jcr->dir_bsock = m_sock;
- if (!authenticate_director(&jcr, m_dir, cons, buf, sizeof(buf))) {
+ if (!authenticate_director(jcr, m_dir, cons, buf, sizeof(buf))) {
display_text(buf);
- return;
+ goto bail_out;
}
if (buf[0]) {
display_text(buf);
mainWin->set_status(_("Connected"));
startTimer(); /* start message timer */
+
+bail_out:
+ delete jcr;
return;
}