No empty .Rs/.Re
[netbsd-mini2440.git] / distrib / utils / libhack / yplib.c
blobe57823f1e900b30f9156039717238013d3dc6fd9
1 /* $NetBSD: yplib.c,v 1.4 2003/08/06 13:43:32 itojun Exp $ */
3 /*
4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
26 * SUCH DAMAGE.
30 * This file provides "stubs" for all the YP library functions.
31 * It is not needed unless you pull in things that call YP, and
32 * if you use all the get* files here then the YP stuff should
33 * not get dragged in. But if it does, one can use this.
35 * This was copied from:
36 * lib/libc/yp/yplib.c
37 * (and then completely gutted! 8^)
39 #include <sys/cdefs.h>
41 #ifdef __weak_alias
42 #define yp_all _yp_all
43 #define yp_bind _yp_bind
44 #define yp_first _yp_first
45 #define yp_get_default_domain _yp_get_default_domain
46 #define yp_maplist _yp_maplist
47 #define yp_master _yp_master
48 #define yp_match _yp_match
49 #define yp_next _yp_next
50 #define yp_order _yp_order
51 #define yp_unbind _yp_unbind
52 #define yperr_string _yperr_string
53 #define ypprot_err _ypprot_err
54 #endif
56 #include <sys/types.h>
58 #include <errno.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <unistd.h>
64 #include <rpc/rpc.h>
65 #include <rpc/xdr.h>
66 #include <rpcsvc/yp_prot.h>
67 #include <rpcsvc/ypclnt.h>
69 struct dom_binding *_ypbindlist;
70 char _yp_domain[256];
72 #define YPLIB_TIMEOUT 10
73 #define YPLIB_RPC_RETRIES 4
75 struct timeval _yplib_timeout = { YPLIB_TIMEOUT, 0 };
76 struct timeval _yplib_rpc_timeout = { YPLIB_TIMEOUT / YPLIB_RPC_RETRIES,
77 1000000 * (YPLIB_TIMEOUT % YPLIB_RPC_RETRIES) / YPLIB_RPC_RETRIES };
78 int _yplib_nerrs = 5;
81 #ifdef __weak_alias
82 __weak_alias(yp_all,_yp_all);
83 __weak_alias(yp_bind, _yp_bind);
84 __weak_alias(yp_first,_yp_first);
85 __weak_alias(yp_get_default_domain, _yp_get_default_domain);
86 __weak_alias(yp_maplist,_yp_maplist);
87 __weak_alias(yp_master,_yp_master);
88 __weak_alias(yp_match,_yp_match);
89 __weak_alias(yp_next,_yp_next);
90 __weak_alias(yp_order,_yp_order);
91 __weak_alias(yp_unbind, _yp_unbind);
92 __weak_alias(yperr_string,_yperr_string);
93 __weak_alias(ypprot_err,_ypprot_err);
94 #endif
96 void __yp_unbind __P((struct dom_binding *));
97 int _yp_invalid_domain __P((const char *));
99 int
100 _yp_dobind(dom, ypdb)
101 const char *dom;
102 struct dom_binding **ypdb;
104 return YPERR_YPBIND;
107 void
108 __yp_unbind(ypb)
109 struct dom_binding *ypb;
114 yp_bind(dom)
115 const char *dom;
117 return _yp_dobind(dom, NULL);
120 void
121 yp_unbind(dom)
122 const char *dom;
127 yp_get_default_domain(domp)
128 char **domp;
130 *domp = NULL;
131 if (_yp_domain[0] == '\0')
132 if (getdomainname(_yp_domain, sizeof(_yp_domain)))
133 return YPERR_NODOM;
134 *domp = _yp_domain;
135 return 0;
139 _yp_check(dom)
140 char **dom;
142 char *unused;
144 if (_yp_domain[0] == '\0')
145 if (yp_get_default_domain(&unused))
146 return 0;
148 if (dom)
149 *dom = _yp_domain;
151 if (yp_bind(_yp_domain) == 0)
152 return 1;
153 return 0;
157 _yp_invalid_domain(dom)
158 const char *dom;
160 if (dom == NULL || *dom == '\0')
161 return 1;
163 if (strlen(dom) > YPMAXDOMAIN)
164 return 1;
166 if (strchr(dom, '/') != NULL)
167 return 1;
169 return 0;
173 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
174 const char *indomain;
175 const char *inmap;
176 const char *inkey;
177 int inkeylen;
178 char **outval;
179 int *outvallen;
181 *outval = NULL;
182 *outvallen = 0;
184 return YPERR_DOMAIN;
188 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
189 const char *indomain;
190 const char *inmap;
191 char **outkey;
192 int *outkeylen;
193 char **outval;
194 int *outvallen;
197 *outkey = *outval = NULL;
198 *outkeylen = *outvallen = 0;
200 return YPERR_DOMAIN;
204 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
205 const char *indomain;
206 const char *inmap;
207 const char *inkey;
208 int inkeylen;
209 char **outkey;
210 int *outkeylen;
211 char **outval;
212 int *outvallen;
214 *outkey = *outval = NULL;
215 *outkeylen = *outvallen = 0;
217 return YPERR_DOMAIN;
221 yp_all(indomain, inmap, incallback)
222 const char *indomain;
223 const char *inmap;
224 struct ypall_callback *incallback;
226 return YPERR_DOMAIN;
230 yp_order(indomain, inmap, outorder)
231 const char *indomain;
232 const char *inmap;
233 int *outorder;
235 return YPERR_DOMAIN;
239 yp_master(indomain, inmap, outname)
240 const char *indomain;
241 const char *inmap;
242 char **outname;
244 return YPERR_DOMAIN;
248 yp_maplist(indomain, outmaplist)
249 const char *indomain;
250 struct ypmaplist **outmaplist;
252 return YPERR_DOMAIN;
255 char *
256 yperr_string(incode)
257 int incode;
259 static char err[80];
261 if (incode == 0)
262 return "Success";
264 snprintf(err, sizeof(err), "YP FAKE error %d\n", incode);
265 return err;
269 ypprot_err(incode)
270 unsigned int incode;
272 switch (incode) {
273 case YP_TRUE: /* success */
274 return 0;
275 case YP_FALSE: /* failure */
276 return YPERR_YPBIND;
278 return YPERR_YPERR;