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
@@ -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) {
@@ -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


Reply via email to