From 64aa2622a3baea1f62732f136230543c9d669cd1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Nov 2019 23:28:05 +0100 Subject: [PATCH] libcrypt-util: add superficial validator for UNIX hashed password strings --- src/shared/libcrypt-util.c | 11 +++++++++++ src/shared/libcrypt-util.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index b1a8168030..f41685ae45 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 3da1ab5ad9..93f0e13ffb 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);