summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/RequestManager.cpp9
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.cpp37
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.h8
-rw-r--r--src/Common/XmlPacket.h17
4 files changed, 52 insertions, 19 deletions
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index afcfa4b..b5acc5c 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -24,8 +24,6 @@
#include "RequestHandlers/DisconnectRequestHandler.h"
#include "Logger.h"
-#include <Net/Packets/ErrorPacket.h>
-
#include <sigc++/bind.h>
#include <sigc++/retype_return.h>
@@ -163,7 +161,12 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
}
Logger::log(Logger::ERROR, "Received an unexpected packet.");
- connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Exception(Exception::UNEXPECTED_PACKET)));
+
+ XmlPacket ret;
+ ret.setType("Error");
+ ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+
+ connection->send(ret.encode(requestId));
}
bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<RequestBase> request) {
diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp
index 05fb373..7f4617a 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.cpp
+++ b/src/Common/Requests/GSSAPIAuthRequest.cpp
@@ -19,6 +19,7 @@
#include "GSSAPIAuthRequest.h"
#include "../Logger.h"
+#include "../XmlPacket.h"
#include <Net/Connection.h>
#include <cstring>
@@ -65,7 +66,11 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques
return;
}
- if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, requestId, buffer.value, buffer.length))) {
+ XmlPacket ret;
+ ret.setType("AuthGSSAPI");
+ ret.addBinary("authToken", buffer.value, buffer.length);
+
+ if(!connection->send(ret.encode(requestId))) {
gss_release_buffer(&minStat, &buffer);
return;
}
@@ -73,8 +78,8 @@ void GSSAPIAuthRequest::sendRequest(Net::Connection *connection, uint16_t reques
gss_release_buffer(&minStat, &buffer);
}
-void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
- if(packet.getType() != Net::Packet::GSSAPI_AUTH) {
+void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) {
+ if(packet.getType() != "AuthGSSAPI") {
finishWithError(Exception(Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
@@ -85,9 +90,11 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac
// Needs error handling!
if(gssContinue) {
- recvBuffer.length = packet.getLength();
+ const void *pkgData;
+ packet["authToken"].getBinaryData(&pkgData, &recvBuffer.length);
+
recvBuffer.value = std::malloc(recvBuffer.length);
- std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length);
+ std::memcpy(recvBuffer.value, pkgData, recvBuffer.length);
majStat = gss_init_sec_context(&minStat, GSS_C_NO_CREDENTIAL, &gssContext, gssServiceName, GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG | GSS_C_INTEG_FLAG,
0, GSS_C_NO_CHANNEL_BINDINGS, &recvBuffer, 0, &sendBuffer, 0, 0);
@@ -103,7 +110,11 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac
return;
}
- if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) {
+ XmlPacket ret;
+ ret.setType("AuthGSSAPI");
+ ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
+
+ if(!connection->send(ret.encode(requestId))) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
@@ -111,9 +122,11 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac
gss_release_buffer(&minStat, &sendBuffer);
}
else {
- recvBuffer.length = packet.getLength();
+ const void *pkgData;
+ packet["certMic"].getBinaryData(&pkgData, &recvBuffer.length);
+
recvBuffer.value = std::malloc(recvBuffer.length);
- std::memcpy(recvBuffer.value, packet.getData(), recvBuffer.length);
+ std::memcpy(recvBuffer.value, pkgData, recvBuffer.length);
const gnutls_datum_t *cert = connection->getPeerCertificate();
@@ -137,14 +150,18 @@ void GSSAPIAuthRequest::handlePacket(Net::Connection *connection, const Net::Pac
return;
}
- if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) {
+ XmlPacket ret;
+ ret.setType("AuthGSSAPI");
+ ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
+
+ if(!connection->send(ret.encode(requestId))) {
gss_release_buffer(&minStat, &sendBuffer);
return;
}
gss_release_buffer(&minStat, &sendBuffer);
- finish();
+ finish(XmlPacket());
}
}
diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h
index 8f2328b..d9f5c9c 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.h
+++ b/src/Common/Requests/GSSAPIAuthRequest.h
@@ -20,7 +20,7 @@
#ifndef MAD_COMMON_REQUESTS_GSSAPIAUTHREQUEST_H_
#define MAD_COMMON_REQUESTS_GSSAPIAUTHREQUEST_H_
-#include "../Request.h"
+#include "../XmlRequest.h"
#include <string>
#include <gssapi/gssapi.h>
@@ -30,7 +30,7 @@ namespace Requests {
// TODO Logging & error handling!
-class GSSAPIAuthRequest : public Request<> {
+class GSSAPIAuthRequest : public XmlRequest {
private:
std::string serviceName;
gss_name_t gssServiceName;
@@ -39,11 +39,11 @@ class GSSAPIAuthRequest : public Request<> {
bool gssContinue;
virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+ virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet);
public:
GSSAPIAuthRequest(const std::string &serviceName0, slot_type slot)
- : Request<>(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {}
+ : XmlRequest(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {}
virtual ~GSSAPIAuthRequest();
};
diff --git a/src/Common/XmlPacket.h b/src/Common/XmlPacket.h
index 196da24..43ee2b2 100644
--- a/src/Common/XmlPacket.h
+++ b/src/Common/XmlPacket.h
@@ -130,8 +130,17 @@ class XmlPacket {
return 0;
}
- bool isEmpty() const {
- return (getSize() == 0);
+ virtual bool isEmpty() const {
+ switch(type) {
+ case NONE:
+ return true;
+ case BINARY:
+ return (value.var_size != 0);
+ case STRING:
+ return str.empty();
+ default:
+ return false;
+ }
}
virtual Entry& operator[](size_t) {
@@ -419,6 +428,10 @@ class XmlPacket {
return entries.size();
}
+ virtual bool isEmpty() const {
+ return entries.empty();
+ }
+
virtual Entry& operator[](size_t i) {
return *entries[i];
}