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