Fix range error handling in sgetspent.
[glibc.git] / nis / yp_xdr.c
blob76e0f2f21680043962f8eef7337a6b6ae9f98cfd
1 /*
2 * Copyright (c) 2010, Oracle America, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
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.
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.
32 #include <rpcsvc/yp.h>
33 #include <rpcsvc/ypclnt.h>
35 bool_t
36 xdr_ypstat (XDR *xdrs, ypstat *objp)
38 return xdr_enum (xdrs, (enum_t *) objp);
40 libnsl_hidden_def (xdr_ypstat)
42 bool_t
43 xdr_ypxfrstat (XDR *xdrs, ypxfrstat *objp)
45 return xdr_enum (xdrs, (enum_t *) objp);
47 libnsl_hidden_def (xdr_ypxfrstat)
49 bool_t
50 xdr_domainname (XDR *xdrs, domainname *objp)
52 return xdr_string (xdrs, objp, ~0);
54 libnsl_hidden_def (xdr_domainname)
56 bool_t
57 xdr_mapname (XDR *xdrs, mapname *objp)
59 return xdr_string (xdrs, objp, ~0);
61 libnsl_hidden_def (xdr_mapname)
63 bool_t
64 xdr_peername (XDR *xdrs, peername *objp)
66 return xdr_string (xdrs, objp, ~0);
68 libnsl_hidden_def (xdr_peername)
70 bool_t
71 xdr_keydat (XDR *xdrs, keydat *objp)
73 return xdr_bytes (xdrs, (char **) &objp->keydat_val,
74 (u_int *) &objp->keydat_len, ~0);
76 libnsl_hidden_def (xdr_keydat)
78 bool_t
79 xdr_valdat (XDR *xdrs, valdat *objp)
81 return xdr_bytes (xdrs, (char **) &objp->valdat_val,
82 (u_int *) &objp->valdat_len, ~0);
84 libnsl_hidden_def (xdr_valdat)
86 bool_t
87 xdr_ypmap_parms (XDR *xdrs, ypmap_parms *objp)
89 if (!xdr_domainname (xdrs, &objp->domain))
90 return FALSE;
91 if (!xdr_mapname (xdrs, &objp->map))
92 return FALSE;
93 if (!xdr_u_int (xdrs, &objp->ordernum))
94 return FALSE;
95 return xdr_peername (xdrs, &objp->peer);
97 libnsl_hidden_def (xdr_ypmap_parms)
99 bool_t
100 xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
102 if (!xdr_domainname (xdrs, &objp->domain))
103 return FALSE;
104 if (!xdr_mapname (xdrs, &objp->map))
105 return FALSE;
106 return xdr_keydat (xdrs, &objp->key);
108 libnsl_hidden_def (xdr_ypreq_key)
110 bool_t
111 xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
113 if (!xdr_domainname (xdrs, &objp->domain))
114 return FALSE;
115 return xdr_mapname (xdrs, &objp->map);
117 libnsl_hidden_def (xdr_ypreq_nokey)
119 bool_t
120 xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp)
122 if (!xdr_ypmap_parms (xdrs, &objp->map_parms))
123 return FALSE;
124 if (!xdr_u_int (xdrs, &objp->transid))
125 return FALSE;
126 if (!xdr_u_int (xdrs, &objp->prog))
127 return FALSE;
128 return xdr_u_int (xdrs, &objp->port);
131 bool_t
132 xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
134 if (!xdr_ypstat (xdrs, &objp->stat))
135 return FALSE;
136 return xdr_valdat (xdrs, &objp->val);
138 libnsl_hidden_def (xdr_ypresp_val)
140 bool_t
141 xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
143 if (!xdr_ypstat (xdrs, &objp->stat))
144 return FALSE;
145 if (!xdr_valdat (xdrs, &objp->val))
146 return FALSE;
147 return xdr_keydat (xdrs, &objp->key);
149 libnsl_hidden_def (xdr_ypresp_key_val)
151 bool_t
152 xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
154 if (!xdr_ypstat (xdrs, &objp->stat))
155 return FALSE;
156 return xdr_peername (xdrs, &objp->peer);
158 libnsl_hidden_def (xdr_ypresp_master)
160 bool_t
161 xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
163 if (!xdr_ypstat (xdrs, &objp->stat))
164 return FALSE;
165 return xdr_u_int (xdrs, &objp->ordernum);
167 libnsl_hidden_def (xdr_ypresp_order)
169 bool_t
170 xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
172 if (!xdr_bool (xdrs, &objp->more))
173 return FALSE;
174 switch (objp->more)
176 case TRUE:
177 return xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val);
178 case FALSE:
179 break;
180 default:
181 return FALSE;
183 return TRUE;
185 libnsl_hidden_def (xdr_ypresp_all)
187 bool_t
188 xdr_ypresp_xfr (XDR *xdrs, ypresp_xfr *objp)
190 if (!xdr_u_int (xdrs, &objp->transid))
191 return FALSE;
192 return xdr_ypxfrstat (xdrs, &objp->xfrstat);
195 bool_t
196 xdr_ypmaplist (XDR *xdrs, ypmaplist *objp)
198 if (!xdr_mapname (xdrs, &objp->map))
199 return FALSE;
200 /* Prevent gcc warning about alias violation. */
201 char **tp = (void *) &objp->next;
202 return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
204 libnsl_hidden_def (xdr_ypmaplist)
206 bool_t
207 xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
209 if (!xdr_ypstat (xdrs, &objp->stat))
210 return FALSE;
211 /* Prevent gcc warning about alias violation. */
212 char **tp = (void *) &objp->maps;
213 return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
215 libnsl_hidden_def (xdr_ypresp_maplist)
217 bool_t
218 xdr_yppush_status (XDR *xdrs, yppush_status *objp)
220 return xdr_enum (xdrs, (enum_t *) objp);
222 libnsl_hidden_def (xdr_yppush_status)
224 bool_t
225 xdr_yppushresp_xfr (XDR *xdrs, yppushresp_xfr *objp)
227 if (!xdr_u_int (xdrs, &objp->transid))
228 return FALSE;
229 return xdr_yppush_status (xdrs, &objp->status);
232 bool_t
233 xdr_ypbind_resptype (XDR *xdrs, ypbind_resptype *objp)
235 return xdr_enum (xdrs, (enum_t *) objp);
237 libnsl_hidden_def (xdr_ypbind_resptype)
239 bool_t
240 xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp)
242 if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4))
243 return FALSE;
244 return xdr_opaque (xdrs, objp->ypbind_binding_port, 2);
246 libnsl_hidden_def (xdr_ypbind_binding)
248 bool_t
249 xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp)
251 if (!xdr_ypbind_resptype (xdrs, &objp->ypbind_status))
252 return FALSE;
253 switch (objp->ypbind_status)
255 case YPBIND_FAIL_VAL:
256 return xdr_u_int (xdrs, &objp->ypbind_resp_u.ypbind_error);
257 case YPBIND_SUCC_VAL:
258 return xdr_ypbind_binding (xdrs, &objp->ypbind_resp_u.ypbind_bindinfo);
260 return FALSE;
262 libnsl_hidden_def (xdr_ypbind_resp)
264 bool_t
265 xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
267 if (!xdr_domainname (xdrs, &objp->ypsetdom_domain))
268 return FALSE;
269 if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding))
270 return FALSE;
271 return xdr_u_int (xdrs, &objp->ypsetdom_vers);
274 bool_t
275 xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
277 struct ypresp_key_val out;
278 char key[YPMAXRECORD], val[YPMAXRECORD];
281 * Set up key/val struct to be used during the transaction.
283 memset(&out, 0, sizeof out);
284 out.key.keydat_val = key;
285 out.key.keydat_len = sizeof(key);
286 out.val.valdat_val = val;
287 out.val.valdat_len = sizeof(val);
289 for (;;) {
290 bool_t more, status;
292 /* Values pending? */
293 if (!xdr_bool(xdrs, &more))
294 return FALSE; /* can't tell! */
295 if (!more)
296 return TRUE; /* no more */
298 /* Transfer key/value pair. */
299 status = xdr_ypresp_key_val(xdrs, &out);
302 * If we succeeded, call the callback function.
303 * The callback will return TRUE when it wants
304 * no more values. If we fail, indicate the
305 * error.
307 if (status) {
308 if ((*incallback->foreach)(out.stat,
309 (char *)out.key.keydat_val, out.key.keydat_len,
310 (char *)out.val.valdat_val, out.val.valdat_len,
311 incallback->data))
312 return TRUE;
313 } else
314 return FALSE;