1 /* $OpenBSD: ypmatch.c,v 1.16 2015/02/08 23:40:35 deraadt Exp $ */
2 /* $NetBSD: ypmatch.c,v 1.8 1996/05/07 01:24:52 jtc Exp $ */
5 * Copyright (c) 1992, 1993, 1996 Theo de Raadt <deraadt@theos.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
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
30 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
47 #include <rpcsvc/yp_prot.h>
48 #include <rpcsvc/ypclnt.h>
50 static const struct ypalias {
53 { "passwd", "passwd.byname" },
54 { "master.passwd", "master.passwd.byname" },
55 { "shadow", "shadow.byname" },
56 { "group", "group.byname" },
57 { "networks", "networks.byaddr" },
58 { "hosts", "hosts.byname" },
59 { "protocols", "protocols.bynumber" },
60 { "services", "services.byname" },
61 { "aliases", "mail.aliases" },
62 { "ethers", "ethers.byname" },
68 fprintf(stderr, "%s\n%s\n",
69 "usage: ypmatch [-kt] [-d domainname] key ... mapname",
75 main(int argc, char *argv[])
77 char *domainname, *inkey, *inmap, *outbuf;
78 int outbuflen, key, notrans, rval;
84 while ((c = getopt(argc, argv, "xd:kt")) != -1)
87 for (i = 0; i < nitems(ypaliases); i++)
88 printf("Use \"%s\" for \"%s\"\n",
105 if (argc - optind < 2)
108 if (domainname == NULL)
109 yp_get_default_domain(&domainname);
111 inmap = argv[argc-1];
113 for (i = 0; i < nitems(ypaliases); i++)
114 if (strcmp(inmap, ypaliases[i].alias) == 0)
115 inmap = ypaliases[i].name;
119 for (; optind < argc - 1; optind++) {
120 inkey = argv[optind];
122 r = yp_match(domainname, inmap, inkey,
123 strlen(inkey), &outbuf, &outbuflen);
127 printf("%s: ", inkey);
128 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
131 errx(1, "not running ypbind");
133 errx(1, "can't match key %s in map %s. reason: %s",
134 inkey, inmap, yperr_string(r));