From c5e1ad6be64df9b77ce0aecc8fe5d9db8476b9de Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sat, 19 Oct 2013 19:52:07 +0200 Subject: [PATCH] Deleting users in idm client. --- idm.cpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/idm.cpp b/idm.cpp index 40ef207..6b92837 100644 --- a/idm.cpp +++ b/idm.cpp @@ -23,8 +23,10 @@ static void usage(const char *prg) { printf(" -c,--config .... dmlite config file [" DMLITE_CONFIG_DEFAULT "]\n"); printf(" -u,--user ...... user name []\n\n"); printf("COMMANDS are:\n"); - printf(" listusers,lu\n"); - printf(" listgroups,lg\n"); + printf(" listusers,lu ........... list users\n"); + printf(" listgroups,lg .......... list groups\n"); + printf(" deleteuser,du USER ..... delete user\n"); + printf(" deletegroup,dg GROUP ... delete group\n"); } @@ -105,8 +107,10 @@ int main(int argc, char *argv[]) { } while (optind < argc) { - std::string operation; + std::string operation, arg; + if (optind + 1 < argc) arg = argv[optind + 1]; + else arg = ""; try { authn = stack->getAuthn(); @@ -120,6 +124,7 @@ int main(int argc, char *argv[]) { uids = authn->getUsers(); for (size_t i = 0; i < uids.size(); i++) dumpInfo(uids[i].name, uids[i]); + printf("\n"); } else if ( strcasecmp(argv[optind], "listgroups") == 0 || strcasecmp(argv[optind], "lg") == 0 @@ -131,6 +136,35 @@ int main(int argc, char *argv[]) { gids = authn->getGroups(); for (size_t i = 0; i < gids.size(); i++) dumpInfo(gids[i].name, gids[i]); + printf("\n"); + } else if ( + strcasecmp(argv[optind], "deleteuser") == 0 || + strcasecmp(argv[optind], "du") == 0 + ) { + operation = "delete user"; + if (arg.empty()) { + printf("Missing argument.\n"); + usage(argv[0]); + return 1; + } + optind++; + + authn->deleteUser(arg); + printf("User '%s' deleted.\n\n", arg.c_str()); + } else if ( + strcasecmp(argv[optind], "deletegroup") == 0 || + strcasecmp(argv[optind], "dg") == 0 + ) { + operation = "delete group"; + if (arg.empty()) { + printf("Missing argument.\n"); + usage(argv[0]); + return 1; + } + optind++; + + authn->deleteGroup(arg); + printf("Group '%s' deleted.\n\n", arg.c_str()); } else { printf("Unknown command.\n"); usage(argv[0]); -- 1.8.2.3