From dd5895dba0a0d745b4b8d5b5bac6a159b4d79dcd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
Date: Mon, 25 Jul 2016 13:50:13 +0200
Subject: [PATCH 1/2] sssctl: Consistent commands naming

Fixes:
https://fedorahosted.org/sssd/ticket/3087

Use TOPIC-ACTION pattern for sssctl command
names.
---
 src/tools/common/sss_tools.h      |  2 ++
 src/tools/sss_override.c          | 26 +++++++-------
 src/tools/sssctl/sssctl.c         | 47 ++++++++++++++++++++------
 src/tools/sssctl/sssctl.h         | 71 ++++++++++++++++++++++++++++++++-------
 src/tools/sssctl/sssctl_cache.c   | 42 ++++++++++++++++++-----
 src/tools/sssctl/sssctl_data.c    | 48 +++++++++++++++++++++-----
 src/tools/sssctl/sssctl_domains.c | 14 ++++++--
 src/tools/sssctl/sssctl_logs.c    | 20 +++++++++--
 8 files changed, 211 insertions(+), 59 deletions(-)

diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h
index a9ebabe..41c8b10 100644
--- a/src/tools/common/sss_tools.h
+++ b/src/tools/common/sss_tools.h
@@ -46,7 +46,9 @@ typedef errno_t
                 void *pvt);
 
 #define SSS_TOOL_COMMAND(cmd, msg, err, fn) {cmd, _(msg), err, fn}
+#define SSS_TOOL_COMMAND_NOMSG(cmd, err, fn) {cmd, NULL, err, fn}
 #define SSS_TOOL_DELIMITER(message) {"", (message), 0, NULL}
+#define SSS_TOOL_LAST {NULL, NULL, 0, NULL}
 
 struct sss_route_cmd {
     const char *command;
diff --git a/src/tools/sss_override.c b/src/tools/sss_override.c
index 45a28fd..d41da52 100644
--- a/src/tools/sss_override.c
+++ b/src/tools/sss_override.c
@@ -1913,19 +1913,19 @@ static int override_group_export(struct sss_cmdline *cmdline,
 int main(int argc, const char **argv)
 {
     struct sss_route_cmd commands[] = {
-        {"user-add", NULL, 0, override_user_add},
-        {"user-del", NULL, 0, override_user_del},
-        {"user-find", NULL, 0, override_user_find},
-        {"user-show", NULL, 0, override_user_show},
-        {"user-import", NULL, 0, override_user_import},
-        {"user-export", NULL, 0, override_user_export},
-        {"group-add", NULL, 0, override_group_add},
-        {"group-del", NULL, 0, override_group_del},
-        {"group-find", NULL, 0, override_group_find},
-        {"group-show", NULL, 0, override_group_show},
-        {"group-import", NULL, 0, override_group_import},
-        {"group-export", NULL, 0, override_group_export},
-        {NULL, NULL, 0, NULL}
+        SSS_TOOL_COMMAND_NOMSG("user-add", 0, override_user_add),
+        SSS_TOOL_COMMAND_NOMSG("user-del", 0, override_user_del),
+        SSS_TOOL_COMMAND_NOMSG("user-find", 0, override_user_find),
+        SSS_TOOL_COMMAND_NOMSG("user-show", 0, override_user_show),
+        SSS_TOOL_COMMAND_NOMSG("user-import", 0, override_user_import),
+        SSS_TOOL_COMMAND_NOMSG("user-export", 0, override_user_export),
+        SSS_TOOL_COMMAND_NOMSG("group-add", 0, override_group_add),
+        SSS_TOOL_COMMAND_NOMSG("group-del", 0, override_group_del),
+        SSS_TOOL_COMMAND_NOMSG("group-find", 0, override_group_find),
+        SSS_TOOL_COMMAND_NOMSG("group-show", 0, override_group_show),
+        SSS_TOOL_COMMAND_NOMSG("group-import", 0, override_group_import),
+        SSS_TOOL_COMMAND_NOMSG("group-export", 0, override_group_export),
+        SSS_TOOL_LAST
     };
 
     return sss_tool_main(argc, argv, commands, NULL);
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
index 86656f1..079d339 100644
--- a/src/tools/sssctl/sssctl.c
+++ b/src/tools/sssctl/sssctl.c
@@ -32,6 +32,19 @@
     #define SSSD_SVC_CMD(cmd) "service sssd " cmd
 #endif
 
+void sssctl_deprecated_cmd_err(const char *old_name,
+                               const char *new_name)
+{
+    ERROR("Command '%s' is deprecated and may be removed in future versions.",
+          old_name);
+
+    if (new_name) {
+        ERROR(" Use '%s' instead.\n", new_name);
+    } else {
+        fprintf(stderr, "\n");
+    }
+}
+
 static const char *
 sssctl_prompt_str(enum sssctl_prompt_result result)
 {
@@ -257,25 +270,37 @@ int main(int argc, const char **argv)
 {
     struct sss_route_cmd commands[] = {
         SSS_TOOL_DELIMITER("SSSD Status:"),
-        SSS_TOOL_COMMAND("list-domains", "List available domains", 0, sssctl_list_domains),
+        SSS_TOOL_COMMAND("domain-list", "List available domains", 0, sssctl_domain_list),
         SSS_TOOL_COMMAND("domain-status", "Print information about domain", 0, sssctl_domain_status),
         SSS_TOOL_DELIMITER("Information about cached content:"),
-        SSS_TOOL_COMMAND("user", "Information about cached user", 0, sssctl_user),
-        SSS_TOOL_COMMAND("group", "Information about cached group", 0, sssctl_group),
-        SSS_TOOL_COMMAND("netgroup", "Information about cached netgroup", 0, sssctl_netgroup),
+        SSS_TOOL_COMMAND("user-show", "Information about cached user", 0, sssctl_user_show),
+        SSS_TOOL_COMMAND("group-show", "Information about cached group", 0, sssctl_group_show),
+        SSS_TOOL_COMMAND("netgroup-show", "Information about cached netgroup", 0, sssctl_netgroup_show),
         SSS_TOOL_DELIMITER("Local data tools:"),
-        SSS_TOOL_COMMAND("backup-local-data", "Backup local data", 0, sssctl_backup_local_data),
-        SSS_TOOL_COMMAND("restore-local-data", "Restore local data from backup", 0, sssctl_restore_local_data),
-        SSS_TOOL_COMMAND("remove-cache", "Backup local data and remove cached content", 0, sssctl_remove_cache),
-        SSS_TOOL_COMMAND("upgrade-cache", "Perform cache upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_upgrade_cache),
+        SSS_TOOL_COMMAND("client-data-backup", "Backup local data", 0, sssctl_client_data_backup),
+        SSS_TOOL_COMMAND("client-data-restore", "Restore local data from backup", 0, sssctl_client_data_restore),
+        SSS_TOOL_COMMAND("cache-remove", "Backup local data and remove cached content", 0, sssctl_cache_remove),
+        SSS_TOOL_COMMAND("cache-upgrade", "Perform cache upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_cache_upgrade),
         SSS_TOOL_DELIMITER("Log files tools:"),
-        SSS_TOOL_COMMAND("remove-logs", "Remove existing SSSD log files", 0, sssctl_remove_logs),
-        SSS_TOOL_COMMAND("fetch-logs", "Archive SSSD log files in tarball", 0, sssctl_fetch_logs),
+        SSS_TOOL_COMMAND("logs-remove", "Remove existing SSSD log files", 0, sssctl_logs_remove),
+        SSS_TOOL_COMMAND("logs-fetch", "Archive SSSD log files in tarball", 0, sssctl_logs_fetch),
 #ifdef HAVE_LIBINI_CONFIG_V1_3
         SSS_TOOL_DELIMITER("Configuration files tools:"),
         SSS_TOOL_COMMAND("config-check", "Perform static analysis of SSSD configuration", 0, sssctl_config_check),
 #endif
-        {NULL, NULL, 0, NULL}
+        /* Deprecated commands */
+        SSS_TOOL_DELIMITER("Deprecated commands that may be removed in the future:"),
+        SSS_TOOL_COMMAND("list-domains", "Obsolete alias for domain-list", 0, sssctl_list_domains),
+        SSS_TOOL_COMMAND("user", "Obsolete alias for user-show", 0, sssctl_user),
+        SSS_TOOL_COMMAND("group", "Obsolete alias for group-show", 0, sssctl_group),
+        SSS_TOOL_COMMAND("netgroup", "Obsolete alias for netgroup-show", 0, sssctl_netgroup),
+        SSS_TOOL_COMMAND("backup-local-data", "Obsolete alias for client-data-backup", 0, sssctl_backup_local_data),
+        SSS_TOOL_COMMAND("restore-local-data", "Obsolete alias for client-data-restore", 0, sssctl_restore_local_data),
+        SSS_TOOL_COMMAND("remove-cache", "Obsolete alias for cache-remove", 0, sssctl_remove_cache),
+        SSS_TOOL_COMMAND("upgrade-cache", "Obsolete alias for cache-upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_upgrade_cache),
+        SSS_TOOL_COMMAND("remove-logs", "Obsolete alias for logs-remove", 0, sssctl_remove_logs),
+        SSS_TOOL_COMMAND("fetch-logs", "Obsolete alias for logs-fetch", 0, sssctl_fetch_logs),
+        SSS_TOOL_LAST
     };
 
     return sss_tool_main(argc, argv, commands, NULL);
diff --git a/src/tools/sssctl/sssctl.h b/src/tools/sssctl/sssctl.h
index be62475..6cb0545 100644
--- a/src/tools/sssctl/sssctl.h
+++ b/src/tools/sssctl/sssctl.h
@@ -56,14 +56,63 @@ void _sssctl_sifp_error(sss_sifp_ctx *sifp,
 #define sssctl_sifp_error(sifp, error, message) \
     _sssctl_sifp_error(sifp, error, _(message))
 
-errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
+void sssctl_deprecated_cmd_err(const char *old_name,
+                               const char *new_name);
+
+errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt);
+
+errno_t sssctl_domain_status(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt);
+
+errno_t sssctl_client_data_backup(struct sss_cmdline *cmdline,
+                                  struct sss_tool_ctx *tool_ctx,
+                                  void *pvt);
+
+errno_t sssctl_client_data_restore(struct sss_cmdline *cmdline,
+                                   struct sss_tool_ctx *tool_ctx,
+                                   void *pvt);
+
+errno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
                             struct sss_tool_ctx *tool_ctx,
                             void *pvt);
 
-errno_t sssctl_domain_status(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_upgrade(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt);
+
+errno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt);
+
+errno_t sssctl_logs_fetch(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt);
+
+errno_t sssctl_user_show(struct sss_cmdline *cmdline,
+                         struct sss_tool_ctx *tool_ctx,
+                         void *pvt);
+
+errno_t sssctl_group_show(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt);
+
+errno_t sssctl_netgroup_show(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt);
 
+errno_t sssctl_config_check(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt);
+
+/* Deprecated commands */
+
+errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt);
+
 errno_t sssctl_backup_local_data(struct sss_cmdline *cmdline,
                                  struct sss_tool_ctx *tool_ctx,
                                  void *pvt);
@@ -80,14 +129,6 @@ errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt);
 
-errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
-                           struct sss_tool_ctx *tool_ctx,
-                           void *pvt);
-
-errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
-                          struct sss_tool_ctx *tool_ctx,
-                          void *pvt);
-
 errno_t sssctl_user(struct sss_cmdline *cmdline,
                     struct sss_tool_ctx *tool_ctx,
                     void *pvt);
@@ -100,8 +141,12 @@ errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
                         struct sss_tool_ctx *tool_ctx,
                         void *pvt);
 
-errno_t sssctl_config_check(struct sss_cmdline *cmdline,
-                            struct sss_tool_ctx *tool_ctx,
-                            void *pvt);
+errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt);
+
+errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt);
 
 #endif /* _SSSCTL_H_ */
diff --git a/src/tools/sssctl/sssctl_cache.c b/src/tools/sssctl/sssctl_cache.c
index 4a1f355..b21a889 100644
--- a/src/tools/sssctl/sssctl_cache.c
+++ b/src/tools/sssctl/sssctl_cache.c
@@ -569,9 +569,9 @@ struct sssctl_cache_opts {
     int id;
 };
 
-errno_t sssctl_user(struct sss_cmdline *cmdline,
-                    struct sss_tool_ctx *tool_ctx,
-                    void *pvt)
+errno_t sssctl_user_show(struct sss_cmdline *cmdline,
+                         struct sss_tool_ctx *tool_ctx,
+                         void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     const char *attr;
@@ -616,9 +616,17 @@ errno_t sssctl_user(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_group(struct sss_cmdline *cmdline,
-                     struct sss_tool_ctx *tool_ctx,
-                     void *pvt)
+errno_t sssctl_user(struct sss_cmdline *cmdline,
+                    struct sss_tool_ctx *tool_ctx,
+                    void *pvt)
+{
+    sssctl_deprecated_cmd_err("user", "user-show");
+    return sssctl_user_show(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_group_show(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     const char *attr;
@@ -662,9 +670,17 @@ errno_t sssctl_group(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
-                        struct sss_tool_ctx *tool_ctx,
-                        void *pvt)
+errno_t sssctl_group(struct sss_cmdline *cmdline,
+                     struct sss_tool_ctx *tool_ctx,
+                     void *pvt)
+{
+    sssctl_deprecated_cmd_err("group", "group-show");
+    return sssctl_group_show(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_netgroup_show(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt)
 {
     struct sssctl_cache_opts opts = {0};
     errno_t ret;
@@ -692,3 +708,11 @@ errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
 
     return EOK;
 }
+
+errno_t sssctl_netgroup(struct sss_cmdline *cmdline,
+                        struct sss_tool_ctx *tool_ctx,
+                        void *pvt)
+{
+    sssctl_deprecated_cmd_err("netgroup", "netgroup-show");
+    return sssctl_netgroup_show(cmdline, tool_ctx, pvt);
+}
diff --git a/src/tools/sssctl/sssctl_data.c b/src/tools/sssctl/sssctl_data.c
index 3ab2ddf..77dedab 100644
--- a/src/tools/sssctl/sssctl_data.c
+++ b/src/tools/sssctl/sssctl_data.c
@@ -124,9 +124,9 @@ static errno_t sssctl_backup(bool force)
     return ret;
 }
 
-errno_t sssctl_backup_local_data(struct sss_cmdline *cmdline,
-                                 struct sss_tool_ctx *tool_ctx,
-                                 void *pvt)
+errno_t sssctl_client_data_backup(struct sss_cmdline *cmdline,
+                                  struct sss_tool_ctx *tool_ctx,
+                                  void *pvt)
 {
     struct sssctl_data_opts opts = {0};
     errno_t ret;
@@ -184,9 +184,9 @@ static errno_t sssctl_restore(bool force_start, bool force_restart)
     return ret;
 }
 
-errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
-                                  struct sss_tool_ctx *tool_ctx,
-                                  void *pvt)
+errno_t sssctl_client_data_restore(struct sss_cmdline *cmdline,
+                                   struct sss_tool_ctx *tool_ctx,
+                                   void *pvt)
 {
     struct sssctl_data_opts opts = {0};
     errno_t ret;
@@ -207,7 +207,7 @@ errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
     return sssctl_restore(opts.start, opts.restart);
 }
 
-errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
                             struct sss_tool_ctx *tool_ctx,
                             void *pvt)
 {
@@ -259,7 +259,7 @@ errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
+errno_t sssctl_cache_upgrade(struct sss_cmdline *cmdline,
                              struct sss_tool_ctx *tool_ctx,
                              void *pvt)
 {
@@ -286,3 +286,35 @@ errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
 
     return EOK;
 }
+
+errno_t sssctl_remove_cache(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt)
+{
+    sssctl_deprecated_cmd_err("remove-cache", "cache-remove");
+    return sssctl_cache_remove(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_upgrade_cache(struct sss_cmdline *cmdline,
+                             struct sss_tool_ctx *tool_ctx,
+                             void *pvt)
+{
+    sssctl_deprecated_cmd_err("upgrade-cache", "cache-upgrade");
+    return sssctl_cache_upgrade(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_backup_local_data(struct sss_cmdline *cmdline,
+                                 struct sss_tool_ctx *tool_ctx,
+                                 void *pvt)
+{
+    sssctl_deprecated_cmd_err("backup-local-data", "client-data-backup");
+    return sssctl_client_data_backup(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_restore_local_data(struct sss_cmdline *cmdline,
+                                  struct sss_tool_ctx *tool_ctx,
+                                  void *pvt)
+{
+    sssctl_deprecated_cmd_err("restore-local-data", "client-data-restore");
+    return sssctl_client_data_restore(cmdline, tool_ctx, pvt);
+}
diff --git a/src/tools/sssctl/sssctl_domains.c b/src/tools/sssctl/sssctl_domains.c
index 5aaaf77..5d8817a 100644
--- a/src/tools/sssctl/sssctl_domains.c
+++ b/src/tools/sssctl/sssctl_domains.c
@@ -27,9 +27,9 @@
 #include "sbus/sssd_dbus.h"
 #include "responder/ifp/ifp_iface.h"
 
-errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
-                            struct sss_tool_ctx *tool_ctx,
-                            void *pvt)
+errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt)
 {
     sss_sifp_ctx *sifp;
     sss_sifp_error error;
@@ -73,6 +73,14 @@ errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
     return EOK;
 }
 
+errno_t sssctl_list_domains(struct sss_cmdline *cmdline,
+                            struct sss_tool_ctx *tool_ctx,
+                            void *pvt)
+{
+    sssctl_deprecated_cmd_err("list-domains", "domain-list");
+    return sssctl_domain_list(cmdline, tool_ctx, pvt);
+}
+
 static errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx,
                                            const char *domain_path,
                                            bool force_start)
diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c
index a203474..7f37ec9 100644
--- a/src/tools/sssctl/sssctl_logs.c
+++ b/src/tools/sssctl/sssctl_logs.c
@@ -34,7 +34,7 @@ struct sssctl_logs_opts {
     int archived;
 };
 
-errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
                            struct sss_tool_ctx *tool_ctx,
                            void *pvt)
 {
@@ -74,7 +74,7 @@ errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
     return EOK;
 }
 
-errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
+errno_t sssctl_logs_fetch(struct sss_cmdline *cmdline,
                           struct sss_tool_ctx *tool_ctx,
                           void *pvt)
 {
@@ -104,3 +104,19 @@ errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
 
     return EOK;
 }
+
+errno_t sssctl_remove_logs(struct sss_cmdline *cmdline,
+                           struct sss_tool_ctx *tool_ctx,
+                           void *pvt)
+{
+    sssctl_deprecated_cmd_err("remove-logs", "logs-remove");
+    return sssctl_logs_remove(cmdline, tool_ctx, pvt);
+}
+
+errno_t sssctl_fetch_logs(struct sss_cmdline *cmdline,
+                          struct sss_tool_ctx *tool_ctx,
+                          void *pvt)
+{
+    sssctl_deprecated_cmd_err("fetch-logs", "logs-fetch");
+    return sssctl_logs_fetch(cmdline, tool_ctx, pvt);
+}
-- 
2.5.0

