X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=loginutils%2Fcryptpw.c;h=db5d95920a94ccbc6b309cb1278fc3bfff153890;hb=9b44613202a6f2f080ec23746d0680dcef88628d;hp=54babdc80dc4cf97534e88c0089ce65446581719;hpb=57bf668d118804060cee998408bdfbfb5512e670;p=oweals%2Fbusybox.git diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index 54babdc80..db5d95920 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c @@ -1,28 +1,58 @@ /* vi: set sw=4 ts=4: */ /* * cryptpw.c - * + * * Cooked from passwd.c by Thomas Lundquist */ -#include "busybox.h" +#include "libbb.h" -int cryptpw_main(int argc, char **argv); -int cryptpw_main(int argc, char **argv) +#define TESTING 0 + +/* +set TESTING to 1 and pipe some file through this script +if you played with bbox's crypt implementation. + +while read line; do + n=`./busybox cryptpw -a des -- "$line"` + o=`./busybox_org cryptpw -a des -- "$line"` + test "$n" != "$o" && { + echo n="$n" + echo o="$o" + exit + } + n=`./busybox cryptpw -- "$line"` + o=`./busybox_org cryptpw -- "$line"` + test "$n" != "$o" && { + echo n="$n" + echo o="$o" + exit + } +done + */ + +int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int cryptpw_main(int argc UNUSED_PARAM, char **argv) { char salt[sizeof("$N$XXXXXXXX")]; + char *opt_a; - if (!getopt32(argc, argv, "a:", NULL) || argv[optind - 1][0] != 'd') { - strcpy(salt, "$1$"); - /* 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 */ + if (!getopt32(argv, "a:", &opt_a) || opt_a[0] != 'd') { + salt[0] = '$'; + salt[1] = '1'; + salt[2] = '$'; + crypt_make_salt(salt + 3, 4, 0); /* md5 */ +#if TESTING + strcpy(salt + 3, "ajg./bcf"); +#endif } else { - crypt_make_salt(salt, 1); /* des */ + crypt_make_salt(salt, 1, 0); /* des */ +#if TESTING + strcpy(salt, "a."); +#endif } - puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt)); + puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_fgetline(stdin), salt, 1)); return 0; }