]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libcrypt-util: move looks_like_hashed_password()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Nov 2025 00:27:14 +0000 (09:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 2 Jan 2026 03:54:00 +0000 (12:54 +0900)
No functional change, just preparation for later change.

src/shared/libcrypt-util.c
src/shared/libcrypt-util.h

index 594963ac6b05f17cae9e10c96447d23aab91fcf1..f981c1b9973fc1bc862f56a6d8d9e29a6065eed1 100644 (file)
@@ -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", "*");
+}
index 27c5f055a389fd8300c872eec19d8c639b1a3c0b..ed2993f82ceadd83666ca8489822d3dc98f9a49e 100644 (file)
@@ -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);