44#include "errno-util.h"
55#include "home-util.h"
66#include "libcrypt-util.h"
7- #include "pwquality -util.h"
7+ #include "password-quality -util.h"
88#include "strv.h"
9- #include "user-record-pwquality .h"
9+ #include "user-record-password-quality .h"
1010#include "user-record-util.h"
1111
12- #if HAVE_PWQUALITY
12+ #if HAVE_PASSWDQC || HAVE_PWQUALITY
1313
14- int user_record_quality_check_password (
14+ int user_record_check_password_quality (
1515 UserRecord * hr ,
1616 UserRecord * secret ,
1717 sd_bus_error * error ) {
1818
19- _cleanup_ (sym_pwquality_free_settingsp ) pwquality_settings_t * pwq = NULL ;
20- char buf [PWQ_MAX_ERROR_MESSAGE_LEN ];
21- void * auxerror ;
19+ _cleanup_free_ char * auxerror = NULL ;
2220 int r ;
2321
2422 assert (hr );
2523 assert (secret );
2624
27- r = pwq_allocate_context (& pwq );
28- if (ERRNO_IS_NOT_SUPPORTED (r ))
29- return 0 ;
30- if (r < 0 )
31- return log_debug_errno (r , "Failed to allocate libpwquality context: %m" );
32-
33- /* This is a bit more complex than one might think at first. pwquality_check() would like to know the
25+ /* This is a bit more complex than one might think at first. check_password_quality() would like to know the
3426 * old password to make security checks. We support arbitrary numbers of passwords however, hence we
3527 * call the function once for each combination of old and new password. */
3628
@@ -56,30 +48,35 @@ int user_record_quality_check_password(
5648 if (r > 0 ) /* This is a new password, not suitable as old password */
5749 continue ;
5850
59- r = sym_pwquality_check (pwq , * pp , * old , hr -> user_name , & auxerror );
60- if (r < 0 )
61- return sd_bus_error_setf (error , BUS_ERROR_LOW_PASSWORD_QUALITY , "Password too weak: %s" ,
62- sym_pwquality_strerror (buf , sizeof (buf ), r , auxerror ));
51+ r = check_password_quality (* pp , * old , hr -> user_name , & auxerror );
52+ if (r <= 0 )
53+ goto error ;
6354
6455 called = true;
6556 }
6657
6758 if (called )
6859 continue ;
6960
70- /* If there are no old passwords, let's call pwquality_check() without any. */
71- r = sym_pwquality_check (pwq , * pp , NULL , hr -> user_name , & auxerror );
72- if (r < 0 )
73- return sd_bus_error_setf (error , BUS_ERROR_LOW_PASSWORD_QUALITY , "Password too weak: %s" ,
74- sym_pwquality_strerror (buf , sizeof (buf ), r , auxerror ));
61+ /* If there are no old passwords, let's call check_password_quality() without any. */
62+ r = check_password_quality (* pp , /* old */ NULL , hr -> user_name , & auxerror );
63+ if (r <= 0 )
64+ goto error ;
7565 }
76-
7766 return 1 ;
67+
68+ error :
69+ if (r == 0 )
70+ return sd_bus_error_setf (error , BUS_ERROR_LOW_PASSWORD_QUALITY ,
71+ "Password too weak: %s" , auxerror );
72+ if (ERRNO_IS_NOT_SUPPORTED (r ))
73+ return 0 ;
74+ return log_debug_errno (r , "Failed to check password quality: %m" );
7875}
7976
8077#else
8178
82- int user_record_quality_check_password (
79+ int user_record_check_password_quality (
8380 UserRecord * hr ,
8481 UserRecord * secret ,
8582 sd_bus_error * error ) {
0 commit comments