Sun Jun 21 14:59:53 2009 UTC ()
Sync usage with man page.


(wiz)
diff -r1.18 -r1.19 src/usr.bin/ypmatch/ypmatch.c

cvs diff -r1.18 -r1.19 src/usr.bin/ypmatch/ypmatch.c (switch to unified diff)

--- src/usr.bin/ypmatch/ypmatch.c 2009/06/20 19:27:26 1.18
+++ src/usr.bin/ypmatch/ypmatch.c 2009/06/21 14:59:53 1.19
@@ -1,154 +1,154 @@ @@ -1,154 +1,154 @@
1/* $NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $ */ 1/* $NetBSD: ypmatch.c,v 1.19 2009/06/21 14:59:53 wiz Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca> 4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30#ifndef lint 30#ifndef lint
31__RCSID("$NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $"); 31__RCSID("$NetBSD: ypmatch.c,v 1.19 2009/06/21 14:59:53 wiz Exp $");
32#endif 32#endif
33 33
34#include <sys/param.h> 34#include <sys/param.h>
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/socket.h> 36#include <sys/socket.h>
37#include <ctype.h> 37#include <ctype.h>
38#include <err.h> 38#include <err.h>
39#include <stdio.h> 39#include <stdio.h>
40#include <stdlib.h> 40#include <stdlib.h>
41#include <string.h> 41#include <string.h>
42#include <unistd.h> 42#include <unistd.h>
43 43
44#include <rpc/rpc.h> 44#include <rpc/rpc.h>
45#include <rpc/xdr.h> 45#include <rpc/xdr.h>
46#include <rpcsvc/yp_prot.h> 46#include <rpcsvc/yp_prot.h>
47#include <rpcsvc/ypclnt.h> 47#include <rpcsvc/ypclnt.h>
48 48
49#include "ypalias_init.h" 49#include "ypalias_init.h"
50 50
51static void usage(void) __attribute__((__noreturn__)); 51static void usage(void) __attribute__((__noreturn__));
52 52
53int 53int
54main(int argc, char *argv[]) 54main(int argc, char *argv[])
55{ 55{
56 char *domainname; 56 char *domainname;
57 char *inkey, *outbuf; 57 char *inkey, *outbuf;
58 const char *inmap; 58 const char *inmap;
59 int outbuflen, key, null, notrans; 59 int outbuflen, key, null, notrans;
60 int c, r, len; 60 int c, r, len;
61 size_t i; 61 size_t i;
62 int rval; 62 int rval;
63 const struct ypalias *ypaliases; 63 const struct ypalias *ypaliases;
64 64
65 setprogname(*argv); 65 setprogname(*argv);
66 domainname = NULL; 66 domainname = NULL;
67 notrans = key = null = 0; 67 notrans = key = null = 0;
68 ypaliases = ypalias_init(); 68 ypaliases = ypalias_init();
69 while ((c = getopt(argc, argv, "xd:ktz")) != -1) { 69 while ((c = getopt(argc, argv, "xd:ktz")) != -1) {
70 switch (c) { 70 switch (c) {
71 case 'x': 71 case 'x':
72 for(i = 0; ypaliases[i].alias; i++) 72 for(i = 0; ypaliases[i].alias; i++)
73 printf("Use \"%s\" for \"%s\"\n", 73 printf("Use \"%s\" for \"%s\"\n",
74 ypaliases[i].alias, 74 ypaliases[i].alias,
75 ypaliases[i].name); 75 ypaliases[i].name);
76 return 0; 76 return 0;
77 77
78 case 'd': 78 case 'd':
79 domainname = optarg; 79 domainname = optarg;
80 break; 80 break;
81 81
82 case 't': 82 case 't':
83 notrans++; 83 notrans++;
84 break; 84 break;
85 85
86 case 'k': 86 case 'k':
87 key++; 87 key++;
88 break; 88 break;
89 89
90 case 'z': 90 case 'z':
91 null++; 91 null++;
92 break; 92 break;
93 93
94 default: 94 default:
95 usage(); 95 usage();
96 } 96 }
97 } 97 }
98 98
99 argc -= optind; 99 argc -= optind;
100 argv += optind; 100 argv += optind;
101 101
102 if (argc < 2) 102 if (argc < 2)
103 usage(); 103 usage();
104 104
105 if (domainname == NULL) 105 if (domainname == NULL)
106 yp_get_default_domain(&domainname); 106 yp_get_default_domain(&domainname);
107 107
108 inmap = argv[argc - 1]; 108 inmap = argv[argc - 1];
109 if (notrans == 0) { 109 if (notrans == 0) {
110 for (i = 0; ypaliases[i].alias; i++) 110 for (i = 0; ypaliases[i].alias; i++)
111 if (strcmp(inmap, ypaliases[i].alias) == 0) 111 if (strcmp(inmap, ypaliases[i].alias) == 0)
112 inmap = ypaliases[i].name; 112 inmap = ypaliases[i].name;
113 } 113 }
114 114
115 rval = 0; 115 rval = 0;
116 for(c = 0; c < (argc - 1); c++) { 116 for(c = 0; c < (argc - 1); c++) {
117 inkey = argv[c]; 117 inkey = argv[c];
118 118
119 len = strlen(inkey); 119 len = strlen(inkey);
120 if (null) 120 if (null)
121 len++; 121 len++;
122 r = yp_match(domainname, inmap, inkey, len, 122 r = yp_match(domainname, inmap, inkey, len,
123 &outbuf, &outbuflen); 123 &outbuf, &outbuflen);
124 switch (r) { 124 switch (r) {
125 case 0: 125 case 0:
126 if (key) 126 if (key)
127 printf("%s: ", inkey); 127 printf("%s: ", inkey);
128 fwrite(outbuf, outbuflen, 1, stdout); 128 fwrite(outbuf, outbuflen, 1, stdout);
129 putc('\n', stdout); 129 putc('\n', stdout);
130 break; 130 break;
131 131
132 case YPERR_YPBIND: 132 case YPERR_YPBIND:
133 errx(1, "not running ypbind"); 133 errx(1, "not running ypbind");
134 134
135 default: 135 default:
136 warnx("can't match key %s in map %s. Reason: %s", 136 warnx("can't match key %s in map %s. Reason: %s",
137 inkey, inmap, yperr_string(r)); 137 inkey, inmap, yperr_string(r));
138 rval = 1; 138 rval = 1;
139 break; 139 break;
140 } 140 }
141 } 141 }
142 142
143 return rval; 143 return rval;
144} 144}
145 145
146static void 146static void
147usage(void) 147usage(void)
148{ 148{
149 149
150 (void)fprintf(stderr, "Usage: %s [-d domain] [-tkz] key [key ...] " 150 (void)fprintf(stderr, "Usage: %s [-ktz] [-d domain] key ... "
151 "mapname\n", getprogname()); 151 "mapname\n", getprogname());
152 (void)fprintf(stderr, " %s -x\n", getprogname()); 152 (void)fprintf(stderr, " %s -x\n", getprogname());
153 exit(1); 153 exit(1);
154} 154}