summaryrefslogtreecommitdiffstats
path: root/servers/auth_server_lin/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-11 23:00:58 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-11 23:00:58 -0500
commit26a027c9395bd75403ba0a1e429dcf683bf26633 (patch)
tree38ce101a98912ef7838737ceb11d37ff0ebc042f /servers/auth_server_lin/src
parent962bc5cda4215281e8dcd0d60e8427fe9b7439e2 (diff)
downloadulab-26a027c9395bd75403ba0a1e429dcf683bf26633.tar.gz
ulab-26a027c9395bd75403ba0a1e429dcf683bf26633.zip
Allow multiple connections to backend servers which have cleared the single instance flag
Diffstat (limited to 'servers/auth_server_lin/src')
-rw-r--r--servers/auth_server_lin/src/auth_conn.cpp102
1 files changed, 70 insertions, 32 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp
index 12993d2..b2f2834 100644
--- a/servers/auth_server_lin/src/auth_conn.cpp
+++ b/servers/auth_server_lin/src/auth_conn.cpp
@@ -417,6 +417,7 @@ void AuthSocket::commandLoop() {
while (m_databaseStationsCursor->next()) {
bool authorized = false;
bool in_use = false;
+ bool multi_use = false;
int ngroups = 0;
gid_t *groups;
@@ -461,8 +462,8 @@ void AuthSocket::commandLoop() {
in_use = true;
}
}
-
- if ((authorized) && (!in_use)) {
+
+ if (authorized) {
StationType st;
st.id = m_databaseStationsCursor->value("pk").toInt();
st.name = m_databaseStationsCursor->value("name").toString();
@@ -480,6 +481,7 @@ void AuthSocket::commandLoop() {
char tempchar;
tempchar = m_databaseServiceTypesCursor->value("single_instance").toInt();
svt.singleInstance = (tempchar != 0);
+ if (!svt.singleInstance) multi_use = true;
}
if (svt.name == "") {
svt.name = i18n("<unknown>");
@@ -489,8 +491,10 @@ void AuthSocket::commandLoop() {
}
st.services.append(svt);
}
-
- m_slist.append(st);
+
+ if ((!in_use) || (multi_use)) {
+ m_slist.append(st);
+ }
}
}
@@ -573,44 +577,78 @@ void AuthSocket::commandLoop() {
}
else {
// Find the service ID for the specified client library name
- TQ_INT32 sid = -1;
+ TQInt32List sidList;
m_databaseServiceTypesCursor->select(TQString("client_library='%1'").arg(libname));
if (m_databaseServiceTypesCursor->next()) {
- sid = m_databaseServiceTypesCursor->value("serviceid").toInt();
+ sidList.append(m_databaseServiceTypesCursor->value("serviceid").toInt());
}
- if (sid < 0) {
+ if (sidList.empty()) {
ds << TQString("ERRNOSERV");
writeEndOfFrame();
}
else {
// Attempt to connect to the backend server
- m_databaseServicesCursor->select(TQString("servicetype=%1 AND station=%2").arg(sid).arg(m_stationID));
- if (m_databaseServicesCursor->next()) {
- 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();
-
- updateStatistics(STATISTICS_NEW_CONNECTION_EVENT);
-
- if (!m_servClientSocket) m_servClientSocket = new TDEKerberosClientSocket;
- m_servClientSocket->setServiceName("ulab");
+ TQ_INT32 sid = -1;
+ while (1) {
+ m_databaseServicesCursor->select(TQString("servicetype=%1 AND station=%2").arg(sidList[0]).arg(m_stationID));
+ if (m_databaseServicesCursor->next()) {
+ sid = sidList[0];
+ break;
+ }
+ sidList.remove(sidList.at(0));
+ if (sidList.isEmpty()) {
+ break;
+ }
+ }
+ if (sid != -1) {
+ // Enforce single instance flags
+ bool available = true;
+ m_databaseServiceTypesCursor->select(TQString("serviceid=%1").arg(sid));
+ if (m_databaseServiceTypesCursor->next()) {
+ char tempchar;
+ tempchar = m_databaseServiceTypesCursor->value("single_instance").toInt();
+ if (tempchar != 0) {
+ // Verify that service is not already in use
+ m_databaseActivityCursor->select(TQString("station=%1 AND serviceid=%2").arg(m_databaseStationsCursor->value("pk").toInt()).arg(sid));
+ while (m_databaseActivityCursor->next()) {
+ if (m_databaseActivityCursor->value("username").toString() != "") {
+ available = false;
+ }
+ }
+ }
+ }
+
+ if (available) {
+ 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();
+
+ updateStatistics(STATISTICS_NEW_CONNECTION_EVENT);
+
+ if (!m_servClientSocket) m_servClientSocket = new TDEKerberosClientSocket;
+ m_servClientSocket->setServiceName("ulab");
- m_servClientSocket->setServerFQDN(m_srvServiceHostName);
- m_servClientSocket->connectToHost(m_srvServiceHostName, m_srvServicePort);
+ m_servClientSocket->setServerFQDN(m_srvServiceHostName);
+ m_servClientSocket->connectToHost(m_srvServiceHostName, m_srvServicePort);
- m_servState = 0;
- m_servActive = true;
+ m_servState = 0;
+ m_servActive = true;
+ }
+ else {
+ ds << TQString("ERRNOSERV");
+ writeEndOfFrame();
+ }
}
else {
ds << TQString("ERRNOSERV");