From bed33391552a320c410e7f1915581ad5b241cffd Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Mon, 2 Jun 2014 14:24:58 +0200 Subject: [PATCH] Fix Traymonitor does not close connections when login fails. Fixes #303: Traymonitor does not close connections when login fails --- src/qt-tray-monitor/authenticate.cpp | 41 ++++++++++++++-------------- src/qt-tray-monitor/authenticate.h | 2 +- src/qt-tray-monitor/monitoritem.cpp | 9 ++++-- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/qt-tray-monitor/authenticate.cpp b/src/qt-tray-monitor/authenticate.cpp index 229a787e4b7..0cda030d994 100644 --- a/src/qt-tray-monitor/authenticate.cpp +++ b/src/qt-tray-monitor/authenticate.cpp @@ -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(); @@ -81,7 +81,7 @@ 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); @@ -89,25 +89,25 @@ static int authenticate_director(JCR *jcr) 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, "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(); @@ -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); @@ -140,7 +140,7 @@ 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); @@ -148,23 +148,23 @@ static int authenticate_storage_daemon(JCR *jcr, STORERES* store) stop_bsock_timer(tid); Jmsg1(jcr, M_FATAL, 0, _("bdirdbstrerror()); - return 0; + return false; } Dmsg1(110, "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(); @@ -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); @@ -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, "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: @@ -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; } diff --git a/src/qt-tray-monitor/authenticate.h b/src/qt-tray-monitor/authenticate.h index 7b6a613d7e1..dbe12097b29 100644 --- a/src/qt-tray-monitor/authenticate.h +++ b/src/qt-tray-monitor/authenticate.h @@ -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 diff --git a/src/qt-tray-monitor/monitoritem.cpp b/src/qt-tray-monitor/monitoritem.cpp index 34b5754e9df..3dd2149b8dd 100644 --- a/src/qt-tray-monitor/monitoritem.cpp +++ b/src/qt-tray-monitor/monitoritem.cpp @@ -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) { @@ -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; }