diff options
author | Denis Vlasenko | 2007-05-09 21:27:15 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-05-09 21:27:15 +0000 |
commit | 57bf668d118804060cee998408bdfbfb5512e670 (patch) | |
tree | 73c8241c94c6be8edc40e5761be496f9c17b0b26 | |
parent | 68de7207231fbb3c92487e30b381268737ee2228 (diff) | |
download | busybox-57bf668d118804060cee998408bdfbfb5512e670.zip busybox-57bf668d118804060cee998408bdfbfb5512e670.tar.gz |
cryptpw: size reduction
function old new delta
cryptpw_main 198 140 -58
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-58) Total: -58 bytes
-rw-r--r-- | loginutils/cryptpw.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index d4bcad3..54babdc 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c @@ -3,7 +3,6 @@ * cryptpw.c * * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no> - * */ #include "busybox.h" @@ -11,27 +10,19 @@ int cryptpw_main(int argc, char **argv); int cryptpw_main(int argc, char **argv) { - char *clear; - char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */ - const char *opt_a = "md5"; - - getopt32(argc, argv, "a:", &opt_a); - /* move past the commandline options */ - /*argc -= optind; - unused */ - argv += optind; + char salt[sizeof("$N$XXXXXXXX")]; - crypt_make_salt(salt, 1); /* des */ - if (strcasecmp(opt_a, "md5") == 0) { + if (!getopt32(argc, argv, "a:", NULL) || argv[optind - 1][0] != 'd') { strcpy(salt, "$1$"); - crypt_make_salt(salt + 3, 4); - } else if (strcasecmp(opt_a, "des") != 0) { - bb_show_usage(); + /* Too ugly, and needs even more magic to handle endianness: */ + //((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000; + /* Hope one day gcc will do it itself (inlining strcpy) */ + crypt_make_salt(salt + 3, 4); /* md5 */ + } else { + crypt_make_salt(salt, 1); /* des */ } - clear = argv[0]; - if (!clear) - clear = xmalloc_getline(stdin); + puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt)); - puts(pw_encrypt(clear, salt)); return 0; } |