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
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
49 static const struct ypalias {
52 { "passwd", "passwd.byname" },
53 { "master.passwd", "master.passwd.byname" },
54 { "shadow", "shadow.byname" },
55 { "group", "group.byname" },
56 { "networks", "networks.byaddr" },
57 { "hosts", "hosts.byname" },
58 { "protocols", "protocols.bynumber" },
59 { "services", "services.byname" },
60 { "aliases", "mail.aliases" },
61 { "ethers", "ethers.byname" },
67 fprintf(stderr, "%s\n%s\n",
68 "usage: ypmatch [-kt] [-d domainname] key ... mapname",
74 main(int argc, char *argv[])
76 char *domainname, *inkey, *inmap, *outbuf;
77 int outbuflen, key, notrans, rval;
83 while ((c = getopt(argc, argv, "xd:kt")) != -1)
86 for (i = 0; i < nitems(ypaliases); i++)
87 printf("Use \"%s\" for \"%s\"\n",
104 if (argc - optind < 2)
107 if (domainname == NULL)
108 yp_get_default_domain(&domainname);
110 inmap = argv[argc-1];
112 for (i = 0; i < nitems(ypaliases); i++)
113 if (strcmp(inmap, ypaliases[i].alias) == 0)
114 inmap = ypaliases[i].name;
118 for (; optind < argc - 1; optind++) {
119 inkey = argv[optind];
121 r = yp_match(domainname, inmap, inkey,
122 strlen(inkey), &outbuf, &outbuflen);
126 printf("%s: ", inkey);
127 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
130 errx(1, "not running ypbind");
132 errx(1, "can't match key %s in map %s. reason: %s",
133 inkey, inmap, yperr_string(r));