1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

shared/libcrypt-util: do not refuse passwords if some other hash is unsupported

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-09-11 08:27:43 +02:00
parent 9de324c3c9
commit 35e22827a9
2 changed files with 14 additions and 2 deletions

View File

@ -182,8 +182,12 @@ int test_password_one(const char *hashed_password, const char *password) {
errno = 0;
k = crypt_ra(password, hashed_password, &cd_data, &cd_size);
if (!k)
return errno_or_else(EINVAL);
if (!k) {
if (errno == ENOMEM)
return -ENOMEM;
/* Unknown or unavailable hashing method or string too short */
return 0;
}
return streq(k, hashed_password);
}

View File

@ -40,10 +40,18 @@ static void test_hash_password_full(void) {
hashed,
"$y$j9T$SAayASazWZIQeJd9AS02m/$"),
i) == true);
assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
hashed,
"$y$j9T$SAayASazWZIQeJd9AS02m/$"),
i) == true);
assert_se(test_password_many(STRV_MAKE("$y$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH",
hashed,
"$y$j9T$SAayASazWZIQeJd9AS02m/$"),
"") == false);
assert_se(test_password_many(STRV_MAKE("$W$j9T$dlCXwkX0GC5L6B8Gf.4PN/$VCyEH", /* no such method exists... */
hashed,
"$y$j9T$SAayASazWZIQeJd9AS02m/$"),
"") == false);
}
}