xref: /netbsd-src/crypto/external/bsd/netpgp/dist/src/hkpclient/main.c (revision 39e763161db9ed15549ddc86060f36024f8b14a9)
1267df97bSagc /*-
2267df97bSagc  * Copyright (c) 2010 Alistair Crooks <agc@NetBSD.org>
3267df97bSagc  * All rights reserved.
4267df97bSagc  *
5267df97bSagc  * Redistribution and use in source and binary forms, with or without
6267df97bSagc  * modification, are permitted provided that the following conditions
7267df97bSagc  * are met:
8267df97bSagc  * 1. Redistributions of source code must retain the above copyright
9267df97bSagc  *    notice, this list of conditions and the following disclaimer.
10267df97bSagc  * 2. Redistributions in binary form must reproduce the above copyright
11267df97bSagc  *    notice, this list of conditions and the following disclaimer in the
12267df97bSagc  *    documentation and/or other materials provided with the distribution.
13267df97bSagc  *
14267df97bSagc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15267df97bSagc  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16267df97bSagc  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17267df97bSagc  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18267df97bSagc  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19267df97bSagc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20267df97bSagc  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21267df97bSagc  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22267df97bSagc  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23267df97bSagc  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24267df97bSagc  */
25267df97bSagc #include <sys/types.h>
26267df97bSagc 
27267df97bSagc #include <inttypes.h>
28267df97bSagc #include <netpgp.h>
29267df97bSagc #include <stdio.h>
30267df97bSagc #include <stdlib.h>
31267df97bSagc #include <string.h>
32267df97bSagc #include <unistd.h>
33267df97bSagc 
34267df97bSagc #include "hkpc.h"
35267df97bSagc 
36267df97bSagc int
main(int argc,char ** argv)37267df97bSagc main(int argc, char **argv)
38267df97bSagc {
39267df97bSagc 	char	*res;
40267df97bSagc 	char	 server[BUFSIZ];
41267df97bSagc 	int	 family;
42267df97bSagc 	int	 port;
43267df97bSagc 	int	 i;
44267df97bSagc 
45267df97bSagc 	port = 11371;
46267df97bSagc 	family = 4;
47267df97bSagc 	(void) snprintf(server, sizeof(server), "localhost");
48267df97bSagc 	while ((i = getopt(argc, argv, "f:h:p:")) != -1) {
49267df97bSagc 		switch(i) {
50267df97bSagc 		case 'f':
51267df97bSagc 			family = atoi(optarg);
52267df97bSagc 			break;
53267df97bSagc 		case 'h':
54267df97bSagc 			(void) snprintf(server, sizeof(server), optarg);
55267df97bSagc 			break;
56267df97bSagc 		case 'p':
57267df97bSagc 			port = atoi(optarg);
58267df97bSagc 			break;
59267df97bSagc 		default:
60267df97bSagc 			break;
61267df97bSagc 		}
62267df97bSagc 	}
63267df97bSagc 	for (i = optind + 1 ; i < argc ; i++) {
64*39e76316Sagc 		if (hkpc_get(&res, server, port, family, argv[optind], argv[i]) >= 0) {
65267df97bSagc 			hkpc_print_key(stdout, argv[optind], res);
66267df97bSagc 		}
67267df97bSagc 	}
68267df97bSagc 	exit(EXIT_SUCCESS);
69267df97bSagc }
70