pwquality: fix quality_check_password return value

quality_check_password() used to return the same value 0 in two
different cases: when pwq_allocate_context() failed with a
ERRNO_IS_NOT_SUPPORTED() code, and when pwquality_check() rejected the
password.  As result, users of quality_check_password() used to report
password weakness also in case when the underlying library was not
available.

Fix this by changing quality_check_password() to forward the
ERRNO_IS_NOT_SUPPORTED() code to its callers, and change the callers
to handle this case gracefully.
This commit is contained in:
Dmitry V. Levin
2023-07-06 10:59:41 +00:00
parent 29dd2e253c
commit 7fc3f9c032
3 changed files with 15 additions and 8 deletions
+1 -4
View File
@@ -141,11 +141,8 @@ int quality_check_password(const char *password, const char *username, char **re
assert(password);
r = pwq_allocate_context(&pwq);
if (r < 0) {
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) {