Skip to content

Commit 5b9df25

Browse files
ldv-altbluca
authored andcommitted
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. (cherry picked from commit 7fc3f9c) (cherry picked from commit 9ebacd3) (cherry picked from commit 74b60f1)
1 parent bc20a13 commit 5b9df25

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/cryptenroll/cryptenroll-password.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "ask-password-api.h"
44
#include "cryptenroll-password.h"
55
#include "env-util.h"
6+
#include "errno-util.h"
67
#include "escape.h"
78
#include "memory-util.h"
89
#include "pwquality-util.h"
@@ -78,8 +79,12 @@ int enroll_password(
7879
}
7980

8081
r = quality_check_password(new_password, NULL, &error);
81-
if (r < 0)
82-
return log_error_errno(r, "Failed to check password for quality: %m");
82+
if (r < 0) {
83+
if (ERRNO_IS_NOT_SUPPORTED(r))
84+
log_warning("Password quality check is not supported, proceeding anyway.");
85+
else
86+
return log_error_errno(r, "Failed to check password quality: %m");
87+
}
8388
if (r == 0)
8489
log_warning("Specified password does not pass quality checks (%s), proceeding anyway.", error);
8590

src/firstboot/firstboot.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "creds-util.h"
1515
#include "dissect-image.h"
1616
#include "env-file.h"
17+
#include "errno-util.h"
1718
#include "fd-util.h"
1819
#include "fileio.h"
1920
#include "fs-util.h"
@@ -641,8 +642,12 @@ static int prompt_root_password(void) {
641642
}
642643

643644
r = quality_check_password(*a, "root", &error);
644-
if (r < 0)
645-
return log_error_errno(r, "Failed to check quality of password: %m");
645+
if (r < 0) {
646+
if (ERRNO_IS_NOT_SUPPORTED(r))
647+
log_warning("Password quality check is not supported, proceeding anyway.");
648+
else
649+
return log_error_errno(r, "Failed to check password quality: %m");
650+
}
646651
if (r == 0)
647652
log_warning("Password is weak, accepting anyway: %s", error);
648653

src/shared/pwquality-util.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,8 @@ int quality_check_password(const char *password, const char *username, char **re
145145
assert(password);
146146

147147
r = pwq_allocate_context(&pwq);
148-
if (r < 0) {
149-
if (ERRNO_IS_NOT_SUPPORTED(r))
150-
return 0;
148+
if (r < 0)
151149
return log_debug_errno(r, "Failed to allocate libpwquality context: %m");
152-
}
153150

154151
r = sym_pwquality_check(pwq, password, NULL, username, &auxerror);
155152
if (r < 0) {

0 commit comments

Comments
 (0)