kgdb(1): Add missing "
[dragonfly.git] / usr.bin / ypcat / ypcat.c
blob117508a0d6e234c083b8f7291b742dd1a6c15edb
1 /*
2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * $FreeBSD: src/usr.bin/ypcat/ypcat.c,v 1.4.2.2 2002/02/15 00:46:56 des Exp $
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <ctype.h>
36 #include <err.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
42 #include <rpc/rpc.h>
43 #include <rpc/xdr.h>
44 #include <rpcsvc/yp_prot.h>
45 #include <rpcsvc/ypclnt.h>
47 static const struct ypalias {
48 const char *alias, *name;
49 } ypaliases[] = {
50 { "passwd", "passwd.byname" },
51 { "master.passwd", "master.passwd.byname" },
52 { "group", "group.byname" },
53 { "networks", "networks.byaddr" },
54 { "hosts", "hosts.byaddr" },
55 { "protocols", "protocols.bynumber" },
56 { "services", "services.byname" },
57 { "aliases", "mail.aliases" },
58 { "ethers", "ethers.byname" },
61 static int key;
63 static void
64 usage(void)
66 fprintf(stderr, "%s\n%s\n",
67 "usage: ypcat [-k] [-d domainname] [-t] mapname",
68 " ypcat -x");
69 exit(1);
72 static int
73 printit(unsigned long instatus, char *inkey, int inkeylen, char *inval, int invallen,
74 void *indata __unused)
76 if (instatus != YP_TRUE)
77 return (instatus);
78 if (key)
79 printf("%*.*s ", inkeylen, inkeylen, inkey);
80 printf("%*.*s\n", invallen, invallen, inval);
81 return (0);
84 int
85 main(int argc, char *argv[])
87 char *domainname = NULL;
88 struct ypall_callback ypcb;
89 char *inmap;
90 int notrans;
91 int c, r;
92 u_int i;
94 notrans = key = 0;
96 while ((c = getopt(argc, argv, "xd:kt")) != -1)
97 switch (c) {
98 case 'x':
99 for (i = 0; i < NELEM(ypaliases); i++)
100 printf("Use \"%s\" for \"%s\"\n",
101 ypaliases[i].alias,
102 ypaliases[i].name);
103 exit(0);
104 case 'd':
105 domainname = optarg;
106 break;
107 case 't':
108 notrans++;
109 break;
110 case 'k':
111 key++;
112 break;
113 default:
114 usage();
117 if (optind + 1 != argc)
118 usage();
120 if (!domainname)
121 yp_get_default_domain(&domainname);
123 inmap = argv[optind];
124 for (i = 0; (!notrans) && i < NELEM(ypaliases); i++)
125 if (strcmp(inmap, ypaliases[i].alias) == 0)
126 inmap = __DECONST(char *, ypaliases[i].name);
127 ypcb.foreach = printit;
128 ypcb.data = NULL;
130 r = yp_all(domainname, inmap, &ypcb);
131 switch (r) {
132 case 0:
133 break;
134 case YPERR_YPBIND:
135 errx(1, "not running ypbind");
136 default:
137 errx(1, "no such map %s. reason: %s", inmap, yperr_string(r));
139 exit(0);