add opendir alias
[minix.git] / lib / libc / yp / xdryp.c
blob368ce948879accc828e2cf31a236e5c6fd2b0638
1 /* $NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $ */
3 /*
4 * Copyright (c) 1996 Jason R. Thorpe <thorpej@NetBSD.org>.
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.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Jason R. Thorpe.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
36 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
50 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
51 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
53 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
62 #include <sys/cdefs.h>
63 #if defined(LIBC_SCCS) && !defined(lint)
64 __RCSID("$NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $");
65 #endif
68 * XDR routines used by the YP protocol. Note that these routines do
69 * not strictly conform to the RPC definition in yp.x. This file
70 * replicates the functions exported by the Sun YP API; reality is
71 * often inaccurate.
74 #include "namespace.h"
76 #include <sys/param.h>
77 #include <sys/socket.h>
79 #include <assert.h>
80 #include <ctype.h>
81 #include <stdio.h>
82 #include <stdlib.h>
83 #include <string.h>
85 #include <rpc/rpc.h>
86 #include <rpc/xdr.h>
87 #include <rpcsvc/yp_prot.h>
88 #include <rpcsvc/ypclnt.h>
90 #ifdef __weak_alias
91 __weak_alias(xdr_datum,_xdr_datum)
92 __weak_alias(xdr_domainname,_xdr_domainname)
93 __weak_alias(xdr_mapname,_xdr_mapname)
94 __weak_alias(xdr_peername,_xdr_peername)
95 __weak_alias(xdr_yp_inaddr,_xdr_yp_inaddr)
96 __weak_alias(xdr_ypall,_xdr_ypall)
97 __weak_alias(xdr_ypbind_resp,_xdr_ypbind_resp)
98 __weak_alias(xdr_ypbind_setdom,_xdr_ypbind_setdom)
99 __weak_alias(xdr_ypdomain_wrap_string,_xdr_ypdomain_wrap_string)
100 __weak_alias(xdr_ypmap_parms,_xdr_ypmap_parms)
101 __weak_alias(xdr_ypmap_wrap_string,_xdr_ypmap_wrap_string)
102 __weak_alias(xdr_ypmaplist,_xdr_ypmaplist)
103 __weak_alias(xdr_ypowner_wrap_string,_xdr_ypowner_wrap_string)
104 __weak_alias(xdr_yppushresp_xfr,_xdr_yppushresp_xfr)
105 __weak_alias(xdr_ypreq_key,_xdr_ypreq_key)
106 __weak_alias(xdr_ypreq_nokey,_xdr_ypreq_nokey)
107 __weak_alias(xdr_ypreq_xfr,_xdr_ypreq_xfr)
108 __weak_alias(xdr_ypresp_key_val,_xdr_ypresp_key_val)
109 __weak_alias(xdr_ypresp_maplist,_xdr_ypresp_maplist)
110 __weak_alias(xdr_ypresp_master,_xdr_ypresp_master)
111 __weak_alias(xdr_ypresp_order,_xdr_ypresp_order)
112 __weak_alias(xdr_ypresp_val,_xdr_ypresp_val)
113 #endif
116 * Functions used only within this file.
118 static bool_t xdr_ypbind_binding(XDR *, struct ypbind_binding *);
119 static bool_t xdr_ypbind_resptype(XDR *, enum ypbind_resptype *);
120 static bool_t xdr_ypstat(XDR *, enum ypbind_resptype *);
121 static bool_t xdr_ypmaplist_str(XDR *, char *);
123 __warn_references(xdr_domainname,
124 "warning: this program uses xdr_domainname(), which is deprecated and buggy.")
126 bool_t
127 xdr_domainname(XDR *xdrs, char *objp)
130 _DIAGASSERT(xdrs != NULL);
131 _DIAGASSERT(objp != NULL);
133 return xdr_string(xdrs, &objp, YPMAXDOMAIN);
136 __warn_references(xdr_peername,
137 "warning: this program uses xdr_peername(), which is deprecated and buggy.")
139 bool_t
140 xdr_peername(XDR *xdrs, char *objp)
143 _DIAGASSERT(xdrs != NULL);
144 _DIAGASSERT(objp != NULL);
146 return xdr_string(xdrs, &objp, YPMAXPEER);
149 __warn_references(xdr_mapname,
150 "warning: this program uses xdr_mapname(), which is deprecated and buggy.")
152 bool_t
153 xdr_mapname(XDR *xdrs, char *objp)
156 _DIAGASSERT(xdrs != NULL);
157 _DIAGASSERT(objp != NULL);
159 return xdr_string(xdrs, &objp, YPMAXMAP);
162 bool_t
163 xdr_ypdomain_wrap_string(XDR *xdrs, char **objp)
166 _DIAGASSERT(xdrs != NULL);
167 _DIAGASSERT(objp != NULL);
169 return xdr_string(xdrs, objp, YPMAXDOMAIN);
172 bool_t
173 xdr_ypmap_wrap_string(XDR *xdrs, char **objp)
176 _DIAGASSERT(xdrs != NULL);
177 _DIAGASSERT(objp != NULL);
179 return xdr_string(xdrs, objp, YPMAXMAP);
182 bool_t
183 xdr_ypowner_wrap_string(XDR *xdrs, char **objp)
186 _DIAGASSERT(xdrs != NULL);
187 _DIAGASSERT(objp != NULL);
189 return xdr_string(xdrs, objp, YPMAXPEER);
192 bool_t
193 xdr_datum(XDR *xdrs, datum *objp)
196 _DIAGASSERT(xdrs != NULL);
197 _DIAGASSERT(objp != NULL);
199 return xdr_bytes(xdrs, __UNCONST(&objp->dptr),
200 (u_int *)&objp->dsize, YPMAXRECORD);
203 bool_t
204 xdr_ypreq_key(XDR *xdrs, struct ypreq_key *objp)
207 _DIAGASSERT(xdrs != NULL);
208 _DIAGASSERT(objp != NULL);
210 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
211 return FALSE;
213 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
214 return FALSE;
216 if (!xdr_datum(xdrs, &objp->keydat))
217 return FALSE;
219 return TRUE;
222 bool_t
223 xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *objp)
226 _DIAGASSERT(xdrs != NULL);
227 _DIAGASSERT(objp != NULL);
229 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
230 return FALSE;
232 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
233 return FALSE;
235 return TRUE;
238 bool_t
239 xdr_yp_inaddr(XDR *xdrs, struct in_addr *objp)
242 _DIAGASSERT(xdrs != NULL);
243 _DIAGASSERT(objp != NULL);
245 return xdr_opaque(xdrs, (caddr_t)(void *)&objp->s_addr,
246 (u_int)sizeof objp->s_addr);
249 static bool_t
250 xdr_ypbind_binding(XDR *xdrs, struct ypbind_binding *objp)
253 _DIAGASSERT(xdrs != NULL);
254 _DIAGASSERT(objp != NULL);
256 if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr))
257 return FALSE;
259 if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port,
260 (u_int)sizeof objp->ypbind_binding_port))
261 return FALSE;
263 return TRUE;
266 static bool_t
267 xdr_ypbind_resptype(XDR *xdrs, enum ypbind_resptype *objp)
270 _DIAGASSERT(xdrs != NULL);
271 _DIAGASSERT(objp != NULL);
273 return xdr_enum(xdrs, (enum_t *)(void *)objp);
276 static bool_t
277 xdr_ypstat(XDR *xdrs, enum ypbind_resptype *objp)
280 _DIAGASSERT(xdrs != NULL);
281 _DIAGASSERT(objp != NULL);
283 return xdr_enum(xdrs, (enum_t *)(void *)objp);
286 bool_t
287 xdr_ypbind_resp(XDR *xdrs, struct ypbind_resp *objp)
290 _DIAGASSERT(xdrs != NULL);
291 _DIAGASSERT(objp != NULL);
293 if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status))
294 return FALSE;
296 switch (objp->ypbind_status) {
297 case YPBIND_FAIL_VAL:
298 return xdr_u_int(xdrs,
299 (u_int *)&objp->ypbind_respbody.ypbind_error);
301 case YPBIND_SUCC_VAL:
302 return xdr_ypbind_binding(xdrs,
303 &objp->ypbind_respbody.ypbind_bindinfo);
305 default:
306 return FALSE;
308 /* NOTREACHED */
311 bool_t
312 xdr_ypresp_val(XDR *xdrs, struct ypresp_val *objp)
315 _DIAGASSERT(xdrs != NULL);
316 _DIAGASSERT(objp != NULL);
318 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
319 return FALSE;
321 if (!xdr_datum(xdrs, &objp->valdat))
322 return FALSE;
324 return TRUE;
327 bool_t
328 xdr_ypbind_setdom(XDR *xdrs, struct ypbind_setdom *objp)
330 char *cp;
332 _DIAGASSERT(xdrs != NULL);
333 _DIAGASSERT(objp != NULL);
335 cp = objp->ypsetdom_domain;
337 if (!xdr_ypdomain_wrap_string(xdrs, &cp))
338 return FALSE;
340 if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding))
341 return FALSE;
343 if (!xdr_u_int(xdrs, &objp->ypsetdom_vers))
344 return FALSE;
346 return TRUE;
349 bool_t
350 xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *objp)
353 _DIAGASSERT(xdrs != NULL);
354 _DIAGASSERT(objp != NULL);
356 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
357 return FALSE;
359 if (!xdr_datum(xdrs, &objp->valdat))
360 return FALSE;
362 if (!xdr_datum(xdrs, &objp->keydat))
363 return FALSE;
365 return TRUE;
368 bool_t
369 xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
371 struct ypresp_key_val out;
372 char key[YPMAXRECORD], val[YPMAXRECORD];
373 bool_t more, status;
375 _DIAGASSERT(xdrs != NULL);
376 _DIAGASSERT(incallback != NULL);
379 * Set up key/val struct to be used during the transaction.
381 memset(&out, 0, sizeof out);
382 out.keydat.dptr = key;
383 out.keydat.dsize = sizeof(key);
384 out.valdat.dptr = val;
385 out.valdat.dsize = sizeof(val);
387 for (;;) {
388 /* Values pending? */
389 if (!xdr_bool(xdrs, &more))
390 return FALSE; /* can't tell! */
391 if (!more)
392 return TRUE; /* no more */
394 /* Transfer key/value pair. */
395 status = xdr_ypresp_key_val(xdrs, &out);
398 * If we succeeded, call the callback function.
399 * The callback will return TRUE when it wants
400 * no more values. If we fail, indicate the
401 * error.
403 if (status) {
404 if ((*incallback->foreach)((int)out.status,
405 __UNCONST(out.keydat.dptr), out.keydat.dsize,
406 __UNCONST(out.valdat.dptr), out.valdat.dsize,
407 incallback->data))
408 return TRUE;
409 } else
410 return FALSE;
414 bool_t
415 xdr_ypresp_master(XDR *xdrs, struct ypresp_master *objp)
418 _DIAGASSERT(xdrs != NULL);
419 _DIAGASSERT(objp != NULL);
421 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
422 return FALSE;
424 if (!xdr_string(xdrs, &objp->master, YPMAXPEER))
425 return FALSE;
427 return TRUE;
430 static bool_t
431 xdr_ypmaplist_str(XDR *xdrs, char *objp)
434 _DIAGASSERT(xdrs != NULL);
435 _DIAGASSERT(objp != NULL);
437 return xdr_string(xdrs, &objp, YPMAXMAP+1);
440 bool_t
441 xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp)
444 _DIAGASSERT(xdrs != NULL);
445 _DIAGASSERT(objp != NULL);
447 if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
448 return FALSE;
450 if (!xdr_pointer(xdrs, (char **)(void *)&objp->ypml_next,
451 (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
452 return FALSE;
454 return TRUE;
457 bool_t
458 xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp)
461 _DIAGASSERT(xdrs != NULL);
462 _DIAGASSERT(objp != NULL);
464 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
465 return FALSE;
467 if (!xdr_pointer(xdrs, (char **)(void *)&objp->list,
468 (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
469 return FALSE;
471 return TRUE;
474 bool_t
475 xdr_ypresp_order(XDR *xdrs, struct ypresp_order *objp)
478 _DIAGASSERT(xdrs != NULL);
479 _DIAGASSERT(objp != NULL);
481 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
482 return FALSE;
484 if (!xdr_u_int(xdrs, &objp->ordernum))
485 return FALSE;
487 return TRUE;
490 bool_t
491 xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *objp)
494 _DIAGASSERT(xdrs != NULL);
495 _DIAGASSERT(objp != NULL);
497 if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
498 return FALSE;
500 if (!xdr_u_int(xdrs, &objp->transid))
501 return FALSE;
503 if (!xdr_u_int(xdrs, &objp->proto))
504 return FALSE;
506 if (!xdr_u_int(xdrs, &objp->port))
507 return FALSE;
509 return TRUE;
512 bool_t
513 xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *objp)
516 _DIAGASSERT(xdrs != NULL);
517 _DIAGASSERT(objp != NULL);
519 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
520 return FALSE;
522 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
523 return FALSE;
525 if (!xdr_u_int(xdrs, &objp->ordernum))
526 return FALSE;
528 if (!xdr_ypowner_wrap_string(xdrs, &objp->owner))
529 return FALSE;
531 return TRUE;
534 bool_t
535 xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *objp)
538 _DIAGASSERT(xdrs != NULL);
539 _DIAGASSERT(objp != NULL);
541 if (!xdr_u_int(xdrs, &objp->transid))
542 return FALSE;
544 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
545 return FALSE;
547 return TRUE;