Update.
[glibc.git] / nis / nis_xdr.c
blobefeb7d09dd23ebe0b7b3df6b1f8a679cfba2c4d7
1 /* Copyright (c) 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <rpcsvc/nis.h>
21 #include <rpcsvc/nis_callback.h> /* for "official" Solaris xdr functions */
23 /* This functions do exist without beginning "_" under Solaris 2.x, but
24 we have no prototypes for them. To avoid the same problems as with the
25 YP xdr functions, we don't make them public. */
26 #include "nis_xdr.h"
28 static bool_t
29 xdr_nis_attr (XDR *xdrs, nis_attr *objp)
31 if (!xdr_string (xdrs, &objp->zattr_ndx, ~0))
32 return FALSE;
33 if (!xdr_bytes (xdrs, (char **) &objp->zattr_val.zattr_val_val,
34 (u_int *) & objp->zattr_val.zattr_val_len, ~0))
35 return FALSE;
36 return TRUE;
39 bool_t
40 _xdr_nis_name (XDR *xdrs, nis_name *objp)
42 if (!xdr_string (xdrs, objp, ~0))
43 return FALSE;
44 return TRUE;
47 static bool_t
48 xdr_zotypes (XDR *xdrs, zotypes *objp)
50 if (!xdr_enum (xdrs, (enum_t *) objp))
51 return FALSE;
52 return TRUE;
55 static bool_t
56 xdr_nstype (XDR *xdrs, nstype *objp)
58 if (!xdr_enum (xdrs, (enum_t *) objp))
59 return FALSE;
60 return TRUE;
63 static bool_t
64 xdr_oar_mask (XDR *xdrs, oar_mask *objp)
66 if (!xdr_u_long (xdrs, &objp->oa_rights))
67 return FALSE;
68 if (!xdr_zotypes (xdrs, &objp->oa_otype))
69 return FALSE;
70 return TRUE;
73 static bool_t
74 xdr_endpoint (XDR *xdrs, endpoint *objp)
76 if (!xdr_string (xdrs, &objp->uaddr, ~0))
77 return FALSE;
78 if (!xdr_string (xdrs, &objp->family, ~0))
79 return FALSE;
80 if (!xdr_string (xdrs, &objp->proto, ~0))
81 return FALSE;
82 return TRUE;
85 bool_t
86 _xdr_nis_server (XDR *xdrs, nis_server *objp)
88 if (!_xdr_nis_name (xdrs, &objp->name))
89 return FALSE;
90 if (!xdr_array (xdrs, (char **) &objp->ep.ep_val, (u_int *) &objp->ep.ep_len,
91 ~0, sizeof (endpoint), (xdrproc_t) xdr_endpoint))
92 return FALSE;
93 if (!xdr_u_long (xdrs, &objp->key_type))
94 return FALSE;
95 if (!xdr_netobj (xdrs, &objp->pkey))
96 return FALSE;
97 return TRUE;
100 bool_t
101 _xdr_directory_obj (XDR *xdrs, directory_obj *objp)
103 if (!_xdr_nis_name (xdrs, &objp->do_name))
104 return FALSE;
105 if (!xdr_nstype (xdrs, &objp->do_type))
106 return FALSE;
107 if (!xdr_array (xdrs, (char **) &objp->do_servers.do_servers_val,
108 (u_int *) & objp->do_servers.do_servers_len, ~0,
109 sizeof (nis_server), (xdrproc_t) _xdr_nis_server))
110 return FALSE;
112 if (!xdr_u_long (xdrs, &objp->do_ttl))
113 return FALSE;
114 if (!xdr_array (xdrs, (char **) &objp->do_armask.do_armask_val,
115 (u_int *) & objp->do_armask.do_armask_len, ~0,
116 sizeof (oar_mask), (xdrproc_t) xdr_oar_mask))
117 return FALSE;
118 return TRUE;
121 static bool_t
122 xdr_entry_col (XDR *xdrs, entry_col *objp)
124 if (!xdr_u_long (xdrs, &objp->ec_flags))
125 return FALSE;
126 if (!xdr_bytes (xdrs, (char **) &objp->ec_value.ec_value_val,
127 (u_int *) &objp->ec_value.ec_value_len, ~0))
128 return FALSE;
129 return TRUE;
132 static bool_t
133 xdr_entry_obj (XDR *xdrs, entry_obj *objp)
135 if (!xdr_string (xdrs, &objp->en_type, ~0))
136 return FALSE;
137 if (!xdr_array (xdrs, (char **) &objp->en_cols.en_cols_val,
138 (u_int *) &objp->en_cols.en_cols_len, ~0,
139 sizeof (entry_col), (xdrproc_t) xdr_entry_col))
140 return FALSE;
141 return TRUE;
144 static bool_t
145 xdr_group_obj (XDR *xdrs, group_obj *objp)
147 if (!xdr_u_long (xdrs, &objp->gr_flags))
148 return FALSE;
149 if (!xdr_array (xdrs, (char **) &objp->gr_members.gr_members_val,
150 (u_int *) &objp->gr_members.gr_members_len, ~0,
151 sizeof (nis_name), (xdrproc_t) _xdr_nis_name))
152 return FALSE;
153 return TRUE;
156 static bool_t
157 xdr_link_obj (XDR *xdrs, link_obj *objp)
159 if (!xdr_zotypes (xdrs, &objp->li_rtype))
160 return FALSE;
161 if (!xdr_array (xdrs, (char **) &objp->li_attrs.li_attrs_val,
162 (u_int *) &objp->li_attrs.li_attrs_len, ~0,
163 sizeof (nis_attr), (xdrproc_t) xdr_nis_attr))
164 return FALSE;
165 if (!_xdr_nis_name (xdrs, &objp->li_name))
166 return FALSE;
167 return TRUE;
170 static bool_t
171 xdr_table_col (XDR *xdrs, table_col *objp)
173 if (!xdr_string (xdrs, &objp->tc_name, 64))
174 return FALSE;
175 if (!xdr_u_long (xdrs, &objp->tc_flags))
176 return FALSE;
177 if (!xdr_u_long (xdrs, &objp->tc_rights))
178 return FALSE;
179 return TRUE;
182 static bool_t
183 xdr_table_obj (XDR *xdrs, table_obj *objp)
185 if (!xdr_string (xdrs, &objp->ta_type, 64))
186 return FALSE;
187 if (!xdr_int (xdrs, &objp->ta_maxcol))
188 return FALSE;
189 if (!xdr_u_char (xdrs, &objp->ta_sep))
190 return FALSE;
191 if (!xdr_array (xdrs, (char **) &objp->ta_cols.ta_cols_val,
192 (u_int *) &objp->ta_cols.ta_cols_len, ~0,
193 sizeof (table_col), (xdrproc_t) xdr_table_col))
194 return FALSE;
195 if (!xdr_string (xdrs, &objp->ta_path, ~0))
196 return FALSE;
197 return TRUE;
200 static bool_t
201 xdr_objdata (XDR *xdrs, objdata *objp)
203 if (!xdr_zotypes (xdrs, &objp->zo_type))
204 return FALSE;
205 switch (objp->zo_type)
207 case NIS_DIRECTORY_OBJ:
208 if (!_xdr_directory_obj (xdrs, &objp->objdata_u.di_data))
209 return FALSE;
210 break;
211 case NIS_GROUP_OBJ:
212 if (!xdr_group_obj (xdrs, &objp->objdata_u.gr_data))
213 return FALSE;
214 break;
215 case NIS_TABLE_OBJ:
216 if (!xdr_table_obj (xdrs, &objp->objdata_u.ta_data))
217 return FALSE;
218 break;
219 case NIS_ENTRY_OBJ:
220 if (!xdr_entry_obj (xdrs, &objp->objdata_u.en_data))
221 return FALSE;
222 break;
223 case NIS_LINK_OBJ:
224 if (!xdr_link_obj (xdrs, &objp->objdata_u.li_data))
225 return FALSE;
226 break;
227 case NIS_PRIVATE_OBJ:
228 if (!xdr_bytes (xdrs, (char **) &objp->objdata_u.po_data.po_data_val,
229 (u_int *) & objp->objdata_u.po_data.po_data_len, ~0))
230 return FALSE;
231 break;
232 case NIS_NO_OBJ:
233 break;
234 case NIS_BOGUS_OBJ:
235 break;
236 default:
237 break;
239 return TRUE;
242 static bool_t
243 xdr_nis_oid (XDR *xdrs, nis_oid *objp)
245 if (!xdr_u_long (xdrs, &objp->ctime))
246 return FALSE;
247 if (!xdr_u_long (xdrs, &objp->mtime))
248 return FALSE;
249 return TRUE;
252 bool_t
253 _xdr_nis_object (XDR *xdrs, nis_object *objp)
255 if (!xdr_nis_oid (xdrs, &objp->zo_oid))
256 return FALSE;
257 if (!_xdr_nis_name (xdrs, &objp->zo_name))
258 return FALSE;
259 if (!_xdr_nis_name (xdrs, &objp->zo_owner))
260 return FALSE;
261 if (!_xdr_nis_name (xdrs, &objp->zo_group))
262 return FALSE;
263 if (!_xdr_nis_name (xdrs, &objp->zo_domain))
264 return FALSE;
265 if (!xdr_u_long (xdrs, &objp->zo_access))
266 return FALSE;
267 if (!xdr_u_long (xdrs, &objp->zo_ttl))
268 return FALSE;
269 if (!xdr_objdata (xdrs, &objp->zo_data))
270 return FALSE;
271 return TRUE;
274 bool_t
275 _xdr_nis_error (XDR *xdrs, nis_error *objp)
277 if (!xdr_enum (xdrs, (enum_t *) objp))
278 return FALSE;
279 return TRUE;
282 bool_t
283 _xdr_nis_result (XDR *xdrs, nis_result *objp)
285 register long *buf;
287 if (xdrs->x_op == XDR_ENCODE)
289 if (!_xdr_nis_error (xdrs, &objp->status))
290 return FALSE;
291 if (!xdr_array (xdrs, (char **) &objp->objects.objects_val,
292 (u_int *) &objp->objects.objects_len, ~0,
293 sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
294 return FALSE;
295 if (!xdr_netobj (xdrs, &objp->cookie))
296 return FALSE;
297 buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
298 if (buf == NULL)
300 if (!xdr_u_long (xdrs, &objp->zticks))
301 return FALSE;
302 if (!xdr_u_long (xdrs, &objp->dticks))
303 return FALSE;
304 if (!xdr_u_long (xdrs, &objp->aticks))
305 return FALSE;
306 if (!xdr_u_long (xdrs, &objp->cticks))
307 return FALSE;
309 else
311 IXDR_PUT_U_LONG (buf, objp->zticks);
312 IXDR_PUT_U_LONG (buf, objp->dticks);
313 IXDR_PUT_U_LONG (buf, objp->aticks);
314 IXDR_PUT_U_LONG (buf, objp->cticks);
316 return TRUE;
318 else if (xdrs->x_op == XDR_DECODE)
320 if (!_xdr_nis_error (xdrs, &objp->status))
321 return FALSE;
322 if (!xdr_array (xdrs, (char **) &objp->objects.objects_val,
323 (u_int *) &objp->objects.objects_len, ~0,
324 sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
325 return FALSE;
326 if (!xdr_netobj (xdrs, &objp->cookie))
327 return FALSE;
328 buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
329 if (buf == NULL)
331 if (!xdr_u_long (xdrs, &objp->zticks))
332 return FALSE;
333 if (!xdr_u_long (xdrs, &objp->dticks))
334 return FALSE;
335 if (!xdr_u_long (xdrs, &objp->aticks))
336 return FALSE;
337 if (!xdr_u_long (xdrs, &objp->cticks))
338 return FALSE;
340 else
342 objp->zticks = IXDR_GET_U_LONG (buf);
343 objp->dticks = IXDR_GET_U_LONG (buf);
344 objp->aticks = IXDR_GET_U_LONG (buf);
345 objp->cticks = IXDR_GET_U_LONG (buf);
347 return TRUE;
350 if (!_xdr_nis_error (xdrs, &objp->status))
351 return FALSE;
352 if (!xdr_array (xdrs, (char **) &objp->objects.objects_val,
353 (u_int *) &objp->objects.objects_len, ~0,
354 sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
355 return FALSE;
356 if (!xdr_netobj (xdrs, &objp->cookie))
357 return FALSE;
358 if (!xdr_u_long (xdrs, &objp->zticks))
359 return FALSE;
360 if (!xdr_u_long (xdrs, &objp->dticks))
361 return FALSE;
362 if (!xdr_u_long (xdrs, &objp->aticks))
363 return FALSE;
364 if (!xdr_u_long (xdrs, &objp->cticks))
365 return FALSE;
366 return TRUE;
369 bool_t
370 _xdr_ns_request (XDR *xdrs, ns_request *objp)
372 if (!_xdr_nis_name (xdrs, &objp->ns_name))
373 return FALSE;
374 if (!xdr_array (xdrs, (char **) &objp->ns_object.ns_object_val,
375 (u_int *) &objp->ns_object.ns_object_len, 1,
376 sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
377 return FALSE;
378 return TRUE;
381 bool_t
382 _xdr_ib_request (XDR *xdrs, ib_request *objp)
384 if (!_xdr_nis_name (xdrs, &objp->ibr_name))
385 return FALSE;
386 if (!xdr_array (xdrs, (char **) &objp->ibr_srch.ibr_srch_val,
387 (u_int *) &objp->ibr_srch.ibr_srch_len, ~0,
388 sizeof (nis_attr), (xdrproc_t) xdr_nis_attr))
389 return FALSE;
390 if (!xdr_u_long (xdrs, &objp->ibr_flags))
391 return FALSE;
392 if (!xdr_array (xdrs, (char **) &objp->ibr_obj.ibr_obj_val,
393 (u_int *) &objp->ibr_obj.ibr_obj_len, 1,
394 sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
395 return FALSE;
396 if (!xdr_array (xdrs, (char **) &objp->ibr_cbhost.ibr_cbhost_val,
397 (u_int *) &objp->ibr_cbhost.ibr_cbhost_len, 1,
398 sizeof (nis_server), (xdrproc_t) _xdr_nis_server))
399 return FALSE;
400 if (!xdr_u_long (xdrs, &objp->ibr_bufsize))
401 return FALSE;
402 if (!xdr_netobj (xdrs, &objp->ibr_cookie))
403 return FALSE;
404 return TRUE;
407 bool_t
408 _xdr_ping_args (XDR *xdrs, ping_args *objp)
410 if (!_xdr_nis_name (xdrs, &objp->dir))
411 return FALSE;
412 if (!xdr_u_long (xdrs, &objp->stamp))
413 return FALSE;
414 return TRUE;
417 bool_t
418 _xdr_cp_result (XDR *xdrs, cp_result *objp)
420 if (!_xdr_nis_error (xdrs, &objp->cp_status))
421 return FALSE;
422 if (!xdr_u_long (xdrs, &objp->cp_zticks))
423 return FALSE;
424 if (!xdr_u_long (xdrs, &objp->cp_dticks))
425 return FALSE;
426 return TRUE;
429 bool_t
430 _xdr_nis_tag (XDR *xdrs, nis_tag *objp)
432 if (!xdr_u_long (xdrs, &objp->tag_type))
434 return FALSE;
436 if (!xdr_string (xdrs, &objp->tag_val, 1024))
438 return FALSE;
440 return TRUE;
443 bool_t
444 _xdr_nis_taglist (XDR *xdrs, nis_taglist *objp)
446 if (!xdr_array (xdrs, (char **) &objp->tags.tags_val,
447 (u_int *) &objp->tags.tags_len, ~0, sizeof (nis_tag),
448 (xdrproc_t) _xdr_nis_tag))
449 return FALSE;
450 return TRUE;
453 bool_t
454 _xdr_fd_args (XDR *xdrs, fd_args *objp)
456 if (!_xdr_nis_name (xdrs, &objp->dir_name))
457 return FALSE;
458 if (!_xdr_nis_name (xdrs, &objp->requester))
459 return FALSE;
460 return TRUE;
463 bool_t
464 _xdr_fd_result (XDR *xdrs, fd_result *objp)
466 if (!_xdr_nis_error (xdrs, &objp->status))
467 return FALSE;
468 if (!_xdr_nis_name (xdrs, &objp->source))
469 return FALSE;
470 if (!xdr_bytes (xdrs, (char **) &objp->dir_data.dir_data_val,
471 (u_int *) &objp->dir_data.dir_data_len, ~0))
472 return FALSE;
473 if (!xdr_bytes (xdrs, (char **) &objp->signature.signature_val,
474 (u_int *) &objp->signature.signature_len, ~0))
475 return FALSE;
476 return TRUE;
479 /* The following functions have prototypes in nis_callback.h. So
480 we make them public */
481 bool_t
482 xdr_obj_p (XDR *xdrs, obj_p *objp)
484 if (!xdr_pointer (xdrs, (char **)objp, sizeof (nis_object),
485 (xdrproc_t)_xdr_nis_object))
486 return FALSE;
487 return TRUE;
490 bool_t
491 xdr_cback_data (XDR *xdrs, cback_data *objp)
493 if (!xdr_array (xdrs, (char **)&objp->entries.entries_val,
494 (u_int *) &objp->entries.entries_len, ~0,
495 sizeof (obj_p), (xdrproc_t) xdr_obj_p))
496 return FALSE;
497 return TRUE;