Blame SOURCES/sudo-1.8.23-Ignore-PAM_NEW_AUTHTOK_REQD-and-PAM_AUTHTOK_EXPIRED.patch

e33993
From 0f303a2de843c31afb03b558dfb7287be79e6e17 Mon Sep 17 00:00:00 2001
e33993
From: "Todd C. Miller" <Todd.Miller@sudo.ws>
e33993
Date: Thu, 26 Jul 2018 12:31:29 -0600
e33993
Subject: [PATCH] Ignore PAM_NEW_AUTHTOK_REQD and PAM_AUTHTOK_EXPIRED errors
e33993
 from pam_acct_mgmt() if authentication is disabled for the user. Bug #843
e33993
e33993
---
e33993
 plugins/sudoers/auth/bsdauth.c   |  2 +-
e33993
 plugins/sudoers/auth/pam.c       | 10 +++++++++-
e33993
 plugins/sudoers/auth/sudo_auth.c |  4 ++--
e33993
 plugins/sudoers/auth/sudo_auth.h |  6 +++---
e33993
 plugins/sudoers/check.c          |  4 +++-
e33993
 plugins/sudoers/sudoers.h        |  2 +-
e33993
 6 files changed, 19 insertions(+), 9 deletions(-)
e33993
e33993
diff --git a/plugins/sudoers/auth/bsdauth.c b/plugins/sudoers/auth/bsdauth.c
e33993
index 444cd337..390263d3 100644
e33993
--- a/plugins/sudoers/auth/bsdauth.c
e33993
+++ b/plugins/sudoers/auth/bsdauth.c
e33993
@@ -168,7 +168,7 @@ bsdauth_verify(struct passwd *pw, char *prompt, sudo_auth *auth, struct sudo_con
e33993
 }
e33993
 
e33993
 int
e33993
-bsdauth_approval(struct passwd *pw, sudo_auth *auth)
e33993
+bsdauth_approval(struct passwd *pw, sudo_auth *auth, bool exempt)
e33993
 {
e33993
     struct bsdauth_state *state = auth->data;
e33993
     debug_decl(bsdauth_approval, SUDOERS_DEBUG_AUTH)
e33993
diff --git a/plugins/sudoers/auth/pam.c b/plugins/sudoers/auth/pam.c
e33993
index 347289da..a4749448 100644
e33993
--- a/plugins/sudoers/auth/pam.c
e33993
+++ b/plugins/sudoers/auth/pam.c
e33993
@@ -202,7 +202,7 @@ sudo_pam_verify(struct passwd *pw, char *prompt, sudo_auth *auth, struct sudo_co
e33993
 }
e33993
 
e33993
 int
e33993
-sudo_pam_approval(struct passwd *pw, sudo_auth *auth)
e33993
+sudo_pam_approval(struct passwd *pw, sudo_auth *auth, bool exempt)
e33993
 {
e33993
     const char *s;
e33993
     int *pam_status = (int *) auth->data;
e33993
@@ -217,6 +217,10 @@ sudo_pam_approval(struct passwd *pw, sudo_auth *auth)
e33993
 		"is your account locked?"));
e33993
 	    debug_return_int(AUTH_FATAL);
e33993
 	case PAM_NEW_AUTHTOK_REQD:
e33993
+	    /* Ignore if user is exempt from password restrictions. */
e33993
+	    if (exempt)
e33993
+		debug_return_int(AUTH_SUCCESS);
e33993
+	    /* New password required, try to change it. */
e33993
 	    log_warningx(0, N_("Account or password is "
e33993
 		"expired, reset your password and try again"));
e33993
 	    *pam_status = pam_chauthtok(pamh,
e33993
@@ -229,6 +233,10 @@ sudo_pam_approval(struct passwd *pw, sudo_auth *auth)
e33993
 		N_("unable to change expired password: %s"), s);
e33993
 	    debug_return_int(AUTH_FAILURE);
e33993
 	case PAM_AUTHTOK_EXPIRED:
e33993
+	    /* Ignore if user is exempt from password restrictions. */
e33993
+	    if (exempt)
e33993
+		debug_return_int(AUTH_SUCCESS);
e33993
+	    /* Password expired, cannot be updated by user. */
e33993
 	    log_warningx(0,
e33993
 		N_("Password expired, contact your system administrator"));
e33993
 	    debug_return_int(AUTH_FATAL);
e33993
diff --git a/plugins/sudoers/auth/sudo_auth.c b/plugins/sudoers/auth/sudo_auth.c
e33993
index 6ef9bd72..5d9382dc 100644
e33993
--- a/plugins/sudoers/auth/sudo_auth.c
e33993
+++ b/plugins/sudoers/auth/sudo_auth.c
e33993
@@ -163,7 +163,7 @@ sudo_auth_init(struct passwd *pw)
e33993
  * Returns true on success, false on failure and -1 on error.
e33993
  */
e33993
 int
e33993
-sudo_auth_approval(struct passwd *pw, int validated)
e33993
+sudo_auth_approval(struct passwd *pw, int validated, bool exempt)
e33993
 {
e33993
     sudo_auth *auth;
e33993
     debug_decl(sudo_auth_approval, SUDOERS_DEBUG_AUTH)
e33993
@@ -171,7 +171,7 @@ sudo_auth_approval(struct passwd *pw, int validated)
e33993
     /* Call approval routines. */
e33993
     for (auth = auth_switch; auth->name; auth++) {
e33993
 	if (auth->approval && !IS_DISABLED(auth)) {
e33993
-	    int status = (auth->approval)(pw, auth);
e33993
+	    int status = (auth->approval)(pw, auth, exempt);
e33993
 	    if (status != AUTH_SUCCESS) {
e33993
 		/* Assume error msg already printed. */
e33993
 		log_auth_failure(validated, 0);
e33993
diff --git a/plugins/sudoers/auth/sudo_auth.h b/plugins/sudoers/auth/sudo_auth.h
e33993
index ea5ed9cd..9ae69cd5 100644
e33993
--- a/plugins/sudoers/auth/sudo_auth.h
e33993
+++ b/plugins/sudoers/auth/sudo_auth.h
e33993
@@ -31,7 +31,7 @@ typedef struct sudo_auth {
e33993
     int (*init)(struct passwd *pw, struct sudo_auth *auth);
e33993
     int (*setup)(struct passwd *pw, char **prompt, struct sudo_auth *auth);
e33993
     int (*verify)(struct passwd *pw, char *p, struct sudo_auth *auth, struct sudo_conv_callback *callback);
e33993
-    int (*approval)(struct passwd *pw, struct sudo_auth *auth);
e33993
+    int (*approval)(struct passwd *pw, struct sudo_auth *auth, bool exempt);
e33993
     int (*cleanup)(struct passwd *pw, struct sudo_auth *auth);
e33993
     int (*begin_session)(struct passwd *pw, char **user_env[], struct sudo_auth *auth);
e33993
     int (*end_session)(struct passwd *pw, struct sudo_auth *auth);
e33993
@@ -56,7 +56,7 @@ extern sudo_conv_t sudo_conv;
e33993
 /* Prototypes for standalone methods */
e33993
 int bsdauth_init(struct passwd *pw, sudo_auth *auth);
e33993
 int bsdauth_verify(struct passwd *pw, char *prompt, sudo_auth *auth, struct sudo_conv_callback *callback);
e33993
-int bsdauth_approval(struct passwd *pw, sudo_auth *auth);
e33993
+int bsdauth_approval(struct passwd *pw, sudo_auth *auth, bool exempt);
e33993
 int bsdauth_cleanup(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_aix_init(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_aix_verify(struct passwd *pw, char *pass, sudo_auth *auth, struct sudo_conv_callback *callback);
e33993
@@ -67,7 +67,7 @@ int sudo_fwtk_cleanup(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_pam_init(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_pam_init_quiet(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_pam_verify(struct passwd *pw, char *prompt, sudo_auth *auth, struct sudo_conv_callback *callback);
e33993
-int sudo_pam_approval(struct passwd *pw, sudo_auth *auth);
e33993
+int sudo_pam_approval(struct passwd *pw, sudo_auth *auth, bool exempt);
e33993
 int sudo_pam_cleanup(struct passwd *pw, sudo_auth *auth);
e33993
 int sudo_pam_begin_session(struct passwd *pw, char **user_env[], sudo_auth *auth);
e33993
 int sudo_pam_end_session(struct passwd *pw, sudo_auth *auth);
e33993
diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c
e33993
index ed49d63a..486a80d8 100644
e33993
--- a/plugins/sudoers/check.c
e33993
+++ b/plugins/sudoers/check.c
e33993
@@ -175,6 +175,7 @@ check_user(int validated, int mode)
e33993
 {
e33993
     struct passwd *auth_pw;
e33993
     int ret = -1;
e33993
+    bool exempt = false;
e33993
     debug_decl(check_user, SUDOERS_DEBUG_AUTH)
e33993
 
e33993
     /*
e33993
@@ -194,6 +195,7 @@ check_user(int validated, int mode)
e33993
 	sudo_debug_printf(SUDO_DEBUG_INFO, "%s: %s", __func__,
e33993
 	    !def_authenticate ? "authentication disabled" :
e33993
 	    "user exempt from authentication");
e33993
+	exempt = true;
e33993
 	ret = true;
e33993
 	goto done;
e33993
     }
e33993
@@ -218,7 +220,7 @@ check_user(int validated, int mode)
e33993
 done:
e33993
     if (ret == true) {
e33993
 	/* The approval function may disallow a user post-authentication. */
e33993
-	ret = sudo_auth_approval(auth_pw, validated);
e33993
+	ret = sudo_auth_approval(auth_pw, validated, exempt);
e33993
     }
e33993
     sudo_auth_cleanup(auth_pw);
e33993
     sudo_pw_delref(auth_pw);
e33993
diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h
e33993
index 57db74c1..956cb084 100644
e33993
--- a/plugins/sudoers/sudoers.h
e33993
+++ b/plugins/sudoers/sudoers.h
e33993
@@ -265,7 +265,7 @@ int verify_user(struct passwd *pw, char *prompt, int validated, struct sudo_conv
e33993
 int sudo_auth_begin_session(struct passwd *pw, char **user_env[]);
e33993
 int sudo_auth_end_session(struct passwd *pw);
e33993
 int sudo_auth_init(struct passwd *pw);
e33993
-int sudo_auth_approval(struct passwd *pw, int validated);
e33993
+int sudo_auth_approval(struct passwd *pw, int validated, bool exempt);
e33993
 int sudo_auth_cleanup(struct passwd *pw);
e33993
 
e33993
 /* set_perms.c */
e33993
-- 
e33993
2.13.6
e33993