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

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