diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-18 10:06:27 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-18 10:06:27 -0500 |
commit | 9178fa8161fa97247a4b660e0eaa5c1a763969d6 (patch) | |
tree | d649d7ddd0abae8f7c54eb7282dc2b0a0c202a62 /servers/auth_server_lin/src | |
parent | b140795f1f54f64dc704f9e3055b00d4aee20c3c (diff) | |
download | ulab-9178fa8161fa97247a4b660e0eaa5c1a763969d6.tar.gz ulab-9178fa8161fa97247a4b660e0eaa5c1a763969d6.zip |
Add logout timer to remote server and client
Diffstat (limited to 'servers/auth_server_lin/src')
-rw-r--r-- | servers/auth_server_lin/src/auth_conn.cpp | 65 | ||||
-rw-r--r-- | servers/auth_server_lin/src/auth_conn.h | 4 |
2 files changed, 58 insertions, 11 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index f3f3474..2ed9860 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -41,7 +41,7 @@ struct exit_exception { instance of this class. */ AuthSocket::AuthSocket(int sock, int serverID, TQObject *parent, const char *name) : - TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_bound(false), m_serverID(serverID), m_servActive(false), m_servState(0), m_servClientSocket(NULL), m_servClientTimeout(NULL), m_loopTimer(NULL), m_config(static_cast<AuthServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL), + TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_bound(false), m_serviceID(0), m_serverID(serverID), m_terminationStamp(0), m_servActive(false), m_servState(0), m_servClientSocket(NULL), m_servClientTimeout(NULL), m_loopTimer(NULL), m_pollTimer(NULL), m_config(static_cast<AuthServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL), m_databaseServicesCursor(NULL), m_databaseServiceTypesCursor(NULL), m_databasePermissionsCursor(NULL), m_databaseActivityCursor(NULL) { @@ -59,6 +59,10 @@ AuthSocket::AuthSocket(int sock, int serverID, TQObject *parent, const char *nam if (connectToDatabase() != 0) { exit(1); } + + m_pollTimer = new TQTimer(); + connect(m_pollTimer, SIGNAL(timeout()), this, SLOT(pollFlags())); + m_pollTimer->start(0, TRUE); } AuthSocket::~AuthSocket() { @@ -67,6 +71,11 @@ AuthSocket::~AuthSocket() { delete m_kerberosInitTimer; m_kerberosInitTimer = NULL; } + if (m_pollTimer) { + m_pollTimer->stop(); + delete m_pollTimer; + m_pollTimer = NULL; + } if (m_loopTimer) { m_loopTimer->stop(); delete m_loopTimer; @@ -102,13 +111,11 @@ void AuthSocket::close() { void AuthSocket::connectionClosedHandler() { printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii()); - if (m_bound) { - // Update database - m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3'").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); - if (m_databaseActivityCursor->next()) { - m_databaseActivityCursor->primeDelete(); - m_databaseActivityCursor->del(true); - } + // Update database + m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3' AND serviceid=%4").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName).arg(m_serviceID)); + if (m_databaseActivityCursor->next()) { + m_databaseActivityCursor->primeDelete(); + m_databaseActivityCursor->del(true); } if (m_criticalSection > 0) { @@ -321,6 +328,24 @@ int AuthSocket::servLoop() { } } +void AuthSocket::pollFlags() { + if ((m_bound) || (m_servActive)) { + long long timestamp = TQDateTime::currentDateTime().toTime_t(); + m_databaseActivityCursor->select(TQString("station='%1' AND username='%2' AND realmname='%3' AND serviceid=%4").arg(m_stationID).arg(m_authenticatedUserName).arg(m_authenticatedRealmName).arg(m_serviceID)); + if (m_databaseActivityCursor->next()) { + m_terminationStamp = m_databaseActivityCursor->value("terminate").toLongLong(); + if (m_terminationStamp > 0) { + if (m_terminationStamp <= timestamp) { + printf("[DEBUG] Got termination request from database (%lld <= %lld)\n\r", m_terminationStamp, timestamp); fflush(stdout); + close(); + } + } + } + } + + m_pollTimer->start(1000, TRUE); +} + void AuthSocket::commandLoop() { bool transferred_data; @@ -447,6 +472,8 @@ void AuthSocket::commandLoop() { buffer->setValue("realmname", m_authenticatedRealmName); buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t()); buffer->setValue("serverid", m_serverID); + buffer->setValue("serviceid", 0); + buffer->setValue("terminate", 0); m_databaseActivityCursor->insert(); ds << TQString("OK"); @@ -465,7 +492,7 @@ void AuthSocket::commandLoop() { clearFrameTail(); printf("[DEBUG] SERV command parameter was %s from user %s@%s\n\r", libname.ascii(), m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout); - m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); + m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2' AND serviceid=0").arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); if (m_databaseActivityCursor->next()) { m_stationID = m_databaseActivityCursor->value("station").toInt(); } @@ -497,6 +524,18 @@ void AuthSocket::commandLoop() { m_srvServiceHostName = m_databaseServicesCursor->value("hostname").toString(); m_srvServicePort = m_databaseServicesCursor->value("port").toInt(); + // Update database + m_serviceID = sid; + TQSqlRecord *buffer = m_databaseActivityCursor->primeInsert(); + buffer->setValue("station", m_stationID); + buffer->setValue("username", m_authenticatedUserName); + buffer->setValue("realmname", m_authenticatedRealmName); + buffer->setValue("logontime", TQDateTime::currentDateTime().toTime_t()); + buffer->setValue("serverid", m_serverID); + buffer->setValue("serviceid", m_serviceID); + buffer->setValue("terminate", 0); + m_databaseActivityCursor->insert(); + if (!m_servClientSocket) m_servClientSocket = new TDEKerberosClientSocket; m_servClientSocket->setServiceName("remotefpga"); @@ -514,6 +553,10 @@ void AuthSocket::commandLoop() { } } } + else if (command == "TSTP") { + ds << m_terminationStamp; + writeEndOfFrame(); + } else { ds << TQString("ERRINVCMD"); writeEndOfFrame(); @@ -589,9 +632,9 @@ AuthServer::AuthServer(TQObject* parent) : // Delete existing activity entries for this server ID TQSqlCursor databaseActivityCursor("activity", TRUE, m_database); databaseActivityCursor.select(TQString("serverid='%1'").arg(m_serverID)); - if (databaseActivityCursor.next()) { + while (databaseActivityCursor.next()) { databaseActivityCursor.primeDelete(); - databaseActivityCursor.del(true); + databaseActivityCursor.del(false); } if ( !ok() ) { diff --git a/servers/auth_server_lin/src/auth_conn.h b/servers/auth_server_lin/src/auth_conn.h index d1245be..af816b9 100644 --- a/servers/auth_server_lin/src/auth_conn.h +++ b/servers/auth_server_lin/src/auth_conn.h @@ -60,6 +60,7 @@ class AuthSocket : public TDEKerberosServerSocket void connectionClosedHandler(); void commandLoop(); int servLoop(); + void pollFlags(); private: int line; @@ -67,7 +68,9 @@ class AuthSocket : public TDEKerberosServerSocket TQString m_remoteHost; int m_stationID; bool m_bound; + int m_serviceID; int m_serverID; + TQ_ULLONG m_terminationStamp; bool m_servActive; int m_servState; @@ -78,6 +81,7 @@ class AuthSocket : public TDEKerberosServerSocket TQTimer* m_kerberosInitTimer; TQTimer* m_loopTimer; + TQTimer* m_pollTimer; TQByteArray m_loopBuffer; KSimpleConfig* m_config; |