diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/ConnectionManager.cpp | 6 | ||||
-rw-r--r-- | src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp | 40 | ||||
-rw-r--r-- | src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h | 6 | ||||
-rw-r--r-- | src/Core/Requests/CommandRequest.cpp | 1 |
4 files changed, 34 insertions, 19 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp index 6136edb..f70f640 100644 --- a/src/Core/ConnectionManager.cpp +++ b/src/Core/ConnectionManager.cpp @@ -135,8 +135,7 @@ void ConnectionManager::doInit() { Net::Connection::init(); - Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH); - + Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI"); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>("DaemonCommand"); Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>("DaemonFSInfo"); Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); @@ -155,8 +154,7 @@ void ConnectionManager::doDeinit() { for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) delete *con; - Common::RequestManager::get()->unregisterPacketType(Net::Packet::GSSAPI_AUTH); - + Common::RequestManager::get()->unregisterPacketType("AuthGSSAPI"); Common::RequestManager::get()->unregisterPacketType("DaemonCommand"); Common::RequestManager::get()->unregisterPacketType("DaemonFSInfo"); Common::RequestManager::get()->unregisterPacketType("FSInfo"); diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp index e459511..d9694c8 100644 --- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp +++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.cpp @@ -18,9 +18,10 @@ */ #include "GSSAPIAuthRequestHandler.h" +#include <Common/Exception.h> #include <Common/Logger.h> +#include <Common/XmlPacket.h> #include <Net/Connection.h> -#include <Net/Packets/ErrorPacket.h> #include <cstring> @@ -30,10 +31,15 @@ namespace RequestHandlers { // TODO Error handling -void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) { - if(packet.getType() != Net::Packet::GSSAPI_AUTH) { +void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet) { + if(packet.getType() != "AuthGSSAPI") { Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); - connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET))); + + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Common::Exception::UNEXPECTED_PACKET); + + connection->send(ret.encode(requestId)); signalFinished().emit(); return; @@ -45,9 +51,11 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N // 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_accept_sec_context(&minStat, &gssContext, GSS_C_NO_CREDENTIAL, &recvBuffer, GSS_C_NO_CHANNEL_BINDINGS, 0, 0, &sendBuffer, 0, 0, 0); @@ -62,7 +70,11 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N return; } - if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { + Common::XmlPacket ret; + ret.setType("AuthGSSAPI"); + ret.addBinary("authToken", sendBuffer.value, sendBuffer.length); + + if(!connection->send(ret.encode(requestId))) { gss_release_buffer(&minStat, &sendBuffer); return; } @@ -70,7 +82,7 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N gss_release_buffer(&minStat, &sendBuffer); } else if(!sentSignature) { - if(packet.getLength() != 0) + if(!packet["binary"].isEmpty()) return; const gnutls_datum_t *cert = connection->getCertificate(); @@ -85,7 +97,11 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N return; } - if(!connection->send(Net::Packet(Net::Packet::GSSAPI_AUTH, packet.getRequestId(), sendBuffer.value, sendBuffer.length))) { + Common::XmlPacket ret; + ret.setType("AuthGSSAPI"); + ret.addBinary("certMic", sendBuffer.value, sendBuffer.length); + + if(!connection->send(ret.encode(requestId))) { gss_release_buffer(&minStat, &sendBuffer); return; } @@ -95,9 +111,11 @@ void GSSAPIAuthRequestHandler::handlePacket(Net::Connection *connection, const N sentSignature = true; } else { - 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_process_context_token(&minStat, gssContext, &recvBuffer); diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h index e222fef..7f8ce3b 100644 --- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h +++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h @@ -20,21 +20,21 @@ #ifndef MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ #define MAD_CORE_REQUESTHANDLERS_GSSAPIAUTHREQUESTHANDLER_H_ -#include <Common/RequestHandler.h> +#include <Common/XmlRequestHandler.h> #include <gssapi/gssapi.h> namespace Mad { namespace Core { namespace RequestHandlers { -class GSSAPIAuthRequestHandler : public Common::RequestHandler { +class GSSAPIAuthRequestHandler : public Common::XmlRequestHandler { private: gss_ctx_id_t gssContext; bool gssContinue, sentSignature; protected: - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const Common::XmlPacket &packet); public: GSSAPIAuthRequestHandler() : gssContext(GSS_C_NO_CONTEXT), gssContinue(true), sentSignature(false) {} diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp index a34a551..8fdd4c2 100644 --- a/src/Core/Requests/CommandRequest.cpp +++ b/src/Core/Requests/CommandRequest.cpp @@ -19,7 +19,6 @@ #include "CommandRequest.h" #include <Net/Connection.h> -#include <Net/Packets/ErrorPacket.h> namespace Mad { namespace Core { |