[hackers] [ubase] [PATCH 1/2] pw_check: Simplify slightly

From: Michael Forney <mforney_AT_mforney.org>
Date: Tue, 25 Jun 2019 19:20:23 -0700

Use common check for password field starting with '*' or '!'.
---
 libutil/passwd.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/libutil/passwd.c b/libutil/passwd.c
index 0798225..c1233a1 100644
--- a/libutil/passwd.c
+++ b/libutil/passwd.c
_AT_@ -23,19 +23,13 @@ pw_check(const struct passwd *pw, const char *pass)
 	struct spwd *spw;
 
 	p = pw->pw_passwd;
-	if (p[0] == '!' || p[0] == '*') {
-		weprintf("denied\n");
-		return -1;
-	}
-
-	if (pw->pw_passwd[0] == '\0') {
+	if (p[0] == '\0') {
 		if (pass[0] == '\0')
 			return 1;
 		weprintf("incorrect password\n");
 		return 0;
 	}
-
-	if (pw->pw_passwd[0] == 'x' && pw->pw_passwd[1] == '\0') {
+	if (p[0] == 'x' && p[1] == '\0') {
 		errno = 0;
 		spw = getspnam(pw->pw_name);
 		if (!spw) {
_AT_@ -46,10 +40,10 @@ pw_check(const struct passwd *pw, const char *pass)
 			return -1;
 		}
 		p = spw->sp_pwdp;
-		if (p[0] == '!' || p[0] == '*') {
-			weprintf("denied\n");
-			return -1;
-		}
+	}
+	if (p[0] == '!' || p[0] == '*') {
+		weprintf("denied\n");
+		return -1;
 	}
 
 	cryptpass = crypt(pass, p);
-- 
2.20.1
Received on Wed Jun 26 2019 - 04:20:23 CEST

This archive was generated by hypermail 2.3.0 : Wed Jun 26 2019 - 04:24:23 CEST