2007-05-08 23:23:35 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* cryptpw.c
|
2007-05-30 00:29:55 +00:00
|
|
|
*
|
2007-05-08 23:23:35 +00:00
|
|
|
* Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no>
|
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2007-05-08 23:23:35 +00:00
|
|
|
|
2008-06-12 16:55:59 +00:00
|
|
|
#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_old cryptpw -a des -- "$line"`
|
|
|
|
test "$n" != "$o" && {
|
|
|
|
echo n="$n"
|
|
|
|
echo o="$o"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
n=`./busybox cryptpw -- "$line"`
|
|
|
|
o=`./busybox_old cryptpw -- "$line"`
|
|
|
|
test "$n" != "$o" && {
|
|
|
|
echo n="$n"
|
|
|
|
echo o="$o"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
done
|
|
|
|
*/
|
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-03-17 09:00:54 +00:00
|
|
|
int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
2007-05-08 23:23:35 +00:00
|
|
|
{
|
2007-05-09 21:27:15 +00:00
|
|
|
char salt[sizeof("$N$XXXXXXXX")];
|
2007-05-08 23:23:35 +00:00
|
|
|
|
2007-08-18 15:32:12 +00:00
|
|
|
if (!getopt32(argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
|
2007-05-08 23:23:35 +00:00
|
|
|
strcpy(salt, "$1$");
|
2007-05-09 21:27:15 +00:00
|
|
|
/* 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) */
|
2007-07-20 21:28:41 +00:00
|
|
|
crypt_make_salt(salt + 3, 4, 0); /* md5 */
|
2008-06-12 16:55:59 +00:00
|
|
|
#if TESTING
|
|
|
|
strcpy(salt + 3, "ajg./bcf");
|
|
|
|
#endif
|
2007-05-09 21:27:15 +00:00
|
|
|
} else {
|
2007-07-20 21:28:41 +00:00
|
|
|
crypt_make_salt(salt, 1, 0); /* des */
|
2008-06-12 16:55:59 +00:00
|
|
|
#if TESTING
|
|
|
|
strcpy(salt, "a.");
|
|
|
|
#endif
|
2007-05-08 23:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 16:55:59 +00:00
|
|
|
puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_fgetline(stdin), salt, 1));
|
2007-05-08 23:23:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|