diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-05-22 00:23:59 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-05-22 00:23:59 +0200 |
commit | 264cd7947d7291f78065f12824523ba6178a9936 (patch) | |
tree | 7261b9a33519cd783f614b147c44f484a1217618 /src/Server | |
parent | e0e254548b6200d16bc3f4be3bd255b041a76532 (diff) | |
download | mad-264cd7947d7291f78065f12824523ba6178a9936.tar mad-264cd7947d7291f78065f12824523ba6178a9936.zip |
GroupListRequest hinzugef?gt
Diffstat (limited to 'src/Server')
-rw-r--r-- | src/Server/ConnectionManager.cpp | 5 | ||||
-rw-r--r-- | src/Server/RequestHandlers/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Server/RequestHandlers/GroupListRequestHandler.cpp | 73 | ||||
-rw-r--r-- | src/Server/RequestHandlers/GroupListRequestHandler.h | 42 | ||||
-rw-r--r-- | src/Server/UserBackend.h | 5 | ||||
-rw-r--r-- | src/Server/UserManager.cpp | 10 | ||||
-rw-r--r-- | src/Server/UserManager.h | 3 |
7 files changed, 138 insertions, 2 deletions
diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index abb66b0..3065c05 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -28,7 +28,8 @@ #include "RequestHandlers/DaemonFSInfoRequestHandler.h" #include "RequestHandlers/DaemonListRequestHandler.h" #include "RequestHandlers/DaemonStatusRequestHandler.h" -#include "RequestHandlers/GSSAPIAuthRequestHandler.h" +//#include "RequestHandlers/GSSAPIAuthRequestHandler.h" +#include "RequestHandlers/GroupListRequestHandler.h" #include "RequestHandlers/IdentifyRequestHandler.h" #include "RequestHandlers/LogRequestHandler.h" #include "RequestHandlers/UserInfoRequestHandler.h" @@ -194,6 +195,7 @@ void ConnectionManager::doInit() { Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonListRequestHandler>("ListHosts"); Common::RequestManager::get()->registerPacketType<RequestHandlers::UserInfoRequestHandler>("GetUserInfo"); Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>("ListUsers"); + Common::RequestManager::get()->registerPacketType<RequestHandlers::GroupListRequestHandler>("ListGroups"); Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>("Log"); } @@ -210,6 +212,7 @@ void ConnectionManager::doDeinit() { Common::RequestManager::get()->unregisterPacketType("ListHosts"); Common::RequestManager::get()->unregisterPacketType("GetUserInfo"); Common::RequestManager::get()->unregisterPacketType("ListUsers"); + Common::RequestManager::get()->unregisterPacketType("ListGroups"); Common::RequestManager::get()->unregisterPacketType("Log"); } diff --git a/src/Server/RequestHandlers/CMakeLists.txt b/src/Server/RequestHandlers/CMakeLists.txt index e340a1e..9215348 100644 --- a/src/Server/RequestHandlers/CMakeLists.txt +++ b/src/Server/RequestHandlers/CMakeLists.txt @@ -3,7 +3,7 @@ include_directories(${INCLUDES}) add_library(ServerRequestHandlers DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp - IdentifyRequestHandler.cpp + GroupListRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp UserInfoRequestHandler.cpp UserListRequestHandler.cpp ) diff --git a/src/Server/RequestHandlers/GroupListRequestHandler.cpp b/src/Server/RequestHandlers/GroupListRequestHandler.cpp new file mode 100644 index 0000000..1ca2b92 --- /dev/null +++ b/src/Server/RequestHandlers/GroupListRequestHandler.cpp @@ -0,0 +1,73 @@ +/* + * GroupListRequestHandler.cpp + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include "GroupListRequestHandler.h" +#include "../UserManager.h" +#include <Net/Exception.h> +#include <Common/Logger.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void GroupListRequestHandler::handlePacket(const Common::XmlPacket &packet) { + if(packet.getType() != "ListGroups") { + Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet."); + + Common::XmlPacket ret; + ret.setType("Error"); + ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET); + + sendPacket(ret); + + signalFinished()(); + return; + } + + // TODO Require authentication + + boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > info = UserManager::get()->getGroupList(); + + Common::XmlPacket ret; + + if(info) { + ret.setType("OK"); + ret.addList("groups"); + + for(std::map<unsigned long, Common::GroupInfo>::iterator group = info->begin(); group != info->end(); ++group) { + ret["groups"].addEntry(); + Common::XmlPacket::Entry &entry = ret["groups"].back(); + + entry.add("gid", group->second.getGid()); + entry.add("name", group->second.getName()); + } + } + + else { + ret.setType("Error"); + ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED); + } + + sendPacket(ret); + signalFinished()(); +} + +} +} +} diff --git a/src/Server/RequestHandlers/GroupListRequestHandler.h b/src/Server/RequestHandlers/GroupListRequestHandler.h new file mode 100644 index 0000000..d7d6a9c --- /dev/null +++ b/src/Server/RequestHandlers/GroupListRequestHandler.h @@ -0,0 +1,42 @@ +/* + * GroupListRequestHandler.h + * + * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MAD_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_ +#define MAD_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +class GroupListRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(const Common::XmlPacket &packet); + + public: + GroupListRequestHandler(Common::Connection *connection, boost::uint16_t requestId) + : RequestHandler(connection, requestId) {} +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_GROUPLISTREQUESTHANDLER_H_ */ diff --git a/src/Server/UserBackend.h b/src/Server/UserBackend.h index a673fa9..6d59615 100644 --- a/src/Server/UserBackend.h +++ b/src/Server/UserBackend.h @@ -23,6 +23,7 @@ #include <config.h> #include <Common/UserInfo.h> +#include <Common/GroupInfo.h> #include <map> #include <string> @@ -49,6 +50,10 @@ class UserBackend { return boost::shared_ptr<Common::UserInfo>(); } + virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList() { + return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >(); + } + // TODO Better interface... virtual bool setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) { return false; diff --git a/src/Server/UserManager.cpp b/src/Server/UserManager.cpp index 3b5887a..e32cb57 100644 --- a/src/Server/UserManager.cpp +++ b/src/Server/UserManager.cpp @@ -54,6 +54,16 @@ boost::shared_ptr<Common::UserInfo> UserManager::getUserInfo(unsigned long uid) return boost::shared_ptr<Common::UserInfo>(); } +boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserManager::getGroupList() { + for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { + boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > ret = (*backend)->getGroupList(); + if(ret) + return ret; + } + + return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >(); +} + bool UserManager::setPassword(unsigned long uid, const std::string &password) { for(std::set<boost::shared_ptr<UserBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { if((*backend)->setPassword(uid, password)) diff --git a/src/Server/UserManager.h b/src/Server/UserManager.h index c3d990d..e33b678 100644 --- a/src/Server/UserManager.h +++ b/src/Server/UserManager.h @@ -21,6 +21,7 @@ #define MAD_SERVER_USERMANAGER_H_ #include <Common/UserInfo.h> +#include <Common/GroupInfo.h> #include <map> #include <set> @@ -57,6 +58,8 @@ class UserManager : boost::noncopyable { boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList(); boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid); + boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList(); + bool setPassword(unsigned long uid, const std::string &password); bool addUser(const Common::UserInfo &userInfo); |