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 04e622a commit 7b012bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
41 changes: 21 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 @@ -81,33 +81,33 @@ 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 @@ -130,7 +130,7 @@ 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;
}

ASSERT(store->password.encoding == p_encoding_md5);
Expand All @@ -140,31 +140,31 @@ static int authenticate_storage_daemon(JCR *jcr, STORERES* store)
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 @@ -187,7 +187,7 @@ 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;
}

ASSERT(client->password.encoding == p_encoding_md5);
Expand All @@ -197,28 +197,28 @@ static int authenticate_file_daemon(JCR *jcr, CLIENTRES* client)
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 @@ -229,7 +229,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
9 changes: 6 additions & 3 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 Down Expand Up @@ -208,6 +208,9 @@ 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();
delete d->DSock;
d->DSock = NULL;
return false;
}
Expand Down

0 comments on commit 7b012bd

Please sign in to comment.