changeset 3508:b85c96ba56df HEAD

Open/close PAM session if -session option is given. Patch by Pasi Sj�m.
author Timo Sirainen <tss@iki.fi>
date Fri, 22 Jul 2005 20:07:04 +0300
parents 5bec038753f5
children 5cec18e2ddd1
files src/auth/passdb-pam.c
diffstat 1 files changed, 40 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/passdb-pam.c	Fri Jul 22 20:01:47 2005 +0300
+++ b/src/auth/passdb-pam.c	Fri Jul 22 20:07:04 2005 +0300
@@ -71,6 +71,7 @@
 	const char *pass;
 };
 
+static int pam_session;
 static char *service_name;
 static struct timeout *to_wait;
 
@@ -193,6 +194,22 @@
 		return status;
 	}
 
+	if (pam_session) {
+	        if ((status = pam_open_session(pamh, 0)) != PAM_SUCCESS) {
+			*error = t_strdup_printf(
+					"pam_open_session() failed: %s",
+					pam_strerror(pamh, status));
+	                return status;
+	        }
+
+	        if ((status = pam_close_session(pamh, 0)) != PAM_SUCCESS) {
+			*error = t_strdup_printf(
+					"pam_close_session() failed: %s",
+	                                pam_strerror(pamh, status));
+	                return status;
+	        }
+	}
+
 	status = pam_get_item(pamh, PAM_USER, (linux_const void **)&item);
 	if (status != PAM_SUCCESS) {
 		*error = t_strdup_printf("pam_get_item() failed: %s",
@@ -387,8 +404,29 @@
 
 static void pam_init(const char *args)
 {
-	service_name = strcmp(args, "*") == 0 ? NULL :
-		i_strdup(*args != '\0' ? args : "dovecot");
+	const char *const *t_args;
+	int i;
+
+	pam_session = FALSE;
+	service_name = i_strdup("dovecot");
+
+	t_push();
+	t_args = t_strsplit(args, " ");
+        for(i = 0; t_args[i] != NULL; i++) {
+		if (strcmp(t_args[i], "-session") == 0)
+			pam_session = TRUE;
+		else if (strcmp(t_args[i], "*") == 0) {
+			i_free(service_name);
+			service_name = NULL;
+		} else {
+			if (*t_args[i] != '\0') {
+				i_free(service_name);
+				service_name = i_strdup(t_args[i]);
+			}
+		}
+	}
+	t_pop();
+
 	to_wait = NULL;
 }