Blame SOURCES/sudo-1.8.29-expired-password-part1.patch

c86b7a
From 4b6de608c25a6ffbdb507be958e12f814b43077c Mon Sep 17 00:00:00 2001
c86b7a
From: "Todd C. Miller" <Todd.Miller@sudo.ws>
c86b7a
Date: Wed, 4 Dec 2019 12:38:22 -0700
c86b7a
Subject: [PATCH] Only update the time stamp entry after the approval function
c86b7a
 has succeeded. Bug #910
c86b7a
c86b7a
---
c86b7a
 plugins/sudoers/check.c | 59 +++++++++++++++++++----------------------
c86b7a
 1 file changed, 27 insertions(+), 32 deletions(-)
c86b7a
c86b7a
diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c
c86b7a
index db8e05161..ea1d89085 100644
c86b7a
--- a/plugins/sudoers/check.c
c86b7a
+++ b/plugins/sudoers/check.c
c86b7a
@@ -51,6 +51,7 @@ static bool display_lecture(int);
c86b7a
 static struct passwd *get_authpw(int);
c86b7a
 
c86b7a
 struct getpass_closure {
c86b7a
+    int tstat;
c86b7a
     void *cookie;
c86b7a
     struct passwd *auth_pw;
c86b7a
 };
c86b7a
@@ -89,27 +90,20 @@ getpass_resume(int signo, void *vclosure)
c86b7a
  * or -1 on fatal error.
c86b7a
  */
c86b7a
 static int
c86b7a
-check_user_interactive(int validated, int mode, struct passwd *auth_pw)
c86b7a
+check_user_interactive(int validated, int mode, struct getpass_closure *closure)
c86b7a
 {
c86b7a
     struct sudo_conv_callback cb, *callback = NULL;
c86b7a
-    struct getpass_closure closure;
c86b7a
-    int status = TS_ERROR;
c86b7a
     int ret = -1;
c86b7a
     char *prompt;
c86b7a
     bool lectured;
c86b7a
     debug_decl(check_user_interactive, SUDOERS_DEBUG_AUTH)
c86b7a
 
c86b7a
-    /* Setup closure for getpass_{suspend,resume} */
c86b7a
-    closure.auth_pw = auth_pw;
c86b7a
-    closure.cookie = NULL;
c86b7a
-    sudo_pw_addref(closure.auth_pw);
c86b7a
-
c86b7a
     /* Open, lock and read time stamp file if we are using it. */
c86b7a
     if (!ISSET(mode, MODE_IGNORE_TICKET)) {
c86b7a
 	/* Open time stamp file and check its status. */
c86b7a
-	closure.cookie = timestamp_open(user_name, user_sid);
c86b7a
-	if (timestamp_lock(closure.cookie, closure.auth_pw))
c86b7a
-	    status = timestamp_status(closure.cookie, closure.auth_pw);
c86b7a
+	closure->cookie = timestamp_open(user_name, user_sid);
c86b7a
+	if (timestamp_lock(closure->cookie, closure->auth_pw))
c86b7a
+	    closure->tstat = timestamp_status(closure->cookie, closure->auth_pw);
c86b7a
 
c86b7a
 	/* Construct callback for getpass function. */
c86b7a
 	memset(&cb, 0, sizeof(cb));
c86b7a
@@ -120,7 +114,7 @@ check_user_interactive(int validated, int mode, struct passwd *auth_pw)
c86b7a
 	callback = &cb;
c86b7a
     }
c86b7a
 
c86b7a
-    switch (status) {
c86b7a
+    switch (closure->tstat) {
c86b7a
     case TS_FATAL:
c86b7a
 	/* Fatal error (usually setuid failure), unsafe to proceed. */
c86b7a
 	goto done;
c86b7a
@@ -144,32 +138,22 @@ check_user_interactive(int validated, int mode, struct passwd *auth_pw)
c86b7a
 	}
c86b7a
 
c86b7a
 	/* XXX - should not lecture if askpass helper is being used. */
c86b7a
-	lectured = display_lecture(status);
c86b7a
+	lectured = display_lecture(closure->tstat);
c86b7a
 
c86b7a
 	/* Expand any escapes in the prompt. */
c86b7a
 	prompt = expand_prompt(user_prompt ? user_prompt : def_passprompt,
c86b7a
-	    closure.auth_pw->pw_name);
c86b7a
+	    closure->auth_pw->pw_name);
c86b7a
 	if (prompt == NULL)
c86b7a
 	    goto done;
c86b7a
 
c86b7a
-	ret = verify_user(closure.auth_pw, prompt, validated, callback);
c86b7a
+	ret = verify_user(closure->auth_pw, prompt, validated, callback);
c86b7a
 	if (ret == true && lectured)
c86b7a
 	    (void)set_lectured();	/* lecture error not fatal */
c86b7a
 	free(prompt);
c86b7a
 	break;
c86b7a
     }
c86b7a
 
c86b7a
-    /*
c86b7a
-     * Only update time stamp if user was validated.
c86b7a
-     * Failure to update the time stamp is not a fatal error.
c86b7a
-     */
c86b7a
-    if (ret == true && ISSET(validated, VALIDATE_SUCCESS) && status != TS_ERROR)
c86b7a
-	(void)timestamp_update(closure.cookie, closure.auth_pw);
c86b7a
 done:
c86b7a
-    if (closure.cookie != NULL)
c86b7a
-	timestamp_close(closure.cookie);
c86b7a
-    sudo_pw_delref(closure.auth_pw);
c86b7a
-
c86b7a
     debug_return_int(ret);
c86b7a
 }
c86b7a
 
c86b7a
@@ -180,7 +164,7 @@ done:
c86b7a
 int
c86b7a
 check_user(int validated, int mode)
c86b7a
 {
c86b7a
-    struct passwd *auth_pw;
c86b7a
+    struct getpass_closure closure = { TS_ERROR };
c86b7a
     int ret = -1;
c86b7a
     bool exempt = false;
c86b7a
     debug_decl(check_user, SUDOERS_DEBUG_AUTH)
c86b7a
@@ -189,9 +173,9 @@ check_user(int validated, int mode)
c86b7a
      * Init authentication system regardless of whether we need a password.
c86b7a
      * Required for proper PAM session support.
c86b7a
      */
c86b7a
-    if ((auth_pw = get_authpw(mode)) == NULL)
c86b7a
+    if ((closure.auth_pw = get_authpw(mode)) == NULL)
c86b7a
 	goto done;
c86b7a
-    if (sudo_auth_init(auth_pw) == -1)
c86b7a
+    if (sudo_auth_init(closure.auth_pw) == -1)
c86b7a
 	goto done;
c86b7a
 
c86b7a
     /*
c86b7a
@@ -222,15 +206,26 @@ check_user(int validated, int mode)
c86b7a
 	}
c86b7a
     }
c86b7a
 
c86b7a
-    ret = check_user_interactive(validated, mode, auth_pw);
c86b7a
+    ret = check_user_interactive(validated, mode, &closure);
c86b7a
 
c86b7a
 done:
c86b7a
     if (ret == true) {
c86b7a
 	/* The approval function may disallow a user post-authentication. */
c86b7a
-	ret = sudo_auth_approval(auth_pw, validated, exempt);
c86b7a
+	ret = sudo_auth_approval(closure.auth_pw, validated, exempt);
c86b7a
+
c86b7a
+	/*
c86b7a
+	 * Only update time stamp if user validated and was approved.
c86b7a
+	 * Failure to update the time stamp is not a fatal error.
c86b7a
+	 */
c86b7a
+	if (ret == true && closure.tstat != TS_ERROR) {
c86b7a
+	    if (ISSET(validated, VALIDATE_SUCCESS))
c86b7a
+		(void)timestamp_update(closure.cookie, closure.auth_pw);
c86b7a
+	}
c86b7a
     }
c86b7a
-    sudo_auth_cleanup(auth_pw);
c86b7a
-    sudo_pw_delref(auth_pw);
c86b7a
+    timestamp_close(closure.cookie);
c86b7a
+    sudo_auth_cleanup(closure.auth_pw);
c86b7a
+    if (closure.auth_pw != NULL)
c86b7a
+	sudo_pw_delref(closure.auth_pw);
c86b7a
 
c86b7a
     debug_return_int(ret);
c86b7a
 }
c86b7a
-- 
c86b7a
2.25.1
c86b7a