X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fcorrect_password.c;h=fd7e0b56c8d85e26796dc93635c0d2a7fafadd71;hb=d3d004dd3507f841745956a035fff68936378f9c;hp=1da83c4413b01d21cc6aa1d095854dacfccf2448;hpb=c7bda1ce659294d6e22c06e087f6f265983c7578;p=oweals%2Fbusybox.git diff --git a/libbb/correct_password.c b/libbb/correct_password.c index 1da83c441..fd7e0b56c 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -28,51 +28,38 @@ * SUCH DAMAGE. */ -#include -#include -#include -#include -#include -#include -#include -#include - #include "libbb.h" - - /* Ask the user for a password. Return 1 if the user gives the correct password for entry PW, 0 if not. Return 1 without asking for a password if run by UID 0 or if PW has an empty password. */ -int correct_password ( const struct passwd *pw ) +int correct_password(const struct passwd *pw) { char *unencrypted, *encrypted, *correct; #ifdef CONFIG_FEATURE_SHADOWPASSWDS - if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) { - struct spwd *sp = getspnam ( pw-> pw_name ); + if (!strcmp(pw->pw_passwd, "x") || !strcmp(pw->pw_passwd, "*")) { + struct spwd *sp = getspnam(pw->pw_name); - if ( !sp ) - bb_error_msg_and_die ( "no valid shadow password" ); + if (!sp) + bb_error_msg_and_die("no valid shadow password"); - correct = sp-> sp_pwdp; + correct = sp->sp_pwdp; } else #endif - correct = pw-> pw_passwd; + correct = pw->pw_passwd; - if ( correct == 0 || correct[0] == '\0' ) + if (!correct || correct[0] == '\0') return 1; - unencrypted = getpass ( "Password: " ); - if ( !unencrypted ) - { - fputs ( "getpass: cannot open /dev/tty\n", stderr ); + unencrypted = bb_askpass(0, "Password: "); + if (!unencrypted) { return 0; } - encrypted = crypt ( unencrypted, correct ); - memset ( unencrypted, 0, bb_strlen ( unencrypted )); - return ( strcmp ( encrypted, correct ) == 0 ) ? 1 : 0; + encrypted = crypt(unencrypted, correct); + memset(unencrypted, 0, strlen(unencrypted)); + return (!strcmp(encrypted, correct)) ? 1 : 0; }