xref: /netbsd-src/libexec/makekey/makekey.c (revision 0c4ddb1599a0bea866fde8522a74cfbd2f68cd1b)
1*0c4ddb15Slukem /*	$NetBSD: makekey.c,v 1.8 2008/07/20 01:09:07 lukem Exp $	*/
2a5a68ff5Smrg 
361f28255Scgd /*-
4037708cbStls  * Copyright (c) 1990, 1993
5037708cbStls  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
158e6ab883Sagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
32a5a68ff5Smrg #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
34*0c4ddb15Slukem __COPYRIGHT("@(#) Copyright (c) 1990, 1993\
35*0c4ddb15Slukem  The Regents of the University of California.  All rights reserved.");
36a5a68ff5Smrg #if 0
37a5a68ff5Smrg static char sccsid[] = "from: @(#)makekey.c	8.1 (Berkeley) 6/4/93";
38a5a68ff5Smrg #else
39*0c4ddb15Slukem __RCSID("$NetBSD: makekey.c,v 1.8 2008/07/20 01:09:07 lukem Exp $");
40a5a68ff5Smrg #endif
4161f28255Scgd #endif /* not lint */
4261f28255Scgd 
43037708cbStls #include <err.h>
4461f28255Scgd #include <errno.h>
4561f28255Scgd #include <string.h>
46bcc8ec99Scgd #include <stdlib.h>
47037708cbStls #include <unistd.h>
4861f28255Scgd 
497cc2f769Swiz static void get(char *, int);
507cc2f769Swiz int main(void);
5161f28255Scgd 
52037708cbStls int
main(void)537cc2f769Swiz main(void)
5461f28255Scgd {
5561f28255Scgd 	int len;
5661f28255Scgd 	char *r, key[9], salt[3];
5761f28255Scgd 
5861f28255Scgd 	get(key, sizeof(key) - 1);
5961f28255Scgd 	get(salt, sizeof(salt) - 1);
6061f28255Scgd 	len = strlen(r = crypt(key, salt));
6161f28255Scgd 	if (write(STDOUT_FILENO, r, len) != len)
62037708cbStls 		err(1, "stdout");
6361f28255Scgd 	exit(0);
6461f28255Scgd }
6561f28255Scgd 
6661f28255Scgd static void
get(char * bp,int len)677cc2f769Swiz get(char *bp, int len)
6861f28255Scgd {
697cc2f769Swiz 	int nr;
7061f28255Scgd 
7161f28255Scgd 	bp[len] = '\0';
7261f28255Scgd 	if ((nr = read(STDIN_FILENO, bp, len)) == len)
7361f28255Scgd 		return;
7461f28255Scgd 	if (nr >= 0)
7561f28255Scgd 		errno = EFTYPE;
76037708cbStls 	err(1, "stdin");
7761f28255Scgd }
78