Search users for one with a valid salt.

If the root account is locked (eg password "!!" or "*LK*") keep looking
until we find a user with a valid salt to use for crypting passwords of
invalid users.  ok djm@
This commit is contained in:
Darren Tucker 2016-07-21 14:17:31 +10:00
parent e8b58f48fb
commit dbf788b4d9
1 changed files with 15 additions and 9 deletions

View File

@ -65,7 +65,9 @@
/* /*
* Pick an appropriate password encryption type and salt for the running * Pick an appropriate password encryption type and salt for the running
* system. * system by searching through accounts until we find one that has a valid
* salt. Usually this will be root unless the root account is locked out.
* If we don't find one we return a traditional DES-based salt.
*/ */
static const char * static const char *
pick_salt(void) pick_salt(void)
@ -78,14 +80,18 @@ pick_salt(void)
if (salt[0] != '\0') if (salt[0] != '\0')
return salt; return salt;
strlcpy(salt, "xx", sizeof(salt)); strlcpy(salt, "xx", sizeof(salt));
if ((pw = getpwuid(0)) == NULL) setpwent();
return salt; while ((pw = getpwent()) != NULL) {
passwd = shadow_pw(pw); passwd = shadow_pw(pw);
if (passwd[0] != '$' || (p = strrchr(passwd + 1, '$')) == NULL) if (passwd[0] == '$' && (p = strrchr(passwd+1, '$')) != NULL) {
return salt; /* no $, DES */
typelen = p - passwd + 1; typelen = p - passwd + 1;
strlcpy(salt, passwd, MIN(typelen, sizeof(salt))); strlcpy(salt, passwd, MIN(typelen, sizeof(salt)));
explicit_bzero(passwd, strlen(passwd)); explicit_bzero(passwd, strlen(passwd));
goto out;
}
}
out:
endpwent();
return salt; return salt;
} }