>From d561a20c6db3aca21424281c49808f4992332ee2 Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Wed, 8 Jul 2015 07:17:28 -0400
Subject: [PATCH] UTIL: Function 2string for enum sss_cli_command

Improvement of debug messages.
Instead of:"(0x0400): Running command [17]..."
We could see:"(0x0400): Running command [17][SSS_NSS_GETPWNAM]..."
(It's not used in sss_client. There are only hex numbers of commands.)

Resolves:
https://fedorahosted.org/sssd/ticket/2708
---
 Makefile.am                      |   4 +-
 src/providers/dp_pam_data_util.c |  27 +----
 src/responder/nss/nsssrv_cmd.c   |  54 +++++----
 src/sss_client/pam_sss.c         |   6 +-
 src/tools/tools_mc_util.c        |   4 +-
 src/util/sss_cli_cmd.c           | 238 +++++++++++++++++++++++++++++++++++++++
 src/util/sss_cli_cmd.h           |  28 +++++
 7 files changed, 306 insertions(+), 55 deletions(-)
 create mode 100644 src/util/sss_cli_cmd.c
 create mode 100644 src/util/sss_cli_cmd.h

diff --git a/Makefile.am b/Makefile.am
index 9cc5f384586e0d1c6e35ba48c357779eb69307ca..52a2168f190fa6f770271ae50786f4a600210724 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -689,7 +689,9 @@ endif
 pkglib_LTLIBRARIES += libsss_debug.la
 libsss_debug_la_SOURCES = \
     src/util/debug.c \
-    src/util/sss_log.c
+    src/util/sss_log.c \
+    src/util/sss_cli_cmd.c \
+    $(NULL)
 libsss_debug_la_LIBADD = \
     $(SYSLOG_LIBS)
 libsss_debug_la_LDFLAGS = \
diff --git a/src/providers/dp_pam_data_util.c b/src/providers/dp_pam_data_util.c
index 8724bf936f3f46fb8393c8a3da57215a73b4191a..10e91f5f7286db5e76ad98b6c7519f2482d006db 100644
--- a/src/providers/dp_pam_data_util.c
+++ b/src/providers/dp_pam_data_util.c
@@ -23,33 +23,10 @@
 */
 
 #include "providers/data_provider.h"
-
+#include "util/sss_cli_cmd.h"
 
 #define PAM_SAFE_ITEM(item) item ? item : "not set"
 
-static const char *pamcmd2str(int cmd) {
-    switch (cmd) {
-    case SSS_PAM_AUTHENTICATE:
-        return "PAM_AUTHENTICATE";
-    case SSS_PAM_SETCRED:
-        return "PAM_SETCRED";
-    case SSS_PAM_ACCT_MGMT:
-        return "PAM_ACCT_MGMT";
-    case SSS_PAM_OPEN_SESSION:
-        return "PAM_OPEN_SESSION";
-    case SSS_PAM_CLOSE_SESSION:
-        return "PAM_CLOSE_SESSION";
-    case SSS_PAM_CHAUTHTOK:
-        return "PAM_CHAUTHTOK";
-    case SSS_PAM_CHAUTHTOK_PRELIM:
-        return "PAM_CHAUTHTOK_PRELIM";
-    case SSS_PAM_PREAUTH:
-        return "SSS_PAM_PREAUTH";
-    default:
-        return "UNKNOWN";
-    }
-}
-
 int pam_data_destructor(void *ptr)
 {
     struct pam_data *pd = talloc_get_type(ptr, struct pam_data);
@@ -183,7 +160,7 @@ failed:
 
 void pam_print_data(int l, struct pam_data *pd)
 {
-    DEBUG(l, "command: %s\n", pamcmd2str(pd->cmd));
+    DEBUG(l, "command: %s\n", sss_cmd2str(pd->cmd));
     DEBUG(l, "domain: %s\n", PAM_SAFE_ITEM(pd->domain));
     DEBUG(l, "user: %s\n", PAM_SAFE_ITEM(pd->user));
     DEBUG(l, "service: %s\n", PAM_SAFE_ITEM(pd->service));
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index e754245eac7200c2f667760540a1d04c9203843d..42383889dd24f51643af0da487acf5750f4c16eb 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -21,6 +21,7 @@
 
 #include "util/util.h"
 #include "util/sss_nss.h"
+#include "util/sss_cli_cmd.h"
 #include "responder/nss/nsssrv.h"
 #include "responder/nss/nsssrv_private.h"
 #include "responder/nss/nsssrv_netgroup.h"
@@ -1071,8 +1072,8 @@ static int nss_cmd_assume_upn(struct nss_dom_ctx *dctx)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -1123,8 +1124,8 @@ static void nss_cmd_getby_dp_callback(uint16_t err_maj, uint32_t err_min,
                 ret = nss_cmd_getbysid_send_reply(dctx);
                 break;
             default:
-                DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                            dctx->cmdctx->cmd);
+                DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+                      dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
                 ret = EINVAL;
             }
             goto done;
@@ -1246,8 +1247,8 @@ static void nss_cmd_getby_dp_callback(uint16_t err_maj, uint32_t err_min,
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -1353,7 +1354,8 @@ static int nss_cmd_getbynam(enum sss_cli_command cmd, struct cli_ctx *cctx)
     case SSS_NSS_GETORIGBYNAME:
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d].\n", cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d][%s].\n",
+              cmd, sss_cmd2str(cmd));
         return EINVAL;
     }
 
@@ -1389,8 +1391,8 @@ static int nss_cmd_getbynam(enum sss_cli_command cmd, struct cli_ctx *cctx)
     rawname = (const char *)body;
     dctx->mc_name = rawname;
 
-    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d] with input [%s].\n",
-                               dctx->cmdctx->cmd, rawname);
+    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d][%s] with input [%s].\n",
+          cmd, sss_cmd2str(dctx->cmdctx->cmd), rawname);
 
     if (dctx->cmdctx->cmd == SSS_NSS_GETSIDBYNAME) {
         ret = nss_check_name_of_well_known_sid(cmdctx, rawname);
@@ -1509,8 +1511,8 @@ static int nss_cmd_getbynam(enum sss_cli_command cmd, struct cli_ctx *cctx)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -1611,8 +1613,8 @@ static void nss_cmd_getbynam_done(struct tevent_req *req)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                     dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -1779,7 +1781,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
     case SSS_NSS_GETSIDBYID:
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d].\n", cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d][%s].\n",
+              cmd, sss_cmd2str(cmd));
         return EINVAL;
     }
 
@@ -1808,8 +1811,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
     }
     SAFEALIGN_COPY_UINT32(&cmdctx->id, body, NULL);
 
-    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d] with id [%"PRIu32"].\n",
-                              dctx->cmdctx->cmd, cmdctx->id);
+    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d][%s] with id [%"PRIu32"].\n",
+          dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd), cmdctx->id);
 
     switch(dctx->cmdctx->cmd) {
     case SSS_NSS_GETPWUID:
@@ -1850,8 +1853,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
         goto done;
     }
@@ -1896,8 +1899,8 @@ static int nss_cmd_getbyid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -1964,8 +1967,8 @@ static void nss_cmd_getbyid_done(struct tevent_req *req)
         }
         break;
     default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d].\n",
-                                    dctx->cmdctx->cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command [%d][%s].\n",
+              dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd));
         ret = EINVAL;
     }
 
@@ -5259,7 +5262,8 @@ static int nss_cmd_getbysid(enum sss_cli_command cmd, struct cli_ctx *cctx)
     size_t bin_sid_length;
 
     if (cmd != SSS_NSS_GETNAMEBYSID && cmd != SSS_NSS_GETIDBYSID) {
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d].\n", cmd);
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid command type [%d][%s].\n",
+              cmd, sss_cmd2str(cmd));
         return EINVAL;
     }
 
@@ -5301,8 +5305,8 @@ static int nss_cmd_getbysid(enum sss_cli_command cmd, struct cli_ctx *cctx)
         goto done;
     }
 
-    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d] with SID [%s].\n",
-                               dctx->cmdctx->cmd, sid_str);
+    DEBUG(SSSDBG_TRACE_FUNC, "Running command [%d][%s] with SID [%s].\n",
+          dctx->cmdctx->cmd, sss_cmd2str(dctx->cmdctx->cmd), sid_str);
 
     cmdctx->secid = talloc_strdup(cmdctx, sid_str);
     if (cmdctx->secid == NULL) {
diff --git a/src/sss_client/pam_sss.c b/src/sss_client/pam_sss.c
index 431f5dc62655dd1e6901f16f72dcad9703f037ac..b4f7efe49017870186f1cd9e91603033a5354770 100644
--- a/src/sss_client/pam_sss.c
+++ b/src/sss_client/pam_sss.c
@@ -1209,7 +1209,7 @@ static int send_and_receive(pam_handle_t *pamh, struct pam_items *pi,
         case SSS_PAM_PREAUTH:
             break;
         default:
-            D(("Illegal task [%d]", task));
+            D(("Illegal task [%#x]", task));
             return PAM_SYSTEM_ERR;
     }
 
@@ -1672,7 +1672,7 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
 
     bindtextdomain(PACKAGE, LOCALEDIR);
 
-    D(("Hello pam_sssd: %d", task));
+    D(("Hello pam_sssd: %#x", task));
 
     eval_argv(pamh, argc, argv, &flags, &retries, &quiet_mode, &domains);
 
@@ -1748,7 +1748,7 @@ static int pam_sss(enum sss_cli_command task, pam_handle_t *pamh,
             case SSS_PAM_CLOSE_SESSION:
                 break;
             default:
-                D(("Illegal task [%d]", task));
+                D(("Illegal task [%#x]", task));
                 return PAM_SYSTEM_ERR;
         }
 
diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c
index 65c461093e859d4da73761782a3a694bf5bda8fb..41d8a6558a06b03787e0ff37f37b31f223a9da34 100644
--- a/src/tools/tools_mc_util.c
+++ b/src/tools/tools_mc_util.c
@@ -27,6 +27,7 @@
 #include "util/util.h"
 #include "tools/tools_util.h"
 #include "util/mmap_cache.h"
+#include "util/sss_cli_cmd.h"
 #include "sss_client/sss_cli.h"
 
 /* This is a copy of sss_mc_set_recycled present in
@@ -260,7 +261,8 @@ static errno_t sss_mc_refresh_ent(const char *name, enum sss_tools_ent ent)
     }
 
     if (cmd == SSS_CLI_NULL) {
-        DEBUG(SSSDBG_OP_FAILURE, "Unknown object %d to refresh\n", cmd);
+        DEBUG(SSSDBG_OP_FAILURE, "Unknown object [%d][%s] to refresh\n",
+              cmd, sss_cmd2str(cmd));
         return EINVAL;
     }
 
diff --git a/src/util/sss_cli_cmd.c b/src/util/sss_cli_cmd.c
new file mode 100644
index 0000000000000000000000000000000000000000..820ac6de1e17bc28947c12fafa92e59a1cf87665
--- /dev/null
+++ b/src/util/sss_cli_cmd.c
@@ -0,0 +1,238 @@
+/*
+   SSSD - cmd2str util
+
+   Copyright (C) Petr Cech <pcech@redhat.com> 2015
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "sss_client/sss_cli.h"
+#include "util/sss_cli_cmd.h"
+#include "util/util.h"
+
+const char *sss_cmd2str(enum sss_cli_command cmd)
+{
+    switch (cmd) {
+    /* null */
+    case SSS_CLI_NULL:
+        return "SSS_CLI_NULL";
+
+    /* version */
+    case SSS_GET_VERSION:
+        return "SSS_GET_VERSION";
+
+    /* passwd */
+    case SSS_NSS_GETPWNAM:
+        return "SSS_NSS_GETPWNAM";
+    case SSS_NSS_GETPWUID:
+        return "SSS_NSS_GETPWUID";
+    case SSS_NSS_SETPWENT:
+        return "SSS_NSS_SETPWENT";
+    case SSS_NSS_GETPWENT:
+        return "SSS_NSS_GETPWENT";
+    case SSS_NSS_ENDPWENT:
+        return "SSS_NSS_ENDPWENT";
+
+    /* group */
+    case SSS_NSS_GETGRNAM:
+        return "SSS_NSS_GETGRNAM";
+    case SSS_NSS_GETGRGID:
+        return "SSS_NSS_GETGRGID";
+    case SSS_NSS_SETGRENT:
+        return "SSS_NSS_SETGRENT";
+    case SSS_NSS_GETGRENT:
+        return "SSS_NSS_GETGRENT";
+    case SSS_NSS_ENDGRENT:
+        return "SSS_NSS_ENDGRENT";
+    case SSS_NSS_INITGR:
+        return "SSS_NSS_INITGR";
+
+#if 0
+    /* aliases */
+    case SSS_NSS_GETALIASBYNAME:
+        return "SSS_NSS_GETALIASBYNAME";
+    case SSS_NSS_GETALIASBYPORT:
+        return "SSS_NSS_GETALIASBYPORT";
+    case SSS_NSS_SETALIASENT:
+        return "SSS_NSS_SETALIASENT";
+    case SSS_NSS_GETALIASENT:
+        return "SSS_NSS_GETALIASENT";
+    case SSS_NSS_ENDALIASENT:
+        return "SSS_NSS_ENDALIASENT";
+
+    /* ethers */
+    case SSS_NSS_GETHOSTTON:
+        return "SSS_NSS_GETHOSTTON";
+    case SSS_NSS_GETNTOHOST:
+        return "SSS_NSS_GETNTOHOST";
+    case SSS_NSS_SETETHERENT:
+        return "SSS_NSS_SETETHERENT";
+    case SSS_NSS_GETETHERENT:
+        return "SSS_NSS_GETETHERENT";
+    case SSS_NSS_ENDETHERENT:
+        return "SSS_NSS_ENDETHERENT";
+
+    /* hosts */
+    case SSS_NSS_GETHOSTBYNAME:
+        return "SSS_NSS_GETHOSTBYNAME";
+    case SSS_NSS_GETHOSTBYNAME2:
+        return "SSS_NSS_GETHOSTBYNAME2";
+    case SSS_NSS_GETHOSTBYADDR:
+        return "SSS_NSS_GETHOSTBYADDR";
+    case SSS_NSS_SETHOSTENT:
+        return "SSS_NSS_SETHOSTENT";
+    case SSS_NSS_GETHOSTENT:
+        return "SSS_NSS_GETHOSTENT";
+    case SSS_NSS_ENDHOSTENT:
+        return "SSS_NSS_ENDHOSTENT";
+#endif
+
+    /* netgroup */
+    case SSS_NSS_SETNETGRENT:
+        return "SSS_NSS_SETNETGRENT";
+    case SSS_NSS_GETNETGRENT:
+        return "SSS_NSS_GETNETGRENT";
+    case SSS_NSS_ENDNETGRENT:
+        return "SSS_NSS_ENDNETGRENT";
+    /* SSS_NSS_INNETGR:
+        return "SSS_NSS_INNETGR";
+        break; */
+
+#if 0
+    /* networks */
+    case SSS_NSS_GETNETBYNAME:
+        return "SSS_NSS_GETNETBYNAME";
+    case SSS_NSS_GETNETBYADDR:
+        return "SSS_NSS_GETNETBYADDR";
+    case SSS_NSS_SETNETENT:
+        return "SSS_NSS_SETNETENT";
+    case SSS_NSS_GETNETENT:
+        return "SSS_NSS_GETNETENT";
+    case SSS_NSS_ENDNETENT:
+        return "SSS_NSS_ENDNETENT";
+
+    /* protocols */
+    case SSS_NSS_GETPROTOBYNAME:
+        return "SSS_NSS_GETPROTOBYNAME";
+    case SSS_NSS_GETPROTOBYNUM:
+        return "SSS_NSS_GETPROTOBYNUM";
+    case SSS_NSS_SETPROTOENT:
+        return "SSS_NSS_SETPROTOENT";
+    case SSS_NSS_GETPROTOENT:
+        return "SSS_NSS_GETPROTOENT";
+    case SSS_NSS_ENDPROTOENT:
+        return "SSS_NSS_ENDPROTOENT";
+
+    /* rpc */
+    case SSS_NSS_GETRPCBYNAME:
+        return "SSS_NSS_GETRPCBYNAME";
+    case SSS_NSS_GETRPCBYNUM:
+        return "SSS_NSS_GETRPCBYNUM";
+    case SSS_NSS_SETRPCENT:
+        return "SSS_NSS_SETRPCENT";
+    case SSS_NSS_GETRPCENT:
+        return "SSS_NSS_GETRPCENT";
+    case SSS_NSS_ENDRPCENT:
+        return "SSS_NSS_ENDRPCENT";
+#endif
+
+    /* services */
+    case SSS_NSS_GETSERVBYNAME:
+        return "SSS_NSS_GETSERVBYNAME";
+    case SSS_NSS_GETSERVBYPORT:
+        return "SSS_NSS_GETSERVBYPORT";
+    case SSS_NSS_SETSERVENT:
+        return "SSS_NSS_SETSERVENT";
+    case SSS_NSS_GETSERVENT:
+        return "SSS_NSS_GETSERVENT";
+    case SSS_NSS_ENDSERVENT:
+        return "SSS_NSS_ENDSERVENT";
+
+#if 0
+    /* shadow */
+    case SSS_NSS_GETSPNAM:
+        return "SSS_NSS_GETSPNAM";
+    case SSS_NSS_GETSPUID:
+        return "SSS_NSS_GETSPUID";
+    case SSS_NSS_SETSPENT:
+        return "SSS_NSS_SETSPENT";
+    case SSS_NSS_GETSPENT:
+        return "SSS_NSS_GETSPENT";
+    case SSS_NSS_ENDSPENT:
+        return "SSS_NSS_ENDSPENT";
+#endif
+
+    /* SUDO */
+    case SSS_SUDO_GET_SUDORULES:
+        return "SSS_SUDO_GET_SUDORULES";
+    case SSS_SUDO_GET_DEFAULTS:
+        return "SSS_SUDO_GET_DEFAULTS";
+
+    /* autofs */
+    case SSS_AUTOFS_SETAUTOMNTENT:
+        return "SSS_AUTOFS_SETAUTOMNTENT";
+    case SSS_AUTOFS_GETAUTOMNTENT:
+        return "SSS_AUTOFS_GETAUTOMNTENT";
+    case SSS_AUTOFS_GETAUTOMNTBYNAME:
+        return "SSS_AUTOFS_GETAUTOMNTBYNAME";
+    case SSS_AUTOFS_ENDAUTOMNTENT:
+        return "SSS_AUTOFS_ENDAUTOMNTENT";
+
+    /* SSH */
+    case SSS_SSH_GET_USER_PUBKEYS:
+        return "SSS_SSH_GET_USER_PUBKEYS";
+    case SSS_SSH_GET_HOST_PUBKEYS:
+        return "SSS_SSH_GET_HOST_PUBKEYS";
+
+    /* PAM related calls */
+    case SSS_PAM_AUTHENTICATE:
+        return "SSS_PAM_AUTHENTICATE";
+    case SSS_PAM_SETCRED:
+        return "SSS_PAM_SETCRED";
+    case SSS_PAM_ACCT_MGMT:
+        return "SSS_PAM_ACCT_MGMT";
+    case SSS_PAM_OPEN_SESSION:
+        return "SSS_PAM_OPEN_SESSION";
+    case SSS_PAM_CLOSE_SESSION:
+        return "SSS_PAM_CLOSE_SESSION";
+    case SSS_PAM_CHAUTHTOK:
+        return "SSS_PAM_CHAUTHTOK";
+    case SSS_PAM_CHAUTHTOK_PRELIM:
+        return "SSS_PAM_CHAUTHTOK_PRELIM";
+    case SSS_CMD_RENEW:
+        return "SSS_CMD_RENEW";
+    case SSS_PAM_PREAUTH:
+        return "SSS_PAM_PREAUTH";
+
+    /* PAC responder calls */
+    case SSS_PAC_ADD_PAC_USER:
+        return "SSS_PAC_ADD_PAC_USER";
+
+    /* ID-SID mapping calls */
+    case SSS_NSS_GETSIDBYNAME:
+        return "SSS_NSS_GETSIDBYNAME";
+    case SSS_NSS_GETSIDBYID:
+        return "SSS_NSS_GETSIDBYID";
+    case SSS_NSS_GETNAMEBYSID:
+        return "SSS_NSS_GETNAMEBYSID";
+    case SSS_NSS_GETIDBYSID:
+        return "SSS_NSS_GETIDBYSID";
+    case SSS_NSS_GETORIGBYNAME:
+        return "SSS_NSS_GETORIGBYNAME";
+    default:
+        DEBUG(SSSDBG_MINOR_FAILURE,
+              "Translation's string is missing for command [%#x].\n", cmd);
+        return "UNKNOWN COMMAND";
+    }
+}
diff --git a/src/util/sss_cli_cmd.h b/src/util/sss_cli_cmd.h
new file mode 100644
index 0000000000000000000000000000000000000000..66ad076b12591fc1fa828144ea2c3a8170b155c6
--- /dev/null
+++ b/src/util/sss_cli_cmd.h
@@ -0,0 +1,28 @@
+/*
+   SSSD - cmd2str util
+
+   Copyright (C) Petr Cech <pcech@redhat.com> 2015
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __SSS_CLI_CMD_H__
+#define __SSS_CLI_CMD_H__
+
+#include "sss_client/sss_cli.h"
+
+/* Translate sss_cli_command to human readable form. */
+const char *sss_cmd2str(enum sss_cli_command cmd);
+
+#endif /* __SSS_CLI_CMD_H__ */
-- 
2.4.3

