summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Client/CommandManager.cpp26
-rw-r--r--src/Client/CommandManager.h1
-rw-r--r--src/Client/CommandParser.cpp9
-rw-r--r--src/Client/CommandParser.h1
-rw-r--r--src/Common/GroupInfo.h46
-rw-r--r--src/Common/Requests/GroupListRequest.h39
-rw-r--r--src/Common/UserInfo.h4
-rw-r--r--src/Server/ConnectionManager.cpp5
-rw-r--r--src/Server/RequestHandlers/CMakeLists.txt2
-rw-r--r--src/Server/RequestHandlers/GroupListRequestHandler.cpp73
-rw-r--r--src/Server/RequestHandlers/GroupListRequestHandler.h42
-rw-r--r--src/Server/UserBackend.h5
-rw-r--r--src/Server/UserManager.cpp10
-rw-r--r--src/Server/UserManager.h3
-rw-r--r--src/mad-server.conf2
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp22
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h2
17 files changed, 287 insertions, 5 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index f46bdcd..b427db7 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -251,5 +251,31 @@ void CommandManager::userListRequestFinished(const Common::Request &request) {
requestFinished();
}
+void CommandManager::groupListRequestFinished(const Common::Request &request) {
+ try {
+ const Common::XmlPacket &packet = request.getResult();
+
+ const Common::XmlPacket::Element &groups = packet["groups"];
+
+ if(groups.isEmpty()) {
+ std::cout << "Group list is empty." << std::endl;
+ }
+ else {
+ std::cout << "Found " << groups.getSize() << " groups:" << std::endl;
+
+
+ for(size_t i = 0; i < groups.getSize(); ++i)
+ std::cout << " " << (unsigned long)groups[i]["gid"] << ", " << (const std::string&)groups[i]["name"] << 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 7635542..3cfc502 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -60,6 +60,7 @@ class CommandManager {
void statusRequestFinished(const Common::Request &request);
void userInfoRequestFinished(const Common::Request &request);
void userListRequestFinished(const Common::Request &request);
+ void groupListRequestFinished(const Common::Request &request);
CommandManager() : activeRequests(0), disconnect(false) {}
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 78b3570..044a64c 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -26,6 +26,7 @@
#include <Common/RequestManager.h>
#include <Common/Requests/FSInfoRequest.h>
#include <Common/Requests/DisconnectRequest.h>
+#include <Common/Requests/GroupListRequest.h>
#include <Common/Requests/StatusRequest.h>
#include <Common/Requests/UserInfoRequest.h>
#include <Common/Requests/UserListRequest.h>
@@ -48,6 +49,7 @@ 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_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},
{{0}, 0, 0, 0, 0}
};
@@ -290,6 +292,13 @@ void CommandParser::listUsersCommand(const std::vector<std::string>&) {
boost::bind(&CommandManager::userListRequestFinished, CommandManager::get(), _1));
}
+void CommandParser::listGroupsCommand(const std::vector<std::string>&) {
+ ++CommandManager::get()->activeRequests;
+
+ Common::RequestManager::get()->sendRequest<Common::Requests::GroupListRequest>(connection,
+ boost::bind(&CommandManager::groupListRequestFinished, CommandManager::get(), _1));
+}
+
void CommandParser::exitCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 4b44656..727181e 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -65,6 +65,7 @@ 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 listGroupsCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
CommandParser() : connection(0) {}
diff --git a/src/Common/GroupInfo.h b/src/Common/GroupInfo.h
new file mode 100644
index 0000000..e32648e
--- /dev/null
+++ b/src/Common/GroupInfo.h
@@ -0,0 +1,46 @@
+/*
+ * GroupInfo.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_GROUPINFO_H_
+#define MAD_COMMON_GROUPINFO_H_
+
+#include <string>
+
+namespace Mad {
+namespace Common {
+
+class GroupInfo {
+ private:
+ unsigned long gid;
+ std::string name;
+
+ public:
+ GroupInfo(unsigned long gid0 = 0, const std::string& name0 = std::string()) : gid(gid0), name(name0) {}
+
+ void setGid(unsigned long newGid) {gid = newGid;}
+ unsigned long getGid() const {return gid;}
+
+ void setName(const std::string& newName) {name = newName;}
+ const std::string& getName() const {return name;}
+};
+
+}
+}
+
+#endif /* MAD_COMMON_GROUPINFO_H_ */
diff --git a/src/Common/Requests/GroupListRequest.h b/src/Common/Requests/GroupListRequest.h
new file mode 100644
index 0000000..86322ad
--- /dev/null
+++ b/src/Common/Requests/GroupListRequest.h
@@ -0,0 +1,39 @@
+/*
+ * UserListRequest.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_GROUPLISTREQUEST_H_
+#define MAD_COMMON_REQUESTS_GROUPLISTREQUEST_H_
+
+#include "SimpleRequest.h"
+
+namespace Mad {
+namespace Common {
+namespace Requests {
+
+class GroupListRequest : public SimpleRequest {
+ public:
+ GroupListRequest(Connection *connection, uint16_t requestId, slot_type slot)
+ : SimpleRequest(connection, requestId, slot, "ListGroups") {}
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_REQUESTS_GROUPLISTREQUEST_H_ */
diff --git a/src/Common/UserInfo.h b/src/Common/UserInfo.h
index 94c0c60..b8897e3 100644
--- a/src/Common/UserInfo.h
+++ b/src/Common/UserInfo.h
@@ -39,8 +39,8 @@ class UserInfo {
void setUid(unsigned long newUid) {uid = newUid;}
unsigned long getUid() const {return uid;}
- void setGid(unsigned long newUid) {uid = newUid;}
- unsigned long getGid() const {return uid;}
+ void setGid(unsigned long newGid) {gid = newGid;}
+ unsigned long getGid() const {return gid;}
void setUsername(const std::string& newUsername) {username = newUsername;}
const std::string& getUsername() const {return username;}
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);
diff --git a/src/mad-server.conf b/src/mad-server.conf
index 45927cf..188833b 100644
--- a/src/mad-server.conf
+++ b/src/mad-server.conf
@@ -17,7 +17,7 @@ UserBackendMysql {
Queries {
ListUsers "SELECT id, gid, username, fullname FROM users"
- #ListGroups
+ ListGroups "SELECT id, name FROM groups"
#ListUserGroups
#ListGroupUsers
UserById "SELECT id, gid, username, fullname FROM users WHERE id = {ID}"
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index a8751ee..139a416 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -193,6 +193,28 @@ boost::shared_ptr<Common::UserInfo> UserBackendMysql::getUserInfo(unsigned long
return boost::shared_ptr<Common::UserInfo>();
}
+boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > UserBackendMysql::getGroupList() {
+ Net::ThreadManager::get()->detach();
+
+ mysql_ping(mysql);
+
+ mysql_real_query(mysql, queryListGroups.c_str(), queryListGroups.length());
+ MYSQL_RES *result = mysql_use_result(mysql);
+
+ if(mysql_num_fields(result) < 2)
+ return boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> >(); // TODO Error
+
+ boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > groups(new std::map<unsigned long, Common::GroupInfo>());
+
+ while(MYSQL_ROW row = mysql_fetch_row(result)) {
+ Common::GroupInfo group(strtoul(row[0], 0, 10), row[1]);
+
+ groups->insert(std::make_pair(group.getGid(), group));
+ }
+
+ return groups;
+}
+
void UserBackendMysql::registerBackend() {
if(backend)
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h
index de28069..8a75a6b 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -53,6 +53,8 @@ class UserBackendMysql : public Server::UserBackend, private Common::Configurabl
virtual boost::shared_ptr<std::map<unsigned long, Common::UserInfo> > getUserList();
virtual boost::shared_ptr<Common::UserInfo> getUserInfo(unsigned long uid);
+ virtual boost::shared_ptr<std::map<unsigned long, Common::GroupInfo> > getGroupList();
+
public:
virtual ~UserBackendMysql() {
if(mysql) {