Skip to content

Commit

Permalink
pwquality: fix quality_check_password return value
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 7fc3f9c)
  • Loading branch information
ldv-alt authored and bluca committed Jul 7, 2023
1 parent ac531ec commit 9ebacd3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/cryptenroll/cryptenroll-password.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ask-password-api.h"
#include "cryptenroll-password.h"
#include "env-util.h"
#include "errno-util.h"
#include "escape.h"
#include "memory-util.h"
#include "pwquality-util.h"
Expand Down Expand Up @@ -158,8 +159,12 @@ int enroll_password(
}

r = quality_check_password(new_password, NULL, &error);
if (r < 0)
return log_error_errno(r, "Failed to check password for quality: %m");
if (r < 0) {
if (ERRNO_IS_NOT_SUPPORTED(r))
log_warning("Password quality check is not supported, proceeding anyway.");
else
return log_error_errno(r, "Failed to check password quality: %m");
}
if (r == 0)
log_warning("Specified password does not pass quality checks (%s), proceeding anyway.", error);

Expand Down
9 changes: 7 additions & 2 deletions src/firstboot/firstboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "creds-util.h"
#include "dissect-image.h"
#include "env-file.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
Expand Down Expand Up @@ -657,8 +658,12 @@ static int prompt_root_password(void) {
}

r = quality_check_password(*a, "root", &error);
if (r < 0)
return log_error_errno(r, "Failed to check quality of password: %m");
if (r < 0) {
if (ERRNO_IS_NOT_SUPPORTED(r))
log_warning("Password quality check is not supported, proceeding anyway.");
else
return log_error_errno(r, "Failed to check password quality: %m");
}
if (r == 0)
log_warning("Password is weak, accepting anyway: %s", error);

Expand Down
5 changes: 1 addition & 4 deletions src/shared/pwquality-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,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) {
Expand Down

0 comments on commit 9ebacd3

Please sign in to comment.