1 /* $NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $ */
4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $");
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
46 #include <rpcsvc/yp_prot.h>
47 #include <rpcsvc/ypclnt.h>
49 #include "ypalias_init.h"
51 static void usage(void) __attribute__((__noreturn__
));
54 main(int argc
, char *argv
[])
59 int outbuflen
, key
, null
, notrans
;
63 const struct ypalias
*ypaliases
;
67 notrans
= key
= null
= 0;
68 ypaliases
= ypalias_init();
69 while ((c
= getopt(argc
, argv
, "xd:ktz")) != -1) {
72 for(i
= 0; ypaliases
[i
].alias
; i
++)
73 printf("Use \"%s\" for \"%s\"\n",
105 if (domainname
== NULL
)
106 yp_get_default_domain(&domainname
);
108 inmap
= argv
[argc
- 1];
110 for (i
= 0; ypaliases
[i
].alias
; i
++)
111 if (strcmp(inmap
, ypaliases
[i
].alias
) == 0)
112 inmap
= ypaliases
[i
].name
;
116 for(c
= 0; c
< (argc
- 1); c
++) {
122 r
= yp_match(domainname
, inmap
, inkey
, len
,
123 &outbuf
, &outbuflen
);
127 printf("%s: ", inkey
);
128 fwrite(outbuf
, outbuflen
, 1, stdout
);
133 errx(1, "not running ypbind");
136 warnx("can't match key %s in map %s. Reason: %s",
137 inkey
, inmap
, yperr_string(r
));
150 (void)fprintf(stderr
, "Usage: %s [-ktz] [-d domain] key ... "
151 "mapname\n", getprogname());
152 (void)fprintf(stderr
, " %s -x\n", getprogname());