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