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