2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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
29 * $FreeBSD: src/usr.bin/ypmatch/ypmatch.c,v 1.7.2.2 2002/02/15 00:46:56 des Exp $
30 * $DragonFly: src/usr.bin/ypmatch/ypmatch.c,v 1.3 2003/10/04 20:36:55 hmp Exp $
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
45 #include <rpcsvc/yp_prot.h>
46 #include <rpcsvc/ypclnt.h>
51 { "passwd", "passwd.byname" },
52 { "master.passwd", "master.passwd.byname" },
53 { "group", "group.byname" },
54 { "networks", "networks.byaddr" },
55 { "hosts", "hosts.byname" },
56 { "protocols", "protocols.bynumber" },
57 { "services", "services.byname" },
58 { "aliases", "mail.aliases" },
59 { "ethers", "ethers.byname" },
65 fprintf(stderr
, "%s\n%s\n",
66 "usage: ypmatch [-d domain] [-t] [-k] key [key ...] mname",
72 main(int argc
, char **argv
)
74 char *domainname
= NULL
;
75 char *inkey
, *inmap
, *outbuf
;
76 int outbuflen
, key
, notrans
;
81 while ((c
= getopt(argc
, argv
, "xd:kt")) != -1)
84 for (i
= 0; i
<sizeof ypaliases
/sizeof ypaliases
[0]; i
++)
85 printf("Use \"%s\" for \"%s\"\n",
102 if ((argc
-optind
) < 2)
106 yp_get_default_domain(&domainname
);
108 inmap
= argv
[argc
-1];
109 for (i
= 0; (!notrans
) && i
<sizeof ypaliases
/sizeof ypaliases
[0]; i
++)
110 if (strcmp(inmap
, ypaliases
[i
].alias
) == 0)
111 inmap
= ypaliases
[i
].name
;
112 for (; optind
< argc
-1; optind
++) {
113 inkey
= argv
[optind
];
115 r
= yp_match(domainname
, inmap
, inkey
,
116 strlen(inkey
), &outbuf
, &outbuflen
);
120 printf("%s ", inkey
);
121 printf("%*.*s\n", outbuflen
, outbuflen
, outbuf
);
124 errx(1, "not running ypbind");
126 errx(1, "can't match key %s in map %s. reason: %s",
127 inkey
, inmap
, yperr_string(r
));