shared: add password quality check abstraction layer to support both pwquality and passwdqc

Co-authored-by: Dmitry V. Levin <ldv@altlinux.org>
This commit is contained in:
Egor Ignatov
2023-07-06 10:59:41 +00:00
committed by Dmitry V. Levin
co-authored by Dmitry V. Levin
parent 6377f57fa7
commit d34b1823ca
12 changed files with 54 additions and 47 deletions
+1 -1
View File
@@ -128,11 +128,11 @@ shared_sources = files(
'pager.c',
'parse-argument.c',
'parse-helpers.c',
'password-quality-util-pwquality.c',
'pcre2-util.c',
'pkcs11-util.c',
'pretty-print.c',
'ptyfwd.c',
'pwquality-util.c',
'qrcode-util.c',
'quota-util.c',
'reboot-util.c',
@@ -7,7 +7,7 @@
#include "log.h"
#include "macro.h"
#include "memory-util.h"
#include "pwquality-util.h"
#include "password-quality-util.h"
#include "strv.h"
#if HAVE_PWQUALITY
@@ -36,7 +36,7 @@ int dlopen_pwquality(void) {
DLSYM_ARG(pwquality_strerror));
}
void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
static void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
char buf[PWQ_MAX_ERROR_MESSAGE_LEN];
const char *path;
int r;
@@ -69,7 +69,7 @@ void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq) {
sym_pwquality_strerror(buf, sizeof(buf), r, NULL));
}
int pwq_allocate_context(pwquality_settings_t **ret) {
static int pwq_allocate_context(pwquality_settings_t **ret) {
_cleanup_(sym_pwquality_free_settingsp) pwquality_settings_t *pwq = NULL;
char buf[PWQ_MAX_ERROR_MESSAGE_LEN];
void *auxerror;
@@ -96,8 +96,6 @@ int pwq_allocate_context(pwquality_settings_t **ret) {
return 0;
}
#define N_SUGGESTIONS 6
int suggest_passwords(void) {
_cleanup_(sym_pwquality_free_settingsp) pwquality_settings_t *pwq = NULL;
_cleanup_strv_free_erase_ char **suggestions = NULL;
@@ -132,7 +130,7 @@ int suggest_passwords(void) {
return 1;
}
int quality_check_password(const char *password, const char *old, const char *username, char **ret_error) {
int check_password_quality(const char *password, const char *old, 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;
@@ -146,7 +144,6 @@ int quality_check_password(const char *password, const char *old, const char *us
r = sym_pwquality_check(pwq, password, old, username, &auxerror);
if (r < 0) {
if (ret_error) {
_cleanup_free_ char *e = NULL;
@@ -21,21 +21,7 @@ int dlopen_pwquality(void);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pwquality_settings_t*, sym_pwquality_free_settings, NULL);
void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq);
int pwq_allocate_context(pwquality_settings_t **ret);
int suggest_passwords(void);
int quality_check_password(const char *password, const char *old, const char *username, char **ret_error);
#else
static inline int suggest_passwords(void) {
return 0;
}
static inline int quality_check_password(const char *password, const char *old, const char *username, char **ret_error) {
if (ret_error)
*ret_error = NULL;
return 1; /* all good */
}
int check_password_quality(const char *password, const char *old, const char *username, char **ret_error);
#endif
+26
View File
@@ -0,0 +1,26 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#define N_SUGGESTIONS 6
#if HAVE_PWQUALITY
#include "password-quality-util-pwquality.h"
#else
static inline int suggest_passwords(void) {
return 0;
}
static inline int check_password_quality(
const char *password,
const char *old,
const char *username,
char **ret_error) {
if (ret_error)
*ret_error = NULL;
return 1; /* all good */
}
#endif