diff options
-rw-r--r-- | src/Client/CommandManager.cpp | 58 | ||||
-rw-r--r-- | src/Client/CommandManager.h | 2 | ||||
-rw-r--r-- | src/Client/CommandParser.cpp | 58 | ||||
-rw-r--r-- | src/Client/CommandParser.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Common/Requests/GroupListRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/GroupUserListRequest.cpp | 36 | ||||
-rw-r--r-- | src/Common/Requests/GroupUserListRequest.h | 45 | ||||
-rw-r--r-- | src/Common/Requests/UserGroupListRequest.cpp | 36 | ||||
-rw-r--r-- | src/Common/Requests/UserGroupListRequest.h | 45 | ||||
-rw-r--r-- | src/Server/ConnectionManager.cpp | 6 | ||||
-rw-r--r-- | src/Server/RequestHandlers/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Server/RequestHandlers/GroupUserListRequestHandler.cpp | 74 | ||||
-rw-r--r-- | src/Server/RequestHandlers/GroupUserListRequestHandler.h | 42 | ||||
-rw-r--r-- | src/Server/RequestHandlers/UserGroupListRequestHandler.cpp | 74 | ||||
-rw-r--r-- | src/Server/RequestHandlers/UserGroupListRequestHandler.h | 42 | ||||
-rw-r--r-- | src/Server/UserBackend.h | 1 |
17 files changed, 521 insertions, 8 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp index b427db7..603f679 100644 --- a/src/Client/CommandManager.cpp +++ b/src/Client/CommandManager.cpp @@ -235,7 +235,7 @@ void CommandManager::userListRequestFinished(const Common::Request &request) { std::cout << "User list is empty." << std::endl; } else { - std::cout << "Found " << users.getSize() << " users:" << std::endl; + std::cout << "Found " << users.getSize() << " user" << (users.getSize()==1 ? "" : "s") << ":" << std::endl; for(size_t i = 0; i < users.getSize(); ++i) @@ -251,6 +251,33 @@ void CommandManager::userListRequestFinished(const Common::Request &request) { requestFinished(); } +void CommandManager::userGroupListRequestFinished(const Common::Request &request) { + try { + const Common::XmlPacket &packet = request.getResult(); + + const Common::XmlPacket::Element &groups = packet["groups"]; + + if(groups.isEmpty()) { + std::cout << "The user isn't member of any group." << std::endl; + } + else { + + std::cout << "User is member of " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl; + + + for(size_t i = 0; i < groups.getSize(); ++i) + std::cout << " " << (unsigned long)groups[i]["gid"] << std::endl; + } + + std::cout << std::endl; + } + catch(Net::Exception &exception) { + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); + } + + requestFinished(); +} + void CommandManager::groupListRequestFinished(const Common::Request &request) { try { const Common::XmlPacket &packet = request.getResult(); @@ -261,7 +288,7 @@ void CommandManager::groupListRequestFinished(const Common::Request &request) { std::cout << "Group list is empty." << std::endl; } else { - std::cout << "Found " << groups.getSize() << " groups:" << std::endl; + std::cout << "Found " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl; for(size_t i = 0; i < groups.getSize(); ++i) @@ -277,5 +304,32 @@ void CommandManager::groupListRequestFinished(const Common::Request &request) { requestFinished(); } +void CommandManager::groupUserListRequestFinished(const Common::Request &request) { + try { + const Common::XmlPacket &packet = request.getResult(); + + const Common::XmlPacket::Element &users = packet["users"]; + + if(users.isEmpty()) { + std::cout << "The group doesn't have any members." << std::endl; + } + else { + + std::cout << "The group has " << users.getSize() << " member" << (users.getSize()==1 ? "" : "s") << ":" << std::endl; + + + for(size_t i = 0; i < users.getSize(); ++i) + std::cout << " " << (unsigned long)users[i]["uid"] << std::endl; + } + + std::cout << std::endl; + } + catch(Net::Exception &exception) { + Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str()); + } + + requestFinished(); +} + } } diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h index 3cfc502..137ec8e 100644 --- a/src/Client/CommandManager.h +++ b/src/Client/CommandManager.h @@ -60,7 +60,9 @@ class CommandManager { void statusRequestFinished(const Common::Request &request); void userInfoRequestFinished(const Common::Request &request); void userListRequestFinished(const Common::Request &request); + void userGroupListRequestFinished(const Common::Request &request); void groupListRequestFinished(const Common::Request &request); + void groupUserListRequestFinished(const Common::Request &request); CommandManager() : activeRequests(0), disconnect(false) {} diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 044a64c..1c0403d 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -27,9 +27,11 @@ #include <Common/Requests/FSInfoRequest.h> #include <Common/Requests/DisconnectRequest.h> #include <Common/Requests/GroupListRequest.h> +#include <Common/Requests/GroupUserListRequest.h> #include <Common/Requests/StatusRequest.h> #include <Common/Requests/UserInfoRequest.h> #include <Common/Requests/UserListRequest.h> +#include <Common/Requests/UserGroupListRequest.h> #include <Common/Tokenizer.h> #include <iostream> @@ -49,8 +51,10 @@ const CommandParser::Command CommandParser::commands[] = { {{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &CommandParser::statusCommand}, {{"user_info", "user", 0}, "user_info uid", "Search for a user id", "Search for a user id.", &CommandParser::userInfoCommand}, {{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &CommandParser::listUsersCommand}, + {{"list_user_groups", "user_groups", 0}, "list_user_groups uid", "List user's groups", "List the groups that the user is member of.", &CommandParser::listUserGroupsCommand}, {{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &CommandParser::listGroupsCommand}, - {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, + {{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &CommandParser::listGroupUsersCommand}, + {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} }; @@ -292,6 +296,32 @@ void CommandParser::listUsersCommand(const std::vector<std::string>&) { boost::bind(&CommandManager::userListRequestFinished, CommandManager::get(), _1)); } +void CommandParser::listUserGroupsCommand(const std::vector<std::string> &args) { + if(args.size() == 1) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No user id given.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + + char *endptr; + unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + Common::Logger::logf(Common::Logger::ERROR, "%s: Unable to parse user id.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + + ++CommandManager::get()->activeRequests; + + Common::RequestManager::get()->sendRequest<Common::Requests::UserGroupListRequest>(connection, + boost::bind(&CommandManager::userGroupListRequestFinished, CommandManager::get(), _1), uid); +} + void CommandParser::listGroupsCommand(const std::vector<std::string>&) { ++CommandManager::get()->activeRequests; @@ -299,6 +329,32 @@ void CommandParser::listGroupsCommand(const std::vector<std::string>&) { boost::bind(&CommandManager::groupListRequestFinished, CommandManager::get(), _1)); } +void CommandParser::listGroupUsersCommand(const std::vector<std::string> &args) { + if(args.size() == 1) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No group id given.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + Common::Logger::logf(Common::Logger::ERROR, "%s: Unable to parse group id.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + + ++CommandManager::get()->activeRequests; + + Common::RequestManager::get()->sendRequest<Common::Requests::GroupUserListRequest>(connection, + boost::bind(&CommandManager::groupUserListRequestFinished, CommandManager::get(), _1), gid); +} + void CommandParser::exitCommand(const std::vector<std::string>&) { ++CommandManager::get()->activeRequests; diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h index 727181e..692eb7e 100644 --- a/src/Client/CommandParser.h +++ b/src/Client/CommandParser.h @@ -65,7 +65,9 @@ class CommandParser { void statusCommand(const std::vector<std::string> &args); void userInfoCommand(const std::vector<std::string> &args); void listUsersCommand(const std::vector<std::string> &args); + void listUserGroupsCommand(const std::vector<std::string> &args); void listGroupsCommand(const std::vector<std::string> &args); + void listGroupUsersCommand(const std::vector<std::string> &args); void exitCommand(const std::vector<std::string>&); CommandParser() : connection(0) {} diff --git a/src/Common/Requests/CMakeLists.txt b/src/Common/Requests/CMakeLists.txt index 54b14e1..ef1d4d9 100644 --- a/src/Common/Requests/CMakeLists.txt +++ b/src/Common/Requests/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${INCLUDES}) add_library(Requests STATIC - DisconnectRequest.cpp IdentifyRequest.cpp SimpleRequest.cpp UserInfoRequest.cpp + DisconnectRequest.cpp GroupUserListRequest.cpp IdentifyRequest.cpp SimpleRequest.cpp UserGroupListRequest.cpp UserInfoRequest.cpp ) target_link_libraries(Requests ${KRB5_LIBRARIES}) diff --git a/src/Common/Requests/GroupListRequest.h b/src/Common/Requests/GroupListRequest.h index 86322ad..5aad003 100644 --- a/src/Common/Requests/GroupListRequest.h +++ b/src/Common/Requests/GroupListRequest.h @@ -1,5 +1,5 @@ /* - * UserListRequest.h + * GroupListRequest.h * * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de> * diff --git a/src/Common/Requests/GroupUserListRequest.cpp b/src/Common/Requests/GroupUserListRequest.cpp new file mode 100644 index 0000000..f77f559 --- /dev/null +++ b/src/Common/Requests/GroupUserListRequest.cpp @@ -0,0 +1,36 @@ +/* + * GroupUserListRequest.cpp + * + * Copyright (C) 2008 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 "GroupUserListRequest.h" + +namespace Mad { +namespace Common { +namespace Requests { + +void GroupUserListRequest::sendRequest() { + Common::XmlPacket packet; + packet.setType("ListGroupUsers"); + packet.add("gid", gid); + + sendPacket(packet); +} + +} +} +} diff --git a/src/Common/Requests/GroupUserListRequest.h b/src/Common/Requests/GroupUserListRequest.h new file mode 100644 index 0000000..fd56a2f --- /dev/null +++ b/src/Common/Requests/GroupUserListRequest.h @@ -0,0 +1,45 @@ +/* + * GroupUserListRequest.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_COMMON_REQUESTS_GROUPUSERLISTREQUEST_H_ +#define MAD_COMMON_REQUESTS_GROUPUSERLISTREQUEST_H_ + +#include "../Request.h" + +namespace Mad { +namespace Common { +namespace Requests { + +class GroupUserListRequest : public Request { + private: + unsigned long gid; + + protected: + virtual void sendRequest(); + + public: + GroupUserListRequest(Connection *connection, uint16_t requestId, slot_type slot, unsigned long gid0) + : Request(connection, requestId, slot), gid(gid0) {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTS_GROUPUSERLISTREQUEST_H_ */ diff --git a/src/Common/Requests/UserGroupListRequest.cpp b/src/Common/Requests/UserGroupListRequest.cpp new file mode 100644 index 0000000..ec7e23c --- /dev/null +++ b/src/Common/Requests/UserGroupListRequest.cpp @@ -0,0 +1,36 @@ +/* + * UserGroupListRequest.cpp + * + * Copyright (C) 2008 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 "UserGroupListRequest.h" + +namespace Mad { +namespace Common { +namespace Requests { + +void UserGroupListRequest::sendRequest() { + Common::XmlPacket packet; + packet.setType("ListUserGroups"); + packet.add("uid", uid); + + sendPacket(packet); +} + +} +} +} diff --git a/src/Common/Requests/UserGroupListRequest.h b/src/Common/Requests/UserGroupListRequest.h new file mode 100644 index 0000000..2ee33d9 --- /dev/null +++ b/src/Common/Requests/UserGroupListRequest.h @@ -0,0 +1,45 @@ +/* + * UserGroupListRequest.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_COMMON_REQUESTS_USERGROUPLISTREQUEST_H_ +#define MAD_COMMON_REQUESTS_USERGROUPLISTREQUEST_H_ + +#include "../Request.h" + +namespace Mad { +namespace Common { +namespace Requests { + +class UserGroupListRequest : public Request { + private: + unsigned long uid; + + protected: + virtual void sendRequest(); + + public: + UserGroupListRequest(Connection *connection, uint16_t requestId, slot_type slot, unsigned long uid0) + : Request(connection, requestId, slot), uid(uid0) {} +}; + +} +} +} + +#endif /* MAD_COMMON_REQUESTS_USERGROUPLISTREQUEST_H_ */ diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index 3065c05..2ce2bb5 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -30,8 +30,10 @@ #include "RequestHandlers/DaemonStatusRequestHandler.h" //#include "RequestHandlers/GSSAPIAuthRequestHandler.h" #include "RequestHandlers/GroupListRequestHandler.h" +#include "RequestHandlers/GroupUserListRequestHandler.h" #include "RequestHandlers/IdentifyRequestHandler.h" #include "RequestHandlers/LogRequestHandler.h" +#include "RequestHandlers/UserGroupListRequestHandler.h" #include "RequestHandlers/UserInfoRequestHandler.h" #include "RequestHandlers/UserListRequestHandler.h" #include <Net/Packet.h> @@ -195,7 +197,9 @@ 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::UserGroupListRequestHandler>("ListUserGroups"); Common::RequestManager::get()->registerPacketType<RequestHandlers::GroupListRequestHandler>("ListGroups"); + Common::RequestManager::get()->registerPacketType<RequestHandlers::GroupUserListRequestHandler>("ListGroupUsers"); Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>("Log"); } @@ -212,7 +216,9 @@ void ConnectionManager::doDeinit() { Common::RequestManager::get()->unregisterPacketType("ListHosts"); Common::RequestManager::get()->unregisterPacketType("GetUserInfo"); Common::RequestManager::get()->unregisterPacketType("ListUsers"); + Common::RequestManager::get()->unregisterPacketType("ListUserGroups"); Common::RequestManager::get()->unregisterPacketType("ListGroups"); + Common::RequestManager::get()->unregisterPacketType("ListGroupUsers"); Common::RequestManager::get()->unregisterPacketType("Log"); } diff --git a/src/Server/RequestHandlers/CMakeLists.txt b/src/Server/RequestHandlers/CMakeLists.txt index 9215348..fe4e71d 100644 --- a/src/Server/RequestHandlers/CMakeLists.txt +++ b/src/Server/RequestHandlers/CMakeLists.txt @@ -3,8 +3,8 @@ include_directories(${INCLUDES}) add_library(ServerRequestHandlers DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp - GroupListRequestHandler.cpp IdentifyRequestHandler.cpp - LogRequestHandler.cpp UserInfoRequestHandler.cpp + GroupListRequestHandler.cpp GroupUserListRequestHandler.cpp IdentifyRequestHandler.cpp + LogRequestHandler.cpp UserGroupListRequestHandler.cpp UserInfoRequestHandler.cpp UserListRequestHandler.cpp ) target_link_libraries(ServerRequestHandlers Server ${KRB5_LIBRARIES}) diff --git a/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp b/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp new file mode 100644 index 0000000..df1253a --- /dev/null +++ b/src/Server/RequestHandlers/GroupUserListRequestHandler.cpp @@ -0,0 +1,74 @@ +/* + * GroupUserListRequestHandler.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 "GroupUserListRequestHandler.h" +#include "../UserManager.h" +#include <Net/Exception.h> +#include <Common/Logger.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void GroupUserListRequestHandler::handlePacket(const Common::XmlPacket &packet) { + if(packet.getType() != "ListGroupUsers") { + 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 + + Common::XmlPacket ret; + + try { + boost::shared_ptr<std::set<unsigned long> > users = UserManager::get()->getGroupUserList((unsigned long)packet["gid"]); + + ret.setType("OK"); + ret.addList("users"); + + for(std::set<unsigned long>::iterator user = users->begin(); user != users->end(); ++user) { + ret["users"].addEntry(); + Common::XmlPacket::Entry &entry = ret["users"].back(); + + entry.add("uid", *user); + } + } + catch(Net::Exception e) { + ret.setType("Error"); + ret.add("ErrorCode", e.getErrorCode()); + ret.add("SubCode", e.getSubCode()); + ret.add("SubSubCode", e.getSubSubCode()); + ret.add("Where", e.getWhere()); + } + + sendPacket(ret); + signalFinished()(); +} + +} +} +} diff --git a/src/Server/RequestHandlers/GroupUserListRequestHandler.h b/src/Server/RequestHandlers/GroupUserListRequestHandler.h new file mode 100644 index 0000000..5e50961 --- /dev/null +++ b/src/Server/RequestHandlers/GroupUserListRequestHandler.h @@ -0,0 +1,42 @@ +/* + * GroupUserListRequestHandler.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_GROUPUSERLISTREQUESTHANDLER_H_ +#define MAD_SERVER_REQUESTHANDLERS_GROUPUSERLISTREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +class GroupUserListRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(const Common::XmlPacket &packet); + + public: + GroupUserListRequestHandler(Common::Connection *connection, uint16_t requestId) + : RequestHandler(connection, requestId) {} +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_GROUPUSERLISTREQUESTHANDLER_H_ */ diff --git a/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp b/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp new file mode 100644 index 0000000..e127649 --- /dev/null +++ b/src/Server/RequestHandlers/UserGroupListRequestHandler.cpp @@ -0,0 +1,74 @@ +/* + * UserGroupListRequestHandler.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 "UserGroupListRequestHandler.h" +#include "../UserManager.h" +#include <Net/Exception.h> +#include <Common/Logger.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +void UserGroupListRequestHandler::handlePacket(const Common::XmlPacket &packet) { + if(packet.getType() != "ListUserGroups") { + 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 + + Common::XmlPacket ret; + + try { + boost::shared_ptr<std::set<unsigned long> > groups = UserManager::get()->getUserGroupList((unsigned long)packet["uid"]); + + ret.setType("OK"); + ret.addList("groups"); + + for(std::set<unsigned long>::iterator group = groups->begin(); group != groups->end(); ++group) { + ret["groups"].addEntry(); + Common::XmlPacket::Entry &entry = ret["groups"].back(); + + entry.add("gid", *group); + } + } + catch(Net::Exception e) { + ret.setType("Error"); + ret.add("ErrorCode", e.getErrorCode()); + ret.add("SubCode", e.getSubCode()); + ret.add("SubSubCode", e.getSubSubCode()); + ret.add("Where", e.getWhere()); + } + + sendPacket(ret); + signalFinished()(); +} + +} +} +} diff --git a/src/Server/RequestHandlers/UserGroupListRequestHandler.h b/src/Server/RequestHandlers/UserGroupListRequestHandler.h new file mode 100644 index 0000000..8e2add0 --- /dev/null +++ b/src/Server/RequestHandlers/UserGroupListRequestHandler.h @@ -0,0 +1,42 @@ +/* + * UserGroupListRequestHandler.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_USERGROUPLISTREQUESTHANDLER_H_ +#define MAD_SERVER_REQUESTHANDLERS_USERGROUPLISTREQUESTHANDLER_H_ + +#include <Common/RequestHandler.h> + +namespace Mad { +namespace Server { +namespace RequestHandlers { + +class UserGroupListRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(const Common::XmlPacket &packet); + + public: + UserGroupListRequestHandler(Common::Connection *connection, uint16_t requestId) + : RequestHandler(connection, requestId) {} +}; + +} +} +} + +#endif /* MAD_SERVER_REQUESTHANDLERS_USERGROUPLISTREQUESTHANDLER_H_ */ diff --git a/src/Server/UserBackend.h b/src/Server/UserBackend.h index 00e63d3..c2f340e 100644 --- a/src/Server/UserBackend.h +++ b/src/Server/UserBackend.h @@ -78,7 +78,6 @@ class UserBackend { throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED)); } - // TODO Better interface... virtual void setPassword(unsigned long uid _UNUSED_PARAMETER_, const std::string &password _UNUSED_PARAMETER_) throw(Net::Exception) { throw(Net::Exception(Net::Exception::NOT_IMPLEMENTED)); } |