vishalmishra434 / rpms / openssh

Forked from rpms/openssh a month ago
Clone
Dmitry Belyavskiy df2698
diff -up openssh-8.0p1/auth-pam.c.preserve-pam-errors openssh-8.0p1/auth-pam.c
Dmitry Belyavskiy df2698
--- openssh-8.0p1/auth-pam.c.preserve-pam-errors	2021-03-31 17:03:15.618592347 +0200
Dmitry Belyavskiy df2698
+++ openssh-8.0p1/auth-pam.c	2021-03-31 17:06:58.115220014 +0200
Dmitry Belyavskiy df2698
@@ -511,7 +511,11 @@ sshpam_thread(void *ctxtp)
Dmitry Belyavskiy df2698
 		goto auth_fail;
Dmitry Belyavskiy df2698
 
Dmitry Belyavskiy df2698
 	if (!do_pam_account()) {
Dmitry Belyavskiy df2698
-		sshpam_err = PAM_ACCT_EXPIRED;
Dmitry Belyavskiy df2698
+		/* Preserve PAM_PERM_DENIED and PAM_USER_UNKNOWN.
Dmitry Belyavskiy df2698
+		 * Backward compatibility for other errors. */
Dmitry Belyavskiy df2698
+		if (sshpam_err != PAM_PERM_DENIED
Dmitry Belyavskiy df2698
+			&& sshpam_err != PAM_USER_UNKNOWN)
Dmitry Belyavskiy df2698
+			sshpam_err = PAM_ACCT_EXPIRED;
Dmitry Belyavskiy df2698
 		goto auth_fail;
Dmitry Belyavskiy df2698
 	}
Dmitry Belyavskiy df2698
 	if (sshpam_authctxt->force_pwchange) {
Dmitry Belyavskiy df2698
@@ -568,8 +572,10 @@ sshpam_thread(void *ctxtp)
Dmitry Belyavskiy df2698
 	    pam_strerror(sshpam_handle, sshpam_err))) != 0)
Dmitry Belyavskiy df2698
 		fatal("%s: buffer error: %s", __func__, ssh_err(r));
Dmitry Belyavskiy df2698
 	/* XXX - can't do much about an error here */
Dmitry Belyavskiy df2698
-	if (sshpam_err == PAM_ACCT_EXPIRED)
Dmitry Belyavskiy df2698
-		ssh_msg_send(ctxt->pam_csock, PAM_ACCT_EXPIRED, buffer);
Dmitry Belyavskiy df2698
+	if (sshpam_err == PAM_PERM_DENIED
Dmitry Belyavskiy df2698
+		|| sshpam_err == PAM_USER_UNKNOWN
Dmitry Belyavskiy df2698
+		|| sshpam_err == PAM_ACCT_EXPIRED)
Dmitry Belyavskiy df2698
+		ssh_msg_send(ctxt->pam_csock, sshpam_err, buffer);
Dmitry Belyavskiy df2698
 	else if (sshpam_maxtries_reached)
Dmitry Belyavskiy df2698
 		ssh_msg_send(ctxt->pam_csock, PAM_MAXTRIES, buffer);
Dmitry Belyavskiy df2698
 	else
Dmitry Belyavskiy ce2e80
@@ -856,9 +862,11 @@ sshpam_query(void *ctx, char **name, cha
Dmitry Belyavskiy df2698
 			free(msg);
Dmitry Belyavskiy df2698
 			break;
Dmitry Belyavskiy df2698
 		case PAM_ACCT_EXPIRED:
Dmitry Belyavskiy df2698
+			sshpam_account_status = 0;
Dmitry Belyavskiy df2698
+			/* FALLTHROUGH */
Dmitry Belyavskiy df2698
 		case PAM_MAXTRIES:
Dmitry Belyavskiy ce2e80
+		case PAM_USER_UNKNOWN:
Dmitry Belyavskiy ce2e80
+		case PAM_PERM_DENIED:
Dmitry Belyavskiy df2698
-			if (type == PAM_ACCT_EXPIRED)
Dmitry Belyavskiy df2698
-				sshpam_account_status = 0;
Dmitry Belyavskiy df2698
 			if (type == PAM_MAXTRIES)
Dmitry Belyavskiy df2698
 				sshpam_set_maxtries_reached(1);
Dmitry Belyavskiy df2698
 			/* FALLTHROUGH */