xref: /csrg-svn/libexec/makekey/makekey.c (revision 46045)
1*46045Sbostic /*-
2*46045Sbostic  * Copyright (c) 1990 The Regents of the University of California.
3*46045Sbostic  * All rights reserved.
4*46045Sbostic  *
5*46045Sbostic  * %sccs.include.redist.c%
622421Sdist  */
722421Sdist 
822421Sdist #ifndef lint
922421Sdist char copyright[] =
10*46045Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
1122421Sdist  All rights reserved.\n";
12*46045Sbostic #endif /* not lint */
1322421Sdist 
1422421Sdist #ifndef lint
15*46045Sbostic static char sccsid[] = "@(#)makekey.c	5.2 (Berkeley) 01/19/91";
16*46045Sbostic #endif /* not lint */
1722421Sdist 
18*46045Sbostic #include <sys/errno.h>
19*46045Sbostic #include <stdlib.h>
20*46045Sbostic #include <string.h>
21*46045Sbostic #include <stdio.h>
22*46045Sbostic #include <unistd.h>
231047Sbill 
241047Sbill main()
251047Sbill {
26*46045Sbostic 	int len;
27*46045Sbostic 	char *r, key[9], salt[3], *crypt();
281047Sbill 
29*46045Sbostic 	get(key, sizeof(key) - 1);
30*46045Sbostic 	get(salt, sizeof(salt) - 1);
31*46045Sbostic 	len = strlen(r = crypt(key, salt));
32*46045Sbostic 	if (write(STDOUT_FILENO, r, len) != len)
33*46045Sbostic 		error();
34*46045Sbostic 	exit(0);
351047Sbill }
36*46045Sbostic 
37*46045Sbostic static
38*46045Sbostic get(bp, len)
39*46045Sbostic 	char *bp;
40*46045Sbostic 	register int len;
41*46045Sbostic {
42*46045Sbostic 	register int nr;
43*46045Sbostic 
44*46045Sbostic 	bp[len] = '\0';
45*46045Sbostic 	if ((nr = read(STDIN_FILENO, bp, len)) == len)
46*46045Sbostic 		return;
47*46045Sbostic 	if (nr >= 0)
48*46045Sbostic 		errno = EFTYPE;
49*46045Sbostic 	error();
50*46045Sbostic }
51*46045Sbostic 
52*46045Sbostic static
53*46045Sbostic error()
54*46045Sbostic {
55*46045Sbostic 	(void)fprintf(stderr, "makekey: %s\n", strerror(errno));
56*46045Sbostic 	exit(1);
57*46045Sbostic }
58