Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/loginutils/chpasswd.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/loginutils/chpasswd.c
r2725 r3232 7 7 */ 8 8 #include "libbb.h" 9 10 //usage:#define chpasswd_trivial_usage 11 //usage: IF_LONG_OPTS("[--md5|--encrypted]") IF_NOT_LONG_OPTS("[-m|-e]") 12 //usage:#define chpasswd_full_usage "\n\n" 13 //usage: "Read user:password from stdin and update /etc/passwd\n" 14 //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" 17 //usage: ) 18 //usage: IF_NOT_LONG_OPTS( 19 //usage: "\n -e Supplied passwords are in encrypted form" 20 //usage: "\n -m Use MD5 encryption instead of DES" 21 //usage: ) 22 23 //TODO: implement -c ALGO 9 24 10 25 #if ENABLE_LONG_OPTS … … 21 36 int chpasswd_main(int argc UNUSED_PARAM, char **argv) 22 37 { 23 char *name, *pass; 24 char salt[sizeof("$N$XXXXXXXX")]; 25 int opt, rc; 26 int rnd = rnd; /* we *want* it to be non-initialized! */ 38 char *name; 39 int opt; 27 40 28 if (getuid() )41 if (getuid() != 0) 29 42 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 30 43 … … 34 47 35 48 while ((name = xmalloc_fgetline(stdin)) != NULL) { 49 char *free_me; 50 char *pass; 51 int rc; 52 36 53 pass = strchr(name, ':'); 37 54 if (!pass) … … 41 58 xuname2uid(name); /* dies if there is no such user */ 42 59 60 free_me = NULL; 43 61 if (!(opt & OPT_ENC)) { 44 rnd = crypt_make_salt(salt, 1, rnd); 62 char salt[sizeof("$N$XXXXXXXX")]; 63 64 crypt_make_salt(salt, 1); 45 65 if (opt & OPT_MD5) { 46 strcpy(salt, "$1$"); 47 rnd = crypt_make_salt(salt + 3, 4, rnd); 66 salt[0] = '$'; 67 salt[1] = '1'; 68 salt[2] = '$'; 69 crypt_make_salt(salt + 3, 4); 48 70 } 49 pass = pw_encrypt(pass, salt, 0);71 free_me = pass = pw_encrypt(pass, salt, 0); 50 72 } 51 73 … … 54 76 #if ENABLE_FEATURE_SHADOWPASSWDS 55 77 rc = update_passwd(bb_path_shadow_file, name, pass, NULL); 56 if (rc == 0) /* no lines updated, no errors detected */ 78 if (rc > 0) /* password in /etc/shadow was updated */ 79 pass = (char*)"x"; 80 if (rc >= 0) 81 /* 0 = /etc/shadow missing (not an error), >0 = passwd changed in /etc/shadow */ 57 82 #endif 58 83 rc = update_passwd(bb_path_passwd_file, name, pass, NULL); … … 65 90 logmode = LOGMODE_STDIO; 66 91 free(name); 67 if (!(opt & OPT_ENC)) 68 free(pass); 92 free(free_me); 69 93 } 70 94 return EXIT_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.