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