From: Yu Watanabe Date: Tue, 18 Nov 2025 00:27:14 +0000 (+0900) Subject: libcrypt-util: move looks_like_hashed_password() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2747481603a43b8f37470763fdd0944902f82da;p=thirdparty%2Fsystemd.git libcrypt-util: move looks_like_hashed_password() No functional change, just preparation for later change. --- diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index 594963ac6b0..f981c1b9973 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -140,22 +140,6 @@ int hash_password_full(const char *password, void **cd_data, int *cd_size, char return strdup_to(ret, p); } -bool looks_like_hashed_password(const char *s) { - /* Returns false if the specified string is certainly not a hashed UNIX password. crypt(5) lists - * various hashing methods. We only reject (return false) strings which are documented to have - * different meanings. - * - * In particular, we allow locked passwords, i.e. strings starting with "!", including just "!", - * i.e. the locked empty password. See also fc58c0c7bf7e4f525b916e3e5be0de2307fef04e. - */ - if (!s) - return false; - - s += strspn(s, "!"); /* Skip (possibly duplicated) locking prefix */ - - return !STR_IN_SET(s, "x", "*"); -} - int test_password_one(const char *hashed_password, const char *password) { _cleanup_(erase_and_freep) void *cd_data = NULL; int cd_size = 0; @@ -186,3 +170,19 @@ int test_password_many(char **hashed_password, const char *password) { return false; } + +bool looks_like_hashed_password(const char *s) { + /* Returns false if the specified string is certainly not a hashed UNIX password. crypt(5) lists + * various hashing methods. We only reject (return false) strings which are documented to have + * different meanings. + * + * In particular, we allow locked passwords, i.e. strings starting with "!", including just "!", + * i.e. the locked empty password. See also fc58c0c7bf7e4f525b916e3e5be0de2307fef04e. + */ + if (!s) + return false; + + s += strspn(s, "!"); /* Skip (possibly duplicated) locking prefix */ + + return !STR_IN_SET(s, "x", "*"); +} diff --git a/src/shared/libcrypt-util.h b/src/shared/libcrypt-util.h index 27c5f055a38..ed2993f82ce 100644 --- a/src/shared/libcrypt-util.h +++ b/src/shared/libcrypt-util.h @@ -8,6 +8,6 @@ int hash_password_full(const char *password, void **cd_data, int *cd_size, char static inline int hash_password(const char *password, char **ret) { return hash_password_full(password, NULL, NULL, ret); } -bool looks_like_hashed_password(const char *s); int test_password_one(const char *hashed_password, const char *password); int test_password_many(char **hashed_password, const char *password); +bool looks_like_hashed_password(const char *s);