summaryrefslogtreecommitdiffstats
path: root/src/Client/UserCommands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/UserCommands.cpp')
-rw-r--r--src/Client/UserCommands.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index fec2a33..9fcaa36 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -17,6 +17,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
+
#include "UserCommands.h"
#include "Application.h"
#include "CommandParser.h"
@@ -221,5 +223,46 @@ void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std
}
}
+void UserCommands::addUserCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() < 5) {
+ std::cerr << args[0] << ": Too few arguments." << std::endl;
+ commandParser->printUsage("add_user");
+ return;
+ }
+ if(args.size() > 5) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("add_user");
+ 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");
+ 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");
+ return;
+ }
+
+ try {
+ Common::UserInfo user(uid, args[3]);
+ user.setGid(gid);
+ user.setFullName(args[4]);
+
+ commandParser->application->getUserManager()->addUser(user);
+
+ std::cout << "User added." << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
}
}