diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-08-18 10:37:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-08-19 10:03:56 +0200 |
commit | 7baf10a7be8bd1bad36d333f7013ed5c2b7b7d13 (patch) | |
tree | 9766eea45ee136569f13363fa383e57e0d1a1059 /src/shared/pwquality-util.c | |
parent | home: make libpwquality dep a runtime dlopen() one (diff) | |
download | systemd-7baf10a7be8bd1bad36d333f7013ed5c2b7b7d13.tar.xz systemd-7baf10a7be8bd1bad36d333f7013ed5c2b7b7d13.zip |
firstboot: hook up with libpwquality
Diffstat (limited to 'src/shared/pwquality-util.c')
-rw-r--r-- | src/shared/pwquality-util.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/shared/pwquality-util.c b/src/shared/pwquality-util.c index 799c39f32b..67332833a5 100644 --- a/src/shared/pwquality-util.c +++ b/src/shared/pwquality-util.c @@ -155,4 +155,37 @@ int suggest_passwords(void) { return 1; } +int quality_check_password(const char *password, const char *username, char **ret_error) { + _cleanup_(sym_pwquality_free_settingsp) pwquality_settings_t *pwq = NULL; + char buf[PWQ_MAX_ERROR_MESSAGE_LEN]; + void *auxerror; + int r; + + assert(password); + + r = pwq_allocate_context(&pwq); + if (ERRNO_IS_NOT_SUPPORTED(r)) + return 0; + if (r < 0) + return log_debug_errno(r, "Failed to allocate libpwquality context: %m"); + + r = sym_pwquality_check(pwq, password, NULL, username, &auxerror); + if (r < 0) { + + if (ret_error) { + _cleanup_free_ char *e = NULL; + + e = strdup(sym_pwquality_strerror(buf, sizeof(buf), r, auxerror)); + if (!e) + return -ENOMEM; + + *ret_error = TAKE_PTR(e); + } + + return 0; /* all bad */ + } + + return 1; /* all good */ +} + #endif |