diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-26 15:43:45 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-26 15:43:45 -0500 |
commit | 249a46324f4f46a6c8afd11f74c8c73ede152184 (patch) | |
tree | 65ef4e06e7db679f96d29039066ee1ed712fb837 /servers/fpga_server_lin | |
parent | fbfb9b1a49003013f646f81b344d5d3a44255c44 (diff) | |
download | ulab-249a46324f4f46a6c8afd11f74c8c73ede152184.tar.gz ulab-249a46324f4f46a6c8afd11f74c8c73ede152184.zip |
Add skeleton for missing functions in tde kerberos library
Diffstat (limited to 'servers/fpga_server_lin')
-rw-r--r-- | servers/fpga_server_lin/acinclude.m4 | 10 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/fpga_conn.cpp | 127 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/fpga_conn.h | 4 | ||||
-rw-r--r-- | servers/fpga_server_lin/src/main.cpp | 13 |
4 files changed, 131 insertions, 23 deletions
diff --git a/servers/fpga_server_lin/acinclude.m4 b/servers/fpga_server_lin/acinclude.m4 index 68a19e6..7424a26 100644 --- a/servers/fpga_server_lin/acinclude.m4 +++ b/servers/fpga_server_lin/acinclude.m4 @@ -244,9 +244,9 @@ AC_DEFUN([KDE_FIND_PATH], AC_DEFUN([KDE_MOC_ERROR_MESSAGE], [ - AC_MSG_ERROR([No Qt meta object compiler (moc) found! + AC_MSG_ERROR([No TQt meta object compiler (tqmoc) found! Please check whether you installed Qt correctly. -You need to have a running moc binary. +You need to have a running tqmoc binary. configure tried to run $ac_cv_path_moc and the test didn't succeed. If configure shouldn't have tried this one, set the environment variable MOC to the right one before running @@ -268,8 +268,8 @@ configure. AC_DEFUN([KDE_UIC_ERROR_MESSAGE], [ - AC_MSG_WARN([No Qt ui compiler (uic) found! -Please check whether you installed Qt correctly. + AC_MSG_WARN([No TQt ui compiler (tquic) found! +Please check whether you installed TQt correctly. You need to have a running uic binary. configure tried to run $ac_cv_path_uic and the test didn't succeed. If configure shouldn't have tried this one, set @@ -334,7 +334,7 @@ AC_DEFUN([AC_PATH_QT_MOC_UIC], qt_bindirs="/usr/share/qt4/bin $qt_bindirs" fi - KDE_FIND_PATH(moc, MOC, [$qt_bindirs], [KDE_MOC_ERROR_MESSAGE]) + KDE_FIND_PATH(tqmoc, MOC, [$qt_bindirs], [KDE_MOC_ERROR_MESSAGE]) if test -z "$UIC_NOT_NEEDED"; then if test $kde_qtver = 3; then KDE_FIND_PATH(uic-tqt, UIC_PATH, [$qt_bindirs], [UIC_PATH=""]) diff --git a/servers/fpga_server_lin/src/fpga_conn.cpp b/servers/fpga_server_lin/src/fpga_conn.cpp index 499d067..1b0927c 100644 --- a/servers/fpga_server_lin/src/fpga_conn.cpp +++ b/servers/fpga_server_lin/src/fpga_conn.cpp @@ -20,7 +20,21 @@ * http://www.raptorengineeringinc.com */ -#include <stdlib.h> +#include <stdio.h> /* perror() */ +#include <stdlib.h> /* atoi() */ +#include <sys/types.h> +#include <sys/socket.h> +#include <unistd.h> /* read() */ +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <fcntl.h> +#include <termios.h> +#include <unistd.h> +#include <sys/signal.h> +#include <sys/types.h> + +#include <tqtimer.h> #include <klocale.h> @@ -38,12 +52,13 @@ struct exit_exception { instance of this class. */ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) : - TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_stationID(-1), m_config(static_cast<FPGAServer*>(parent)->m_config), m_database(NULL), m_databaseStationsCursor(NULL) { + TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_config(static_cast<FPGAServer*>(parent)->m_config) { setServiceName("remotefpga"); line = 0; connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler())); + connect(this, SIGNAL(connectionClosed()), parent, SLOT(remoteConnectionClosed())); setSocket(sock); } @@ -52,8 +67,11 @@ FPGASocket::~FPGASocket() { } void FPGASocket::close() { - TDEKerberosServerSocket::close(); - connectionClosedHandler(); + if (state() == TQSocket::Connected) { + TDEKerberosServerSocket::close(); + connectionClosedHandler(); + TQTimer::singleShot(0, parent(), SLOT(remoteConnectionClosed())); + } } void FPGASocket::connectionClosedHandler() { @@ -76,8 +94,76 @@ int FPGASocket::initiateKerberosHandshake() { } } -void FPGASocket::enterCommandLoop() { - // RAJA FIXME +int FPGASocket::setupSerial() { + struct termios oldtio, newtio; + + m_config->setGroup("FPGA"); + TQString serialDevice = m_config->readEntry("serialdevice", "/dev/ttyS0"); + TQString desiredBaudRate = m_config->readEntry("baudrate", "9600"); + + m_fd_tty = ::open(serialDevice.ascii(), O_RDWR | O_NOCTTY | O_NONBLOCK | O_APPEND); + if (m_fd_tty < 0) { + printf("[FAIL] Unable to open serial device %s\n\r", serialDevice.ascii()); fflush(stdout); + return 1; + } + + tcgetattr(m_fd_tty, &oldtio); // Save current port settings + + long serialBaud; + if (desiredBaudRate == "9600") { + serialBaud = B9600; + } + else if (desiredBaudRate == "115200") { + serialBaud = B115200; + } + else { + printf("[WARNING] Invalid baudrate %s specified, selecting 9600 instead\n\r", desiredBaudRate.ascii()); fflush(stdout); + serialBaud = B9600; + } + + bzero(&newtio, sizeof(newtio)); + newtio.c_cflag = serialBaud | CS8 | CLOCAL | CREAD; + newtio.c_iflag = IGNPAR; + newtio.c_oflag = 0; + + // Set input mode (non-canonical, no echo,...) + newtio.c_lflag = 0; + + newtio.c_cc[VTIME] = 0; // Inter-character timer unused + newtio.c_cc[VMIN] = 0; // Blocking read unused + + tcflush(m_fd_tty, TCIFLUSH); + tcsetattr(m_fd_tty, TCSANOW, &newtio); + + return 0; +} + +int FPGASocket::enterCommandLoop() { + m_criticalSection++; + try { + while (state() == TQSocket::Connected) { + // RAJA FIXME +// cc = read(fd_tty, readbuf, 100000); +// if (cc > 0) { +// write_data_to_client(fd, readbuf, cc); +// fsync(fd_tty); +// printf("[DEBUG] Got %d bytes from the serial port\n\r", cc); fflush(stdout); +// } +// cc = read(fd, writebuf, 100000); +// if (cc > 0) { +// write(fd_tty, writebuf, cc); +// fsync(fd); +// printf("[DEBUG] Got %d bytes from the network interface\n\r", cc); fflush(stdout); +// } + } + + m_criticalSection--; + return 0; + } + catch (...) { + m_criticalSection--; + return -1; + } } /* @@ -93,8 +179,6 @@ FPGAServer::FPGAServer(TQObject* parent, int port, KSimpleConfig* config) : exit(1); } - socketDevice()->setAddressReusable(false); - printf("[INFO] Server started on port %d\n\r", port); fflush(stdout); } @@ -107,21 +191,42 @@ void FPGAServer::newConnection(int socket) { s->m_remoteHost = s->peerAddress().toString(); printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii()); if (m_numberOfConnections > 0) { - printf("[DEBUG] Connection from %s closed due to multiple access attempt\n\r", m_remoteHost.ascii()); + printf("[DEBUG] Connection from %s closed due to multiple access attempt\n\r", s->m_remoteHost.ascii()); s->close(); delete s; s = NULL; + return; } if (s->initiateKerberosHandshake() != 0) { - printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", m_remoteHost.ascii()); + printf("[DEBUG] Connection from %s closed due to Kerberos failure\n\r", s->m_remoteHost.ascii()); + s->close(); + delete s; + s = NULL; + return; + } + m_config->setGroup("Security"); + TQString masterUser = m_config->readEntry("masteruser"); + TQString masterRealm = m_config->readEntry("masterrealm"); + if (masterRealm == "") { + masterRealm = "(NULL)"; + } + if ((s->m_authenticatedUserName != masterUser) || (s->m_authenticatedRealmName != masterRealm)) { + printf("[DEBUG] Connection from %s closed due to authentication failure (attempted connection as user %s@%s)\n\r", s->m_remoteHost.ascii(), masterUser.ascii(), masterRealm.ascii()); + s->close(); + delete s; + s = NULL; + return; + } + if (s->setupSerial() != 0) { + printf("[DEBUG] Connection from %s closed due to serial port initialization failure\n\r", s->m_remoteHost.ascii()); s->close(); delete s; s = NULL; + return; } else { m_numberOfConnections++; connect(s, SIGNAL(connectionClosed()), s, SLOT(deleteLater())); - connect(s, SIGNAL(connectionClosed()), this, SLOT(remoteConnectionClosed())); emit newConnect(s); s->enterCommandLoop(); } diff --git a/servers/fpga_server_lin/src/fpga_conn.h b/servers/fpga_server_lin/src/fpga_conn.h index 1edded2..be11de7 100644 --- a/servers/fpga_server_lin/src/fpga_conn.h +++ b/servers/fpga_server_lin/src/fpga_conn.h @@ -49,15 +49,17 @@ class FPGASocket : public TDEKerberosServerSocket public: void close(); int initiateKerberosHandshake(); - void enterCommandLoop(); + int enterCommandLoop(); private slots: void connectionClosedHandler(); + int setupSerial(); private: int line; int m_criticalSection; TQString m_remoteHost; + int m_fd_tty; KSimpleConfig* m_config; diff --git a/servers/fpga_server_lin/src/main.cpp b/servers/fpga_server_lin/src/main.cpp index fa30af4..5a264d5 100644 --- a/servers/fpga_server_lin/src/main.cpp +++ b/servers/fpga_server_lin/src/main.cpp @@ -27,16 +27,16 @@ #include <unistd.h> #include <stdlib.h> +#include <tqdatetime.h> +#include <tqfile.h> +#include <tqdir.h> + #include <kapplication.h> #include <kstartupinfo.h> #include <kcmdlineargs.h> #include <kaboutdata.h> - #include <ksimpleconfig.h> -#include <tqdatetime.h> -#include <tqfile.h> - #include "fpga_conn.h" static const char description[] = I18N_NOOP("RemoteFPGA Kerberos Authentication Server"); @@ -56,8 +56,9 @@ int main(int argc, char *argv[]) KStartupInfo::appStarted(); - KSimpleConfig config("./remotefpga_fpgaserver.conf", false); - AuthServer authsvr(0, config); + KSimpleConfig config(TQDir::currentDirPath() + "/remotefpga_fpgaserver.conf", false); + config.setGroup("Server"); + FPGAServer fpgasvr(0, config.readNumEntry("port", 4010), &config); return app.exec(); } |