hush: fix incorrect PS2 dispaly and trap handling while reading command
[oweals/busybox.git] / loginutils / chpasswd.c
index 48cf9b1303a6f6852c34d2288ad389e27c3f2bbc..6c4296faa0ff916e48bbe59a9b1adf1f7f6a6ec8 100644 (file)
@@ -7,6 +7,20 @@
  */
 #include "libbb.h"
 
+//usage:#define chpasswd_trivial_usage
+//usage:       IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]")
+//usage:#define chpasswd_full_usage "\n\n"
+//usage:       "Read user:password from stdin and update /etc/passwd\n"
+//usage:     "\nOptions:"
+//usage:       IF_LONG_OPTS(
+//usage:     "\n       -e,--encrypted  Supplied passwords are in encrypted form"
+//usage:     "\n       -m,--md5        Use MD5 encryption instead of DES"
+//usage:       )
+//usage:       IF_NOT_LONG_OPTS(
+//usage:     "\n       -e      Supplied passwords are in encrypted form"
+//usage:     "\n       -m      Use MD5 encryption instead of DES"
+//usage:       )
+
 #if ENABLE_LONG_OPTS
 static const char chpasswd_longopts[] ALIGN1 =
        "encrypted\0" No_argument "e"
@@ -53,7 +67,10 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv)
                 * we try to find & change his passwd in /etc/passwd */
 #if ENABLE_FEATURE_SHADOWPASSWDS
                rc = update_passwd(bb_path_shadow_file, name, pass, NULL);
-               if (rc == 0) /* no lines updated, no errors detected */
+               if (rc > 0) /* password in /etc/shadow was updated */
+                       pass = (char*)"x";
+               if (rc >= 0)
+                       /* 0 = /etc/shadow missing (not an error), >0 = passwd changed in /etc/shadow */
 #endif
                        rc = update_passwd(bb_path_passwd_file, name, pass, NULL);
                /* LOGMODE_BOTH logs to syslog also */