import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / yp_xdr.c
blobcad722b5f057aa5a1b23c13dbaafffddea5a0344
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 * Portions of this source code were derived from Berkeley
33 * under license from the Regents of the University of
34 * California.
37 #pragma ident "%Z%%M% %I% %E% SMI"
40 * This contains ALL xdr routines used by the YP rpc interface.
43 #include "mt.h"
44 #include <unistd.h>
45 #include <stdlib.h>
46 #include <rpc/rpc.h>
47 #include "yp_b.h"
48 #include <rpcsvc/yp_prot.h>
49 #include <rpcsvc/ypclnt.h>
50 #include <sys/types.h>
51 #include <limits.h>
53 static bool xdr_ypmaplist(XDR *, struct ypmaplist **);
54 static bool xdr_ypmaplist_wrap_string(XDR *, char *);
56 typedef struct xdr_discrim XDR_DISCRIM;
57 extern bool xdr_ypreq_key(XDR *, struct ypreq_key *);
58 extern bool xdr_ypreq_nokey(XDR *, struct ypreq_nokey *);
59 extern bool xdr_ypresp_val(XDR *, struct ypresp_val *);
60 extern bool xdr_ypresp_key_val(XDR *, struct ypresp_key_val *);
61 extern bool xdr_ypmap_parms(XDR *, struct ypmap_parms *);
62 extern bool xdr_ypowner_wrap_string(XDR *, char **);
63 extern bool xdr_ypreq_newname_string(XDR *, char **);
67 * Serializes/deserializes a dbm datum data structure.
69 bool
70 xdr_datum(XDR *xdrs, datum *pdatum)
72 bool res;
73 uint_t dsize;
76 * LP64 case :
77 * xdr_bytes() expects a uint_t for the 3rd argument. Since
78 * datum.dsize is a long, we need a new temporary to pass to
79 * xdr_bytes()
81 if (xdrs->x_op == XDR_ENCODE) {
82 if (pdatum->dsize > UINT_MAX)
83 return (FALSE);
85 dsize = (uint_t)pdatum->dsize;
86 res = (bool)xdr_bytes(xdrs, (char **)&(pdatum->dptr), &dsize,
87 YPMAXRECORD);
88 if (xdrs->x_op == XDR_DECODE) {
89 pdatum->dsize = dsize;
92 return (res);
97 * Serializes/deserializes a domain name string. This is a "wrapper" for
98 * xdr_string which knows about the maximum domain name size.
100 bool
101 xdr_ypdomain_wrap_string(XDR *xdrs, char **ppstring)
103 return ((bool)xdr_string(xdrs, ppstring, YPMAXDOMAIN));
107 * Serializes/deserializes a map name string. This is a "wrapper" for
108 * xdr_string which knows about the maximum map name size.
110 bool
111 xdr_ypmap_wrap_string(XDR *xdrs, char **ppstring)
113 return ((bool)xdr_string(xdrs, ppstring, YPMAXMAP));
117 * Serializes/deserializes a ypreq_key structure.
119 bool
120 xdr_ypreq_key(XDR *xdrs, struct ypreq_key *ps)
122 return ((bool)(xdr_ypdomain_wrap_string(xdrs, &ps->domain) &&
123 xdr_ypmap_wrap_string(xdrs, &ps->map) &&
124 xdr_datum(xdrs, &ps->keydat)));
128 * Serializes/deserializes a ypreq_nokey structure.
130 bool
131 xdr_ypreq_nokey(XDR *xdrs, struct ypreq_nokey *ps)
133 return ((bool)(xdr_ypdomain_wrap_string(xdrs, &ps->domain) &&
134 xdr_ypmap_wrap_string(xdrs, &ps->map)));
138 * Serializes/deserializes a ypresp_val structure.
140 bool
141 xdr_ypresp_val(XDR *xdrs, struct ypresp_val *ps)
143 return ((bool)(xdr_u_int(xdrs, &ps->status) &&
144 xdr_datum(xdrs, &ps->valdat)));
148 * Serializes/deserializes a ypresp_key_val structure.
150 bool
151 xdr_ypresp_key_val(XDR *xdrs, struct ypresp_key_val *ps)
153 return ((bool)(xdr_u_int(xdrs, &ps->status) &&
154 xdr_datum(xdrs, &ps->valdat) &&
155 xdr_datum(xdrs, &ps->keydat)));
159 * Serializes/deserializes a peer server's node name
161 bool
162 xdr_ypowner_wrap_string(XDR *xdrs, char **ppstring)
164 return ((bool)xdr_string(xdrs, ppstring, YPMAXPEER));
168 * Serializes/deserializes a ypmap_parms structure.
170 bool
171 xdr_ypmap_parms(XDR *xdrs, struct ypmap_parms *ps)
173 return ((bool)(xdr_ypdomain_wrap_string(xdrs, &ps->domain) &&
174 xdr_ypmap_wrap_string(xdrs, &ps->map) &&
175 xdr_u_int(xdrs, &ps->ordernum) &&
176 xdr_ypowner_wrap_string(xdrs, &ps->owner)));
180 * Serializes/deserializes a ypreq_newxfr name
182 bool
183 xdr_ypreq_newname_string(XDR *xdrs, char **ppstring)
185 return ((bool)xdr_string(xdrs, ppstring, 256));
189 * Serializes/deserializes a ypresp_master structure.
191 bool
192 xdr_ypresp_master(XDR *xdrs, struct ypresp_master *ps)
194 return ((bool)(xdr_u_int(xdrs, &ps->status) &&
195 xdr_ypowner_wrap_string(xdrs, &ps->master)));
199 * Serializes/deserializes a ypresp_order structure.
201 bool
202 xdr_ypresp_order(XDR *xdrs, struct ypresp_order *ps)
204 return ((bool)(xdr_u_int(xdrs, &ps->status) &&
205 xdr_u_int(xdrs, &ps->ordernum)));
209 * This is like xdr_ypmap_wrap_string except that it serializes/deserializes
210 * an array, instead of a pointer, so xdr_reference can work on the structure
211 * containing the char array itself.
213 static bool
214 xdr_ypmaplist_wrap_string(XDR *xdrs, char *pstring)
216 char *s;
218 s = pstring;
219 return ((bool)xdr_string(xdrs, &s, YPMAXMAP));
223 * Serializes/deserializes a ypmaplist.
225 static bool
226 xdr_ypmaplist(XDR *xdrs, struct ypmaplist **lst)
228 bool_t more_elements;
229 int freeing = (xdrs->x_op == XDR_FREE);
230 struct ypmaplist **next;
232 for (;;) {
233 more_elements = (*lst != NULL);
235 if (!xdr_bool(xdrs, &more_elements))
236 return (FALSE);
238 if (!more_elements)
239 return (TRUE); /* All done */
241 if (freeing)
242 next = &((*lst)->ypml_next);
244 if (!xdr_reference(xdrs, (caddr_t *)lst,
245 (uint_t)sizeof (struct ypmaplist),
246 (xdrproc_t)xdr_ypmaplist_wrap_string))
247 return (FALSE);
249 lst = (freeing) ? next : &((*lst)->ypml_next);
251 /*NOTREACHED*/
255 * Serializes/deserializes a ypresp_maplist.
257 bool
258 xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *ps)
260 return ((bool)(xdr_u_int(xdrs, &ps->status) &&
261 xdr_ypmaplist(xdrs, &ps->list)));
265 * Serializes/deserializes a yppushresp_xfr structure.
267 bool
268 xdr_yppushresp_xfr(XDR *xdrs, struct yppushresp_xfr *ps)
270 return ((bool)(xdr_u_int(xdrs, &ps->transid) &&
271 xdr_u_int(xdrs, &ps->status)));
276 * Serializes/deserializes a ypreq_xfr structure.
278 bool
279 xdr_ypreq_newxfr(XDR *xdrs, struct ypreq_newxfr *ps)
281 return ((bool)(xdr_ypmap_parms(xdrs, &ps->map_parms) &&
282 xdr_u_int(xdrs, &ps->transid) &&
283 xdr_u_int(xdrs, &ps->proto) &&
284 xdr_string(xdrs, &ps->name, 256)));
288 * Serializes/deserializes a ypreq_xfr structure.
290 bool
291 xdr_ypreq_xfr(XDR *xdrs, struct ypreq_xfr *ps)
293 return ((bool)(xdr_ypmap_parms(xdrs, &ps->map_parms) &&
294 xdr_u_int(xdrs, &ps->transid) &&
295 xdr_u_int(xdrs, &ps->proto) &&
296 xdr_u_short(xdrs, &ps->port)));
301 * Serializes/deserializes a stream of struct ypresp_key_val's. This is used
302 * only by the client side of the batch enumerate operation.
304 bool
305 xdr_ypall(XDR *xdrs, struct ypall_callback *callback)
307 bool_t more;
308 struct ypresp_key_val kv;
309 char keybuf[YPMAXRECORD];
310 char valbuf[YPMAXRECORD];
312 if (xdrs->x_op == XDR_ENCODE)
313 return (FALSE);
315 if (xdrs->x_op == XDR_FREE)
316 return (TRUE);
318 kv.keydat.dptr = keybuf;
319 kv.valdat.dptr = valbuf;
320 kv.keydat.dsize = YPMAXRECORD;
321 kv.valdat.dsize = YPMAXRECORD;
323 for (;;) {
324 if (!xdr_bool(xdrs, &more))
325 return (FALSE);
327 if (!more)
328 return (TRUE);
330 if (!xdr_ypresp_key_val(xdrs, &kv))
331 return (FALSE);
332 if ((*callback->foreach)(kv.status, kv.keydat.dptr,
333 kv.keydat.dsize, kv.valdat.dptr, kv.valdat.dsize,
334 callback->data))
335 return (TRUE);
339 bool_t
340 xdr_netconfig(XDR *xdrs, struct netconfig *objp)
342 if (!xdr_string(xdrs, &objp->nc_netid, ~0))
343 return (FALSE);
344 if (!xdr_u_int(xdrs, &objp->nc_semantics))
345 return (FALSE);
346 if (!xdr_u_int(xdrs, &objp->nc_flag))
347 return (FALSE);
348 if (!xdr_string(xdrs, &objp->nc_protofmly, ~0))
349 return (FALSE);
350 if (!xdr_string(xdrs, &objp->nc_proto, ~0))
351 return (FALSE);
352 if (!xdr_string(xdrs, &objp->nc_device, ~0))
353 return (FALSE);
354 if (!xdr_array(xdrs, (char **)&objp->nc_lookups,
355 (uint_t *)&objp->nc_nlookups, 100, sizeof (char *),
356 xdr_wrapstring))
357 return (FALSE);
358 return ((bool)xdr_vector(xdrs, (char *)objp->nc_unused,
359 8, sizeof (uint_t), xdr_u_int));