11c8e3
From 513946aec6ddf4cb61d5d460e0478fd7ffd7be21 Mon Sep 17 00:00:00 2001
11c8e3
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd@samba.org>
11c8e3
Date: Wed, 17 Nov 2021 09:56:09 +0100
11c8e3
Subject: [PATCH] pam_winbind: add new pwd_change_prompt option (defaults to
11c8e3
 off).
11c8e3
11c8e3
This change disables the prompt for the change of an expired password by
11c8e3
default (using the PAM_RADIO_TYPE mechanism if present).
11c8e3
11c8e3
BUG: https://bugzilla.samba.org/show_bug.cgi?id=8691
11c8e3
11c8e3
Guenther
11c8e3
11c8e3
Signed-off-by: Guenther Deschner <gd@samba.org>
11c8e3
Reviewed-by: Alexander Bokovoy <ab@samba.org>
11c8e3
Reviewed-by: Andreas Schneider <asn@samba.org>
11c8e3
(cherry picked from commit 20c85cc1da8d8c7f1932fbdd92128bb6dafad472)
11c8e3
---
11c8e3
 docs-xml/manpages/pam_winbind.conf.5.xml |  7 +++++++
11c8e3
 nsswitch/pam_winbind.c                   | 12 ++++++++++--
11c8e3
 nsswitch/pam_winbind.h                   |  1 +
11c8e3
 3 files changed, 18 insertions(+), 2 deletions(-)
11c8e3
11c8e3
diff --git a/docs-xml/manpages/pam_winbind.conf.5.xml b/docs-xml/manpages/pam_winbind.conf.5.xml
11c8e3
index 0bc288f91a1..bae9298fc32 100644
11c8e3
--- a/docs-xml/manpages/pam_winbind.conf.5.xml
11c8e3
+++ b/docs-xml/manpages/pam_winbind.conf.5.xml
11c8e3
@@ -194,6 +194,13 @@
11c8e3
 		</para></listitem>
11c8e3
 		</varlistentry>
11c8e3
 
11c8e3
+		<varlistentry>
11c8e3
+		<term>pwd_change_prompt = yes|no</term>
11c8e3
+		<listitem><para>
11c8e3
+			Generate prompt for changing an expired password. Defaults to "no".
11c8e3
+		</para></listitem>
11c8e3
+		</varlistentry>
11c8e3
+
11c8e3
 		</variablelist>
11c8e3
 
11c8e3
 	</para>
11c8e3
diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c
11c8e3
index 720a4b90d85..06098dd07d8 100644
11c8e3
--- a/nsswitch/pam_winbind.c
11c8e3
+++ b/nsswitch/pam_winbind.c
11c8e3
@@ -479,6 +479,10 @@ static int _pam_parse(const pam_handle_t *pamh,
11c8e3
 		ctrl |= WINBIND_MKHOMEDIR;
11c8e3
 	}
11c8e3
 
11c8e3
+	if (tiniparser_getboolean(d, "global:pwd_change_prompt", false)) {
11c8e3
+		ctrl |= WINBIND_PWD_CHANGE_PROMPT;
11c8e3
+	}
11c8e3
+
11c8e3
 config_from_pam:
11c8e3
 	/* step through arguments */
11c8e3
 	for (i=argc,v=argv; i-- > 0; ++v) {
11c8e3
@@ -522,6 +526,8 @@ config_from_pam:
11c8e3
 		else if (!strncasecmp(*v, "warn_pwd_expire",
11c8e3
 			strlen("warn_pwd_expire")))
11c8e3
 			ctrl |= WINBIND_WARN_PWD_EXPIRE;
11c8e3
+		else if (!strcasecmp(*v, "pwd_change_prompt"))
11c8e3
+			ctrl |= WINBIND_PWD_CHANGE_PROMPT;
11c8e3
 		else if (type != PAM_WINBIND_CLEANUP) {
11c8e3
 			__pam_log(pamh, ctrl, LOG_ERR,
11c8e3
 				 "pam_parse: unknown option: %s", *v);
11c8e3
@@ -976,7 +982,8 @@ static bool _pam_send_password_expiry_message(struct pwb_context *ctx,
11c8e3
 		 * successfully sent the warning message.
11c8e3
 		 * Give the user a chance to change pwd.
11c8e3
 		 */
11c8e3
-		if (ret == PAM_SUCCESS) {
11c8e3
+		if (ret == PAM_SUCCESS &&
11c8e3
+		    (ctx->ctrl & WINBIND_PWD_CHANGE_PROMPT)) {
11c8e3
 			if (change_pwd) {
11c8e3
 				retval = _pam_winbind_change_pwd(ctx);
11c8e3
 				if (retval) {
11c8e3
@@ -1006,7 +1013,8 @@ static bool _pam_send_password_expiry_message(struct pwb_context *ctx,
11c8e3
 		 * successfully sent the warning message.
11c8e3
 		 * Give the user a chance to change pwd.
11c8e3
 		 */
11c8e3
-		if (ret == PAM_SUCCESS) {
11c8e3
+		if (ret == PAM_SUCCESS &&
11c8e3
+		    (ctx->ctrl & WINBIND_PWD_CHANGE_PROMPT)) {
11c8e3
 			if (change_pwd) {
11c8e3
 				retval = _pam_winbind_change_pwd(ctx);
11c8e3
 				if (retval) {
11c8e3
diff --git a/nsswitch/pam_winbind.h b/nsswitch/pam_winbind.h
11c8e3
index c6786d65a4d..2f4a25729bd 100644
11c8e3
--- a/nsswitch/pam_winbind.h
11c8e3
+++ b/nsswitch/pam_winbind.h
11c8e3
@@ -157,6 +157,7 @@ do {                             \
11c8e3
 #define WINBIND_WARN_PWD_EXPIRE		0x00002000
11c8e3
 #define WINBIND_MKHOMEDIR		0x00004000
11c8e3
 #define WINBIND_TRY_AUTHTOK_ARG		0x00008000
11c8e3
+#define WINBIND_PWD_CHANGE_PROMPT	0x00010000
11c8e3
 
11c8e3
 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
11c8e3
 #define _(string) dgettext(MODULE_NAME, string)
11c8e3
-- 
11c8e3
2.35.1
11c8e3