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 * SPDX-License-Identifier: BSD-2-Clause
7 * Copyright (c) 1992, 1993, 1996 Theo de Raadt <deraadt@theos.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
49 #include <rpcsvc/yp_prot.h>
50 #include <rpcsvc/ypclnt.h>
52 static const struct ypalias {
55 { "passwd", "passwd.byname" },
56 { "master.passwd", "master.passwd.byname" },
57 { "shadow", "shadow.byname" },
58 { "group", "group.byname" },
59 { "networks", "networks.byaddr" },
60 { "hosts", "hosts.byname" },
61 { "protocols", "protocols.bynumber" },
62 { "services", "services.byname" },
63 { "aliases", "mail.aliases" },
64 { "ethers", "ethers.byname" },
70 fprintf(stderr, "%s\n%s\n",
71 "usage: ypmatch [-kt] [-d domainname] key ... mapname",
77 main(int argc, char *argv[])
79 char *domainname, *inkey, *inmap, *outbuf;
80 int outbuflen, key, notrans, rval;
86 while ((c = getopt(argc, argv, "xd:kt")) != -1)
89 for (i = 0; i < nitems(ypaliases); i++)
90 printf("Use \"%s\" for \"%s\"\n",
107 if (argc - optind < 2)
110 if (domainname == NULL)
111 yp_get_default_domain(&domainname);
113 inmap = argv[argc-1];
115 for (i = 0; i < nitems(ypaliases); i++)
116 if (strcmp(inmap, ypaliases[i].alias) == 0)
117 inmap = ypaliases[i].name;
121 for (; optind < argc - 1; optind++) {
122 inkey = argv[optind];
124 r = yp_match(domainname, inmap, inkey,
125 strlen(inkey), &outbuf, &outbuflen);
129 printf("%s: ", inkey);
130 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
133 errx(1, "not running ypbind");
135 errx(1, "can't match key %s in map %s. reason: %s",
136 inkey, inmap, yperr_string(r));