summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-07-11 01:11:21 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-07-11 01:11:21 +0200
commitbf4c6ec2b7694f1a844eef5989b77e83a8cab362 (patch)
treea407ccab48195d61d4e04ccf8581b1328fd08e72 /src/Client
parentb8aa377d883c316f544274dd24db9f079fb8f02a (diff)
downloadmad-bf4c6ec2b7694f1a844eef5989b77e83a8cab362.tar
mad-bf4c6ec2b7694f1a844eef5989b77e83a8cab362.zip
Befehle add_user_to_group und delete_user_from_group implementiert
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp2
-rw-r--r--src/Client/UserCommands.cpp74
-rw-r--r--src/Client/UserCommands.h3
3 files changed, 79 insertions, 0 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index 6e8a7d3..644a392 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -54,6 +54,8 @@ const CommandParser::Command CommandParser::commands[] = {
{{"add_user", 0}, "add_user uid gid username full_name", "Add a new user", "Add a new user with the given info to the account database.", &UserCommands::addUserCommand},
{{"update_user", 0}, "update_user uid new_uid gid username full_name", "Update a user", "Update user data in the account database.", &UserCommands::updateUserCommand},
{{"delete_user", 0}, "delete_user uid", "Delete user", "Delete a user from the account database.", &UserCommands::deleteUserCommand},
+ {{"add_user_to_group", 0}, "add_user_to_group uid gid", "Add a user to a group", "Add a user to a group.", &UserCommands::addUserToGroupCommand},
+ {{"delete_user_from_group", 0}, "delete_user_from_group uid gid", "Remove a user from a group", "Remove a user from a group.", &UserCommands::deleteUserFromGroupCommand},
{{"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}
};
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index 96e9cc6..d58eaca 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -342,5 +342,79 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve
}
}
+void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 3) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("add_user_to_group");
+ return;
+ }
+ if(args.size() > 3) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("add_user_to_group");
+ return;
+ }
+
+ char *endptr;
+ unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse user id." << std::endl;
+ commandParser->printUsage("add_user_to_group");
+ return;
+ }
+
+ unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10);
+ if(args[2].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse group id." << std::endl;
+ commandParser->printUsage("add_user_to_group");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->addUserToGroup(uid, gid);
+
+ std::cout << "Added." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
+void UserCommands::deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 3) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("delete_user_from_group");
+ return;
+ }
+ if(args.size() > 3) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("delete_user_from_group");
+ return;
+ }
+
+ char *endptr;
+ unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
+ if(args[1].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse user id." << std::endl;
+ commandParser->printUsage("delete_user_from_group");
+ return;
+ }
+
+ unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10);
+ if(args[2].empty() || *endptr != '\0') {
+ std::cerr << args[0] << ": Unable to parse group id." << std::endl;
+ commandParser->printUsage("delete_user_from_group");
+ return;
+ }
+
+ try {
+ commandParser->application->getUserManager()->deleteUserFromGroup(uid, gid);
+
+ std::cout << "Removed." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
}
}
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index 2feb6a5..b62c8e4 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -44,6 +44,9 @@ class UserCommands {
static void addUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void updateUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void deleteUserCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+
+ static void addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void deleteUserFromGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args);
};
}