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
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]
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
37 #pragma ident "%Z%%M% %I% %E% SMI"
40 * This contains ALL xdr routines used by the YP rpc interface.
48 #include <rpcsvc/yp_prot.h>
49 #include <rpcsvc/ypclnt.h>
50 #include <sys/types.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.
70 xdr_datum(XDR
*xdrs
, datum
*pdatum
)
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
81 if (xdrs
->x_op
== XDR_ENCODE
) {
82 if (pdatum
->dsize
> UINT_MAX
)
85 dsize
= (uint_t
)pdatum
->dsize
;
86 res
= (bool)xdr_bytes(xdrs
, (char **)&(pdatum
->dptr
), &dsize
,
88 if (xdrs
->x_op
== XDR_DECODE
) {
89 pdatum
->dsize
= dsize
;
97 * Serializes/deserializes a domain name string. This is a "wrapper" for
98 * xdr_string which knows about the maximum domain name size.
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.
111 xdr_ypmap_wrap_string(XDR
*xdrs
, char **ppstring
)
113 return ((bool)xdr_string(xdrs
, ppstring
, YPMAXMAP
));
117 * Serializes/deserializes a ypreq_key structure.
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.
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.
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.
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
162 xdr_ypowner_wrap_string(XDR
*xdrs
, char **ppstring
)
164 return ((bool)xdr_string(xdrs
, ppstring
, YPMAXPEER
));
168 * Serializes/deserializes a ypmap_parms structure.
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
183 xdr_ypreq_newname_string(XDR
*xdrs
, char **ppstring
)
185 return ((bool)xdr_string(xdrs
, ppstring
, 256));
189 * Serializes/deserializes a ypresp_master structure.
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.
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.
214 xdr_ypmaplist_wrap_string(XDR
*xdrs
, char *pstring
)
219 return ((bool)xdr_string(xdrs
, &s
, YPMAXMAP
));
223 * Serializes/deserializes a ypmaplist.
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
;
233 more_elements
= (*lst
!= NULL
);
235 if (!xdr_bool(xdrs
, &more_elements
))
239 return (TRUE
); /* All done */
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
))
249 lst
= (freeing
) ? next
: &((*lst
)->ypml_next
);
255 * Serializes/deserializes a ypresp_maplist.
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.
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.
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.
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.
305 xdr_ypall(XDR
*xdrs
, struct ypall_callback
*callback
)
308 struct ypresp_key_val kv
;
309 char keybuf
[YPMAXRECORD
];
310 char valbuf
[YPMAXRECORD
];
312 if (xdrs
->x_op
== XDR_ENCODE
)
315 if (xdrs
->x_op
== XDR_FREE
)
318 kv
.keydat
.dptr
= keybuf
;
319 kv
.valdat
.dptr
= valbuf
;
320 kv
.keydat
.dsize
= YPMAXRECORD
;
321 kv
.valdat
.dsize
= YPMAXRECORD
;
324 if (!xdr_bool(xdrs
, &more
))
330 if (!xdr_ypresp_key_val(xdrs
, &kv
))
332 if ((*callback
->foreach
)(kv
.status
, kv
.keydat
.dptr
,
333 kv
.keydat
.dsize
, kv
.valdat
.dptr
, kv
.valdat
.dsize
,
340 xdr_netconfig(XDR
*xdrs
, struct netconfig
*objp
)
342 if (!xdr_string(xdrs
, &objp
->nc_netid
, ~0))
344 if (!xdr_u_int(xdrs
, &objp
->nc_semantics
))
346 if (!xdr_u_int(xdrs
, &objp
->nc_flag
))
348 if (!xdr_string(xdrs
, &objp
->nc_protofmly
, ~0))
350 if (!xdr_string(xdrs
, &objp
->nc_proto
, ~0))
352 if (!xdr_string(xdrs
, &objp
->nc_device
, ~0))
354 if (!xdr_array(xdrs
, (char **)&objp
->nc_lookups
,
355 (uint_t
*)&objp
->nc_nlookups
, 100, sizeof (char *),
358 return ((bool)xdr_vector(xdrs
, (char *)objp
->nc_unused
,
359 8, sizeof (uint_t
), xdr_u_int
));