summaryrefslogtreecommitdiff
path: root/loginutils/cryptpw.c
blob: dd730461397d4cf7306a80ba283de42506d565bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* vi: set sw=4 ts=4: */
/*
 * cryptpw.c
 *
 * Cooked from passwd.c by Thomas Lundquist <thomasez@zelow.no>
 */

#include "libbb.h"

int cryptpw_main(int argc, char **argv);
int cryptpw_main(int argc, char **argv)
{
	char salt[sizeof("$N$XXXXXXXX")];

	if (!getopt32(argc, argv, "a:", NULL) || argv[optind - 1][0] != 'd') {
		strcpy(salt, "$1$");
		/* 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 */
	}

	puts(pw_encrypt(argv[optind] ? argv[optind] : xmalloc_getline(stdin), salt));

	return 0;
}