Skip to content

Commit 30fdfb9

Browse files
committed
Second blank check with root for non-existent users must never return 1
The commit af0faf6 ("pam_unix: avoid determining if user exists") introduced a regression where the blank check could return 1 if root had an empty password hash because in the second case the password hash of root was used. We now always return 0 in this case. The issue was found by Johannes Löthberg. Fixes #284 * modules/pam_unix/support.c (_unix_blankpasswd): Make the loop to cover the complete blank check so both existing and non existing cases are identical except for the possible return value.
1 parent e50eb50 commit 30fdfb9

1 file changed

Lines changed: 13 additions & 26 deletions

File tree

modules/pam_unix/support.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,9 @@ _unix_blankpasswd (pam_handle_t *pamh, unsigned long long ctrl, const char *name
601601
char *salt = NULL;
602602
int daysleft;
603603
int retval;
604-
int execloop = 1;
605-
int nonexistent = 1;
604+
int blank = 0;
605+
int execloop;
606+
int nonexistent_check = 1;
606607

607608
D(("called"));
608609

@@ -632,43 +633,29 @@ _unix_blankpasswd (pam_handle_t *pamh, unsigned long long ctrl, const char *name
632633
* are equal, making it more difficult to differentiate existing from
633634
* non-existing users.
634635
*/
635-
while (execloop) {
636+
for (execloop = 0; execloop < 2; ++execloop) {
636637
retval = get_pwd_hash(pamh, name, &pwd, &salt);
637638

638639
if (retval == PAM_UNIX_RUN_HELPER) {
639-
execloop = 0;
640-
if(nonexistent) {
641-
get_pwd_hash(pamh, "pam_unix_non_existent:", &pwd, &salt);
642-
}
643-
/* salt will not be set here so we can return immediately */
644640
if (_unix_run_helper_binary(pamh, NULL, ctrl, name) == PAM_SUCCESS)
645-
return 1;
646-
else
647-
return 0;
641+
blank = nonexistent_check;
648642
} else if (retval == PAM_USER_UNKNOWN) {
649643
name = "root";
650-
nonexistent = 0;
651-
} else {
652-
execloop = 0;
644+
nonexistent_check = 0;
645+
continue;
646+
} else if (salt != NULL) {
647+
if (strlen(salt) == 0)
648+
blank = nonexistent_check;
653649
}
654-
}
655-
656-
/* Does this user have a password? */
657-
if (salt == NULL) {
658-
retval = 0;
659-
} else {
660-
if (strlen(salt) == 0)
661-
retval = 1;
662-
else
663-
retval = 0;
650+
name = "pam_unix_non_existent:";
651+
/* non-existent user check will not affect the blank value */
664652
}
665653

666654
/* tidy up */
667-
668655
if (salt)
669656
_pam_delete(salt);
670657

671-
return retval;
658+
return blank;
672659
}
673660

674661
int _unix_verify_password(pam_handle_t * pamh, const char *name

0 commit comments

Comments
 (0)