1 /* $NetBSD: xdryp.c,v 1.32 2012/03/20 16:30:26 matt 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.32 2012/03/20 16:30:26 matt 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(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.")
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.")
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.")
153 xdr_mapname(XDR
*xdrs
, char *objp
)
156 _DIAGASSERT(xdrs
!= NULL
);
157 _DIAGASSERT(objp
!= NULL
);
159 return xdr_string(xdrs
, &objp
, YPMAXMAP
);
163 xdr_ypdomain_wrap_string(XDR
*xdrs
, char **objp
)
166 _DIAGASSERT(xdrs
!= NULL
);
167 _DIAGASSERT(objp
!= NULL
);
169 return xdr_string(xdrs
, objp
, YPMAXDOMAIN
);
173 xdr_ypmap_wrap_string(XDR
*xdrs
, char **objp
)
176 _DIAGASSERT(xdrs
!= NULL
);
177 _DIAGASSERT(objp
!= NULL
);
179 return xdr_string(xdrs
, objp
, YPMAXMAP
);
183 xdr_ypowner_wrap_string(XDR
*xdrs
, char **objp
)
186 _DIAGASSERT(xdrs
!= NULL
);
187 _DIAGASSERT(objp
!= NULL
);
189 return xdr_string(xdrs
, objp
, YPMAXPEER
);
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
);
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
)))
213 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
216 if (!xdr_datum(xdrs
, &objp
->keydat
))
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
)))
232 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
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
);
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
))
259 if (!xdr_opaque(xdrs
, (void *)&objp
->ypbind_binding_port
,
260 (u_int
)sizeof objp
->ypbind_binding_port
))
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
);
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
);
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
))
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
);
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
))
321 if (!xdr_datum(xdrs
, &objp
->valdat
))
328 xdr_ypbind_setdom(XDR
*xdrs
, struct ypbind_setdom
*objp
)
332 _DIAGASSERT(xdrs
!= NULL
);
333 _DIAGASSERT(objp
!= NULL
);
335 cp
= objp
->ypsetdom_domain
;
337 if (!xdr_ypdomain_wrap_string(xdrs
, &cp
))
340 if (!xdr_ypbind_binding(xdrs
, &objp
->ypsetdom_binding
))
343 if (!xdr_u_int(xdrs
, &objp
->ypsetdom_vers
))
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
))
359 if (!xdr_datum(xdrs
, &objp
->valdat
))
362 if (!xdr_datum(xdrs
, &objp
->keydat
))
369 xdr_ypall(XDR
*xdrs
, struct ypall_callback
*incallback
)
371 struct ypresp_key_val out
;
372 char key
[YPMAXRECORD
], val
[YPMAXRECORD
];
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
);
388 /* Values pending? */
389 if (!xdr_bool(xdrs
, &more
))
390 return FALSE
; /* can't tell! */
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
404 if ((*incallback
->foreach
)((int)out
.status
,
405 __UNCONST(out
.keydat
.dptr
), out
.keydat
.dsize
,
406 __UNCONST(out
.valdat
.dptr
), out
.valdat
.dsize
,
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
))
424 if (!xdr_string(xdrs
, &objp
->master
, YPMAXPEER
))
431 xdr_ypmaplist_str(XDR
*xdrs
, char *objp
)
434 _DIAGASSERT(xdrs
!= NULL
);
435 _DIAGASSERT(objp
!= NULL
);
437 return xdr_string(xdrs
, &objp
, YPMAXMAP
+1);
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
))
450 if (!xdr_pointer(xdrs
, (char **)(void *)&objp
->ypml_next
,
451 (u_int
)sizeof(struct ypmaplist
), (xdrproc_t
)xdr_ypmaplist
))
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
))
467 if (!xdr_pointer(xdrs
, (char **)(void *)&objp
->list
,
468 (u_int
)sizeof(struct ypmaplist
), (xdrproc_t
)xdr_ypmaplist
))
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
))
484 if (!xdr_u_int(xdrs
, &objp
->ordernum
))
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
))
500 if (!xdr_u_int(xdrs
, &objp
->transid
))
503 if (!xdr_u_int(xdrs
, &objp
->proto
))
506 if (!xdr_u_int(xdrs
, &objp
->port
))
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
)))
522 if (!xdr_ypmap_wrap_string(xdrs
, __UNCONST(&objp
->map
)))
525 if (!xdr_u_int(xdrs
, &objp
->ordernum
))
528 if (!xdr_ypowner_wrap_string(xdrs
, &objp
->owner
))
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
))
544 if (!xdr_enum(xdrs
, (enum_t
*)&objp
->status
))