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