@@ -16,21 +16,13 @@ int user_record_quality_check_password(
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. quality_check_password() 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,25 +48,31 @@ 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 = quality_check_password (* 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 quality_check_password() without any. */
62+ r = quality_check_password (* pp , /* old */ NULL , hr -> user_name , & auxerror );
63+ if (r <= 0 )
64+ goto error ;
7565 }
7666
7767 return 1 ;
68+
69+ error :
70+ if (r == 0 )
71+ return sd_bus_error_setf (error , BUS_ERROR_LOW_PASSWORD_QUALITY ,
72+ "Password too weak: %s" , auxerror );
73+ if (ERRNO_IS_NOT_SUPPORTED (r ))
74+ return 0 ;
75+ return log_debug_errno (r , "Failed to check password quality: %m" );
7876}
7977
8078#else
0 commit comments