1 /* $NetBSD: xdryp.c,v 1.29 2005/11/29 03:12:01 christos Exp $ */
4 * Copyright (c) 1996 Jason R. Thorpe <thorpej@NetBSD.org>.
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.
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
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
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
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
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 $");
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
74 #include "namespace.h"
76 #include <sys/param.h>
77 #include <sys/socket.h>
87 #include <rpcsvc/yp_prot.h>
88 #include <rpcsvc/ypclnt.h>
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
)
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.")
127 xdr_domainname(xdrs
, 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.")
142 xdr_peername(xdrs
, 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.")
157 xdr_mapname(xdrs
, objp
)
162 _DIAGASSERT(xdrs
!= NULL
);
163 _DIAGASSERT(objp
!= NULL
);
165 return xdr_string(xdrs
, &objp
, YPMAXMAP
);
169 xdr_ypdomain_wrap_string(xdrs
, objp
)
174 _DIAGASSERT(xdrs
!= NULL
);
175 _DIAGASSERT(objp
!= NULL
);
177 return xdr_string(xdrs
, objp
, YPMAXDOMAIN
);
181 xdr_ypmap_wrap_string(xdrs
, objp
)
186 _DIAGASSERT(xdrs
!= NULL
);
187 _DIAGASSERT(objp
!= NULL
);
189 return xdr_string(xdrs
, objp
, YPMAXMAP
);
193 xdr_ypowner_wrap_string(xdrs
, objp
)
198 _DIAGASSERT(xdrs
!= NULL
);
199 _DIAGASSERT(objp
!= NULL
);
201 return xdr_string(xdrs
, objp
, YPMAXPEER
);
205 xdr_datum(xdrs
, objp
)
210 _DIAGASSERT(xdrs
!= NULL
);
211 _DIAGASSERT(objp
!= NULL
);
213 return xdr_bytes(xdrs
, __UNCONST(&objp
->dptr
),
214 (u_int
*)&objp
->dsize
, YPMAXRECORD
);
218 xdr_ypreq_key(xdrs
, objp
)
220 struct ypreq_key
*objp
;
223 _DIAGASSERT(xdrs
!= NULL
);
224 _DIAGASSERT(objp
!= NULL
);
226 if (!xdr_ypdomain_wrap_string(xdrs
, __UNCONST(&objp
->domain
)))
229 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
232 if (!xdr_datum(xdrs
, &objp
->keydat
))
239 xdr_ypreq_nokey(xdrs
, objp
)
241 struct ypreq_nokey
*objp
;
244 _DIAGASSERT(xdrs
!= NULL
);
245 _DIAGASSERT(objp
!= NULL
);
247 if (!xdr_ypdomain_wrap_string(xdrs
, __UNCONST(&objp
->domain
)))
250 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
257 xdr_yp_inaddr(xdrs
, objp
)
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
);
270 xdr_ypbind_binding(xdrs
, objp
)
272 struct ypbind_binding
*objp
;
275 _DIAGASSERT(xdrs
!= NULL
);
276 _DIAGASSERT(objp
!= NULL
);
278 if (!xdr_yp_inaddr(xdrs
, &objp
->ypbind_binding_addr
))
281 if (!xdr_opaque(xdrs
, (void *)&objp
->ypbind_binding_port
,
282 sizeof objp
->ypbind_binding_port
))
289 xdr_ypbind_resptype(xdrs
, objp
)
291 enum ypbind_resptype
*objp
;
294 _DIAGASSERT(xdrs
!= NULL
);
295 _DIAGASSERT(objp
!= NULL
);
297 return xdr_enum(xdrs
, (enum_t
*)(void *)objp
);
301 xdr_ypstat(xdrs
, objp
)
303 enum ypbind_resptype
*objp
;
306 _DIAGASSERT(xdrs
!= NULL
);
307 _DIAGASSERT(objp
!= NULL
);
309 return xdr_enum(xdrs
, (enum_t
*)(void *)objp
);
313 xdr_ypbind_resp(xdrs
, objp
)
315 struct ypbind_resp
*objp
;
318 _DIAGASSERT(xdrs
!= NULL
);
319 _DIAGASSERT(objp
!= NULL
);
321 if (!xdr_ypbind_resptype(xdrs
, &objp
->ypbind_status
))
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
);
340 xdr_ypresp_val(xdrs
, objp
)
342 struct ypresp_val
*objp
;
345 _DIAGASSERT(xdrs
!= NULL
);
346 _DIAGASSERT(objp
!= NULL
);
348 if (!xdr_ypstat(xdrs
, (enum ypbind_resptype
*)(void *)&objp
->status
))
351 if (!xdr_datum(xdrs
, &objp
->valdat
))
358 xdr_ypbind_setdom(xdrs
, objp
)
360 struct ypbind_setdom
*objp
;
364 _DIAGASSERT(xdrs
!= NULL
);
365 _DIAGASSERT(objp
!= NULL
);
367 cp
= objp
->ypsetdom_domain
;
369 if (!xdr_ypdomain_wrap_string(xdrs
, &cp
))
372 if (!xdr_ypbind_binding(xdrs
, &objp
->ypsetdom_binding
))
375 if (!xdr_u_int(xdrs
, &objp
->ypsetdom_vers
))
382 xdr_ypresp_key_val(xdrs
, objp
)
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
))
393 if (!xdr_datum(xdrs
, &objp
->valdat
))
396 if (!xdr_datum(xdrs
, &objp
->keydat
))
403 xdr_ypall(xdrs
, incallback
)
405 struct ypall_callback
*incallback
;
407 struct ypresp_key_val out
;
408 char key
[YPMAXRECORD
], val
[YPMAXRECORD
];
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
);
424 /* Values pending? */
425 if (!xdr_bool(xdrs
, &more
))
426 return FALSE
; /* can't tell! */
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
440 if ((*incallback
->foreach
)((int)out
.status
,
441 __UNCONST(out
.keydat
.dptr
), out
.keydat
.dsize
,
442 __UNCONST(out
.valdat
.dptr
), out
.valdat
.dsize
,
451 xdr_ypresp_master(xdrs
, objp
)
453 struct ypresp_master
*objp
;
456 _DIAGASSERT(xdrs
!= NULL
);
457 _DIAGASSERT(objp
!= NULL
);
459 if (!xdr_ypstat(xdrs
, (enum ypbind_resptype
*)(void *)&objp
->status
))
462 if (!xdr_string(xdrs
, &objp
->master
, YPMAXPEER
))
469 xdr_ypmaplist_str(xdrs
, objp
)
474 _DIAGASSERT(xdrs
!= NULL
);
475 _DIAGASSERT(objp
!= NULL
);
477 return xdr_string(xdrs
, &objp
, YPMAXMAP
+1);
481 xdr_ypmaplist(xdrs
, objp
)
483 struct ypmaplist
*objp
;
486 _DIAGASSERT(xdrs
!= NULL
);
487 _DIAGASSERT(objp
!= NULL
);
489 if (!xdr_ypmaplist_str(xdrs
, objp
->ypml_name
))
492 if (!xdr_pointer(xdrs
, (char **)(void *)&objp
->ypml_next
,
493 sizeof(struct ypmaplist
), (xdrproc_t
)xdr_ypmaplist
))
500 xdr_ypresp_maplist(xdrs
, objp
)
502 struct ypresp_maplist
*objp
;
505 _DIAGASSERT(xdrs
!= NULL
);
506 _DIAGASSERT(objp
!= NULL
);
508 if (!xdr_ypstat(xdrs
, (enum ypbind_resptype
*)(void *)&objp
->status
))
511 if (!xdr_pointer(xdrs
, (char **)(void *)&objp
->list
,
512 sizeof(struct ypmaplist
), (xdrproc_t
)xdr_ypmaplist
))
519 xdr_ypresp_order(xdrs
, objp
)
521 struct ypresp_order
*objp
;
524 _DIAGASSERT(xdrs
!= NULL
);
525 _DIAGASSERT(objp
!= NULL
);
527 if (!xdr_ypstat(xdrs
, (enum ypbind_resptype
*)(void *)&objp
->status
))
530 if (!xdr_u_int(xdrs
, &objp
->ordernum
))
537 xdr_ypreq_xfr(xdrs
, objp
)
539 struct ypreq_xfr
*objp
;
542 _DIAGASSERT(xdrs
!= NULL
);
543 _DIAGASSERT(objp
!= NULL
);
545 if (!xdr_ypmap_parms(xdrs
, &objp
->map_parms
))
548 if (!xdr_u_int(xdrs
, &objp
->transid
))
551 if (!xdr_u_int(xdrs
, &objp
->proto
))
554 if (!xdr_u_int(xdrs
, &objp
->port
))
561 xdr_ypmap_parms(xdrs
, objp
)
563 struct ypmap_parms
*objp
;
566 _DIAGASSERT(xdrs
!= NULL
);
567 _DIAGASSERT(objp
!= NULL
);
569 if (!xdr_ypdomain_wrap_string(xdrs
, __UNCONST(&objp
->domain
)))
572 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
575 if (!xdr_u_int(xdrs
, &objp
->ordernum
))
578 if (!xdr_ypowner_wrap_string(xdrs
, &objp
->owner
))
585 xdr_yppushresp_xfr(xdrs
, objp
)
587 struct yppushresp_xfr
*objp
;
590 _DIAGASSERT(xdrs
!= NULL
);
591 _DIAGASSERT(objp
!= NULL
);
593 if (!xdr_u_int(xdrs
, &objp
->transid
))
596 if (!xdr_enum(xdrs
, (enum_t
*)&objp
->status
))