summaryrefslogtreecommitdiffstats
path: root/servers
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-23 17:23:49 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-06-23 17:23:49 -0500
commit8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2 (patch)
treea0a77ec1d7d7cd826e1f2ba92ea4f96351bae5e3 /servers
parentb48b26b86975d2166a4da7fc41086facefb3c4f2 (diff)
downloadulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.tar.gz
ulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.zip
Fix a number of crashes and generally clean up the code
Diffstat (limited to 'servers')
-rw-r--r--servers/auth_server_lin/src/Makefile.am1
-rw-r--r--servers/auth_server_lin/src/auth_conn.cpp59
-rw-r--r--servers/auth_server_lin/src/auth_conn.h2
3 files changed, 49 insertions, 13 deletions
diff --git a/servers/auth_server_lin/src/Makefile.am b/servers/auth_server_lin/src/Makefile.am
index c9c9fde..2da637d 100644
--- a/servers/auth_server_lin/src/Makefile.am
+++ b/servers/auth_server_lin/src/Makefile.am
@@ -1,4 +1,5 @@
INCLUDES= $(all_includes) $(KDE_INCLUDES)/tde -I/usr/include/sasl
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
bin_PROGRAMS = remotefpga_authserver
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp
index 013b9bd..396218a 100644
--- a/servers/auth_server_lin/src/auth_conn.cpp
+++ b/servers/auth_server_lin/src/auth_conn.cpp
@@ -24,18 +24,23 @@
#include "auth_conn.h"
+/* exception handling */
+struct exit_exception {
+ int c;
+ exit_exception(int c):c(c) { }
+};
+
/*
The AuthSocket class provides a socket that is connected with a client.
For every client that connects to the server, the server creates a new
instance of this class.
*/
AuthSocket::AuthSocket(int sock, TQObject *parent, const char *name) :
- TDEKerberosServerSocket( parent, name ) {
+ TDEKerberosServerSocket( parent, name ), m_criticalSection(0) {
setServiceName("remotefpga");
line = 0;
- connect(this, SIGNAL(connectionClosed()), SLOT(deleteLater()));
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
setSocket( sock );
}
@@ -45,17 +50,18 @@ AuthSocket::~AuthSocket() {
}
void AuthSocket::close() {
- TQSocket::close();
+ TDEKerberosServerSocket::close();
connectionClosedHandler();
}
void AuthSocket::connectionClosedHandler() {
printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii());
+ if (m_criticalSection > 0) {
+ throw exit_exception(-1);
+ }
}
int AuthSocket::initiateKerberosHandshake() {
- bool user_authorized = false;
-
if (setUsingKerberos(true) == 0) {
TQ_UINT32 magicnum = MAGIC_NUMBER;
TQ_UINT32 protover = PROTOCOL_VERSION;
@@ -64,14 +70,6 @@ int AuthSocket::initiateKerberosHandshake() {
ds << magicnum;
ds << protover;
- // RAJA FIXME
- if (user_authorized == 1) {
- // Send list of available servers...
- writeBlock("OK�", strlen("OK�"));
- }
-
- writeBlock("TESTING", strlen("TESTING"));
-
return 0;
}
else {
@@ -79,6 +77,37 @@ int AuthSocket::initiateKerberosHandshake() {
}
}
+int AuthSocket::enterCommandLoop() {
+ m_criticalSection++;
+ try {
+ TQString command;
+ TQDataStream ds(this);
+
+ while (state() == TQSocket::Connected) {
+ ds >> command;
+printf("[RAJA DEBUG 500.0] Got command %s\n\r", command.ascii()); fflush(stdout);
+ if (command == "LIST") {
+ // Send list of available servers...
+ // RAJA FIXME
+ StationList slist;
+ ds << slist;
+ }
+ else {
+ ds << "ERRINVCMD";
+ }
+ tqApp->processEvents();
+ }
+
+ m_criticalSection--;
+ return 0;
+ }
+ catch (...) {
+ m_criticalSection--;
+ return -1;
+ }
+
+}
+
/*
The AuthServer class handles new connections to the server. For every
client that connects, it creates a new AuthSocket -- that instance is now
@@ -103,8 +132,12 @@ void AuthServer::newConnection(int socket) {
printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii());
if (s->initiateKerberosHandshake() != 0) {
s->close();
+ delete s;
+ s = NULL;
}
else {
+ connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater()));
emit newConnect(s);
+ s->enterCommandLoop();
}
}
diff --git a/servers/auth_server_lin/src/auth_conn.h b/servers/auth_server_lin/src/auth_conn.h
index e9432f5..3ce82e2 100644
--- a/servers/auth_server_lin/src/auth_conn.h
+++ b/servers/auth_server_lin/src/auth_conn.h
@@ -47,12 +47,14 @@ class AuthSocket : public TDEKerberosServerSocket
public:
void close();
int initiateKerberosHandshake();
+ int enterCommandLoop();
private slots:
void connectionClosedHandler();
private:
int line;
+ int m_criticalSection;
TQString m_remoteHost;
friend class AuthServer;