yplib.c revision 1.5 1 1.5 agc /* $NetBSD: yplib.c,v 1.5 2003/12/10 12:06:25 agc Exp $ */
2 1.1 gwr
3 1.1 gwr /*
4 1.1 gwr * Copyright (c) 1992, 1993 Theo de Raadt <deraadt (at) fsa.ca>
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * Redistribution and use in source and binary forms, with or without
8 1.1 gwr * modification, are permitted provided that the following conditions
9 1.1 gwr * are met:
10 1.1 gwr * 1. Redistributions of source code must retain the above copyright
11 1.1 gwr * notice, this list of conditions and the following disclaimer.
12 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 gwr * notice, this list of conditions and the following disclaimer in the
14 1.1 gwr * documentation and/or other materials provided with the distribution.
15 1.1 gwr *
16 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 1.1 gwr * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 gwr * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 1.1 gwr * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 gwr * SUCH DAMAGE.
27 1.1 gwr */
28 1.1 gwr
29 1.1 gwr /*
30 1.1 gwr * This file provides "stubs" for all the YP library functions.
31 1.1 gwr * It is not needed unless you pull in things that call YP, and
32 1.1 gwr * if you use all the get* files here then the YP stuff should
33 1.1 gwr * not get dragged in. But if it does, one can use this.
34 1.1 gwr *
35 1.1 gwr * This was copied from:
36 1.1 gwr * lib/libc/yp/yplib.c
37 1.1 gwr * (and then completely gutted! 8^)
38 1.1 gwr */
39 1.3 christos #include <sys/cdefs.h>
40 1.3 christos
41 1.3 christos #ifdef __weak_alias
42 1.3 christos #define yp_all _yp_all
43 1.3 christos #define yp_bind _yp_bind
44 1.3 christos #define yp_first _yp_first
45 1.3 christos #define yp_get_default_domain _yp_get_default_domain
46 1.3 christos #define yp_maplist _yp_maplist
47 1.3 christos #define yp_master _yp_master
48 1.3 christos #define yp_match _yp_match
49 1.3 christos #define yp_next _yp_next
50 1.3 christos #define yp_order _yp_order
51 1.3 christos #define yp_unbind _yp_unbind
52 1.3 christos #define yperr_string _yperr_string
53 1.3 christos #define ypprot_err _ypprot_err
54 1.3 christos #endif
55 1.1 gwr
56 1.1 gwr #include <sys/types.h>
57 1.1 gwr
58 1.2 sommerfe #include <errno.h>
59 1.2 sommerfe #include <stdio.h>
60 1.2 sommerfe #include <stdlib.h>
61 1.2 sommerfe #include <string.h>
62 1.2 sommerfe #include <unistd.h>
63 1.2 sommerfe
64 1.2 sommerfe #include <rpc/rpc.h>
65 1.2 sommerfe #include <rpc/xdr.h>
66 1.2 sommerfe #include <rpcsvc/yp_prot.h>
67 1.2 sommerfe #include <rpcsvc/ypclnt.h>
68 1.1 gwr
69 1.3 christos struct dom_binding *_ypbindlist;
70 1.3 christos char _yp_domain[256];
71 1.3 christos
72 1.3 christos #define YPLIB_TIMEOUT 10
73 1.3 christos #define YPLIB_RPC_RETRIES 4
74 1.3 christos
75 1.3 christos struct timeval _yplib_timeout = { YPLIB_TIMEOUT, 0 };
76 1.3 christos struct timeval _yplib_rpc_timeout = { YPLIB_TIMEOUT / YPLIB_RPC_RETRIES,
77 1.3 christos 1000000 * (YPLIB_TIMEOUT % YPLIB_RPC_RETRIES) / YPLIB_RPC_RETRIES };
78 1.3 christos int _yplib_nerrs = 5;
79 1.3 christos
80 1.3 christos
81 1.3 christos #ifdef __weak_alias
82 1.3 christos __weak_alias(yp_all,_yp_all);
83 1.3 christos __weak_alias(yp_bind, _yp_bind);
84 1.3 christos __weak_alias(yp_first,_yp_first);
85 1.3 christos __weak_alias(yp_get_default_domain, _yp_get_default_domain);
86 1.3 christos __weak_alias(yp_maplist,_yp_maplist);
87 1.3 christos __weak_alias(yp_master,_yp_master);
88 1.3 christos __weak_alias(yp_match,_yp_match);
89 1.3 christos __weak_alias(yp_next,_yp_next);
90 1.3 christos __weak_alias(yp_order,_yp_order);
91 1.3 christos __weak_alias(yp_unbind, _yp_unbind);
92 1.3 christos __weak_alias(yperr_string,_yperr_string);
93 1.3 christos __weak_alias(ypprot_err,_ypprot_err);
94 1.3 christos #endif
95 1.3 christos
96 1.3 christos void __yp_unbind __P((struct dom_binding *));
97 1.3 christos int _yp_invalid_domain __P((const char *));
98 1.1 gwr
99 1.1 gwr int
100 1.1 gwr _yp_dobind(dom, ypdb)
101 1.1 gwr const char *dom;
102 1.2 sommerfe struct dom_binding **ypdb;
103 1.1 gwr {
104 1.1 gwr return YPERR_YPBIND;
105 1.1 gwr }
106 1.1 gwr
107 1.3 christos void
108 1.3 christos __yp_unbind(ypb)
109 1.3 christos struct dom_binding *ypb;
110 1.3 christos {
111 1.3 christos }
112 1.3 christos
113 1.1 gwr int
114 1.1 gwr yp_bind(dom)
115 1.1 gwr const char *dom;
116 1.1 gwr {
117 1.1 gwr return _yp_dobind(dom, NULL);
118 1.1 gwr }
119 1.1 gwr
120 1.1 gwr void
121 1.1 gwr yp_unbind(dom)
122 1.1 gwr const char *dom;
123 1.1 gwr {
124 1.1 gwr }
125 1.1 gwr
126 1.1 gwr int
127 1.3 christos yp_get_default_domain(domp)
128 1.3 christos char **domp;
129 1.3 christos {
130 1.3 christos *domp = NULL;
131 1.3 christos if (_yp_domain[0] == '\0')
132 1.3 christos if (getdomainname(_yp_domain, sizeof(_yp_domain)))
133 1.3 christos return YPERR_NODOM;
134 1.3 christos *domp = _yp_domain;
135 1.3 christos return 0;
136 1.3 christos }
137 1.3 christos
138 1.3 christos int
139 1.3 christos _yp_check(dom)
140 1.3 christos char **dom;
141 1.3 christos {
142 1.3 christos char *unused;
143 1.3 christos
144 1.3 christos if (_yp_domain[0] == '\0')
145 1.3 christos if (yp_get_default_domain(&unused))
146 1.3 christos return 0;
147 1.3 christos
148 1.3 christos if (dom)
149 1.3 christos *dom = _yp_domain;
150 1.3 christos
151 1.3 christos if (yp_bind(_yp_domain) == 0)
152 1.3 christos return 1;
153 1.3 christos return 0;
154 1.3 christos }
155 1.3 christos
156 1.3 christos int
157 1.3 christos _yp_invalid_domain(dom)
158 1.3 christos const char *dom;
159 1.3 christos {
160 1.3 christos if (dom == NULL || *dom == '\0')
161 1.3 christos return 1;
162 1.3 christos
163 1.3 christos if (strlen(dom) > YPMAXDOMAIN)
164 1.3 christos return 1;
165 1.3 christos
166 1.3 christos if (strchr(dom, '/') != NULL)
167 1.3 christos return 1;
168 1.3 christos
169 1.3 christos return 0;
170 1.3 christos }
171 1.3 christos
172 1.3 christos int
173 1.1 gwr yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
174 1.1 gwr const char *indomain;
175 1.1 gwr const char *inmap;
176 1.1 gwr const char *inkey;
177 1.1 gwr int inkeylen;
178 1.1 gwr char **outval;
179 1.1 gwr int *outvallen;
180 1.1 gwr {
181 1.1 gwr *outval = NULL;
182 1.1 gwr *outvallen = 0;
183 1.1 gwr
184 1.1 gwr return YPERR_DOMAIN;
185 1.1 gwr }
186 1.1 gwr
187 1.1 gwr int
188 1.1 gwr yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
189 1.1 gwr const char *indomain;
190 1.1 gwr const char *inmap;
191 1.1 gwr char **outkey;
192 1.1 gwr int *outkeylen;
193 1.1 gwr char **outval;
194 1.1 gwr int *outvallen;
195 1.1 gwr {
196 1.1 gwr
197 1.1 gwr *outkey = *outval = NULL;
198 1.1 gwr *outkeylen = *outvallen = 0;
199 1.1 gwr
200 1.1 gwr return YPERR_DOMAIN;
201 1.1 gwr }
202 1.1 gwr
203 1.1 gwr int
204 1.1 gwr yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
205 1.1 gwr const char *indomain;
206 1.1 gwr const char *inmap;
207 1.1 gwr const char *inkey;
208 1.1 gwr int inkeylen;
209 1.1 gwr char **outkey;
210 1.1 gwr int *outkeylen;
211 1.1 gwr char **outval;
212 1.1 gwr int *outvallen;
213 1.1 gwr {
214 1.1 gwr *outkey = *outval = NULL;
215 1.1 gwr *outkeylen = *outvallen = 0;
216 1.1 gwr
217 1.1 gwr return YPERR_DOMAIN;
218 1.1 gwr }
219 1.1 gwr
220 1.1 gwr int
221 1.1 gwr yp_all(indomain, inmap, incallback)
222 1.1 gwr const char *indomain;
223 1.1 gwr const char *inmap;
224 1.2 sommerfe struct ypall_callback *incallback;
225 1.1 gwr {
226 1.1 gwr return YPERR_DOMAIN;
227 1.1 gwr }
228 1.1 gwr
229 1.1 gwr int
230 1.1 gwr yp_order(indomain, inmap, outorder)
231 1.1 gwr const char *indomain;
232 1.1 gwr const char *inmap;
233 1.1 gwr int *outorder;
234 1.1 gwr {
235 1.1 gwr return YPERR_DOMAIN;
236 1.1 gwr }
237 1.1 gwr
238 1.1 gwr int
239 1.1 gwr yp_master(indomain, inmap, outname)
240 1.1 gwr const char *indomain;
241 1.1 gwr const char *inmap;
242 1.1 gwr char **outname;
243 1.1 gwr {
244 1.1 gwr return YPERR_DOMAIN;
245 1.1 gwr }
246 1.1 gwr
247 1.1 gwr int
248 1.1 gwr yp_maplist(indomain, outmaplist)
249 1.1 gwr const char *indomain;
250 1.1 gwr struct ypmaplist **outmaplist;
251 1.1 gwr {
252 1.1 gwr return YPERR_DOMAIN;
253 1.1 gwr }
254 1.1 gwr
255 1.1 gwr char *
256 1.1 gwr yperr_string(incode)
257 1.1 gwr int incode;
258 1.1 gwr {
259 1.1 gwr static char err[80];
260 1.1 gwr
261 1.1 gwr if (incode == 0)
262 1.1 gwr return "Success";
263 1.1 gwr
264 1.4 itojun snprintf(err, sizeof(err), "YP FAKE error %d\n", incode);
265 1.1 gwr return err;
266 1.1 gwr }
267 1.1 gwr
268 1.1 gwr int
269 1.1 gwr ypprot_err(incode)
270 1.1 gwr unsigned int incode;
271 1.1 gwr {
272 1.1 gwr switch (incode) {
273 1.1 gwr case YP_TRUE: /* success */
274 1.1 gwr return 0;
275 1.1 gwr case YP_FALSE: /* failure */
276 1.1 gwr return YPERR_YPBIND;
277 1.1 gwr }
278 1.1 gwr return YPERR_YPERR;
279 1.1 gwr }
280 1.1 gwr
281