From: Lennart Poettering Date: Wed, 13 Nov 2019 22:28:05 +0000 (+0100) Subject: libcrypt-util: add superficial validator for UNIX hashed password strings X-Git-Tag: v245-rc1~116^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=64aa2622a3baea1f62732f136230543c9d669cd1;p=thirdparty%2Fsystemd.git libcrypt-util: add superficial validator for UNIX hashed password strings --- diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index b1a81680305..f41685ae450 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -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, "$", "!$"); +} diff --git a/src/shared/libcrypt-util.h b/src/shared/libcrypt-util.h index 3da1ab5ad98..93f0e13ffbe 100644 --- a/src/shared/libcrypt-util.h +++ b/src/shared/libcrypt-util.h @@ -18,3 +18,5 @@ #include int make_salt(char **ret); + +bool hashed_password_valid(const char *s);