]> git.ipfire.org Git - thirdparty/glibc.git/blob - nis/nis_xdr.c
* nis/nis_xdr.c: Remove unnecessary cast which might hide bugs.
[thirdparty/glibc.git] / nis / nis_xdr.c
1 /* Copyright (c) 1997, 1998, 2005 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.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20 #include <rpcsvc/nis.h>
21 #include <rpcsvc/nis_callback.h> /* for "official" Solaris xdr functions */
22
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"
27
28 static bool_t
29 xdr_nis_attr (XDR *xdrs, nis_attr *objp)
30 {
31 bool_t res = xdr_string (xdrs, &objp->zattr_ndx, ~0);
32 if (__builtin_expect (res, TRUE))
33 res = xdr_bytes (xdrs, (char **) &objp->zattr_val.zattr_val_val,
34 &objp->zattr_val.zattr_val_len, ~0);
35 return res;
36 }
37
38 bool_t
39 _xdr_nis_name (XDR *xdrs, nis_name *objp)
40 {
41 return xdr_string (xdrs, objp, ~0);
42 }
43
44 static bool_t
45 xdr_zotypes (XDR *xdrs, zotypes *objp)
46 {
47 return xdr_enum (xdrs, (enum_t *) objp);
48 }
49
50 static bool_t
51 xdr_nstype (XDR *xdrs, nstype *objp)
52 {
53 return xdr_enum (xdrs, (enum_t *) objp);
54 }
55
56 static bool_t
57 xdr_oar_mask (XDR *xdrs, oar_mask *objp)
58 {
59 bool_t res = xdr_u_int (xdrs, &objp->oa_rights);
60 if (__builtin_expect (res, TRUE))
61 res = xdr_zotypes (xdrs, &objp->oa_otype);
62 return res;
63 }
64
65 static bool_t
66 xdr_endpoint (XDR *xdrs, endpoint *objp)
67 {
68 bool_t res = xdr_string (xdrs, &objp->uaddr, ~0);
69 if (__builtin_expect (res, TRUE))
70 {
71 res = xdr_string (xdrs, &objp->family, ~0);
72 if (__builtin_expect (res, 1))
73 res = xdr_string (xdrs, &objp->proto, ~0);
74 }
75 return res;
76 }
77
78 bool_t
79 _xdr_nis_server (XDR *xdrs, nis_server *objp)
80 {
81 bool_t res = _xdr_nis_name (xdrs, &objp->name);
82 if (__builtin_expect (res, TRUE))
83 {
84 res = xdr_array (xdrs, (char **) &objp->ep.ep_val, &objp->ep.ep_len,
85 ~0, sizeof (endpoint), (xdrproc_t) xdr_endpoint);
86 if (__builtin_expect (res, TRUE))
87 {
88 res = xdr_u_int (xdrs, &objp->key_type);
89 if (__builtin_expect (res, TRUE))
90 res = xdr_netobj (xdrs, &objp->pkey);
91 }
92 }
93 return res;
94 }
95
96 bool_t
97 _xdr_directory_obj (XDR *xdrs, directory_obj *objp)
98 {
99 bool_t res = _xdr_nis_name (xdrs, &objp->do_name);
100 if (__builtin_expect (res, TRUE))
101 {
102 res = xdr_nstype (xdrs, &objp->do_type);
103 if (__builtin_expect (res, TRUE))
104 {
105 res = xdr_array (xdrs, (char **) &objp->do_servers.do_servers_val,
106 &objp->do_servers.do_servers_len, ~0,
107 sizeof (nis_server), (xdrproc_t) _xdr_nis_server);
108 if (__builtin_expect (res, TRUE))
109 {
110 res = xdr_uint32_t (xdrs, &objp->do_ttl);
111 if (__builtin_expect (res, TRUE))
112 res = xdr_array (xdrs,
113 (char **) &objp->do_armask.do_armask_val,
114 &objp->do_armask.do_armask_len, ~0,
115 sizeof (oar_mask), (xdrproc_t) xdr_oar_mask);
116 }
117 }
118 }
119 return res;
120 }
121
122 static bool_t
123 xdr_entry_col (XDR *xdrs, entry_col *objp)
124 {
125 bool_t res = xdr_u_int (xdrs, &objp->ec_flags);
126 if (__builtin_expect (res, TRUE))
127 res = xdr_bytes (xdrs, (char **) &objp->ec_value.ec_value_val,
128 &objp->ec_value.ec_value_len, ~0);
129 return res;
130 }
131
132 static bool_t
133 xdr_entry_obj (XDR *xdrs, entry_obj *objp)
134 {
135 bool_t res = xdr_string (xdrs, &objp->en_type, ~0);
136 if (__builtin_expect (res, TRUE))
137 res = xdr_array (xdrs, (char **) &objp->en_cols.en_cols_val,
138 &objp->en_cols.en_cols_len, ~0,
139 sizeof (entry_col), (xdrproc_t) xdr_entry_col);
140 return res;
141 }
142
143 static bool_t
144 xdr_group_obj (XDR *xdrs, group_obj *objp)
145 {
146 bool_t res = xdr_u_int (xdrs, &objp->gr_flags);
147 if (__builtin_expect (res, TRUE))
148 res = xdr_array (xdrs, (char **) &objp->gr_members.gr_members_val,
149 &objp->gr_members.gr_members_len, ~0,
150 sizeof (nis_name), (xdrproc_t) _xdr_nis_name);
151 return res;
152 }
153
154 static bool_t
155 xdr_link_obj (XDR *xdrs, link_obj *objp)
156 {
157 bool_t res = xdr_zotypes (xdrs, &objp->li_rtype);
158 if (__builtin_expect (res, TRUE))
159 {
160 res = xdr_array (xdrs, (char **) &objp->li_attrs.li_attrs_val,
161 &objp->li_attrs.li_attrs_len, ~0,
162 sizeof (nis_attr), (xdrproc_t) xdr_nis_attr);
163 if (__builtin_expect (res, TRUE))
164 res = _xdr_nis_name (xdrs, &objp->li_name);
165 }
166 return res;
167 }
168
169 static bool_t
170 xdr_table_col (XDR *xdrs, table_col *objp)
171 {
172 bool_t res = xdr_string (xdrs, &objp->tc_name, 64);
173 if (__builtin_expect (res, TRUE))
174 {
175 res = xdr_u_int (xdrs, &objp->tc_flags);
176 if (__builtin_expect (res, TRUE))
177 res = xdr_u_int (xdrs, &objp->tc_rights);
178 }
179 return res;
180 }
181
182 static bool_t
183 xdr_table_obj (XDR *xdrs, table_obj *objp)
184 {
185 bool_t res = xdr_string (xdrs, &objp->ta_type, 64);
186 if (__builtin_expect (res, TRUE))
187 {
188 res = xdr_int (xdrs, &objp->ta_maxcol);
189 if (__builtin_expect (res, TRUE))
190 {
191 res = xdr_u_char (xdrs, &objp->ta_sep);
192 if (__builtin_expect (res, TRUE))
193 {
194 res = xdr_array (xdrs, (char **) &objp->ta_cols.ta_cols_val,
195 &objp->ta_cols.ta_cols_len, ~0,
196 sizeof (table_col), (xdrproc_t) xdr_table_col);
197 if (__builtin_expect (res, TRUE))
198 res = xdr_string (xdrs, &objp->ta_path, ~0);
199 }
200 }
201 }
202 return res;
203 }
204
205 static bool_t
206 xdr_objdata (XDR *xdrs, objdata *objp)
207 {
208 bool_t res = xdr_zotypes (xdrs, &objp->zo_type);
209 if (!__builtin_expect (res, TRUE))
210 return res;
211 switch (objp->zo_type)
212 {
213 case NIS_DIRECTORY_OBJ:
214 return _xdr_directory_obj (xdrs, &objp->objdata_u.di_data);
215 case NIS_GROUP_OBJ:
216 return xdr_group_obj (xdrs, &objp->objdata_u.gr_data);
217 case NIS_TABLE_OBJ:
218 return xdr_table_obj (xdrs, &objp->objdata_u.ta_data);
219 case NIS_ENTRY_OBJ:
220 return xdr_entry_obj (xdrs, &objp->objdata_u.en_data);
221 case NIS_LINK_OBJ:
222 return xdr_link_obj (xdrs, &objp->objdata_u.li_data);
223 case NIS_PRIVATE_OBJ:
224 return xdr_bytes (xdrs, &objp->objdata_u.po_data.po_data_val,
225 &objp->objdata_u.po_data.po_data_len, ~0);
226 case NIS_NO_OBJ:
227 case NIS_BOGUS_OBJ:
228 default:
229 return TRUE;
230 }
231 }
232
233 static bool_t
234 xdr_nis_oid (XDR *xdrs, nis_oid *objp)
235 {
236 bool_t res = xdr_uint32_t (xdrs, &objp->ctime);
237 if (__builtin_expect (res, TRUE))
238 res = xdr_uint32_t (xdrs, &objp->mtime);
239 return res;
240 }
241
242 bool_t
243 _xdr_nis_object (XDR *xdrs, nis_object *objp)
244 {
245 bool_t res = xdr_nis_oid (xdrs, &objp->zo_oid);
246 if (__builtin_expect (res, TRUE))
247 {
248 res = _xdr_nis_name (xdrs, &objp->zo_name);
249 if (__builtin_expect (res, TRUE))
250 {
251 res = _xdr_nis_name (xdrs, &objp->zo_owner);
252 if (__builtin_expect (res, TRUE))
253 {
254 res = _xdr_nis_name (xdrs, &objp->zo_group);
255 if (__builtin_expect (res, TRUE))
256 {
257 res = _xdr_nis_name (xdrs, &objp->zo_domain);
258 if (__builtin_expect (res, TRUE))
259 {
260 res = xdr_u_int (xdrs, &objp->zo_access);
261 if (__builtin_expect (res, TRUE))
262 {
263 res = xdr_uint32_t (xdrs, &objp->zo_ttl);
264 if (__builtin_expect (res, TRUE))
265 res = xdr_objdata (xdrs, &objp->zo_data);
266 }
267 }
268 }
269 }
270 }
271 }
272 return res;
273 }
274
275 bool_t
276 _xdr_nis_error (XDR *xdrs, nis_error *objp)
277 {
278 return xdr_enum (xdrs, (enum_t *) objp);
279 }
280
281 bool_t
282 _xdr_nis_result (XDR *xdrs, nis_result *objp)
283 {
284 bool res = _xdr_nis_error (xdrs, &objp->status);
285 if (__builtin_expect (res, TRUE))
286 {
287 res = xdr_array (xdrs, (char **) &objp->objects.objects_val,
288 &objp->objects.objects_len, ~0,
289 sizeof (nis_object), (xdrproc_t) _xdr_nis_object);
290 if (__builtin_expect (res, TRUE))
291 {
292 res = xdr_netobj (xdrs, &objp->cookie);
293 if (__builtin_expect (res, TRUE))
294 {
295 res = xdr_uint32_t (xdrs, &objp->zticks);
296 if (__builtin_expect (res, TRUE))
297 {
298 res = xdr_uint32_t (xdrs, &objp->dticks);
299 if (__builtin_expect (res, TRUE))
300 {
301 res = xdr_uint32_t (xdrs, &objp->aticks);
302 if (__builtin_expect (res, TRUE))
303 res = xdr_uint32_t (xdrs, &objp->cticks);
304 }
305 }
306 }
307 }
308 }
309 return res;
310 }
311
312 bool_t
313 _xdr_ns_request (XDR *xdrs, ns_request *objp)
314 {
315 bool_t res = _xdr_nis_name (xdrs, &objp->ns_name);
316 if (__builtin_expect (res, TRUE))
317 res = xdr_array (xdrs, (char **) &objp->ns_object.ns_object_val,
318 &objp->ns_object.ns_object_len, 1,
319 sizeof (nis_object), (xdrproc_t) _xdr_nis_object);
320 return res;
321 }
322
323 bool_t
324 _xdr_ib_request (XDR *xdrs, ib_request *objp)
325 {
326 bool_t res = _xdr_nis_name (xdrs, &objp->ibr_name);
327 if (__builtin_expect (res, TRUE))
328 {
329 res = xdr_array (xdrs, (char **) &objp->ibr_srch.ibr_srch_val,
330 &objp->ibr_srch.ibr_srch_len, ~0,
331 sizeof (nis_attr), (xdrproc_t) xdr_nis_attr);
332 if (__builtin_expect (res, TRUE))
333 {
334 res = xdr_u_int (xdrs, &objp->ibr_flags);
335 if (__builtin_expect (res, TRUE))
336 {
337 res = xdr_array (xdrs, (char **) &objp->ibr_obj.ibr_obj_val,
338 &objp->ibr_obj.ibr_obj_len, 1,
339 sizeof (nis_object),
340 (xdrproc_t) _xdr_nis_object);
341 if (__builtin_expect (res, TRUE))
342 {
343 res = xdr_array (xdrs,
344 (char **) &objp->ibr_cbhost.ibr_cbhost_val,
345 &objp->ibr_cbhost.ibr_cbhost_len, 1,
346 sizeof (nis_server),
347 (xdrproc_t) _xdr_nis_server);
348 if (__builtin_expect (res, TRUE))
349 {
350 res = xdr_u_int (xdrs, &objp->ibr_bufsize);
351 if (__builtin_expect (res, TRUE))
352 res = xdr_netobj (xdrs, &objp->ibr_cookie);
353 }
354 }
355 }
356 }
357 }
358 return res;
359 }
360
361 bool_t
362 _xdr_ping_args (XDR *xdrs, ping_args *objp)
363 {
364 bool_t res = _xdr_nis_name (xdrs, &objp->dir);
365 if (__builtin_expect (res, TRUE))
366 res = xdr_uint32_t (xdrs, &objp->stamp);
367 return res;
368 }
369
370 bool_t
371 _xdr_cp_result (XDR *xdrs, cp_result *objp)
372 {
373 bool_t res = _xdr_nis_error (xdrs, &objp->cp_status);
374 if (__builtin_expect (res, TRUE))
375 {
376 res = xdr_uint32_t (xdrs, &objp->cp_zticks);
377 if (__builtin_expect (res, TRUE))
378 res = xdr_uint32_t (xdrs, &objp->cp_dticks);
379 }
380 return res;
381 }
382
383 bool_t
384 _xdr_nis_tag (XDR *xdrs, nis_tag *objp)
385 {
386 bool_t res = xdr_u_int (xdrs, &objp->tag_type);
387 if (__builtin_expect (res, TRUE))
388 res = xdr_string (xdrs, &objp->tag_val, ~0);
389 return res;
390 }
391
392 bool_t
393 _xdr_nis_taglist (XDR *xdrs, nis_taglist *objp)
394 {
395 return xdr_array (xdrs, (char **) &objp->tags.tags_val,
396 &objp->tags.tags_len, ~0, sizeof (nis_tag),
397 (xdrproc_t) _xdr_nis_tag);
398 }
399
400 bool_t
401 _xdr_fd_args (XDR *xdrs, fd_args *objp)
402 {
403 bool_t res = _xdr_nis_name (xdrs, &objp->dir_name);
404 if (__builtin_expect (res, TRUE))
405 res = _xdr_nis_name (xdrs, &objp->requester);
406 return res;
407 }
408
409 bool_t
410 _xdr_fd_result (XDR *xdrs, fd_result *objp)
411 {
412 bool_t res = _xdr_nis_error (xdrs, &objp->status);
413 if (__builtin_expect (res, TRUE))
414 {
415 res = _xdr_nis_name (xdrs, &objp->source);
416 if (__builtin_expect (res, TRUE))
417 {
418 res = xdr_bytes (xdrs, (char **) &objp->dir_data.dir_data_val,
419 &objp->dir_data.dir_data_len, ~0);
420 if (__builtin_expect (res, TRUE))
421 res = xdr_bytes (xdrs, (char **) &objp->signature.signature_val,
422 &objp->signature.signature_len, ~0);
423 }
424 }
425 return res;
426 }
427
428 /* The following functions have prototypes in nis_callback.h. So
429 we make them public */
430 bool_t
431 xdr_obj_p (XDR *xdrs, obj_p *objp)
432 {
433 return xdr_pointer (xdrs, (char **)objp, sizeof (nis_object),
434 (xdrproc_t)_xdr_nis_object);
435 }
436
437 bool_t
438 xdr_cback_data (XDR *xdrs, cback_data *objp)
439 {
440 return xdr_array (xdrs, (char **)&objp->entries.entries_val,
441 &objp->entries.entries_len, ~0,
442 sizeof (obj_p), (xdrproc_t) xdr_obj_p);
443 }