Fix mdoc(7)/man(7) mix up.
[netbsd-mini2440.git] / lib / libc / yp / xdryp.c
blob8dbaed42723aeeffbd68ae8568724ac3d9d72cfc
1 /* $NetBSD: xdryp.c,v 1.29 2005/11/29 03:12:01 christos 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.29 2005/11/29 03:12:01 christos 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 __P((XDR *, struct ypbind_binding *));
119 static bool_t xdr_ypbind_resptype __P((XDR *, enum ypbind_resptype *));
120 static bool_t xdr_ypstat __P((XDR *, enum ypbind_resptype *));
121 static bool_t xdr_ypmaplist_str __P((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(xdrs, objp)
128 XDR *xdrs;
129 char *objp;
132 _DIAGASSERT(xdrs != NULL);
133 _DIAGASSERT(objp != NULL);
135 return xdr_string(xdrs, &objp, YPMAXDOMAIN);
138 __warn_references(xdr_peername,
139 "warning: this program uses xdr_peername(), which is deprecated and buggy.")
141 bool_t
142 xdr_peername(xdrs, objp)
143 XDR *xdrs;
144 char *objp;
147 _DIAGASSERT(xdrs != NULL);
148 _DIAGASSERT(objp != NULL);
150 return xdr_string(xdrs, &objp, YPMAXPEER);
153 __warn_references(xdr_mapname,
154 "warning: this program uses xdr_mapname(), which is deprecated and buggy.")
156 bool_t
157 xdr_mapname(xdrs, objp)
158 XDR *xdrs;
159 char *objp;
162 _DIAGASSERT(xdrs != NULL);
163 _DIAGASSERT(objp != NULL);
165 return xdr_string(xdrs, &objp, YPMAXMAP);
168 bool_t
169 xdr_ypdomain_wrap_string(xdrs, objp)
170 XDR *xdrs;
171 char **objp;
174 _DIAGASSERT(xdrs != NULL);
175 _DIAGASSERT(objp != NULL);
177 return xdr_string(xdrs, objp, YPMAXDOMAIN);
180 bool_t
181 xdr_ypmap_wrap_string(xdrs, objp)
182 XDR *xdrs;
183 char **objp;
186 _DIAGASSERT(xdrs != NULL);
187 _DIAGASSERT(objp != NULL);
189 return xdr_string(xdrs, objp, YPMAXMAP);
192 bool_t
193 xdr_ypowner_wrap_string(xdrs, objp)
194 XDR *xdrs;
195 char **objp;
198 _DIAGASSERT(xdrs != NULL);
199 _DIAGASSERT(objp != NULL);
201 return xdr_string(xdrs, objp, YPMAXPEER);
204 bool_t
205 xdr_datum(xdrs, objp)
206 XDR *xdrs;
207 datum *objp;
210 _DIAGASSERT(xdrs != NULL);
211 _DIAGASSERT(objp != NULL);
213 return xdr_bytes(xdrs, __UNCONST(&objp->dptr),
214 (u_int *)&objp->dsize, YPMAXRECORD);
217 bool_t
218 xdr_ypreq_key(xdrs, objp)
219 XDR *xdrs;
220 struct ypreq_key *objp;
223 _DIAGASSERT(xdrs != NULL);
224 _DIAGASSERT(objp != NULL);
226 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
227 return FALSE;
229 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
230 return FALSE;
232 if (!xdr_datum(xdrs, &objp->keydat))
233 return FALSE;
235 return TRUE;
238 bool_t
239 xdr_ypreq_nokey(xdrs, objp)
240 XDR *xdrs;
241 struct ypreq_nokey *objp;
244 _DIAGASSERT(xdrs != NULL);
245 _DIAGASSERT(objp != NULL);
247 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
248 return FALSE;
250 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
251 return FALSE;
253 return TRUE;
256 bool_t
257 xdr_yp_inaddr(xdrs, objp)
258 XDR *xdrs;
259 struct in_addr *objp;
262 _DIAGASSERT(xdrs != NULL);
263 _DIAGASSERT(objp != NULL);
265 return xdr_opaque(xdrs, (caddr_t)(void *)&objp->s_addr,
266 sizeof objp->s_addr);
269 static bool_t
270 xdr_ypbind_binding(xdrs, objp)
271 XDR *xdrs;
272 struct ypbind_binding *objp;
275 _DIAGASSERT(xdrs != NULL);
276 _DIAGASSERT(objp != NULL);
278 if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr))
279 return FALSE;
281 if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port,
282 sizeof objp->ypbind_binding_port))
283 return FALSE;
285 return TRUE;
288 static bool_t
289 xdr_ypbind_resptype(xdrs, objp)
290 XDR *xdrs;
291 enum ypbind_resptype *objp;
294 _DIAGASSERT(xdrs != NULL);
295 _DIAGASSERT(objp != NULL);
297 return xdr_enum(xdrs, (enum_t *)(void *)objp);
300 static bool_t
301 xdr_ypstat(xdrs, objp)
302 XDR *xdrs;
303 enum ypbind_resptype *objp;
306 _DIAGASSERT(xdrs != NULL);
307 _DIAGASSERT(objp != NULL);
309 return xdr_enum(xdrs, (enum_t *)(void *)objp);
312 bool_t
313 xdr_ypbind_resp(xdrs, objp)
314 XDR *xdrs;
315 struct ypbind_resp *objp;
318 _DIAGASSERT(xdrs != NULL);
319 _DIAGASSERT(objp != NULL);
321 if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status))
322 return FALSE;
324 switch (objp->ypbind_status) {
325 case YPBIND_FAIL_VAL:
326 return xdr_u_int(xdrs,
327 (u_int *)&objp->ypbind_respbody.ypbind_error);
329 case YPBIND_SUCC_VAL:
330 return xdr_ypbind_binding(xdrs,
331 &objp->ypbind_respbody.ypbind_bindinfo);
333 default:
334 return FALSE;
336 /* NOTREACHED */
339 bool_t
340 xdr_ypresp_val(xdrs, objp)
341 XDR *xdrs;
342 struct ypresp_val *objp;
345 _DIAGASSERT(xdrs != NULL);
346 _DIAGASSERT(objp != NULL);
348 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
349 return FALSE;
351 if (!xdr_datum(xdrs, &objp->valdat))
352 return FALSE;
354 return TRUE;
357 bool_t
358 xdr_ypbind_setdom(xdrs, objp)
359 XDR *xdrs;
360 struct ypbind_setdom *objp;
362 char *cp;
364 _DIAGASSERT(xdrs != NULL);
365 _DIAGASSERT(objp != NULL);
367 cp = objp->ypsetdom_domain;
369 if (!xdr_ypdomain_wrap_string(xdrs, &cp))
370 return FALSE;
372 if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding))
373 return FALSE;
375 if (!xdr_u_int(xdrs, &objp->ypsetdom_vers))
376 return FALSE;
378 return TRUE;
381 bool_t
382 xdr_ypresp_key_val(xdrs, objp)
383 XDR *xdrs;
384 struct ypresp_key_val *objp;
387 _DIAGASSERT(xdrs != NULL);
388 _DIAGASSERT(objp != NULL);
390 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
391 return FALSE;
393 if (!xdr_datum(xdrs, &objp->valdat))
394 return FALSE;
396 if (!xdr_datum(xdrs, &objp->keydat))
397 return FALSE;
399 return TRUE;
402 bool_t
403 xdr_ypall(xdrs, incallback)
404 XDR *xdrs;
405 struct ypall_callback *incallback;
407 struct ypresp_key_val out;
408 char key[YPMAXRECORD], val[YPMAXRECORD];
409 bool_t more, status;
411 _DIAGASSERT(xdrs != NULL);
412 _DIAGASSERT(incallback != NULL);
415 * Set up key/val struct to be used during the transaction.
417 memset(&out, 0, sizeof out);
418 out.keydat.dptr = key;
419 out.keydat.dsize = sizeof(key);
420 out.valdat.dptr = val;
421 out.valdat.dsize = sizeof(val);
423 for (;;) {
424 /* Values pending? */
425 if (!xdr_bool(xdrs, &more))
426 return FALSE; /* can't tell! */
427 if (!more)
428 return TRUE; /* no more */
430 /* Transfer key/value pair. */
431 status = xdr_ypresp_key_val(xdrs, &out);
434 * If we succeeded, call the callback function.
435 * The callback will return TRUE when it wants
436 * no more values. If we fail, indicate the
437 * error.
439 if (status) {
440 if ((*incallback->foreach)((int)out.status,
441 __UNCONST(out.keydat.dptr), out.keydat.dsize,
442 __UNCONST(out.valdat.dptr), out.valdat.dsize,
443 incallback->data))
444 return TRUE;
445 } else
446 return FALSE;
450 bool_t
451 xdr_ypresp_master(xdrs, objp)
452 XDR *xdrs;
453 struct ypresp_master *objp;
456 _DIAGASSERT(xdrs != NULL);
457 _DIAGASSERT(objp != NULL);
459 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
460 return FALSE;
462 if (!xdr_string(xdrs, &objp->master, YPMAXPEER))
463 return FALSE;
465 return TRUE;
468 static bool_t
469 xdr_ypmaplist_str(xdrs, objp)
470 XDR *xdrs;
471 char *objp;
474 _DIAGASSERT(xdrs != NULL);
475 _DIAGASSERT(objp != NULL);
477 return xdr_string(xdrs, &objp, YPMAXMAP+1);
480 bool_t
481 xdr_ypmaplist(xdrs, objp)
482 XDR *xdrs;
483 struct ypmaplist *objp;
486 _DIAGASSERT(xdrs != NULL);
487 _DIAGASSERT(objp != NULL);
489 if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
490 return FALSE;
492 if (!xdr_pointer(xdrs, (char **)(void *)&objp->ypml_next,
493 sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
494 return FALSE;
496 return TRUE;
499 bool_t
500 xdr_ypresp_maplist(xdrs, objp)
501 XDR *xdrs;
502 struct ypresp_maplist *objp;
505 _DIAGASSERT(xdrs != NULL);
506 _DIAGASSERT(objp != NULL);
508 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
509 return FALSE;
511 if (!xdr_pointer(xdrs, (char **)(void *)&objp->list,
512 sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
513 return FALSE;
515 return TRUE;
518 bool_t
519 xdr_ypresp_order(xdrs, objp)
520 XDR *xdrs;
521 struct ypresp_order *objp;
524 _DIAGASSERT(xdrs != NULL);
525 _DIAGASSERT(objp != NULL);
527 if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
528 return FALSE;
530 if (!xdr_u_int(xdrs, &objp->ordernum))
531 return FALSE;
533 return TRUE;
536 bool_t
537 xdr_ypreq_xfr(xdrs, objp)
538 XDR *xdrs;
539 struct ypreq_xfr *objp;
542 _DIAGASSERT(xdrs != NULL);
543 _DIAGASSERT(objp != NULL);
545 if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
546 return FALSE;
548 if (!xdr_u_int(xdrs, &objp->transid))
549 return FALSE;
551 if (!xdr_u_int(xdrs, &objp->proto))
552 return FALSE;
554 if (!xdr_u_int(xdrs, &objp->port))
555 return FALSE;
557 return TRUE;
560 bool_t
561 xdr_ypmap_parms(xdrs, objp)
562 XDR *xdrs;
563 struct ypmap_parms *objp;
566 _DIAGASSERT(xdrs != NULL);
567 _DIAGASSERT(objp != NULL);
569 if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
570 return FALSE;
572 if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
573 return FALSE;
575 if (!xdr_u_int(xdrs, &objp->ordernum))
576 return FALSE;
578 if (!xdr_ypowner_wrap_string(xdrs, &objp->owner))
579 return FALSE;
581 return TRUE;
584 bool_t
585 xdr_yppushresp_xfr(xdrs, objp)
586 XDR *xdrs;
587 struct yppushresp_xfr *objp;
590 _DIAGASSERT(xdrs != NULL);
591 _DIAGASSERT(objp != NULL);
593 if (!xdr_u_int(xdrs, &objp->transid))
594 return FALSE;
596 if (!xdr_enum(xdrs, (enum_t *)&objp->status))
597 return FALSE;
599 return TRUE;