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
|
|
|
|
|
|
|
int cryptpw_main(int argc, char **argv);
|
|
|
|
int cryptpw_main(int argc, char **argv)
|
|
|
|
{
|
2007-05-10 02:57:15 +05:30
|
|
|
char salt[sizeof("$N$XXXXXXXX")];
|
2007-05-09 04:53:35 +05:30
|
|
|
|
2007-05-10 02:57:15 +05:30
|
|
|
if (!getopt32(argc, argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
|
2007-05-09 04:53:35 +05:30
|
|
|
strcpy(salt, "$1$");
|
2007-05-10 02:57:15 +05:30
|
|
|
/* 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 */
|
2007-05-09 04:53:35 +05:30
|
|
|
}
|
|
|
|
|
2007-05-10 02:57:15 +05:30
|
|
|
puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt));
|
2007-05-09 04:53:35 +05:30
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|