]>
Commit | Line | Data |
---|---|---|
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> |
6259ec0d | 34 | |
eca5920c PF |
35 | /* The NIS v2 protocol suggests 1024 bytes as a maximum length of all fields. |
36 | Current Linux systems don't use this limit. To remain compatible with | |
37 | recent Linux systems we choose limits large enough to load large key and | |
38 | data values, but small enough to not pose a DoS threat. */ | |
39 | ||
40 | #define XDRMAXNAME 1024 | |
41 | #define XDRMAXRECORD (16 * 1024 * 1024) | |
42 | ||
6259ec0d UD |
43 | bool_t |
44 | xdr_ypstat (XDR *xdrs, ypstat *objp) | |
45 | { | |
7440c23e | 46 | return xdr_enum (xdrs, (enum_t *) objp); |
6259ec0d | 47 | } |
7440c23e | 48 | libnsl_hidden_def (xdr_ypstat) |
6259ec0d UD |
49 | |
50 | bool_t | |
0c6cee5d | 51 | xdr_ypxfrstat (XDR *xdrs, ypxfrstat *objp) |
6259ec0d | 52 | { |
7440c23e | 53 | return xdr_enum (xdrs, (enum_t *) objp); |
6259ec0d | 54 | } |
7440c23e | 55 | libnsl_hidden_def (xdr_ypxfrstat) |
6259ec0d UD |
56 | |
57 | bool_t | |
0c6cee5d | 58 | xdr_domainname (XDR *xdrs, domainname *objp) |
6259ec0d | 59 | { |
eca5920c | 60 | return xdr_string (xdrs, objp, XDRMAXNAME); |
6259ec0d | 61 | } |
7440c23e | 62 | libnsl_hidden_def (xdr_domainname) |
6259ec0d UD |
63 | |
64 | bool_t | |
0c6cee5d | 65 | xdr_mapname (XDR *xdrs, mapname *objp) |
6259ec0d | 66 | { |
eca5920c | 67 | return xdr_string (xdrs, objp, XDRMAXNAME); |
6259ec0d | 68 | } |
7440c23e | 69 | libnsl_hidden_def (xdr_mapname) |
6259ec0d UD |
70 | |
71 | bool_t | |
0c6cee5d | 72 | xdr_peername (XDR *xdrs, peername *objp) |
6259ec0d | 73 | { |
eca5920c | 74 | return xdr_string (xdrs, objp, XDRMAXNAME); |
6259ec0d | 75 | } |
7440c23e | 76 | libnsl_hidden_def (xdr_peername) |
6259ec0d UD |
77 | |
78 | bool_t | |
0c6cee5d | 79 | xdr_keydat (XDR *xdrs, keydat *objp) |
6259ec0d | 80 | { |
7440c23e | 81 | return xdr_bytes (xdrs, (char **) &objp->keydat_val, |
eca5920c | 82 | (u_int *) &objp->keydat_len, XDRMAXRECORD); |
6259ec0d | 83 | } |
7440c23e | 84 | libnsl_hidden_def (xdr_keydat) |
6259ec0d UD |
85 | |
86 | bool_t | |
0c6cee5d | 87 | xdr_valdat (XDR *xdrs, valdat *objp) |
6259ec0d | 88 | { |
7440c23e | 89 | return xdr_bytes (xdrs, (char **) &objp->valdat_val, |
eca5920c | 90 | (u_int *) &objp->valdat_len, XDRMAXRECORD); |
6259ec0d | 91 | } |
7440c23e | 92 | libnsl_hidden_def (xdr_valdat) |
6259ec0d UD |
93 | |
94 | bool_t | |
0c6cee5d | 95 | xdr_ypmap_parms (XDR *xdrs, ypmap_parms *objp) |
6259ec0d | 96 | { |
0c6cee5d UD |
97 | if (!xdr_domainname (xdrs, &objp->domain)) |
98 | return FALSE; | |
99 | if (!xdr_mapname (xdrs, &objp->map)) | |
100 | return FALSE; | |
101 | if (!xdr_u_int (xdrs, &objp->ordernum)) | |
102 | return FALSE; | |
7440c23e | 103 | return xdr_peername (xdrs, &objp->peer); |
6259ec0d | 104 | } |
7440c23e | 105 | libnsl_hidden_def (xdr_ypmap_parms) |
6259ec0d UD |
106 | |
107 | bool_t | |
0c6cee5d | 108 | xdr_ypreq_key (XDR *xdrs, ypreq_key *objp) |
6259ec0d | 109 | { |
0c6cee5d UD |
110 | if (!xdr_domainname (xdrs, &objp->domain)) |
111 | return FALSE; | |
112 | if (!xdr_mapname (xdrs, &objp->map)) | |
113 | return FALSE; | |
7440c23e | 114 | return xdr_keydat (xdrs, &objp->key); |
6259ec0d | 115 | } |
4b481a15 | 116 | libnsl_hidden_def (xdr_ypreq_key) |
6259ec0d UD |
117 | |
118 | bool_t | |
0c6cee5d | 119 | xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp) |
6259ec0d | 120 | { |
0c6cee5d UD |
121 | if (!xdr_domainname (xdrs, &objp->domain)) |
122 | return FALSE; | |
7440c23e | 123 | return xdr_mapname (xdrs, &objp->map); |
6259ec0d | 124 | } |
4b481a15 | 125 | libnsl_hidden_def (xdr_ypreq_nokey) |
6259ec0d UD |
126 | |
127 | bool_t | |
0c6cee5d | 128 | xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp) |
6259ec0d | 129 | { |
0c6cee5d UD |
130 | if (!xdr_ypmap_parms (xdrs, &objp->map_parms)) |
131 | return FALSE; | |
132 | if (!xdr_u_int (xdrs, &objp->transid)) | |
133 | return FALSE; | |
134 | if (!xdr_u_int (xdrs, &objp->prog)) | |
135 | return FALSE; | |
7440c23e | 136 | return xdr_u_int (xdrs, &objp->port); |
6259ec0d UD |
137 | } |
138 | ||
139 | bool_t | |
0c6cee5d | 140 | xdr_ypresp_val (XDR *xdrs, ypresp_val *objp) |
6259ec0d | 141 | { |
0c6cee5d UD |
142 | if (!xdr_ypstat (xdrs, &objp->stat)) |
143 | return FALSE; | |
7440c23e | 144 | return xdr_valdat (xdrs, &objp->val); |
6259ec0d | 145 | } |
4b481a15 | 146 | libnsl_hidden_def (xdr_ypresp_val) |
6259ec0d UD |
147 | |
148 | bool_t | |
0c6cee5d | 149 | xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp) |
6259ec0d | 150 | { |
0c6cee5d UD |
151 | if (!xdr_ypstat (xdrs, &objp->stat)) |
152 | return FALSE; | |
153 | if (!xdr_valdat (xdrs, &objp->val)) | |
154 | return FALSE; | |
7440c23e | 155 | return xdr_keydat (xdrs, &objp->key); |
6259ec0d | 156 | } |
7440c23e | 157 | libnsl_hidden_def (xdr_ypresp_key_val) |
6259ec0d UD |
158 | |
159 | bool_t | |
0c6cee5d | 160 | xdr_ypresp_master (XDR *xdrs, ypresp_master *objp) |
6259ec0d | 161 | { |
0c6cee5d UD |
162 | if (!xdr_ypstat (xdrs, &objp->stat)) |
163 | return FALSE; | |
7440c23e | 164 | return xdr_peername (xdrs, &objp->peer); |
6259ec0d | 165 | } |
4b481a15 | 166 | libnsl_hidden_def (xdr_ypresp_master) |
6259ec0d UD |
167 | |
168 | bool_t | |
0c6cee5d | 169 | xdr_ypresp_order (XDR *xdrs, ypresp_order *objp) |
6259ec0d | 170 | { |
0c6cee5d UD |
171 | if (!xdr_ypstat (xdrs, &objp->stat)) |
172 | return FALSE; | |
7440c23e | 173 | return xdr_u_int (xdrs, &objp->ordernum); |
6259ec0d | 174 | } |
4b481a15 | 175 | libnsl_hidden_def (xdr_ypresp_order) |
6259ec0d UD |
176 | |
177 | bool_t | |
0c6cee5d | 178 | xdr_ypresp_all (XDR *xdrs, ypresp_all *objp) |
6259ec0d | 179 | { |
0c6cee5d UD |
180 | if (!xdr_bool (xdrs, &objp->more)) |
181 | return FALSE; | |
182 | switch (objp->more) | |
183 | { | |
184 | case TRUE: | |
7440c23e | 185 | return xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val); |
0c6cee5d UD |
186 | case FALSE: |
187 | break; | |
188 | default: | |
189 | return FALSE; | |
6259ec0d | 190 | } |
0c6cee5d | 191 | return TRUE; |
6259ec0d | 192 | } |
7440c23e | 193 | libnsl_hidden_def (xdr_ypresp_all) |
6259ec0d UD |
194 | |
195 | bool_t | |
0c6cee5d | 196 | xdr_ypresp_xfr (XDR *xdrs, ypresp_xfr *objp) |
6259ec0d | 197 | { |
0c6cee5d UD |
198 | if (!xdr_u_int (xdrs, &objp->transid)) |
199 | return FALSE; | |
7440c23e | 200 | return xdr_ypxfrstat (xdrs, &objp->xfrstat); |
6259ec0d UD |
201 | } |
202 | ||
203 | bool_t | |
0c6cee5d | 204 | xdr_ypmaplist (XDR *xdrs, ypmaplist *objp) |
6259ec0d | 205 | { |
0c6cee5d UD |
206 | if (!xdr_mapname (xdrs, &objp->map)) |
207 | return FALSE; | |
bd0dcd28 UD |
208 | /* Prevent gcc warning about alias violation. */ |
209 | char **tp = (void *) &objp->next; | |
210 | return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist); | |
6259ec0d | 211 | } |
4b481a15 | 212 | libnsl_hidden_def (xdr_ypmaplist) |
6259ec0d UD |
213 | |
214 | bool_t | |
0c6cee5d | 215 | xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp) |
6259ec0d | 216 | { |
0c6cee5d UD |
217 | if (!xdr_ypstat (xdrs, &objp->stat)) |
218 | return FALSE; | |
bd0dcd28 UD |
219 | /* Prevent gcc warning about alias violation. */ |
220 | char **tp = (void *) &objp->maps; | |
221 | return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist); | |
6259ec0d | 222 | } |
4b481a15 | 223 | libnsl_hidden_def (xdr_ypresp_maplist) |
6259ec0d UD |
224 | |
225 | bool_t | |
0c6cee5d | 226 | xdr_yppush_status (XDR *xdrs, yppush_status *objp) |
6259ec0d | 227 | { |
7440c23e | 228 | return xdr_enum (xdrs, (enum_t *) objp); |
6259ec0d | 229 | } |
7440c23e | 230 | libnsl_hidden_def (xdr_yppush_status) |
6259ec0d UD |
231 | |
232 | bool_t | |
0c6cee5d | 233 | xdr_yppushresp_xfr (XDR *xdrs, yppushresp_xfr *objp) |
6259ec0d | 234 | { |
0c6cee5d UD |
235 | if (!xdr_u_int (xdrs, &objp->transid)) |
236 | return FALSE; | |
7440c23e | 237 | return xdr_yppush_status (xdrs, &objp->status); |
6259ec0d UD |
238 | } |
239 | ||
240 | bool_t | |
0c6cee5d | 241 | xdr_ypbind_resptype (XDR *xdrs, ypbind_resptype *objp) |
6259ec0d | 242 | { |
7440c23e | 243 | return xdr_enum (xdrs, (enum_t *) objp); |
6259ec0d | 244 | } |
7440c23e | 245 | libnsl_hidden_def (xdr_ypbind_resptype) |
6259ec0d UD |
246 | |
247 | bool_t | |
0c6cee5d | 248 | xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp) |
6259ec0d | 249 | { |
0c6cee5d UD |
250 | if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4)) |
251 | return FALSE; | |
7440c23e | 252 | return xdr_opaque (xdrs, objp->ypbind_binding_port, 2); |
6259ec0d | 253 | } |
7440c23e | 254 | libnsl_hidden_def (xdr_ypbind_binding) |
6259ec0d UD |
255 | |
256 | bool_t | |
0c6cee5d | 257 | xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp) |
6259ec0d | 258 | { |
0c6cee5d UD |
259 | if (!xdr_ypbind_resptype (xdrs, &objp->ypbind_status)) |
260 | return FALSE; | |
261 | switch (objp->ypbind_status) | |
262 | { | |
263 | case YPBIND_FAIL_VAL: | |
7440c23e | 264 | return xdr_u_int (xdrs, &objp->ypbind_resp_u.ypbind_error); |
0c6cee5d | 265 | case YPBIND_SUCC_VAL: |
7440c23e | 266 | return xdr_ypbind_binding (xdrs, &objp->ypbind_resp_u.ypbind_bindinfo); |
6259ec0d | 267 | } |
7440c23e | 268 | return FALSE; |
6259ec0d | 269 | } |
4b481a15 | 270 | libnsl_hidden_def (xdr_ypbind_resp) |
6259ec0d UD |
271 | |
272 | bool_t | |
0c6cee5d | 273 | xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp) |
6259ec0d | 274 | { |
0c6cee5d UD |
275 | if (!xdr_domainname (xdrs, &objp->ypsetdom_domain)) |
276 | return FALSE; | |
277 | if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding)) | |
278 | return FALSE; | |
7440c23e | 279 | return xdr_u_int (xdrs, &objp->ypsetdom_vers); |
6259ec0d | 280 | } |
56ad7b2c UD |
281 | |
282 | bool_t | |
283 | xdr_ypall(XDR *xdrs, struct ypall_callback *incallback) | |
284 | { | |
285 | struct ypresp_key_val out; | |
286 | char key[YPMAXRECORD], val[YPMAXRECORD]; | |
287 | ||
288 | /* | |
289 | * Set up key/val struct to be used during the transaction. | |
290 | */ | |
291 | memset(&out, 0, sizeof out); | |
292 | out.key.keydat_val = key; | |
293 | out.key.keydat_len = sizeof(key); | |
294 | out.val.valdat_val = val; | |
295 | out.val.valdat_len = sizeof(val); | |
296 | ||
297 | for (;;) { | |
298 | bool_t more, status; | |
299 | ||
300 | /* Values pending? */ | |
301 | if (!xdr_bool(xdrs, &more)) | |
302 | return FALSE; /* can't tell! */ | |
303 | if (!more) | |
304 | return TRUE; /* no more */ | |
305 | ||
306 | /* Transfer key/value pair. */ | |
307 | status = xdr_ypresp_key_val(xdrs, &out); | |
308 | ||
309 | /* | |
310 | * If we succeeded, call the callback function. | |
311 | * The callback will return TRUE when it wants | |
312 | * no more values. If we fail, indicate the | |
313 | * error. | |
314 | */ | |
315 | if (status) { | |
316 | if ((*incallback->foreach)(out.stat, | |
317 | (char *)out.key.keydat_val, out.key.keydat_len, | |
318 | (char *)out.val.valdat_val, out.val.valdat_len, | |
319 | incallback->data)) | |
320 | return TRUE; | |
321 | } else | |
322 | return FALSE; | |
323 | } | |
324 | } |