dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0095-sssctl-integrate-pam_test_client-into-sssctl.patch

bb7cd1
From 1bc25dba8f4725ef34e394d8e8eee42dbdaed924 Mon Sep 17 00:00:00 2001
bb7cd1
From: Sumit Bose <sbose@redhat.com>
bb7cd1
Date: Thu, 30 Mar 2017 16:21:15 +0200
bb7cd1
Subject: [PATCH 95/96] sssctl: integrate pam_test_client into sssctl
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit 4a9160e2b3b9c531e2b4a7884f49bfbb4a07a992)
bb7cd1
---
bb7cd1
 Makefile.am                                        |  16 +--
bb7cd1
 po/POTFILES.in                                     |   1 -
bb7cd1
 src/tools/sssctl/sssctl.c                          |   1 +
bb7cd1
 src/tools/sssctl/sssctl.h                          |   4 +
bb7cd1
 .../sssctl/sssctl_user_checks.c}                   | 122 +++++++++++----------
bb7cd1
 5 files changed, 72 insertions(+), 72 deletions(-)
bb7cd1
 rename src/{sss_client/pam_test_client.c => tools/sssctl/sssctl_user_checks.c} (62%)
bb7cd1
bb7cd1
diff --git a/Makefile.am b/Makefile.am
bb7cd1
index c4d252357356c2d5452a414fd360fc5370b2c775..f5ac363a35e4aae51e8b70bad27c7fc824be10f2 100644
bb7cd1
--- a/Makefile.am
bb7cd1
+++ b/Makefile.am
bb7cd1
@@ -1724,11 +1724,15 @@ sssctl_SOURCES = \
bb7cd1
     src/tools/sssctl/sssctl_domains.c \
bb7cd1
     src/tools/sssctl/sssctl_sifp.c \
bb7cd1
     src/tools/sssctl/sssctl_config.c \
bb7cd1
+    src/tools/sssctl/sssctl_user_checks.c \
bb7cd1
     $(SSSD_TOOLS_OBJ) \
bb7cd1
     $(NULL)
bb7cd1
 sssctl_LDADD = \
bb7cd1
     $(TOOLS_LIBS) \
bb7cd1
     $(SSSD_INTERNAL_LTLIBS) \
bb7cd1
+    $(PAM_LIBS) \
bb7cd1
+    $(PAM_MISC_LIBS) \
bb7cd1
+    $(LIBADD_DL) \
bb7cd1
     libsss_simpleifp.la \
bb7cd1
     $(NULL)
bb7cd1
 sssctl_CFLAGS = \
bb7cd1
@@ -3449,7 +3453,7 @@ endif # BUILD_KCM
bb7cd1
 
bb7cd1
 endif # HAVE_CMOCKA
bb7cd1
 
bb7cd1
-noinst_PROGRAMS = pam_test_client
bb7cd1
+noinst_PROGRAMS =
bb7cd1
 if BUILD_SUDO
bb7cd1
 noinst_PROGRAMS += sss_sudo_cli
bb7cd1
 endif
bb7cd1
@@ -3460,16 +3464,6 @@ if BUILD_WITH_LIBCURL
bb7cd1
 noinst_PROGRAMS += tcurl-test-tool
bb7cd1
 endif
bb7cd1
 
bb7cd1
-pam_test_client_SOURCES = \
bb7cd1
-    src/sss_client/pam_test_client.c \
bb7cd1
-    $(NULL)
bb7cd1
-pam_test_client_LDADD = \
bb7cd1
-    $(PAM_LIBS) \
bb7cd1
-    $(PAM_MISC_LIBS) \
bb7cd1
-    $(LIBADD_DL) \
bb7cd1
-    libsss_simpleifp.la \
bb7cd1
-    $(NULL)
bb7cd1
-
bb7cd1
 if BUILD_AUTOFS
bb7cd1
 autofs_test_client_SOURCES = \
bb7cd1
     src/sss_client/autofs/autofs_test_client.c \
bb7cd1
diff --git a/po/POTFILES.in b/po/POTFILES.in
bb7cd1
index ee532def223fdd5db632ad98fd11a57e38d0e125..f4e4e095f9e4025d129b6b13422bdd0bc07c8e1a 100644
bb7cd1
--- a/po/POTFILES.in
bb7cd1
+++ b/po/POTFILES.in
bb7cd1
@@ -9,7 +9,6 @@ src/sss_client/common.c
bb7cd1
 src/sss_client/nss_group.c
bb7cd1
 src/sss_client/nss_passwd.c
bb7cd1
 src/sss_client/pam_sss.c
bb7cd1
-src/sss_client/pam_test_client.c
bb7cd1
 src/sss_client/ssh/sss_ssh_authorizedkeys.c
bb7cd1
 src/sss_client/ssh/sss_ssh_knownhostsproxy.c
bb7cd1
 src/tools/sss_useradd.c
bb7cd1
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
bb7cd1
index e1cf46382cd1dee54cd372ca500368f149411b78..509d2e1a00d3b57b541590ce7db5f94d2ff43add 100644
bb7cd1
--- a/src/tools/sssctl/sssctl.c
bb7cd1
+++ b/src/tools/sssctl/sssctl.c
bb7cd1
@@ -263,6 +263,7 @@ int main(int argc, const char **argv)
bb7cd1
         SSS_TOOL_DELIMITER("SSSD Status:"),
bb7cd1
         SSS_TOOL_COMMAND("domain-list", "List available domains", 0, sssctl_domain_list),
bb7cd1
         SSS_TOOL_COMMAND("domain-status", "Print information about domain", 0, sssctl_domain_status),
bb7cd1
+        SSS_TOOL_COMMAND("user-checks", "Print information about a user and check authentication", 0, sssctl_user_checks),
bb7cd1
         SSS_TOOL_DELIMITER("Information about cached content:"),
bb7cd1
         SSS_TOOL_COMMAND("user-show", "Information about cached user", 0, sssctl_user_show),
bb7cd1
         SSS_TOOL_COMMAND("group-show", "Information about cached group", 0, sssctl_group_show),
bb7cd1
diff --git a/src/tools/sssctl/sssctl.h b/src/tools/sssctl/sssctl.h
bb7cd1
index 5270a9ec62dfb288511af179a99e9a542ea26ec4..22626e2210252e5e3fadeb6c5d01d4620cd60e5b 100644
bb7cd1
--- a/src/tools/sssctl/sssctl.h
bb7cd1
+++ b/src/tools/sssctl/sssctl.h
bb7cd1
@@ -121,4 +121,8 @@ errno_t sssctl_netgroup_show(struct sss_cmdline *cmdline,
bb7cd1
 errno_t sssctl_config_check(struct sss_cmdline *cmdline,
bb7cd1
                             struct sss_tool_ctx *tool_ctx,
bb7cd1
                             void *pvt);
bb7cd1
+
bb7cd1
+errno_t sssctl_user_checks(struct sss_cmdline *cmdline,
bb7cd1
+                           struct sss_tool_ctx *tool_ctx,
bb7cd1
+                           void *pvt);
bb7cd1
 #endif /* _SSSCTL_H_ */
bb7cd1
diff --git a/src/sss_client/pam_test_client.c b/src/tools/sssctl/sssctl_user_checks.c
bb7cd1
similarity index 62%
bb7cd1
rename from src/sss_client/pam_test_client.c
bb7cd1
rename to src/tools/sssctl/sssctl_user_checks.c
bb7cd1
index 40ef3f6d480c0108c985fce7e34e983d145f237e..7c7b564bd29100382c9bbef7a3131c379e9aa97e 100644
bb7cd1
--- a/src/sss_client/pam_test_client.c
bb7cd1
+++ b/src/tools/sssctl/sssctl_user_checks.c
bb7cd1
@@ -35,6 +35,9 @@
bb7cd1
 #include <security/pam_appl.h>
bb7cd1
 
bb7cd1
 #include "lib/sifp/sss_sifp.h"
bb7cd1
+#include "util/util.h"
bb7cd1
+#include "tools/common/sss_tools.h"
bb7cd1
+#include "tools/sssctl/sssctl.h"
bb7cd1
 
bb7cd1
 #ifdef HAVE_SECURITY_PAM_MISC_H
bb7cd1
 # include <security/pam_misc.h>
bb7cd1
@@ -85,17 +88,17 @@ static int get_ifp_user(const char *user)
bb7cd1
 
bb7cd1
     error = sss_sifp_init(&sifp);
bb7cd1
     if (error != SSS_SIFP_OK) {
bb7cd1
-        fprintf(stderr, "Unable to connect to the InfoPipe");
bb7cd1
+        fprintf(stderr, _("Unable to connect to the InfoPipe"));
bb7cd1
         return EFAULT;
bb7cd1
     }
bb7cd1
 
bb7cd1
     error = sss_sifp_fetch_user_by_name(sifp, user, &user_obj);
bb7cd1
     if (error != SSS_SIFP_OK) {
bb7cd1
-        fprintf(stderr, "Unable to get user object");
bb7cd1
+        fprintf(stderr, _("Unable to get user object"));
bb7cd1
         return EIO;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    fprintf(stdout, "SSSD InfoPipe user lookup result:\n");
bb7cd1
+    fprintf(stdout, _("SSSD InfoPipe user lookup result:\n"));
bb7cd1
     for (c = 0; ifp_user_attr[c].name != NULL; c++) {
bb7cd1
         if (ifp_user_attr[c].is_string) {
bb7cd1
             error = sss_sifp_find_attr_as_string(user_obj->attrs,
bb7cd1
@@ -107,7 +110,7 @@ static int get_ifp_user(const char *user)
bb7cd1
                                                  &tmp_uint32);
bb7cd1
         }
bb7cd1
         if (error != SSS_SIFP_OK) {
bb7cd1
-            fprintf(stderr, "Unable to get user name attr");
bb7cd1
+            fprintf(stderr, _("Unable to get user name attr"));
bb7cd1
             return EIO;
bb7cd1
         }
bb7cd1
 
bb7cd1
@@ -118,6 +121,7 @@ static int get_ifp_user(const char *user)
bb7cd1
                                                   tmp_uint32);
bb7cd1
         }
bb7cd1
     }
bb7cd1
+    fprintf(stdout, "\n");
bb7cd1
 
bb7cd1
     sss_sifp_free_object(sifp, &user_obj);
bb7cd1
     sss_sifp_free(&sifp);
bb7cd1
@@ -139,14 +143,14 @@ static int sss_getpwnam_check(const char *user)
bb7cd1
 
bb7cd1
     dl_handle = dlopen("libnss_sss.so.2", RTLD_NOW);
bb7cd1
     if (dl_handle == NULL) {
bb7cd1
-        fprintf(stderr, "dlopen failed with [%s].\n", dlerror());
bb7cd1
+        fprintf(stderr, _("dlopen failed with [%s].\n"), dlerror());
bb7cd1
         ret = EIO;
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
     sss_getpwnam_r = dlsym(dl_handle, "_nss_sss_getpwnam_r");
bb7cd1
     if (sss_getpwnam_r == NULL) {
bb7cd1
-        fprintf(stderr, "dlsym failed with [%s].\n", dlerror());
bb7cd1
+        fprintf(stderr, _("dlsym failed with [%s].\n"), dlerror());
bb7cd1
         ret = EIO;
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
@@ -154,25 +158,25 @@ static int sss_getpwnam_check(const char *user)
bb7cd1
     buflen = DEFAULT_BUFSIZE;
bb7cd1
     buffer = malloc(buflen);
bb7cd1
     if (buffer == NULL) {
bb7cd1
-        fprintf(stderr, "malloc failed.\n");
bb7cd1
+        fprintf(stderr, _("malloc failed.\n"));
bb7cd1
         ret = ENOMEM;
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
     status = sss_getpwnam_r(user, &pwd, buffer, buflen, &nss_errno);
bb7cd1
     if (status != NSS_STATUS_SUCCESS) {
bb7cd1
-        fprintf(stderr, "sss_getpwnam_r failed with [%d].\n", status);
bb7cd1
+        fprintf(stderr, _("sss_getpwnam_r failed with [%d].\n"), status);
bb7cd1
         ret = EIO;
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    fprintf(stdout, "SSSD nss user lookup result:\n");
bb7cd1
-    fprintf(stdout, " - user name: %s\n", pwd.pw_name);
bb7cd1
-    fprintf(stdout, " - user id: %d\n", pwd.pw_uid);
bb7cd1
-    fprintf(stdout, " - group id: %d\n", pwd.pw_gid);
bb7cd1
-    fprintf(stdout, " - gecos: %s\n", pwd.pw_gecos);
bb7cd1
-    fprintf(stdout, " - home directory: %s\n", pwd.pw_dir);
bb7cd1
-    fprintf(stdout, " - shell: %s\n", pwd.pw_shell);
bb7cd1
+    fprintf(stdout, _("SSSD nss user lookup result:\n"));
bb7cd1
+    fprintf(stdout, _(" - user name: %s\n"), pwd.pw_name);
bb7cd1
+    fprintf(stdout, _(" - user id: %d\n"), pwd.pw_uid);
bb7cd1
+    fprintf(stdout, _(" - group id: %d\n"), pwd.pw_gid);
bb7cd1
+    fprintf(stdout, _(" - gecos: %s\n"), pwd.pw_gecos);
bb7cd1
+    fprintf(stdout, _(" - home directory: %s\n"), pwd.pw_dir);
bb7cd1
+    fprintf(stdout, _(" - shell: %s\n\n"), pwd.pw_shell);
bb7cd1
 
bb7cd1
     ret = 0;
bb7cd1
 
bb7cd1
@@ -186,87 +190,89 @@ done:
bb7cd1
     return ret;
bb7cd1
 }
bb7cd1
 
bb7cd1
-int main(int argc, char *argv[]) {
bb7cd1
+errno_t sssctl_user_checks(struct sss_cmdline *cmdline,
bb7cd1
+                           struct sss_tool_ctx *tool_ctx,
bb7cd1
+                           void *pvt)
bb7cd1
+{
bb7cd1
 
bb7cd1
     pam_handle_t *pamh;
bb7cd1
-    char *user;
bb7cd1
-    char *action;
bb7cd1
-    char *service;
bb7cd1
+    const char *user = NULL;
bb7cd1
+    const char *action = DEFAULT_ACTION;
bb7cd1
+    const char *service = DEFAULT_SERVICE;
bb7cd1
     int ret;
bb7cd1
     size_t c;
bb7cd1
     char **pam_env;
bb7cd1
 
bb7cd1
-    if (argc == 1) {
bb7cd1
-        fprintf(stderr, "Usage: pam_test_client USERNAME "
bb7cd1
-                        "[auth|acct|setc|chau|open|clos] [pam_service]\n");
bb7cd1
-        return 0;
bb7cd1
-    } else if (argc == 2) {
bb7cd1
-        fprintf(stderr, "using first argument as user name and default action "
bb7cd1
-                        "and service\n");
bb7cd1
-    } else if (argc == 3) {
bb7cd1
-        fprintf(stderr, "using first argument as user name, second as action "
bb7cd1
-                        "and default service\n");
bb7cd1
-    }
bb7cd1
-
bb7cd1
-    user = strdup(argv[1]);
bb7cd1
-    action = argc > 2 ? strdup(argv[2]) : strdup(DEFAULT_ACTION);
bb7cd1
-    service = argc > 3 ? strdup(argv[3]) : strdup(DEFAULT_SERVICE);
bb7cd1
+    /* Parse command line. */
bb7cd1
+    struct poptOption options[] = {
bb7cd1
+        { "action", 'a', POPT_ARG_STRING, &action, 0,
bb7cd1
+          _("PAM action [auth|acct|setc|chau|open|clos], default: "
bb7cd1
+            DEFAULT_ACTION), NULL },
bb7cd1
+        { "service", 's', POPT_ARG_STRING, &service, 0,
bb7cd1
+          _("PAM service, default: " DEFAULT_SERVICE), NULL },
bb7cd1
+        POPT_TABLEEND
bb7cd1
+    };
bb7cd1
 
bb7cd1
-    if (action == NULL || user == NULL || service == NULL) {
bb7cd1
-        fprintf(stderr, "Out of memory!\n");
bb7cd1
-        return 1;
bb7cd1
+    ret = sss_tool_popt_ex(cmdline, options, SSS_TOOL_OPT_OPTIONAL,
bb7cd1
+                           NULL, NULL, "USERNAME", _("Specify user name."),
bb7cd1
+                           &user, NULL);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
bb7cd1
+        return ret;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    fprintf(stdout, "user: %s\naction: %s\nservice: %s\n",
bb7cd1
+    fprintf(stdout, _("user: %s\naction: %s\nservice: %s\n\n"),
bb7cd1
                     user, action, service);
bb7cd1
 
bb7cd1
     if (*user != '\0') {
bb7cd1
         ret = sss_getpwnam_check(user);
bb7cd1
         if (ret != 0) {
bb7cd1
-            fprintf(stderr, "User name lookup with [%s] failed.\n", user);
bb7cd1
+            fprintf(stderr, _("User name lookup with [%s] failed.\n"), user);
bb7cd1
         }
bb7cd1
 
bb7cd1
         ret = get_ifp_user(user);
bb7cd1
         if (ret != 0) {
bb7cd1
-            fprintf(stderr, "InforPipe User lookup with [%s] failed.\n", user);
bb7cd1
+            fprintf(stderr, _("InforPipe User lookup with [%s] failed.\n"),
bb7cd1
+                            user);
bb7cd1
         }
bb7cd1
     }
bb7cd1
 
bb7cd1
     ret = pam_start(service, user, &conv, &pamh);
bb7cd1
     if (ret != PAM_SUCCESS) {
bb7cd1
-        fprintf(stderr, "pam_start failed: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_start failed: %s\n"), pam_strerror(pamh, ret));
bb7cd1
         return 1;
bb7cd1
     }
bb7cd1
 
bb7cd1
     if ( strncmp(action, "auth", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_authenticate\n");
bb7cd1
+        fprintf(stdout, _("testing pam_authenticate\n\n"));
bb7cd1
         ret = pam_authenticate(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_authenticate: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_authenticate: %s\n\n"), pam_strerror(pamh, ret));
bb7cd1
     } else if ( strncmp(action, "chau", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_chauthtok\n");
bb7cd1
+        fprintf(stdout, _("testing pam_chauthtok\n\n"));
bb7cd1
         ret = pam_chauthtok(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_chauthtok: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_chauthtok: %s\n\n"), pam_strerror(pamh, ret));
bb7cd1
     } else if ( strncmp(action, "acct", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_acct_mgmt\n");
bb7cd1
+        fprintf(stdout, _("testing pam_acct_mgmt\n\n"));
bb7cd1
         ret = pam_acct_mgmt(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_acct_mgmt: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_acct_mgmt: %s\n\n"), pam_strerror(pamh, ret));
bb7cd1
     } else if ( strncmp(action, "setc", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_setcred\n");
bb7cd1
+        fprintf(stdout, _("testing pam_setcred\n\n"));
bb7cd1
         ret = pam_setcred(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_setcred: %d[%s]\n", ret, pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_setcred: [%s]\n\n"), pam_strerror(pamh, ret));
bb7cd1
     } else if ( strncmp(action, "open", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_open_session\n");
bb7cd1
+        fprintf(stdout, _("testing pam_open_session\n\n"));
bb7cd1
         ret = pam_open_session(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_open_session: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_open_session: %s\n\n"), pam_strerror(pamh, ret));
bb7cd1
     } else if ( strncmp(action, "clos", 4)== 0 ) {
bb7cd1
-        fprintf(stdout, "testing pam_close_session\n");
bb7cd1
+        fprintf(stdout, _("testing pam_close_session\n\n"));
bb7cd1
         ret = pam_close_session(pamh, 0);
bb7cd1
-        fprintf(stderr, "pam_close_session: %s\n", pam_strerror(pamh, ret));
bb7cd1
+        fprintf(stderr, _("pam_close_session: %s\n\n"),
bb7cd1
+                        pam_strerror(pamh, ret));
bb7cd1
     } else {
bb7cd1
-        fprintf(stderr, "unknown action\n");
bb7cd1
+        fprintf(stderr, _("unknown action\n"));
bb7cd1
     }
bb7cd1
 
bb7cd1
-    fprintf(stderr, "PAM Environment:\n");
bb7cd1
+    fprintf(stderr, _("PAM Environment:\n"));
bb7cd1
     pam_env = pam_getenvlist(pamh);
bb7cd1
     if (pam_env != NULL && pam_env[0] != NULL) {
bb7cd1
         for (c = 0; pam_env[c] != NULL; c++) {
bb7cd1
@@ -274,15 +280,11 @@ int main(int argc, char *argv[]) {
bb7cd1
             free(pam_env[c]);
bb7cd1
         }
bb7cd1
     } else {
bb7cd1
-        fprintf(stderr, " - no env -\n");
bb7cd1
+        fprintf(stderr, _(" - no env -\n"));
bb7cd1
     }
bb7cd1
     free(pam_env);
bb7cd1
 
bb7cd1
     pam_end(pamh, ret);
bb7cd1
 
bb7cd1
-    free(user);
bb7cd1
-    free(action);
bb7cd1
-    free(service);
bb7cd1
-
bb7cd1
     return 0;
bb7cd1
 }
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1