xref: /original-bsd/libexec/makekey/makekey.c (revision 2ca53284)
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.3 (Berkeley) 02/25/91";
16 #endif /* not lint */
17 
18 #include <errno.h>
19 #include <unistd.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 static void error(), get();
25 
26 main()
27 {
28 	int len;
29 	char *r, key[9], salt[3];
30 
31 	get(key, sizeof(key) - 1);
32 	get(salt, sizeof(salt) - 1);
33 	len = strlen(r = crypt(key, salt));
34 	if (write(STDOUT_FILENO, r, len) != len)
35 		error();
36 	exit(0);
37 }
38 
39 static void
40 get(bp, len)
41 	char *bp;
42 	register int len;
43 {
44 	register int nr;
45 
46 	bp[len] = '\0';
47 	if ((nr = read(STDIN_FILENO, bp, len)) == len)
48 		return;
49 	if (nr >= 0)
50 		errno = EFTYPE;
51 	error();
52 }
53 
54 static void
55 error()
56 {
57 	(void)fprintf(stderr, "makekey: %s\n", strerror(errno));
58 	exit(1);
59 }
60