You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.8 KiB

/*
* Remote Laboratory Authentication Server
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (c) 2012 Timothy Pearson
* Raptor Engineering
* http://www.raptorengineeringinc.com
*/
#include <stdlib.h>
#include "auth_conn.h"
/*
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 ) {
setServiceName("remotefpga");
line = 0;
connect(this, SIGNAL(connectionClosed()), SLOT(deleteLater()));
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
setSocket( sock );
}
AuthSocket::~AuthSocket() {
//
}
void AuthSocket::close() {
TQSocket::close();
connectionClosedHandler();
}
void AuthSocket::connectionClosedHandler() {
printf("[DEBUG] Connection from %s closed\n\r", m_remoteHost.ascii());
}
int AuthSocket::initiateKerberosHandshake() {
bool user_authorized = false;
if (setUsingKerberos(true) == 0) {
TQ_UINT32 magicnum = MAGIC_NUMBER;
TQ_UINT32 protover = PROTOCOL_VERSION;
TQDataStream ds(this);
ds << magicnum;
ds << protover;
// RAJA FIXME
if (user_authorized == 1) {
// Send list of available servers...
writeBlock("OK<EFBFBD>", strlen("OK<EFBFBD>"));
}
writeBlock("TESTING", strlen("TESTING"));
return 0;
}
else {
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
responsible for the communication with that client.
*/
AuthServer::AuthServer(TQObject* parent) :
TQServerSocket( 4004, 1, parent ) {
if ( !ok() ) {
printf("[ERROR] Failed to bind to port 4004\n\r");
exit(1);
}
}
AuthServer::~AuthServer() {
//
}
void AuthServer::newConnection(int socket) {
AuthSocket *s = new AuthSocket(socket, this);
s->m_remoteHost = s->peerAddress().toString();
printf("[DEBUG] New connection from %s\n\r", s->m_remoteHost.ascii());
if (s->initiateKerberosHandshake() != 0) {
s->close();
}
else {
emit newConnect(s);
}
}