]> git.ipfire.org Git - thirdparty/glibc.git/blame - nis/yp_xdr.c
build-many-glibcs.py: Add openrisc hard float glibc variant
[thirdparty/glibc.git] / nis / yp_xdr.c
CommitLineData
6259ec0d 1/*
f2933da9 2 * Copyright (c) 2010, Oracle America, Inc.
0c6cee5d 3 *
f2933da9
UD
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
0c6cee5d 7 *
f2933da9
UD
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of the "Oracle America, Inc." nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
0c6cee5d 17 *
f2933da9
UD
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6259ec0d
UD
30 */
31
32#include <rpcsvc/yp.h>
56ad7b2c 33#include <rpcsvc/ypclnt.h>
82f43dd2 34#include <shlib-compat.h>
6259ec0d 35
eca5920c
PF
36/* The NIS v2 protocol suggests 1024 bytes as a maximum length of all fields.
37 Current Linux systems don't use this limit. To remain compatible with
38 recent Linux systems we choose limits large enough to load large key and
39 data values, but small enough to not pose a DoS threat. */
40
41#define XDRMAXNAME 1024
42#define XDRMAXRECORD (16 * 1024 * 1024)
43
6259ec0d
UD
44bool_t
45xdr_ypstat (XDR *xdrs, ypstat *objp)
46{
7440c23e 47 return xdr_enum (xdrs, (enum_t *) objp);
6259ec0d 48}
1e4d83f6 49libnsl_hidden_nolink_def (xdr_ypstat, GLIBC_2_0)
6259ec0d
UD
50
51bool_t
0c6cee5d 52xdr_ypxfrstat (XDR *xdrs, ypxfrstat *objp)
6259ec0d 53{
7440c23e 54 return xdr_enum (xdrs, (enum_t *) objp);
6259ec0d 55}
1e4d83f6 56libnsl_hidden_nolink_def (xdr_ypxfrstat, GLIBC_2_0)
6259ec0d
UD
57
58bool_t
0c6cee5d 59xdr_domainname (XDR *xdrs, domainname *objp)
6259ec0d 60{
eca5920c 61 return xdr_string (xdrs, objp, XDRMAXNAME);
6259ec0d 62}
1e4d83f6 63libnsl_hidden_nolink_def (xdr_domainname, GLIBC_2_0)
6259ec0d
UD
64
65bool_t
0c6cee5d 66xdr_mapname (XDR *xdrs, mapname *objp)
6259ec0d 67{
eca5920c 68 return xdr_string (xdrs, objp, XDRMAXNAME);
6259ec0d 69}
1e4d83f6 70libnsl_hidden_nolink_def (xdr_mapname, GLIBC_2_0)
6259ec0d
UD
71
72bool_t
0c6cee5d 73xdr_peername (XDR *xdrs, peername *objp)
6259ec0d 74{
eca5920c 75 return xdr_string (xdrs, objp, XDRMAXNAME);
6259ec0d 76}
1e4d83f6 77libnsl_hidden_nolink_def (xdr_peername, GLIBC_2_0)
6259ec0d
UD
78
79bool_t
0c6cee5d 80xdr_keydat (XDR *xdrs, keydat *objp)
6259ec0d 81{
7440c23e 82 return xdr_bytes (xdrs, (char **) &objp->keydat_val,
eca5920c 83 (u_int *) &objp->keydat_len, XDRMAXRECORD);
6259ec0d 84}
1e4d83f6 85libnsl_hidden_nolink_def (xdr_keydat, GLIBC_2_0)
6259ec0d
UD
86
87bool_t
0c6cee5d 88xdr_valdat (XDR *xdrs, valdat *objp)
6259ec0d 89{
7440c23e 90 return xdr_bytes (xdrs, (char **) &objp->valdat_val,
eca5920c 91 (u_int *) &objp->valdat_len, XDRMAXRECORD);
6259ec0d 92}
1e4d83f6 93libnsl_hidden_nolink_def (xdr_valdat, GLIBC_2_0)
6259ec0d
UD
94
95bool_t
0c6cee5d 96xdr_ypmap_parms (XDR *xdrs, ypmap_parms *objp)
6259ec0d 97{
0c6cee5d
UD
98 if (!xdr_domainname (xdrs, &objp->domain))
99 return FALSE;
100 if (!xdr_mapname (xdrs, &objp->map))
101 return FALSE;
102 if (!xdr_u_int (xdrs, &objp->ordernum))
103 return FALSE;
7440c23e 104 return xdr_peername (xdrs, &objp->peer);
6259ec0d 105}
1e4d83f6 106libnsl_hidden_nolink_def (xdr_ypmap_parms, GLIBC_2_0)
6259ec0d
UD
107
108bool_t
0c6cee5d 109xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
6259ec0d 110{
0c6cee5d
UD
111 if (!xdr_domainname (xdrs, &objp->domain))
112 return FALSE;
113 if (!xdr_mapname (xdrs, &objp->map))
114 return FALSE;
7440c23e 115 return xdr_keydat (xdrs, &objp->key);
6259ec0d 116}
1e4d83f6 117libnsl_hidden_nolink_def (xdr_ypreq_key, GLIBC_2_0)
6259ec0d
UD
118
119bool_t
0c6cee5d 120xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
6259ec0d 121{
0c6cee5d
UD
122 if (!xdr_domainname (xdrs, &objp->domain))
123 return FALSE;
7440c23e 124 return xdr_mapname (xdrs, &objp->map);
6259ec0d 125}
1e4d83f6 126libnsl_hidden_nolink_def (xdr_ypreq_nokey, GLIBC_2_0)
6259ec0d
UD
127
128bool_t
0c6cee5d 129xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp)
6259ec0d 130{
0c6cee5d
UD
131 if (!xdr_ypmap_parms (xdrs, &objp->map_parms))
132 return FALSE;
133 if (!xdr_u_int (xdrs, &objp->transid))
134 return FALSE;
135 if (!xdr_u_int (xdrs, &objp->prog))
136 return FALSE;
7440c23e 137 return xdr_u_int (xdrs, &objp->port);
6259ec0d 138}
1e4d83f6 139libnsl_hidden_nolink_def (xdr_ypreq_xfr, GLIBC_2_0)
6259ec0d
UD
140
141bool_t
0c6cee5d 142xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
6259ec0d 143{
0c6cee5d
UD
144 if (!xdr_ypstat (xdrs, &objp->stat))
145 return FALSE;
7440c23e 146 return xdr_valdat (xdrs, &objp->val);
6259ec0d 147}
1e4d83f6 148libnsl_hidden_nolink_def (xdr_ypresp_val, GLIBC_2_0)
6259ec0d
UD
149
150bool_t
0c6cee5d 151xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
6259ec0d 152{
0c6cee5d
UD
153 if (!xdr_ypstat (xdrs, &objp->stat))
154 return FALSE;
155 if (!xdr_valdat (xdrs, &objp->val))
156 return FALSE;
7440c23e 157 return xdr_keydat (xdrs, &objp->key);
6259ec0d 158}
1e4d83f6 159libnsl_hidden_nolink_def (xdr_ypresp_key_val, GLIBC_2_0)
6259ec0d
UD
160
161bool_t
0c6cee5d 162xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
6259ec0d 163{
0c6cee5d
UD
164 if (!xdr_ypstat (xdrs, &objp->stat))
165 return FALSE;
7440c23e 166 return xdr_peername (xdrs, &objp->peer);
6259ec0d 167}
1e4d83f6 168libnsl_hidden_nolink_def (xdr_ypresp_master, GLIBC_2_0)
6259ec0d
UD
169
170bool_t
0c6cee5d 171xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
6259ec0d 172{
0c6cee5d
UD
173 if (!xdr_ypstat (xdrs, &objp->stat))
174 return FALSE;
7440c23e 175 return xdr_u_int (xdrs, &objp->ordernum);
6259ec0d 176}
1e4d83f6 177libnsl_hidden_nolink_def (xdr_ypresp_order, GLIBC_2_0)
6259ec0d
UD
178
179bool_t
0c6cee5d 180xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
6259ec0d 181{
0c6cee5d
UD
182 if (!xdr_bool (xdrs, &objp->more))
183 return FALSE;
184 switch (objp->more)
185 {
186 case TRUE:
7440c23e 187 return xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val);
0c6cee5d
UD
188 case FALSE:
189 break;
190 default:
191 return FALSE;
6259ec0d 192 }
0c6cee5d 193 return TRUE;
6259ec0d 194}
1e4d83f6 195libnsl_hidden_nolink_def (xdr_ypresp_all, GLIBC_2_0)
6259ec0d
UD
196
197bool_t
0c6cee5d 198xdr_ypresp_xfr (XDR *xdrs, ypresp_xfr *objp)
6259ec0d 199{
0c6cee5d
UD
200 if (!xdr_u_int (xdrs, &objp->transid))
201 return FALSE;
7440c23e 202 return xdr_ypxfrstat (xdrs, &objp->xfrstat);
6259ec0d 203}
1e4d83f6 204libnsl_hidden_nolink_def (xdr_ypresp_xfr, GLIBC_2_0)
6259ec0d
UD
205
206bool_t
0c6cee5d 207xdr_ypmaplist (XDR *xdrs, ypmaplist *objp)
6259ec0d 208{
0c6cee5d
UD
209 if (!xdr_mapname (xdrs, &objp->map))
210 return FALSE;
bd0dcd28
UD
211 /* Prevent gcc warning about alias violation. */
212 char **tp = (void *) &objp->next;
213 return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
6259ec0d 214}
1e4d83f6 215libnsl_hidden_nolink_def (xdr_ypmaplist, GLIBC_2_0)
6259ec0d
UD
216
217bool_t
0c6cee5d 218xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
6259ec0d 219{
0c6cee5d
UD
220 if (!xdr_ypstat (xdrs, &objp->stat))
221 return FALSE;
bd0dcd28
UD
222 /* Prevent gcc warning about alias violation. */
223 char **tp = (void *) &objp->maps;
224 return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
6259ec0d 225}
1e4d83f6 226libnsl_hidden_nolink_def (xdr_ypresp_maplist, GLIBC_2_0)
6259ec0d
UD
227
228bool_t
0c6cee5d 229xdr_yppush_status (XDR *xdrs, yppush_status *objp)
6259ec0d 230{
7440c23e 231 return xdr_enum (xdrs, (enum_t *) objp);
6259ec0d 232}
1e4d83f6 233libnsl_hidden_nolink_def (xdr_yppush_status, GLIBC_2_0)
6259ec0d
UD
234
235bool_t
0c6cee5d 236xdr_yppushresp_xfr (XDR *xdrs, yppushresp_xfr *objp)
6259ec0d 237{
0c6cee5d
UD
238 if (!xdr_u_int (xdrs, &objp->transid))
239 return FALSE;
7440c23e 240 return xdr_yppush_status (xdrs, &objp->status);
6259ec0d 241}
1e4d83f6 242libnsl_hidden_nolink_def (xdr_yppushresp_xfr, GLIBC_2_0)
6259ec0d
UD
243
244bool_t
0c6cee5d 245xdr_ypbind_resptype (XDR *xdrs, ypbind_resptype *objp)
6259ec0d 246{
7440c23e 247 return xdr_enum (xdrs, (enum_t *) objp);
6259ec0d 248}
1e4d83f6 249libnsl_hidden_nolink_def (xdr_ypbind_resptype, GLIBC_2_0)
6259ec0d
UD
250
251bool_t
0c6cee5d 252xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp)
6259ec0d 253{
0c6cee5d
UD
254 if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4))
255 return FALSE;
7440c23e 256 return xdr_opaque (xdrs, objp->ypbind_binding_port, 2);
6259ec0d 257}
1e4d83f6 258libnsl_hidden_nolink_def (xdr_ypbind_binding, GLIBC_2_0)
6259ec0d
UD
259
260bool_t
0c6cee5d 261xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp)
6259ec0d 262{
0c6cee5d
UD
263 if (!xdr_ypbind_resptype (xdrs, &objp->ypbind_status))
264 return FALSE;
265 switch (objp->ypbind_status)
266 {
267 case YPBIND_FAIL_VAL:
7440c23e 268 return xdr_u_int (xdrs, &objp->ypbind_resp_u.ypbind_error);
0c6cee5d 269 case YPBIND_SUCC_VAL:
7440c23e 270 return xdr_ypbind_binding (xdrs, &objp->ypbind_resp_u.ypbind_bindinfo);
6259ec0d 271 }
7440c23e 272 return FALSE;
6259ec0d 273}
1e4d83f6 274libnsl_hidden_nolink_def (xdr_ypbind_resp, GLIBC_2_0)
6259ec0d
UD
275
276bool_t
0c6cee5d 277xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
6259ec0d 278{
0c6cee5d
UD
279 if (!xdr_domainname (xdrs, &objp->ypsetdom_domain))
280 return FALSE;
281 if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding))
282 return FALSE;
7440c23e 283 return xdr_u_int (xdrs, &objp->ypsetdom_vers);
6259ec0d 284}
1e4d83f6 285libnsl_hidden_nolink_def (xdr_ypbind_setdom, GLIBC_2_0)
56ad7b2c
UD
286
287bool_t
288xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
289{
290 struct ypresp_key_val out;
291 char key[YPMAXRECORD], val[YPMAXRECORD];
292
293 /*
294 * Set up key/val struct to be used during the transaction.
295 */
296 memset(&out, 0, sizeof out);
297 out.key.keydat_val = key;
298 out.key.keydat_len = sizeof(key);
299 out.val.valdat_val = val;
300 out.val.valdat_len = sizeof(val);
301
302 for (;;) {
303 bool_t more, status;
304
305 /* Values pending? */
306 if (!xdr_bool(xdrs, &more))
307 return FALSE; /* can't tell! */
308 if (!more)
309 return TRUE; /* no more */
310
311 /* Transfer key/value pair. */
312 status = xdr_ypresp_key_val(xdrs, &out);
313
314 /*
315 * If we succeeded, call the callback function.
316 * The callback will return TRUE when it wants
317 * no more values. If we fail, indicate the
318 * error.
319 */
320 if (status) {
321 if ((*incallback->foreach)(out.stat,
322 (char *)out.key.keydat_val, out.key.keydat_len,
323 (char *)out.val.valdat_val, out.val.valdat_len,
324 incallback->data))
325 return TRUE;
326 } else
327 return FALSE;
328 }
329}
cdd14619 330libnsl_hidden_nolink_def (xdr_ypall, GLIBC_2_2)