dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0091-pam_test_client-add-service-and-environment-to-PAM-t.patch

ecf709
From a5a6f0ab816be0dfd24b97a59c161adbe15ef406 Mon Sep 17 00:00:00 2001
ecf709
From: Sumit Bose <sbose@redhat.com>
ecf709
Date: Tue, 24 Jan 2017 14:50:20 +0100
ecf709
Subject: [PATCH 91/96] pam_test_client: add service and environment to PAM
ecf709
 test client
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
Related to https://pagure.io/SSSD/sssd/issue/3292
ecf709
ecf709
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ecf709
(cherry picked from commit 7be6624d9eda369e9a4d70c8ee4939b3622229b3)
ecf709
---
ecf709
 src/sss_client/pam_test_client.c | 50 ++++++++++++++++++++++++++++++----------
ecf709
 1 file changed, 38 insertions(+), 12 deletions(-)
ecf709
ecf709
diff --git a/src/sss_client/pam_test_client.c b/src/sss_client/pam_test_client.c
ecf709
index 29d1fcbf01682668d51bf154736aec673bd46501..ea032a75b195a9bf8078ed7d248da154ab0c8430 100644
ecf709
--- a/src/sss_client/pam_test_client.c
ecf709
+++ b/src/sss_client/pam_test_client.c
ecf709
@@ -48,34 +48,44 @@ static struct pam_conv conv = {
ecf709
 # error "Missing text based pam conversation function"
ecf709
 #endif
ecf709
 
ecf709
+#define DEFAULT_ACTION "acct"
ecf709
+#define DEFAULT_SERVICE "system-auth"
ecf709
+
ecf709
 int main(int argc, char *argv[]) {
ecf709
 
ecf709
     pam_handle_t *pamh;
ecf709
     char *user;
ecf709
     char *action;
ecf709
+    char *service;
ecf709
     int ret;
ecf709
+    size_t c;
ecf709
+    char **pam_env;
ecf709
 
ecf709
     if (argc == 1) {
ecf709
-        fprintf(stderr, "missing action and user name, using default\n");
ecf709
-        action = strdup("auth");
ecf709
-        user = strdup("dummy");
ecf709
+        fprintf(stderr, "Usage: pam_test_client USERNAME "
ecf709
+                        "[auth|acct|setc|chau|open|clos] [pam_service]\n");
ecf709
+        return 0;
ecf709
     } else if (argc == 2) {
ecf709
-        fprintf(stdout, "using first argument as action and default user name\n");
ecf709
-        action = strdup(argv[1]);
ecf709
-        user = strdup("dummy");
ecf709
-    } else {
ecf709
-        action = strdup(argv[1]);
ecf709
-        user = strdup(argv[2]);
ecf709
+        fprintf(stderr, "using first argument as user name and default action "
ecf709
+                        "and service\n");
ecf709
+    } else if (argc == 3) {
ecf709
+        fprintf(stderr, "using first argument as user name, second as action "
ecf709
+                        "and default service\n");
ecf709
     }
ecf709
 
ecf709
-    if (action == NULL || user == NULL) {
ecf709
+    user = strdup(argv[1]);
ecf709
+    action = argc > 2 ? strdup(argv[2]) : strdup(DEFAULT_ACTION);
ecf709
+    service = argc > 3 ? strdup(argv[3]) : strdup(DEFAULT_SERVICE);
ecf709
+
ecf709
+    if (action == NULL || user == NULL || service == NULL) {
ecf709
         fprintf(stderr, "Out of memory!\n");
ecf709
         return 1;
ecf709
     }
ecf709
 
ecf709
-    fprintf(stdout, "action: %s\nuser: %s\n", action,user);
ecf709
+    fprintf(stdout, "user: %s\naction: %s\nservice: %s\n",
ecf709
+                    user, action, service);
ecf709
 
ecf709
-    ret = pam_start("sss_test", user, &conv, &pamh);
ecf709
+    ret = pam_start(service, user, &conv, &pamh);
ecf709
     if (ret != PAM_SUCCESS) {
ecf709
         fprintf(stderr, "pam_start failed: %s\n", pam_strerror(pamh, ret));
ecf709
         return 1;
ecf709
@@ -109,7 +119,23 @@ int main(int argc, char *argv[]) {
ecf709
         fprintf(stderr, "unknown action\n");
ecf709
     }
ecf709
 
ecf709
+    fprintf(stderr, "PAM Environment:\n");
ecf709
+    pam_env = pam_getenvlist(pamh);
ecf709
+    if (pam_env != NULL && pam_env[0] != NULL) {
ecf709
+        for (c = 0; pam_env[c] != NULL; c++) {
ecf709
+            fprintf(stderr, " - %s\n", pam_env[c]);
ecf709
+            free(pam_env[c]);
ecf709
+        }
ecf709
+    } else {
ecf709
+        fprintf(stderr, " - no env -\n");
ecf709
+    }
ecf709
+    free(pam_env);
ecf709
+
ecf709
     pam_end(pamh, ret);
ecf709
 
ecf709
+    free(user);
ecf709
+    free(action);
ecf709
+    free(service);
ecf709
+
ecf709
     return 0;
ecf709
 }
ecf709
-- 
ecf709
2.9.3
ecf709