Deleting users in idm client.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 19 Oct 2013 17:52:07 +0000 (19:52 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Sat, 19 Oct 2013 17:52:07 +0000 (19:52 +0200)
idm.cpp

diff --git a/idm.cpp b/idm.cpp
index 40ef207..6b92837 100644 (file)
--- 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]);