diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index cf68f9e..ce1e752 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -427,7 +427,7 @@ void AuthSocket::commandLoop() { if (command == "LIST") { // Send list of available servers... m_slist.clear(); - + // Get all stations from the database m_databaseStationsCursor->select(); while (m_databaseStationsCursor->next()) { @@ -444,13 +444,13 @@ void AuthSocket::commandLoop() { printf("[ERROR] Unable to allocate memory\n\r"); fflush(stdout); exit(EXIT_FAILURE); } - + pw = getpwnam(m_authenticatedUserName.ascii()); if (pw == NULL) { printf("[WARNING] Unable to get detailed information for user '%s', ignoring\n\r", m_authenticatedUserName.ascii()); fflush(stdout); continue; } - + if (getgrouplist(m_authenticatedUserName.ascii(), pw->pw_gid, groups, &ngroups) == -1) { free(groups); groups = (gid_t*)malloc(ngroups*sizeof(gid_t)); @@ -522,10 +522,10 @@ void AuthSocket::commandLoop() { StationType st; ds >> st; clearFrameTail(); - + // Attempt to bind to station matching desired Service Type list... m_stationID = -1; - + // 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)); @@ -552,7 +552,7 @@ void AuthSocket::commandLoop() { } } } - + if (m_stationID < 0) { ds << TQString("ERRUNAVAL"); writeEndOfFrame(); @@ -560,7 +560,7 @@ void AuthSocket::commandLoop() { else { m_bound = true; m_serviceID = 0; - + // Update database TQSqlRecord *buffer = m_databaseActivityCursor->primeInsert(); buffer->setValue("station", m_stationID); @@ -573,7 +573,7 @@ void AuthSocket::commandLoop() { m_databaseActivityCursor->insert(); updateStatistics(STATISTICS_NEW_CONNECTION_EVENT); - + ds << TQString("OK"); writeEndOfFrame(); } @@ -589,12 +589,12 @@ void AuthSocket::commandLoop() { ds >> libname; 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' AND serviceid=0").arg(m_authenticatedUserName).arg(m_authenticatedRealmName)); if (m_databaseActivityCursor->next()) { m_stationID = m_databaseActivityCursor->value("station").toInt(); } - + if (m_bound == true) { ds << TQString("ERRINVCMD"); writeEndOfFrame(); @@ -684,7 +684,7 @@ void AuthSocket::commandLoop() { if (mechList.count() > 0) { m_servClientSocket->setMechanismOverrideList(mechList); } - + m_servClientSocket->setServerFQDN(m_srvServiceHostName); m_servClientSocket->connectToHost(m_srvServiceHostName, m_srvServicePort); @@ -859,45 +859,62 @@ int AuthServer::connectToDatabase() { return -1; } - if (!m_database->tables().contains("stations")) { + TQSqlCursor* testCursor = NULL; + + testCursor = new TQSqlCursor("stations", TRUE, m_database); + testCursor->select(); + if (!testCursor->isActive()) { m_database->close(); printf("[ERROR] Control database '%s' on '%s' does not contain the required 'stations' table\n\r", m_database->databaseName().ascii(), m_database->hostName().ascii()); fflush(stdout); TQSqlDatabase::removeDatabase(m_database); m_database = NULL; return -1; } + delete testCursor; - if (!m_database->tables().contains("services")) { + testCursor = new TQSqlCursor("services", TRUE, m_database); + testCursor->select(); + if (!testCursor->isActive()) { m_database->close(); printf("[ERROR] Control database '%s' on '%s' does not contain the required 'services' table\n\r", m_database->databaseName().ascii(), m_database->hostName().ascii()); fflush(stdout); TQSqlDatabase::removeDatabase(m_database); m_database = NULL; return -1; } + delete testCursor; - if (!m_database->tables().contains("servicetypes")) { + testCursor = new TQSqlCursor("servicetypes", TRUE, m_database); + testCursor->select(); + if (!testCursor->isActive()) { m_database->close(); printf("[ERROR] Control database '%s' on '%s' does not contain the required 'servicetypes' table\n\r", m_database->databaseName().ascii(), m_database->hostName().ascii()); fflush(stdout); TQSqlDatabase::removeDatabase(m_database); m_database = NULL; return -1; } + delete testCursor; - if (!m_database->tables().contains("permissions")) { + testCursor = new TQSqlCursor("permissions", TRUE, m_database); + testCursor->select(); + if (!testCursor->isActive()) { m_database->close(); printf("[ERROR] Control database '%s' on '%s' does not contain the required 'permissions' table\n\r", m_database->databaseName().ascii(), m_database->hostName().ascii()); fflush(stdout); TQSqlDatabase::removeDatabase(m_database); m_database = NULL; return -1; } + delete testCursor; - if (!m_database->tables().contains("activity")) { + testCursor = new TQSqlCursor("activity", TRUE, m_database); + testCursor->select(); + if (!testCursor->isActive()) { m_database->close(); printf("[ERROR] Control database '%s' on '%s' does not contain the required 'activity' table\n\r", m_database->databaseName().ascii(), m_database->hostName().ascii()); fflush(stdout); TQSqlDatabase::removeDatabase(m_database); m_database = NULL; return -1; } + delete testCursor; // Start database ping process // When combined with the MYSQL_OPT_RECONNECT flag passed above, this will keep the connection open even if the database server goes offline and then comes back online