1 /* $NetBSD: yplib.c,v 1.4 2003/08/06 13:43:32 itojun 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
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:
37 * (and then completely gutted! 8^)
39 #include <sys/cdefs.h>
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
56 #include <sys/types.h>
66 #include <rpcsvc/yp_prot.h>
67 #include <rpcsvc/ypclnt.h>
69 struct dom_binding
*_ypbindlist
;
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
};
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
);
96 void __yp_unbind
__P((struct dom_binding
*));
97 int _yp_invalid_domain
__P((const char *));
100 _yp_dobind(dom
, ypdb
)
102 struct dom_binding
**ypdb
;
109 struct dom_binding
*ypb
;
117 return _yp_dobind(dom
, NULL
);
127 yp_get_default_domain(domp
)
131 if (_yp_domain
[0] == '\0')
132 if (getdomainname(_yp_domain
, sizeof(_yp_domain
)))
144 if (_yp_domain
[0] == '\0')
145 if (yp_get_default_domain(&unused
))
151 if (yp_bind(_yp_domain
) == 0)
157 _yp_invalid_domain(dom
)
160 if (dom
== NULL
|| *dom
== '\0')
163 if (strlen(dom
) > YPMAXDOMAIN
)
166 if (strchr(dom
, '/') != NULL
)
173 yp_match(indomain
, inmap
, inkey
, inkeylen
, outval
, outvallen
)
174 const char *indomain
;
188 yp_first(indomain
, inmap
, outkey
, outkeylen
, outval
, outvallen
)
189 const char *indomain
;
197 *outkey
= *outval
= NULL
;
198 *outkeylen
= *outvallen
= 0;
204 yp_next(indomain
, inmap
, inkey
, inkeylen
, outkey
, outkeylen
, outval
, outvallen
)
205 const char *indomain
;
214 *outkey
= *outval
= NULL
;
215 *outkeylen
= *outvallen
= 0;
221 yp_all(indomain
, inmap
, incallback
)
222 const char *indomain
;
224 struct ypall_callback
*incallback
;
230 yp_order(indomain
, inmap
, outorder
)
231 const char *indomain
;
239 yp_master(indomain
, inmap
, outname
)
240 const char *indomain
;
248 yp_maplist(indomain
, outmaplist
)
249 const char *indomain
;
250 struct ypmaplist
**outmaplist
;
264 snprintf(err
, sizeof(err
), "YP FAKE error %d\n", incode
);
273 case YP_TRUE
: /* success */
275 case YP_FALSE
: /* failure */