]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libcrypt-util: add superficial validator for UNIX hashed password strings
authorLennart Poettering <lennart@poettering.net>
Wed, 13 Nov 2019 22:28:05 +0000 (23:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 15 Jan 2020 14:26:51 +0000 (15:26 +0100)
src/shared/libcrypt-util.c
src/shared/libcrypt-util.h

index b1a81680305c33a7bca68f2bda23e12a9dcb146e..f41685ae45010931381e7a53be05c523342c5c6f 100644 (file)
@@ -73,3 +73,14 @@ int make_salt(char **ret) {
         return 0;
 #endif
 }
+
+bool hashed_password_valid(const char *s) {
+
+        /* Returns true if the specified string is a 'valid' hashed UNIX password, i.e. if starts with '$' or
+         * with '!$' (the latter being a valid, yet locked password). */
+
+        if (isempty(s))
+                return false;
+
+        return STARTSWITH_SET(s, "$", "!$");
+}
index 3da1ab5ad9853eebafa3f3084e5791e7c974aab2..93f0e13ffbe7554047601cb40a70c3a339ac7de5 100644 (file)
@@ -18,3 +18,5 @@
 #include <stdlib.h>
 
 int make_salt(char **ret);
+
+bool hashed_password_valid(const char *s);