xref: /csrg-svn/libexec/makekey/makekey.c (revision 46673)
146045Sbostic /*-
246045Sbostic  * Copyright (c) 1990 The Regents of the University of California.
346045Sbostic  * All rights reserved.
446045Sbostic  *
546045Sbostic  * %sccs.include.redist.c%
622421Sdist  */
722421Sdist 
822421Sdist #ifndef lint
922421Sdist char copyright[] =
1046045Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
1122421Sdist  All rights reserved.\n";
1246045Sbostic #endif /* not lint */
1322421Sdist 
1422421Sdist #ifndef lint
15*46673Sbostic static char sccsid[] = "@(#)makekey.c	5.3 (Berkeley) 02/25/91";
1646045Sbostic #endif /* not lint */
1722421Sdist 
18*46673Sbostic #include <errno.h>
19*46673Sbostic #include <unistd.h>
20*46673Sbostic #include <stdio.h>
2146045Sbostic #include <stdlib.h>
2246045Sbostic #include <string.h>
231047Sbill 
24*46673Sbostic static void error(), get();
25*46673Sbostic 
261047Sbill main()
271047Sbill {
2846045Sbostic 	int len;
29*46673Sbostic 	char *r, key[9], salt[3];
301047Sbill 
3146045Sbostic 	get(key, sizeof(key) - 1);
3246045Sbostic 	get(salt, sizeof(salt) - 1);
3346045Sbostic 	len = strlen(r = crypt(key, salt));
3446045Sbostic 	if (write(STDOUT_FILENO, r, len) != len)
3546045Sbostic 		error();
3646045Sbostic 	exit(0);
371047Sbill }
3846045Sbostic 
39*46673Sbostic static void
4046045Sbostic get(bp, len)
4146045Sbostic 	char *bp;
4246045Sbostic 	register int len;
4346045Sbostic {
4446045Sbostic 	register int nr;
4546045Sbostic 
4646045Sbostic 	bp[len] = '\0';
4746045Sbostic 	if ((nr = read(STDIN_FILENO, bp, len)) == len)
4846045Sbostic 		return;
4946045Sbostic 	if (nr >= 0)
5046045Sbostic 		errno = EFTYPE;
5146045Sbostic 	error();
5246045Sbostic }
5346045Sbostic 
54*46673Sbostic static void
5546045Sbostic error()
5646045Sbostic {
5746045Sbostic 	(void)fprintf(stderr, "makekey: %s\n", strerror(errno));
5846045Sbostic 	exit(1);
5946045Sbostic }
60