Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * cryptpw.c |
Denis Vlasenko | 4b924f3 | 2007-05-30 00:29:55 +0000 | [diff] [blame] | 4 | * |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 5 | * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no> |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 8 | #include "libbb.h" |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 9 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 10 | int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame^] | 11 | int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv) |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 12 | { |
Denis Vlasenko | 57bf668 | 2007-05-09 21:27:15 +0000 | [diff] [blame] | 13 | char salt[sizeof("$N$XXXXXXXX")]; |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 14 | |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 15 | if (!getopt32(argv, "a:", NULL) || argv[optind - 1][0] != 'd') { |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 16 | strcpy(salt, "$1$"); |
Denis Vlasenko | 57bf668 | 2007-05-09 21:27:15 +0000 | [diff] [blame] | 17 | /* 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 Vlasenko | 21d1014 | 2007-07-20 21:28:41 +0000 | [diff] [blame] | 20 | crypt_make_salt(salt + 3, 4, 0); /* md5 */ |
Denis Vlasenko | 57bf668 | 2007-05-09 21:27:15 +0000 | [diff] [blame] | 21 | } else { |
Denis Vlasenko | 21d1014 | 2007-07-20 21:28:41 +0000 | [diff] [blame] | 22 | crypt_make_salt(salt, 1, 0); /* des */ |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Denis Vlasenko | 57bf668 | 2007-05-09 21:27:15 +0000 | [diff] [blame] | 25 | puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt)); |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 26 | |
Denis Vlasenko | a035e9f | 2007-05-08 23:23:35 +0000 | [diff] [blame] | 27 | return 0; |
| 28 | } |