X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=loginutils%2Fpasswd.c;h=aa75dd260fa73cc6db133391592de84051216f7e;hb=d25a2645f5273e70616abe73e6ac1adda5016532;hp=a1ad02bf084bf9e29ecfa1dbf57486e3e193d43c;hpb=791976490b7c8838ccd847e30e9348c2c72b5e88;p=oweals%2Fbusybox.git diff --git a/loginutils/passwd.c b/loginutils/passwd.c index a1ad02bf0..aa75dd260 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -1,18 +1,10 @@ /* vi: set sw=4 ts=4: */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +/* + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. + */ #include "busybox.h" +#include static char crypt_passwd[128]; @@ -146,9 +138,6 @@ int passwd_main(int argc, char **argv) int dflg = 0; /* -d - delete password */ const struct passwd *pw; -#if ENABLE_FEATURE_SHADOWPASSWDS - const struct spwd *sp; -#endif amroot = (getuid() == 0); openlog("passwd", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH); while ((flag = getopt(argc, argv, "a:dlu")) != EOF) { @@ -169,7 +158,7 @@ int passwd_main(int argc, char **argv) bb_show_usage(); } } - myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1)); + myname = (char *) xstrdup(bb_getpwuid(NULL, getuid(), -1)); /* exits on error */ if (optind < argc) { name = argv[optind]; @@ -187,18 +176,13 @@ int passwd_main(int argc, char **argv) syslog(LOG_WARNING, "can't change pwd for `%s'", name); bb_error_msg_and_die("Permission denied.\n"); } -#if ENABLE_FEATURE_SHADOWPASSWDS - sp = getspnam(name); - if (!sp) { - sp = (struct spwd *) pwd_to_spwd(pw); - } - cp = sp->sp_pwdp; - np = sp->sp_namp; -#else - cp = pw->pw_passwd; - np = name; -#endif + if (ENABLE_FEATURE_SHADOWPASSWDS) { + struct spwd *sp = getspnam(name); + if (!sp) bb_error_msg_and_die("Unknown user %s", name); + cp = sp->sp_pwdp; + } else cp = pw->pw_passwd; + np = name; safe_strncpy(crypt_passwd, cp, sizeof(crypt_passwd)); if (!(dflg || lflg || uflg)) { if (!amroot) { @@ -231,10 +215,7 @@ int passwd_main(int argc, char **argv) signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); umask(077); - if (setuid(0)) { - syslog(LOG_ERR, "can't setuid(0)"); - bb_error_msg_and_die( "Cannot change ID to root.\n"); - } + xsetuid(0); if (!update_passwd(pw, crypt_passwd)) { syslog(LOG_INFO, "password for `%s' changed by user `%s'", name, myname); @@ -243,6 +224,7 @@ int passwd_main(int argc, char **argv) syslog(LOG_WARNING, "an error occurred updating the password file"); bb_error_msg_and_die("An error occurred updating the password file.\n"); } + if (ENABLE_FEATURE_CLEAN_UP) free(myname); return (0); }