summaryrefslogtreecommitdiffstats
path: root/servers/auth_server_lin
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-27 20:43:57 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-27 20:43:57 -0500
commit8392c611054a5bb058cd778163a7aa4ef8311c94 (patch)
tree5703e9d3ff12474fe474d37bb7c2532418c5b8aa /servers/auth_server_lin
parente3bfbdc4e464d057be5095bb5bbd3240beab8ec6 (diff)
downloadulab-8392c611054a5bb058cd778163a7aa4ef8311c94.tar.gz
ulab-8392c611054a5bb058cd778163a7aa4ef8311c94.zip
Fix a number of problems
Diffstat (limited to 'servers/auth_server_lin')
-rw-r--r--servers/auth_server_lin/src/auth_conn.cpp180
1 files changed, 124 insertions, 56 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp
index 14c234f..28c8427 100644
--- a/servers/auth_server_lin/src/auth_conn.cpp
+++ b/servers/auth_server_lin/src/auth_conn.cpp
@@ -22,6 +22,8 @@
#include <stdlib.h>
+#include <tqtimer.h>
+
#include <klocale.h>
#include "auth_conn.h"
@@ -165,6 +167,8 @@ int AuthSocket::enterCommandLoop() {
if (m_databaseServiceTypesCursor->next()) {
svt.name = m_databaseServiceTypesCursor->value("name").toString();
svt.description = m_databaseServiceTypesCursor->value("description").toString();
+ svt.clientLibrary = m_databaseServiceTypesCursor->value("client_library").toString();
+ svt.version = m_databaseServiceTypesCursor->value("version").toInt();
}
if (svt.name == "") {
svt.name = i18n("<unknown>");
@@ -188,35 +192,46 @@ int AuthSocket::enterCommandLoop() {
// Attempt to bind to station matching desired Service Type list...
m_stationID = -1;
-
- for (StationList::Iterator it(m_slist.begin()); it != m_slist.end(); ++it) {
- if ((*it).services == st.services) {
- m_stationID = (*it).id;
- break;
- }
+
+ // Ensure that this user is not already connected
+ int activeID = -1;
+ m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName));
+ if (m_databaseActivityCursor->next()) {
+ activeID = m_databaseActivityCursor->value("station").toInt();
}
+ if (activeID < 0) {
+ for (StationList::Iterator it(m_slist.begin()); it != m_slist.end(); ++it) {
+ if ((*it).services == st.services) {
+ m_stationID = (*it).id;
+ break;
+ }
+ }
+
+ if (m_stationID < 0) {
+ ds << TQString("ERRUNAVAL");
+ }
+ else {
+ m_bound = true;
- if (m_stationID < 0) {
- ds << TQString("ERRUNAVAL");
+ // Update database
+ 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());
+ m_databaseActivityCursor->insert();
+
+ ds << TQString("OK");
+ }
}
else {
- m_bound = true;
-
- // Update database
- 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());
- m_databaseActivityCursor->insert();
-
- ds << TQString("OK");
+ ds << TQString("ERRPREVCN");
}
}
else if (command == "SERV") {
- // Get desired Service ID from client
- TQ_UINT32 sid;
- ds >> sid;
+ // Get client library name from the client
+ TQString libname;
+ ds >> libname;
m_databaseActivityCursor->select(TQString("username='%1' AND realmname='%2'").arg(m_authenticatedUserName).arg(m_authenticatedRealmName));
if (m_databaseActivityCursor->next()) {
@@ -226,45 +241,98 @@ int AuthSocket::enterCommandLoop() {
if (m_bound == true) {
ds << TQString("ERRINVCMD");
}
-
- if (m_stationID < 0) {
- ds << TQString("ERRNOCONN");
- }
-
- // Attempt to connect to the backend server
- m_databaseServicesCursor->select(TQString("pk=%1 AND station=%2").arg(sid).arg(m_stationID));
- if (m_databaseServicesCursor->next()) {
- TQString serviceHostName = m_databaseServicesCursor->value("hostname").toString();
- int servicePort = m_databaseServicesCursor->value("port").toInt();
-
- TDEKerberosClientSocket clientSocket;
- clientSocket.setServiceName("remotefpga");
-
- clientSocket.setServerFQDN(serviceHostName);
- clientSocket.connectToHost(serviceHostName, servicePort);
-
- while ((clientSocket.state() == TQSocket::Connecting) || (clientSocket.state() == TQSocket::HostLookup)) {
- tqApp->processEvents();
+ else {
+ if (m_stationID < 0) {
+ ds << TQString("ERRNOCONN");
}
- if (clientSocket.state() == TQSocket::Connected) {
- if (clientSocket.setUsingKerberos(true) != 0) {
- clientSocket.close();
- ds << TQString("ERRNOTAVL");
- printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to Kerberos failure\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
+ else {
+ // Find the service ID for the specified client library name
+ TQ_INT32 sid = -1;
+ m_databaseServiceTypesCursor->select(TQString("client_library='%1'").arg(libname));
+ if (m_databaseServiceTypesCursor->next()) {
+ sid = m_databaseServiceTypesCursor->value("serviceid").toInt();
+ }
+ if (sid < 0) {
+ ds << TQString("ERRNOSERV");
}
else {
- printf("[RAJA DEBUG 600.0] Connect OK!\n\r"); fflush(stdout);
- // RAJA FIXME
+ // Attempt to connect to the backend server
+ m_databaseServicesCursor->select(TQString("pk=%1 AND station=%2").arg(sid).arg(m_stationID));
+ if (m_databaseServicesCursor->next()) {
+ TQString serviceHostName = m_databaseServicesCursor->value("hostname").toString();
+ int servicePort = m_databaseServicesCursor->value("port").toInt();
+
+ TDEKerberosClientSocket clientSocket;
+ clientSocket.setServiceName("remotefpga");
+
+ clientSocket.setServerFQDN(serviceHostName);
+ clientSocket.connectToHost(serviceHostName, servicePort);
+
+ TQTimer connectionTimeout;
+ connectionTimeout.start(5000, TRUE);
+ while ((clientSocket.state() == TQSocket::Connecting) || (clientSocket.state() == TQSocket::HostLookup)) {
+ tqApp->processEvents();
+ if (!connectionTimeout.isActive()) {
+ break;
+ }
+ }
+ connectionTimeout.stop();
+ if (clientSocket.state() == TQSocket::Connected) {
+ if (clientSocket.setUsingKerberos(true) != 0) {
+ clientSocket.close();
+ ds << TQString("ERRNOTAVL");
+ printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to Kerberos failure\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
+ }
+ else {
+ TQDataStream clientDS(&clientSocket);
+ TQString server_reply;
+ connectionTimeout.start(5000, TRUE);
+ while ((!clientSocket.canReadLine()) && (clientSocket.state() == TQSocket::Connected)) {
+ tqApp->processEvents();
+ if (!connectionTimeout.isActive()) {
+ break;
+ }
+ }
+ connectionTimeout.stop();
+ if ((clientSocket.canReadLine()) && (clientSocket.state() == TQSocket::Connected)) {
+ clientDS >> server_reply;
+ }
+ if (server_reply == "OK") {
+ ds << TQString("OK");
+ TQByteArray ba(8192);
+ TQ_ULONG reclen;
+ while ((state() == TQSocket::Connected) && (clientSocket.state() == TQSocket::Connected)) {
+ // RAJA FIXME
+ if (canReadLine()) {
+ reclen = readBlock(ba.data(), 8192);
+ clientSocket.writeBlock(ba.data(), reclen);
+ }
+ if (clientSocket.canReadLine()) {
+ reclen = clientSocket.readBlock(ba.data(), 8192);
+ writeBlock(ba.data(), reclen);
+ }
+ tqApp->processEvents();
+ }
+ clientSocket.close();
+ }
+ else {
+ clientSocket.close();
+ ds << TQString("ERRNOTAVL");
+ printf("[DEBUG] Connection failed to %s:%d for user %s@%s due to remote server returning %s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii(), server_reply.ascii()); fflush(stdout);
+ }
+ }
+ }
+ else {
+ clientSocket.close();
+ ds << TQString("ERRNOTAVL");
+ printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
+ }
+ }
+ else {
+ ds << TQString("ERRNOSERV");
+ }
}
}
- else {
- clientSocket.close();
- ds << TQString("ERRNOTAVL");
- printf("[DEBUG] Connection failed to %s:%d for user %s@%s\n\r", serviceHostName.ascii(), servicePort, m_authenticatedUserName.ascii(), m_authenticatedRealmName.ascii()); fflush(stdout);
- }
- }
- else {
- ds << TQString("ERRNOTAVL");
}
}
else {