randomconfig fixes
[oweals/busybox.git] / loginutils / passwd.c
index 03f8ad0a4f4abbb19d70ad24942196b4396a16c6..6c643d3d0c6e40156422bbb5d4fc8f57c9c0e46f 100644 (file)
@@ -12,7 +12,7 @@
 //config:      may change the password for any account. The administrator of a group
 //config:      may change the password for the group.
 //config:
-//config:      Note that Busybox binary must be setuid root for this applet to
+//config:      Note that busybox binary must be setuid root for this applet to
 //config:      work properly.
 //config:
 //config:config FEATURE_PASSWD_WEAK_CHECK
 
 #include "libbb.h"
 #include <syslog.h>
-#include <sys/resource.h> /* setrlimit */
 
 static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo)
 {
        char salt[MAX_PW_SALT_LEN];
-       char *orig = (char*)"";
+       char *orig = NULL;
        char *newp = NULL;
        char *cp = NULL;
        char *ret = NULL; /* failure so far */
@@ -52,7 +51,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
        if (myuid != 0 && pw->pw_passwd[0]) {
                char *encrypted;
 
-               orig = bb_ask_stdin("Old password: "); /* returns ptr to static */
+               orig = bb_ask_noecho_stdin("Old password: "); /* returns malloced str */
                if (!orig)
                        goto err_ret;
                encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
@@ -65,19 +64,17 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
                if (ENABLE_FEATURE_CLEAN_UP)
                        free(encrypted);
        }
-       orig = xstrdup(orig); /* or else bb_ask_stdin() will destroy it */
-       newp = bb_ask_stdin("New password: "); /* returns ptr to static */
+       newp = bb_ask_noecho_stdin("New password: "); /* returns malloced str */
        if (!newp)
                goto err_ret;
-       newp = xstrdup(newp); /* we are going to bb_ask_stdin() again, so save it */
        if (ENABLE_FEATURE_PASSWD_WEAK_CHECK
-        && obscure(orig, newp, pw)
+        && obscure(orig, newp, pw) /* NB: passing NULL orig is ok */
         && myuid != 0
        ) {
                goto err_ret; /* non-root is not allowed to have weak passwd */
        }
 
-       cp = bb_ask_stdin("Retype password: ");
+       cp = bb_ask_noecho_stdin("Retype password: ");
        if (!cp)
                goto err_ret;
        if (strcmp(cp, newp) != 0) {
@@ -99,6 +96,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
        if (ENABLE_FEATURE_CLEAN_UP) free(newp);
 
        nuke_str(cp);
+       if (ENABLE_FEATURE_CLEAN_UP) free(cp);
        return ret;
 }
 
@@ -230,7 +228,7 @@ int passwd_main(int argc UNUSED_PARAM, char **argv)
        /* LOGMODE_BOTH */
        if (rc < 0)
                bb_error_msg_and_die("can't update password file %s", filename);
-       bb_error_msg("password for %s changed by %s", name, myname);
+       bb_info_msg("password for %s changed by %s", name, myname);
 
        /*if (ENABLE_FEATURE_CLEAN_UP) free(newp); - can't, it may be non-malloced */
  skip: