blob: 06817a681c9da7adf9fa5cc6594d390a8172b332 [file] [log] [blame]
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +00001/* vi: set sw=4 ts=4: */
2/*
3 * cryptpw.c
Denis Vlasenko4b924f32007-05-30 00:29:55 +00004 *
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +00005 * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no>
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +00006 */
7
Denis Vlasenkob6adbf12007-05-26 19:00:18 +00008#include "libbb.h"
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +00009
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000010int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000011int cryptpw_main(int argc, char **argv)
12{
Denis Vlasenko57bf6682007-05-09 21:27:15 +000013 char salt[sizeof("$N$XXXXXXXX")];
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000014
Denis Vlasenkofe7cd642007-08-18 15:32:12 +000015 if (!getopt32(argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000016 strcpy(salt, "$1$");
Denis Vlasenko57bf6682007-05-09 21:27:15 +000017 /* Too ugly, and needs even more magic to handle endianness: */
18 //((uint32_t*)&salt)[0] = '$' + '1'*0x100 + '$'*0x10000;
19 /* Hope one day gcc will do it itself (inlining strcpy) */
Denis Vlasenko21d10142007-07-20 21:28:41 +000020 crypt_make_salt(salt + 3, 4, 0); /* md5 */
Denis Vlasenko57bf6682007-05-09 21:27:15 +000021 } else {
Denis Vlasenko21d10142007-07-20 21:28:41 +000022 crypt_make_salt(salt, 1, 0); /* des */
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000023 }
24
Denis Vlasenko57bf6682007-05-09 21:27:15 +000025 puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt));
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000026
Denis Vlasenkoa035e9f2007-05-08 23:23:35 +000027 return 0;
28}