Commit b8db8c2 sssctl: Showing help even when sssd not configured

2 files Authored by amitkumar25nov 11 days ago , Committed by jhrozek 11 days ago ,
sssctl: Showing help even when sssd not configured

On a clean and unconfigured system, it's not possible
to use --help.
1) dnf install sssd-tools
2) sssctl cache-remove --help
Shows:
[confdb_get_domains] (0x0010): No domains configured, fatal error!

Solution: Donot check for confdb initialization when sssctl 3rd
command line argument passed is '--help'.

Please note when we run 'sssctl --help' on unconfigured system
confdb check is not done and proper o/p is seen.

Resolves: https://pagure.io/SSSD/sssd/issue/3634

Reviewed-by: Pavel Březina <pbrezina@redhat.com>

    
 1 @@ -58,11 +58,14 @@
 2       poptContext pc;
 3       int debug = SSSDBG_DEFAULT;
 4       int orig_argc = *argc;
 5 +     int help = 0;
 6       int opt;
 7   
 8       struct poptOption options[] = {
 9           {"debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_STRIP, &debug,
10               0, _("The debug level to run with"), NULL },
11 +         {"help", '?', POPT_ARG_VAL | POPT_ARGFLAG_DOC_HIDDEN, &help,
12 +             1, NULL, NULL },
13           POPT_TABLEEND
14       };
15   
16 @@ -74,6 +77,7 @@
17       /* Strip common options from arguments. We will discard_const here,
18        * since it is not worth the trouble to convert it back and forth. */
19       *argc = poptStrippedArgv(pc, orig_argc, discard_const_p(char *, argv));
20 +     tool_ctx->print_help = help;
21   
22       DEBUG_CLI_INIT(debug);
23   
24 @@ -187,7 +191,6 @@
25       }
26   
27       sss_tool_common_opts(tool_ctx, argc, argv);
28 - 
29       *_tool_ctx = tool_ctx;
30   
31       return EOK;
32 @@ -341,12 +344,14 @@
33                   return tool_ctx->init_err;
34               }
35   
36 -             ret = tool_cmd_init(tool_ctx, &commands[i]);
37 -             if (ret != EOK) {
38 -                 DEBUG(SSSDBG_FATAL_FAILURE,
39 -                       "Command initialization failed [%d] %s\n",
40 -                       ret, sss_strerror(ret));
41 -                 return ret;
42 +             if (!tool_ctx->print_help) {
43 +                 ret = tool_cmd_init(tool_ctx, &commands[i]);
44 +                 if (ret != EOK) {
45 +                     DEBUG(SSSDBG_FATAL_FAILURE,
46 +                           "Command initialization failed [%d] %s\n",
47 +                           ret, sss_strerror(ret));
48 +                     return ret;
49 +                 }
50               }
51   
52               return commands[i].fn(&cmdline, tool_ctx, pvt);
1 @@ -29,6 +29,7 @@
2   struct sss_tool_ctx {
3       struct confdb_ctx *confdb;
4   
5 +     bool print_help;
6       errno_t init_err;
7       char *default_domain;
8       struct sss_domain_info *domains;