Initial public busybox upstream commit
[busybox4maemo] / loginutils / cryptpw.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * cryptpw.c
4  *
5  * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no>
6  */
7
8 #include "libbb.h"
9
10 int cryptpw_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
11 int cryptpw_main(int argc ATTRIBUTE_UNUSED, char **argv)
12 {
13         char salt[sizeof("$N$XXXXXXXX")];
14
15         if (!getopt32(argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
16                 strcpy(salt, "$1$");
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) */
20                 crypt_make_salt(salt + 3, 4, 0); /* md5 */
21         } else {
22                 crypt_make_salt(salt, 1, 0);     /* des */
23         }
24
25         puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt));
26
27         return 0;
28 }