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