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

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