1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "macro.h"
5
6 #if HAVE_PWQUALITY
7 /* pwquality.h uses size_t but doesn't include sys/types.h on its own */
8 #include <sys/types.h>
9 #include <pwquality.h>
10
11 extern int (*sym_pwquality_check)(pwquality_settings_t *pwq, const char *password, const char *oldpassword, const char *user, void **auxerror);
12 extern pwquality_settings_t *(*sym_pwquality_default_settings)(void);
13 extern void (*sym_pwquality_free_settings)(pwquality_settings_t *pwq);
14 extern int (*sym_pwquality_generate)(pwquality_settings_t *pwq, int entropy_bits, char **password);
15 extern int (*sym_pwquality_get_str_value)(pwquality_settings_t *pwq, int setting, const char **value);
16 extern int (*sym_pwquality_read_config)(pwquality_settings_t *pwq, const char *cfgfile, void **auxerror);
17 extern int (*sym_pwquality_set_int_value)(pwquality_settings_t *pwq, int setting, int value);
18 extern const char* (*sym_pwquality_strerror)(char *buf, size_t len, int errcode, void *auxerror);
19
20 int dlopen_pwquality(void);
21
22 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(pwquality_settings_t*, sym_pwquality_free_settings, NULL);
23
24 void pwq_maybe_disable_dictionary(pwquality_settings_t *pwq);
25 int pwq_allocate_context(pwquality_settings_t **ret);
26 int suggest_passwords(void);
27 int quality_check_password(const char *password, const char *username, char **ret_error);
28
29 #else
30
suggest_passwords(void)31 static inline int suggest_passwords(void) {
32 return 0;
33 }
34
quality_check_password(const char * password,const char * username,char ** ret_error)35 static inline int quality_check_password(const char *password, const char *username, char **ret_error) {
36 if (ret_error)
37 *ret_error = NULL;
38 return 1; /* all good */
39 }
40
41 #endif
42