1*8147d218Smatt /* $NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $ */
2693e99f7Scgd
377c037edSderaadt /*
439d96c1fSkeihan * Copyright (c) 1996 Jason R. Thorpe <thorpej@NetBSD.org>.
57a26f6a8Sthorpej * All rights reserved.
67a26f6a8Sthorpej *
777c037edSderaadt * Redistribution and use in source and binary forms, with or without
877c037edSderaadt * modification, are permitted provided that the following conditions
977c037edSderaadt * are met:
1077c037edSderaadt * 1. Redistributions of source code must retain the above copyright
1177c037edSderaadt * notice, this list of conditions and the following disclaimer.
1277c037edSderaadt * 2. Redistributions in binary form must reproduce the above copyright
1377c037edSderaadt * notice, this list of conditions and the following disclaimer in the
1477c037edSderaadt * documentation and/or other materials provided with the distribution.
153bf2b62fSderaadt * 3. All advertising materials mentioning features or use of this software
163bf2b62fSderaadt * must display the following acknowledgement:
177a26f6a8Sthorpej * This product includes software developed for the NetBSD Project
187a26f6a8Sthorpej * by Jason R. Thorpe.
193bf2b62fSderaadt * 4. The name of the author may not be used to endorse or promote products
203bf2b62fSderaadt * derived from this software without specific prior written permission.
2177c037edSderaadt *
2277c037edSderaadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
2377c037edSderaadt * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2477c037edSderaadt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2577c037edSderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
2677c037edSderaadt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2777c037edSderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2877c037edSderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2977c037edSderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3077c037edSderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3177c037edSderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3277c037edSderaadt * SUCH DAMAGE.
3377c037edSderaadt */
3477c037edSderaadt
357db1d33cSagc /*
367db1d33cSagc * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
377db1d33cSagc * All rights reserved.
387db1d33cSagc *
397db1d33cSagc * Redistribution and use in source and binary forms, with or without
407db1d33cSagc * modification, are permitted provided that the following conditions
417db1d33cSagc * are met:
427db1d33cSagc * 1. Redistributions of source code must retain the above copyright
437db1d33cSagc * notice, this list of conditions and the following disclaimer.
447db1d33cSagc * 2. Redistributions in binary form must reproduce the above copyright
457db1d33cSagc * notice, this list of conditions and the following disclaimer in the
467db1d33cSagc * documentation and/or other materials provided with the distribution.
477db1d33cSagc *
487db1d33cSagc *
497db1d33cSagc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
507db1d33cSagc * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
517db1d33cSagc * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
527db1d33cSagc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
537db1d33cSagc * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
547db1d33cSagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
557db1d33cSagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
567db1d33cSagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
577db1d33cSagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
587db1d33cSagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
597db1d33cSagc * SUCH DAMAGE.
607db1d33cSagc */
617db1d33cSagc
62e7cc5503Schristos #include <sys/cdefs.h>
636bb5d0a0Sjtc #if defined(LIBC_SCCS) && !defined(lint)
64*8147d218Smatt __RCSID("$NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt Exp $");
6577c037edSderaadt #endif
6677c037edSderaadt
677a26f6a8Sthorpej /*
687a26f6a8Sthorpej * XDR routines used by the YP protocol. Note that these routines do
697a26f6a8Sthorpej * not strictly conform to the RPC definition in yp.x. This file
707a26f6a8Sthorpej * replicates the functions exported by the Sun YP API; reality is
717a26f6a8Sthorpej * often inaccurate.
727a26f6a8Sthorpej */
737a26f6a8Sthorpej
7443fa6fe3Sjtc #include "namespace.h"
75b48252f3Slukem
7642d384baSderaadt #include <sys/param.h>
7742d384baSderaadt #include <sys/socket.h>
78b48252f3Slukem
79b48252f3Slukem #include <assert.h>
80b48252f3Slukem #include <ctype.h>
8142d384baSderaadt #include <stdio.h>
82fac4c46fSjtc #include <stdlib.h>
83fac4c46fSjtc #include <string.h>
84b48252f3Slukem
8542d384baSderaadt #include <rpc/rpc.h>
8642d384baSderaadt #include <rpc/xdr.h>
8742d384baSderaadt #include <rpcsvc/yp_prot.h>
8842d384baSderaadt #include <rpcsvc/ypclnt.h>
8942d384baSderaadt
9043fa6fe3Sjtc #ifdef __weak_alias
9160549036Smycroft __weak_alias(xdr_datum,_xdr_datum)
9260549036Smycroft __weak_alias(xdr_domainname,_xdr_domainname)
9360549036Smycroft __weak_alias(xdr_mapname,_xdr_mapname)
9460549036Smycroft __weak_alias(xdr_peername,_xdr_peername)
9560549036Smycroft __weak_alias(xdr_yp_inaddr,_xdr_yp_inaddr)
9660549036Smycroft __weak_alias(xdr_ypall,_xdr_ypall)
9760549036Smycroft __weak_alias(xdr_ypbind_resp,_xdr_ypbind_resp)
9860549036Smycroft __weak_alias(xdr_ypbind_setdom,_xdr_ypbind_setdom)
9960549036Smycroft __weak_alias(xdr_ypdomain_wrap_string,_xdr_ypdomain_wrap_string)
10060549036Smycroft __weak_alias(xdr_ypmap_parms,_xdr_ypmap_parms)
10160549036Smycroft __weak_alias(xdr_ypmap_wrap_string,_xdr_ypmap_wrap_string)
10260549036Smycroft __weak_alias(xdr_ypmaplist,_xdr_ypmaplist)
10360549036Smycroft __weak_alias(xdr_ypowner_wrap_string,_xdr_ypowner_wrap_string)
10460549036Smycroft __weak_alias(xdr_yppushresp_xfr,_xdr_yppushresp_xfr)
10560549036Smycroft __weak_alias(xdr_ypreq_key,_xdr_ypreq_key)
10660549036Smycroft __weak_alias(xdr_ypreq_nokey,_xdr_ypreq_nokey)
10760549036Smycroft __weak_alias(xdr_ypreq_xfr,_xdr_ypreq_xfr)
10860549036Smycroft __weak_alias(xdr_ypresp_key_val,_xdr_ypresp_key_val)
10960549036Smycroft __weak_alias(xdr_ypresp_maplist,_xdr_ypresp_maplist)
11060549036Smycroft __weak_alias(xdr_ypresp_master,_xdr_ypresp_master)
11160549036Smycroft __weak_alias(xdr_ypresp_order,_xdr_ypresp_order)
11260549036Smycroft __weak_alias(xdr_ypresp_val,_xdr_ypresp_val)
11343fa6fe3Sjtc #endif
11443fa6fe3Sjtc
1157a26f6a8Sthorpej /*
1167a26f6a8Sthorpej * Functions used only within this file.
1177a26f6a8Sthorpej */
118*8147d218Smatt static bool_t xdr_ypbind_binding(XDR *, struct ypbind_binding *);
119*8147d218Smatt static bool_t xdr_ypbind_resptype(XDR *, enum ypbind_resptype *);
120*8147d218Smatt static bool_t xdr_ypstat(XDR *, enum ypbind_resptype *);
121*8147d218Smatt static bool_t xdr_ypmaplist_str(XDR *, char *);
1227a26f6a8Sthorpej
12314cd9988Sthorpej __warn_references(xdr_domainname,
1242a43f220Sthorpej "warning: this program uses xdr_domainname(), which is deprecated and buggy.")
12514cd9988Sthorpej
12614cd9988Sthorpej bool_t
xdr_domainname(XDR * xdrs,char * objp)127c5e820caSchristos xdr_domainname(XDR *xdrs, char *objp)
12814cd9988Sthorpej {
129b48252f3Slukem
130b48252f3Slukem _DIAGASSERT(xdrs != NULL);
131b48252f3Slukem _DIAGASSERT(objp != NULL);
132b48252f3Slukem
13314cd9988Sthorpej return xdr_string(xdrs, &objp, YPMAXDOMAIN);
13414cd9988Sthorpej }
13514cd9988Sthorpej
13614cd9988Sthorpej __warn_references(xdr_peername,
1372a43f220Sthorpej "warning: this program uses xdr_peername(), which is deprecated and buggy.")
13814cd9988Sthorpej
13914cd9988Sthorpej bool_t
xdr_peername(XDR * xdrs,char * objp)140c5e820caSchristos xdr_peername(XDR *xdrs, char *objp)
14114cd9988Sthorpej {
142b48252f3Slukem
143b48252f3Slukem _DIAGASSERT(xdrs != NULL);
144b48252f3Slukem _DIAGASSERT(objp != NULL);
145b48252f3Slukem
14614cd9988Sthorpej return xdr_string(xdrs, &objp, YPMAXPEER);
14714cd9988Sthorpej }
14814cd9988Sthorpej
14914cd9988Sthorpej __warn_references(xdr_mapname,
1502a43f220Sthorpej "warning: this program uses xdr_mapname(), which is deprecated and buggy.")
15114cd9988Sthorpej
15214cd9988Sthorpej bool_t
xdr_mapname(XDR * xdrs,char * objp)153c5e820caSchristos xdr_mapname(XDR *xdrs, char *objp)
15414cd9988Sthorpej {
155b48252f3Slukem
156b48252f3Slukem _DIAGASSERT(xdrs != NULL);
157b48252f3Slukem _DIAGASSERT(objp != NULL);
158b48252f3Slukem
15914cd9988Sthorpej return xdr_string(xdrs, &objp, YPMAXMAP);
16014cd9988Sthorpej }
16114cd9988Sthorpej
1627a26f6a8Sthorpej bool_t
xdr_ypdomain_wrap_string(XDR * xdrs,char ** objp)163c5e820caSchristos xdr_ypdomain_wrap_string(XDR *xdrs, char **objp)
1647a26f6a8Sthorpej {
165b48252f3Slukem
166b48252f3Slukem _DIAGASSERT(xdrs != NULL);
167b48252f3Slukem _DIAGASSERT(objp != NULL);
168b48252f3Slukem
1697a26f6a8Sthorpej return xdr_string(xdrs, objp, YPMAXDOMAIN);
1707a26f6a8Sthorpej }
1717a26f6a8Sthorpej
1727a26f6a8Sthorpej bool_t
xdr_ypmap_wrap_string(XDR * xdrs,char ** objp)173c5e820caSchristos xdr_ypmap_wrap_string(XDR *xdrs, char **objp)
1747a26f6a8Sthorpej {
175b48252f3Slukem
176b48252f3Slukem _DIAGASSERT(xdrs != NULL);
177b48252f3Slukem _DIAGASSERT(objp != NULL);
178b48252f3Slukem
1797a26f6a8Sthorpej return xdr_string(xdrs, objp, YPMAXMAP);
1807a26f6a8Sthorpej }
1817a26f6a8Sthorpej
1827a26f6a8Sthorpej bool_t
xdr_ypowner_wrap_string(XDR * xdrs,char ** objp)183c5e820caSchristos xdr_ypowner_wrap_string(XDR *xdrs, char **objp)
1847a26f6a8Sthorpej {
185b48252f3Slukem
186b48252f3Slukem _DIAGASSERT(xdrs != NULL);
187b48252f3Slukem _DIAGASSERT(objp != NULL);
188b48252f3Slukem
1897a26f6a8Sthorpej return xdr_string(xdrs, objp, YPMAXPEER);
1907a26f6a8Sthorpej }
1917a26f6a8Sthorpej
19242d384baSderaadt bool_t
xdr_datum(XDR * xdrs,datum * objp)193c5e820caSchristos xdr_datum(XDR *xdrs, datum *objp)
19442d384baSderaadt {
195b48252f3Slukem
196b48252f3Slukem _DIAGASSERT(xdrs != NULL);
197b48252f3Slukem _DIAGASSERT(objp != NULL);
198b48252f3Slukem
19903256c6eSchristos return xdr_bytes(xdrs, __UNCONST(&objp->dptr),
200a667b8f7Schristos (u_int *)&objp->dsize, YPMAXRECORD);
20142d384baSderaadt }
20242d384baSderaadt
20342d384baSderaadt bool_t
xdr_ypreq_key(XDR * xdrs,struct ypreq_key * objp)204c5e820caSchristos xdr_ypreq_key(XDR *xdrs, struct ypreq_key *objp)
20542d384baSderaadt {
206b48252f3Slukem
207b48252f3Slukem _DIAGASSERT(xdrs != NULL);
208b48252f3Slukem _DIAGASSERT(objp != NULL);
209b48252f3Slukem
21003256c6eSchristos if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
211a667b8f7Schristos return FALSE;
2127a26f6a8Sthorpej
21303256c6eSchristos if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
214a667b8f7Schristos return FALSE;
2157a26f6a8Sthorpej
2161d4349e7Schristos if (!xdr_datum(xdrs, &objp->keydat))
2171d4349e7Schristos return FALSE;
2181d4349e7Schristos
2191d4349e7Schristos return TRUE;
22042d384baSderaadt }
22142d384baSderaadt
22242d384baSderaadt bool_t
xdr_ypreq_nokey(XDR * xdrs,struct ypreq_nokey * objp)223c5e820caSchristos xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *objp)
22442d384baSderaadt {
225b48252f3Slukem
226b48252f3Slukem _DIAGASSERT(xdrs != NULL);
227b48252f3Slukem _DIAGASSERT(objp != NULL);
228b48252f3Slukem
22903256c6eSchristos if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
230a667b8f7Schristos return FALSE;
2317a26f6a8Sthorpej
23203256c6eSchristos if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
2331d4349e7Schristos return FALSE;
2341d4349e7Schristos
2351d4349e7Schristos return TRUE;
23642d384baSderaadt }
23742d384baSderaadt
23842d384baSderaadt bool_t
xdr_yp_inaddr(XDR * xdrs,struct in_addr * objp)239c5e820caSchristos xdr_yp_inaddr(XDR *xdrs, struct in_addr *objp)
24042d384baSderaadt {
241b48252f3Slukem
242b48252f3Slukem _DIAGASSERT(xdrs != NULL);
243b48252f3Slukem _DIAGASSERT(objp != NULL);
244b48252f3Slukem
245f4c14791Schristos return xdr_opaque(xdrs, (caddr_t)(void *)&objp->s_addr,
246c5e820caSchristos (u_int)sizeof objp->s_addr);
24742d384baSderaadt }
24842d384baSderaadt
2497a26f6a8Sthorpej static bool_t
xdr_ypbind_binding(XDR * xdrs,struct ypbind_binding * objp)250c5e820caSchristos xdr_ypbind_binding(XDR *xdrs, struct ypbind_binding *objp)
25142d384baSderaadt {
252b48252f3Slukem
253b48252f3Slukem _DIAGASSERT(xdrs != NULL);
254b48252f3Slukem _DIAGASSERT(objp != NULL);
255b48252f3Slukem
2567a26f6a8Sthorpej if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr))
257a667b8f7Schristos return FALSE;
2587a26f6a8Sthorpej
2591d4349e7Schristos if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port,
260c5e820caSchristos (u_int)sizeof objp->ypbind_binding_port))
2611d4349e7Schristos return FALSE;
2621d4349e7Schristos
2631d4349e7Schristos return TRUE;
26442d384baSderaadt }
26542d384baSderaadt
2667a26f6a8Sthorpej static bool_t
xdr_ypbind_resptype(XDR * xdrs,enum ypbind_resptype * objp)267c5e820caSchristos xdr_ypbind_resptype(XDR *xdrs, enum ypbind_resptype *objp)
26842d384baSderaadt {
269b48252f3Slukem
270b48252f3Slukem _DIAGASSERT(xdrs != NULL);
271b48252f3Slukem _DIAGASSERT(objp != NULL);
272b48252f3Slukem
27325cb0b1eSchristos return xdr_enum(xdrs, (enum_t *)(void *)objp);
27442d384baSderaadt }
27542d384baSderaadt
2767a26f6a8Sthorpej static bool_t
xdr_ypstat(XDR * xdrs,enum ypbind_resptype * objp)277c5e820caSchristos xdr_ypstat(XDR *xdrs, enum ypbind_resptype *objp)
27842d384baSderaadt {
279b48252f3Slukem
280b48252f3Slukem _DIAGASSERT(xdrs != NULL);
281b48252f3Slukem _DIAGASSERT(objp != NULL);
282b48252f3Slukem
28325cb0b1eSchristos return xdr_enum(xdrs, (enum_t *)(void *)objp);
28442d384baSderaadt }
28542d384baSderaadt
28642d384baSderaadt bool_t
xdr_ypbind_resp(XDR * xdrs,struct ypbind_resp * objp)287c5e820caSchristos xdr_ypbind_resp(XDR *xdrs, struct ypbind_resp *objp)
28842d384baSderaadt {
289b48252f3Slukem
290b48252f3Slukem _DIAGASSERT(xdrs != NULL);
291b48252f3Slukem _DIAGASSERT(objp != NULL);
292b48252f3Slukem
2937a26f6a8Sthorpej if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status))
294a667b8f7Schristos return FALSE;
295a667b8f7Schristos
29642d384baSderaadt switch (objp->ypbind_status) {
29742d384baSderaadt case YPBIND_FAIL_VAL:
298a667b8f7Schristos return xdr_u_int(xdrs,
299a667b8f7Schristos (u_int *)&objp->ypbind_respbody.ypbind_error);
3007a26f6a8Sthorpej
30142d384baSderaadt case YPBIND_SUCC_VAL:
302a667b8f7Schristos return xdr_ypbind_binding(xdrs,
303a667b8f7Schristos &objp->ypbind_respbody.ypbind_bindinfo);
3047a26f6a8Sthorpej
30542d384baSderaadt default:
306a667b8f7Schristos return FALSE;
30742d384baSderaadt }
308fac4c46fSjtc /* NOTREACHED */
30942d384baSderaadt }
31042d384baSderaadt
31142d384baSderaadt bool_t
xdr_ypresp_val(XDR * xdrs,struct ypresp_val * objp)312c5e820caSchristos xdr_ypresp_val(XDR *xdrs, struct ypresp_val *objp)
31342d384baSderaadt {
314b48252f3Slukem
315b48252f3Slukem _DIAGASSERT(xdrs != NULL);
316b48252f3Slukem _DIAGASSERT(objp != NULL);
317b48252f3Slukem
31825cb0b1eSchristos if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
319a667b8f7Schristos return FALSE;
3207a26f6a8Sthorpej
3211d4349e7Schristos if (!xdr_datum(xdrs, &objp->valdat))
3221d4349e7Schristos return FALSE;
3231d4349e7Schristos
3241d4349e7Schristos return TRUE;
32542d384baSderaadt }
32642d384baSderaadt
32742d384baSderaadt bool_t
xdr_ypbind_setdom(XDR * xdrs,struct ypbind_setdom * objp)328c5e820caSchristos xdr_ypbind_setdom(XDR *xdrs, struct ypbind_setdom *objp)
32942d384baSderaadt {
330b48252f3Slukem char *cp;
331b48252f3Slukem
332b48252f3Slukem _DIAGASSERT(xdrs != NULL);
333b48252f3Slukem _DIAGASSERT(objp != NULL);
334b48252f3Slukem
335b48252f3Slukem cp = objp->ypsetdom_domain;
3367a26f6a8Sthorpej
3371d4349e7Schristos if (!xdr_ypdomain_wrap_string(xdrs, &cp))
338a667b8f7Schristos return FALSE;
3397a26f6a8Sthorpej
3407a26f6a8Sthorpej if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding))
341a667b8f7Schristos return FALSE;
3427a26f6a8Sthorpej
343bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->ypsetdom_vers))
3441d4349e7Schristos return FALSE;
3451d4349e7Schristos
3461d4349e7Schristos return TRUE;
34742d384baSderaadt }
34842d384baSderaadt
34942d384baSderaadt bool_t
xdr_ypresp_key_val(XDR * xdrs,struct ypresp_key_val * objp)350c5e820caSchristos xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *objp)
35142d384baSderaadt {
352b48252f3Slukem
353b48252f3Slukem _DIAGASSERT(xdrs != NULL);
354b48252f3Slukem _DIAGASSERT(objp != NULL);
355b48252f3Slukem
35625cb0b1eSchristos if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
357a667b8f7Schristos return FALSE;
3587a26f6a8Sthorpej
3597a26f6a8Sthorpej if (!xdr_datum(xdrs, &objp->valdat))
360a667b8f7Schristos return FALSE;
3617a26f6a8Sthorpej
3621d4349e7Schristos if (!xdr_datum(xdrs, &objp->keydat))
3631d4349e7Schristos return FALSE;
3641d4349e7Schristos
3651d4349e7Schristos return TRUE;
36642d384baSderaadt }
36742d384baSderaadt
36842d384baSderaadt bool_t
xdr_ypall(XDR * xdrs,struct ypall_callback * incallback)369c5e820caSchristos xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
37042d384baSderaadt {
3717a26f6a8Sthorpej struct ypresp_key_val out;
3727a26f6a8Sthorpej char key[YPMAXRECORD], val[YPMAXRECORD];
3737a26f6a8Sthorpej bool_t more, status;
37442d384baSderaadt
375b48252f3Slukem _DIAGASSERT(xdrs != NULL);
376b48252f3Slukem _DIAGASSERT(incallback != NULL);
377b48252f3Slukem
3787a26f6a8Sthorpej /*
3797a26f6a8Sthorpej * Set up key/val struct to be used during the transaction.
3807a26f6a8Sthorpej */
381fac4c46fSjtc memset(&out, 0, sizeof out);
3827a26f6a8Sthorpej out.keydat.dptr = key;
3837a26f6a8Sthorpej out.keydat.dsize = sizeof(key);
3847a26f6a8Sthorpej out.valdat.dptr = val;
3857a26f6a8Sthorpej out.valdat.dsize = sizeof(val);
38642d384baSderaadt
3877a26f6a8Sthorpej for (;;) {
3887a26f6a8Sthorpej /* Values pending? */
3897a26f6a8Sthorpej if (!xdr_bool(xdrs, &more))
3907a26f6a8Sthorpej return FALSE; /* can't tell! */
3911d4349e7Schristos if (!more)
3927a26f6a8Sthorpej return TRUE; /* no more */
393a667b8f7Schristos
3947a26f6a8Sthorpej /* Transfer key/value pair. */
3957a26f6a8Sthorpej status = xdr_ypresp_key_val(xdrs, &out);
3967a26f6a8Sthorpej
3977a26f6a8Sthorpej /*
3987a26f6a8Sthorpej * If we succeeded, call the callback function.
3997a26f6a8Sthorpej * The callback will return TRUE when it wants
4007a26f6a8Sthorpej * no more values. If we fail, indicate the
4017a26f6a8Sthorpej * error.
4027a26f6a8Sthorpej */
4031d4349e7Schristos if (status) {
404f4c14791Schristos if ((*incallback->foreach)((int)out.status,
40503256c6eSchristos __UNCONST(out.keydat.dptr), out.keydat.dsize,
40603256c6eSchristos __UNCONST(out.valdat.dptr), out.valdat.dsize,
4077a26f6a8Sthorpej incallback->data))
40842d384baSderaadt return TRUE;
4097a26f6a8Sthorpej } else
4107a26f6a8Sthorpej return FALSE;
41142d384baSderaadt }
41242d384baSderaadt }
41342d384baSderaadt
41442d384baSderaadt bool_t
xdr_ypresp_master(XDR * xdrs,struct ypresp_master * objp)415c5e820caSchristos xdr_ypresp_master(XDR *xdrs, struct ypresp_master *objp)
41642d384baSderaadt {
417b48252f3Slukem
418b48252f3Slukem _DIAGASSERT(xdrs != NULL);
419b48252f3Slukem _DIAGASSERT(objp != NULL);
420b48252f3Slukem
42125cb0b1eSchristos if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
422a667b8f7Schristos return FALSE;
4237a26f6a8Sthorpej
4241d4349e7Schristos if (!xdr_string(xdrs, &objp->master, YPMAXPEER))
4251d4349e7Schristos return FALSE;
4261d4349e7Schristos
4271d4349e7Schristos return TRUE;
42842d384baSderaadt }
42942d384baSderaadt
4307a26f6a8Sthorpej static bool_t
xdr_ypmaplist_str(XDR * xdrs,char * objp)431c5e820caSchristos xdr_ypmaplist_str(XDR *xdrs, char *objp)
43242d384baSderaadt {
433b48252f3Slukem
434b48252f3Slukem _DIAGASSERT(xdrs != NULL);
435b48252f3Slukem _DIAGASSERT(objp != NULL);
436b48252f3Slukem
437fac4c46fSjtc return xdr_string(xdrs, &objp, YPMAXMAP+1);
43842d384baSderaadt }
43942d384baSderaadt
44042d384baSderaadt bool_t
xdr_ypmaplist(XDR * xdrs,struct ypmaplist * objp)441c5e820caSchristos xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp)
44242d384baSderaadt {
443b48252f3Slukem
444b48252f3Slukem _DIAGASSERT(xdrs != NULL);
445b48252f3Slukem _DIAGASSERT(objp != NULL);
446b48252f3Slukem
4477a26f6a8Sthorpej if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
448a667b8f7Schristos return FALSE;
4497a26f6a8Sthorpej
4506f4493cdSmrg if (!xdr_pointer(xdrs, (char **)(void *)&objp->ypml_next,
451c5e820caSchristos (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
4521d4349e7Schristos return FALSE;
4531d4349e7Schristos
4541d4349e7Schristos return TRUE;
45542d384baSderaadt }
45642d384baSderaadt
45742d384baSderaadt bool_t
xdr_ypresp_maplist(XDR * xdrs,struct ypresp_maplist * objp)458c5e820caSchristos xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp)
45942d384baSderaadt {
460b48252f3Slukem
461b48252f3Slukem _DIAGASSERT(xdrs != NULL);
462b48252f3Slukem _DIAGASSERT(objp != NULL);
463b48252f3Slukem
46425cb0b1eSchristos if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
465a667b8f7Schristos return FALSE;
4667a26f6a8Sthorpej
4676f4493cdSmrg if (!xdr_pointer(xdrs, (char **)(void *)&objp->list,
468c5e820caSchristos (u_int)sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
4691d4349e7Schristos return FALSE;
4701d4349e7Schristos
4711d4349e7Schristos return TRUE;
47242d384baSderaadt }
47342d384baSderaadt
47442d384baSderaadt bool_t
xdr_ypresp_order(XDR * xdrs,struct ypresp_order * objp)475c5e820caSchristos xdr_ypresp_order(XDR *xdrs, struct ypresp_order *objp)
47642d384baSderaadt {
477b48252f3Slukem
478b48252f3Slukem _DIAGASSERT(xdrs != NULL);
479b48252f3Slukem _DIAGASSERT(objp != NULL);
480b48252f3Slukem
48125cb0b1eSchristos if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)(void *)&objp->status))
482a667b8f7Schristos return FALSE;
4837a26f6a8Sthorpej
484bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->ordernum))
4851d4349e7Schristos return FALSE;
4861d4349e7Schristos
4871d4349e7Schristos return TRUE;
48842d384baSderaadt }
4897a26f6a8Sthorpej
4907a26f6a8Sthorpej bool_t
xdr_ypreq_xfr(XDR * xdrs,struct ypreq_xfr * objp)491c5e820caSchristos xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *objp)
4927a26f6a8Sthorpej {
493b48252f3Slukem
494b48252f3Slukem _DIAGASSERT(xdrs != NULL);
495b48252f3Slukem _DIAGASSERT(objp != NULL);
496b48252f3Slukem
4971d4349e7Schristos if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
4987a26f6a8Sthorpej return FALSE;
4997a26f6a8Sthorpej
500bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->transid))
5017a26f6a8Sthorpej return FALSE;
5027a26f6a8Sthorpej
503bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->proto))
5047a26f6a8Sthorpej return FALSE;
5057a26f6a8Sthorpej
506bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->port))
5077a26f6a8Sthorpej return FALSE;
5087a26f6a8Sthorpej
5097a26f6a8Sthorpej return TRUE;
5107a26f6a8Sthorpej }
5117a26f6a8Sthorpej
5127a26f6a8Sthorpej bool_t
xdr_ypmap_parms(XDR * xdrs,struct ypmap_parms * objp)513c5e820caSchristos xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *objp)
5147a26f6a8Sthorpej {
515b48252f3Slukem
516b48252f3Slukem _DIAGASSERT(xdrs != NULL);
517b48252f3Slukem _DIAGASSERT(objp != NULL);
518b48252f3Slukem
51903256c6eSchristos if (!xdr_ypdomain_wrap_string(xdrs, __UNCONST(&objp->domain)))
5207a26f6a8Sthorpej return FALSE;
5217a26f6a8Sthorpej
52203256c6eSchristos if (!xdr_ypmap_wrap_string(xdrs, __UNCONST(&objp->map)))
5237a26f6a8Sthorpej return FALSE;
5247a26f6a8Sthorpej
525bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->ordernum))
5267a26f6a8Sthorpej return FALSE;
5277a26f6a8Sthorpej
5281d4349e7Schristos if (!xdr_ypowner_wrap_string(xdrs, &objp->owner))
5297a26f6a8Sthorpej return FALSE;
5307a26f6a8Sthorpej
5317a26f6a8Sthorpej return TRUE;
5327a26f6a8Sthorpej }
5337a26f6a8Sthorpej
5347a26f6a8Sthorpej bool_t
xdr_yppushresp_xfr(XDR * xdrs,struct yppushresp_xfr * objp)535c5e820caSchristos xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *objp)
5367a26f6a8Sthorpej {
537b48252f3Slukem
538b48252f3Slukem _DIAGASSERT(xdrs != NULL);
539b48252f3Slukem _DIAGASSERT(objp != NULL);
540b48252f3Slukem
541bb516fa8Sthorpej if (!xdr_u_int(xdrs, &objp->transid))
5427a26f6a8Sthorpej return FALSE;
5437a26f6a8Sthorpej
544bb516fa8Sthorpej if (!xdr_enum(xdrs, (enum_t *)&objp->status))
5457a26f6a8Sthorpej return FALSE;
5467a26f6a8Sthorpej
5477a26f6a8Sthorpej return TRUE;
5487a26f6a8Sthorpej }
549