Skip to content

Commit 9ebacd3

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)
1 parent ac531ec commit 9ebacd3

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"
@@ -158,8 +159,12 @@ int enroll_password(
158159
}
159160

160161
r = quality_check_password(new_password, NULL, &error);
161-
if (r < 0)
162-
return log_error_errno(r, "Failed to check password for quality: %m");
162+
if (r < 0) {
163+
if (ERRNO_IS_NOT_SUPPORTED(r))
164+
log_warning("Password quality check is not supported, proceeding anyway.");
165+
else
166+
return log_error_errno(r, "Failed to check password quality: %m");
167+
}
163168
if (r == 0)
164169
log_warning("Specified password does not pass quality checks (%s), proceeding anyway.", error);
165170

src/firstboot/firstboot.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "creds-util.h"
1616
#include "dissect-image.h"
1717
#include "env-file.h"
18+
#include "errno-util.h"
1819
#include "fd-util.h"
1920
#include "fileio.h"
2021
#include "fs-util.h"
@@ -657,8 +658,12 @@ static int prompt_root_password(void) {
657658
}
658659

659660
r = quality_check_password(*a, "root", &error);
660-
if (r < 0)
661-
return log_error_errno(r, "Failed to check quality of password: %m");
661+
if (r < 0) {
662+
if (ERRNO_IS_NOT_SUPPORTED(r))
663+
log_warning("Password quality check is not supported, proceeding anyway.");
664+
else
665+
return log_error_errno(r, "Failed to check password quality: %m");
666+
}
662667
if (r == 0)
663668
log_warning("Password is weak, accepting anyway: %s", error);
664669

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)