Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/loginutils/chpasswd.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/loginutils/chpasswd.c
r3232 r3621 6 6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 7 */ 8 #include "libbb.h" 8 //config:config CHPASSWD 9 //config: bool "chpasswd" 10 //config: default y 11 //config: help 12 //config: Reads a file of user name and password pairs from standard input 13 //config: and uses this information to update a group of existing users. 14 //config: 15 //config:config FEATURE_DEFAULT_PASSWD_ALGO 16 //config: string "Default password encryption method (passwd -a, cryptpw -m parameter)" 17 //config: default "des" 18 //config: depends on PASSWD || CRYPTPW 19 //config: help 20 //config: Possible choices are "d[es]", "m[d5]", "s[ha256]" or "sha512". 21 22 //applet:IF_CHPASSWD(APPLET(chpasswd, BB_DIR_USR_SBIN, BB_SUID_DROP)) 23 24 //kbuild:lib-$(CONFIG_CHPASSWD) += chpasswd.o 9 25 10 26 //usage:#define chpasswd_trivial_usage 11 //usage: IF_LONG_OPTS("[--md5|--encrypted ]") IF_NOT_LONG_OPTS("[-m|-e]")27 //usage: IF_LONG_OPTS("[--md5|--encrypted|--crypt-method]") IF_NOT_LONG_OPTS("[-m|-e|-c]") 12 28 //usage:#define chpasswd_full_usage "\n\n" 13 29 //usage: "Read user:password from stdin and update /etc/passwd\n" 14 30 //usage: IF_LONG_OPTS( 15 //usage: "\n -e,--encrypted Supplied passwords are in encrypted form" 16 //usage: "\n -m,--md5 Use MD5 encryption instead of DES" 31 //usage: "\n -e,--encrypted Supplied passwords are in encrypted form" 32 //usage: "\n -m,--md5 Use MD5 encryption instead of DES" 33 //usage: "\n -c,--crypt-method Use the specified method to encrypt the passwords" 17 34 //usage: ) 18 35 //usage: IF_NOT_LONG_OPTS( 19 36 //usage: "\n -e Supplied passwords are in encrypted form" 20 37 //usage: "\n -m Use MD5 encryption instead of DES" 38 //usage: "\n -c Use the specified method to encrypt the passwords" 21 39 //usage: ) 22 40 23 //TODO: implement -c ALGO 41 #include "libbb.h" 24 42 25 43 #if ENABLE_LONG_OPTS 26 44 static const char chpasswd_longopts[] ALIGN1 = 27 "encrypted\0" No_argument "e" 28 "md5\0" No_argument "m" 45 "encrypted\0" No_argument "e" 46 "md5\0" No_argument "m" 47 "crypt-method\0" Required_argument "c" 29 48 ; 30 49 #endif … … 37 56 { 38 57 char *name; 58 const char *algo = CONFIG_FEATURE_DEFAULT_PASSWD_ALGO; 39 59 int opt; 40 60 … … 42 62 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 43 63 44 opt_complementary = "m--e :e--m";64 opt_complementary = "m--ec:e--mc:c--em"; 45 65 IF_LONG_OPTS(applet_long_options = chpasswd_longopts;) 46 opt = getopt32(argv, "em ");66 opt = getopt32(argv, "emc:", &algo); 47 67 48 68 while ((name = xmalloc_fgetline(stdin)) != NULL) { … … 60 80 free_me = NULL; 61 81 if (!(opt & OPT_ENC)) { 62 char salt[ sizeof("$N$XXXXXXXX")];82 char salt[MAX_PW_SALT_LEN]; 63 83 64 crypt_make_salt(salt, 1);65 84 if (opt & OPT_MD5) { 66 salt[0] = '$'; 67 salt[1] = '1'; 68 salt[2] = '$'; 69 crypt_make_salt(salt + 3, 4); 85 /* Force MD5 if the -m flag is set */ 86 algo = "md5"; 70 87 } 88 89 crypt_make_pw_salt(salt, algo); 71 90 free_me = pass = pw_encrypt(pass, salt, 0); 72 91 } … … 87 106 bb_error_msg_and_die("an error occurred updating password for %s", name); 88 107 if (rc) 89 bb_ info_msg("Password for '%s' changed", name);108 bb_error_msg("password for '%s' changed", name); 90 109 logmode = LOGMODE_STDIO; 91 110 free(name);
Note:
See TracChangeset
for help on using the changeset viewer.