Skip to content

Commit

Permalink
Fix Traymonitor does not close connections when login fails.
Browse files Browse the repository at this point in the history
Fixes #303: Traymonitor does not close connections when login fails
  • Loading branch information
Marco van Wieringen committed Jun 2, 2014
1 parent 85d2d3a commit bae804b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
50 changes: 30 additions & 20 deletions src/qt-tray-monitor/authenticate.cpp
Expand Up @@ -54,7 +54,7 @@ static char FDOKhello[] = "2000 OK Hello";
/*
* Authenticate Director
*/
static int authenticate_director(JCR *jcr)
static bool authenticate_director(JCR *jcr)
{
const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor();

Expand All @@ -79,31 +79,32 @@ static int authenticate_director(JCR *jcr)
Jmsg(jcr, M_FATAL, 0, _("Director authorization problem.\n"
"Most likely the passwords do not agree.\n"
"Please see %s for help.\n"), MANUAL_AUTH_URL);
return 0;
return false;
}

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;
return false;
}
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;
return false;
} else {
Jmsg0(jcr, M_INFO, 0, dir->msg);
}
return 1;

return true;
}

/*
* Authenticate Storage daemon connection
*/
static int authenticate_storage_daemon(JCR *jcr, STORERES* store)
static bool authenticate_storage_daemon(JCR *jcr, STORERES* store)
{
const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor();

Expand All @@ -123,35 +124,39 @@ static int authenticate_storage_daemon(JCR *jcr, STORERES* store)
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;
return false;
}

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 " MANUAL_AUTH_URL " for help.\n"));
return 0;
return false;
}

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;
return false;
}

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 false;
}
return 1;

return true;
}

/*
* Authenticate File daemon connection
*/
static int authenticate_file_daemon(JCR *jcr, CLIENTRES* client)
static bool authenticate_file_daemon(JCR *jcr, CLIENTRES* client)
{
const MONITORRES *monitor = MonitorItemThread::instance()->getMonitor();

Expand All @@ -171,32 +176,36 @@ static int authenticate_file_daemon(JCR *jcr, CLIENTRES* client)
if (!fd->fsend(SDFDhello, dirname)) {
stop_bsock_timer(tid);
Jmsg(jcr, M_FATAL, 0, _("Error sending Hello to File daemon. ERR=%s\n"), bnet_strerror(fd));
return 0;
return false;
}

if (!cram_md5_respond(fd, client->password, &tls_remote_need, &compatible) ||
!cram_md5_challenge(fd, client->password, tls_local_need, compatible)) {
stop_bsock_timer(tid);
Jmsg(jcr, M_FATAL, 0, _("Director and File daemon passwords or names not the same.\n"
"Please see %s for help.\n"), MANUAL_AUTH_URL);
return 0;
return false;
}

Dmsg1(116, ">filed: %s", fd->msg);
if (fd->recv() <= 0) {
stop_bsock_timer(tid);
Jmsg(jcr, M_FATAL, 0, _("Bad response from File daemon to Hello command: ERR=%s\n"),
fd->bstrerror());
return 0;
fd->bstrerror());
return false;
}

Dmsg1(110, "<stored: %s", fd->msg);
stop_bsock_timer(tid);
if (strncmp(fd->msg, FDOKhello, sizeof(FDOKhello)-1) != 0) {
Jmsg(jcr, M_FATAL, 0, _("File daemon rejected Hello command\n"));
return 0;
return false;
}
return 1;

return true;
}

int authenticate_daemon(MonitorItem* item, JCR *jcr)
bool authenticate_daemon(MonitorItem* item, JCR *jcr)
{
switch (item->type()) {
case R_DIRECTOR:
Expand All @@ -207,7 +216,8 @@ int authenticate_daemon(MonitorItem* item, JCR *jcr)
return authenticate_storage_daemon(jcr, (STORERES*)item->resource());
default:
printf(_("Error, currentitem is not a Client or a Storage..\n"));
return FALSE;
return false;
}

return false;
}
2 changes: 1 addition & 1 deletion src/qt-tray-monitor/authenticate.h
Expand Up @@ -5,6 +5,6 @@ class MONITORRES;
class MonitorItem;
class JCR;

int authenticate_daemon(MonitorItem* item, JCR *jcr);
bool authenticate_daemon(MonitorItem *item, JCR *jcr);

#endif // AUTHENTICATE_H_INCLUDED
14 changes: 8 additions & 6 deletions src/qt-tray-monitor/monitoritem.cpp
Expand Up @@ -142,9 +142,9 @@ bool MonitorItem::doconnect()
JCR jcr;
memset(&jcr, 0, sizeof(jcr));

DIRRES* dird;
CLIENTRES* filed;
STORERES* stored;
DIRRES *dird;
CLIENTRES *filed;
STORERES *stored;
QString message;

switch (d->type) {
Expand All @@ -153,23 +153,23 @@ bool MonitorItem::doconnect()
message = QString("Connecting to Director %1:%2").arg(dird->address).arg(dird->DIRport);
emit showStatusbarMessage(message);
d->DSock = bnet_connect(NULL, d->connectTimeout,
0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0);
0, 0, "Director daemon", dird->address, NULL, dird->DIRport, 0);
jcr.dir_bsock = d->DSock;
break;
case R_CLIENT:
filed = static_cast<CLIENTRES*>(d->resource);
message = QString("Connecting to Client %1:%2").arg(filed->address).arg(filed->FDport);
emit showStatusbarMessage(message);
d->DSock = bnet_connect(NULL, d->connectTimeout,
0, 0, "File daemon", filed->address, NULL, filed->FDport, 0);
0, 0, "File daemon", filed->address, NULL, filed->FDport, 0);
jcr.file_bsock = d->DSock;
break;
case R_STORAGE:
stored = static_cast<STORERES*>(d->resource);
message = QString("Connecting to Storage %1:%2").arg(stored->address).arg(stored->SDport);
emit showStatusbarMessage(message);
d->DSock = bnet_connect(NULL, d->connectTimeout,
0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0);
0, 0, "Storage daemon", stored->address, NULL, stored->SDport, 0);
jcr.store_bsock = d->DSock;
break;
default:
Expand All @@ -193,6 +193,8 @@ bool MonitorItem::doconnect()
emit showStatusbarMessage(message);
emit clearText(get_name());
emit appendText(get_name(), QString("Authentication error : %1").arg(d->DSock->msg));
d->DSock->signal(BNET_TERMINATE); /* send EOF */
d->DSock->close();
d->DSock = NULL;
return false;
}
Expand Down

0 comments on commit bae804b

Please sign in to comment.