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
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>
34 #include <shlib-compat.h>
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. */
41 #define XDRMAXNAME 1024
42 #define XDRMAXRECORD (16 * 1024 * 1024)
45 xdr_ypstat (XDR
*xdrs
, ypstat
*objp
)
47 return xdr_enum (xdrs
, (enum_t
*) objp
);
49 libnsl_hidden_nolink_def (xdr_ypstat
, GLIBC_2_0
)
52 xdr_ypxfrstat (XDR
*xdrs
, ypxfrstat
*objp
)
54 return xdr_enum (xdrs
, (enum_t
*) objp
);
56 libnsl_hidden_nolink_def (xdr_ypxfrstat
, GLIBC_2_0
)
59 xdr_domainname (XDR
*xdrs
, domainname
*objp
)
61 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
63 libnsl_hidden_nolink_def (xdr_domainname
, GLIBC_2_0
)
66 xdr_mapname (XDR
*xdrs
, mapname
*objp
)
68 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
70 libnsl_hidden_nolink_def (xdr_mapname
, GLIBC_2_0
)
73 xdr_peername (XDR
*xdrs
, peername
*objp
)
75 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
77 libnsl_hidden_nolink_def (xdr_peername
, GLIBC_2_0
)
80 xdr_keydat (XDR
*xdrs
, keydat
*objp
)
82 return xdr_bytes (xdrs
, (char **) &objp
->keydat_val
,
83 (u_int
*) &objp
->keydat_len
, XDRMAXRECORD
);
85 libnsl_hidden_nolink_def (xdr_keydat
, GLIBC_2_0
)
88 xdr_valdat (XDR
*xdrs
, valdat
*objp
)
90 return xdr_bytes (xdrs
, (char **) &objp
->valdat_val
,
91 (u_int
*) &objp
->valdat_len
, XDRMAXRECORD
);
93 libnsl_hidden_nolink_def (xdr_valdat
, GLIBC_2_0
)
96 xdr_ypmap_parms (XDR
*xdrs
, ypmap_parms
*objp
)
98 if (!xdr_domainname (xdrs
, &objp
->domain
))
100 if (!xdr_mapname (xdrs
, &objp
->map
))
102 if (!xdr_u_int (xdrs
, &objp
->ordernum
))
104 return xdr_peername (xdrs
, &objp
->peer
);
106 libnsl_hidden_nolink_def (xdr_ypmap_parms
, GLIBC_2_0
)
109 xdr_ypreq_key (XDR
*xdrs
, ypreq_key
*objp
)
111 if (!xdr_domainname (xdrs
, &objp
->domain
))
113 if (!xdr_mapname (xdrs
, &objp
->map
))
115 return xdr_keydat (xdrs
, &objp
->key
);
117 libnsl_hidden_nolink_def (xdr_ypreq_key
, GLIBC_2_0
)
120 xdr_ypreq_nokey (XDR
*xdrs
, ypreq_nokey
*objp
)
122 if (!xdr_domainname (xdrs
, &objp
->domain
))
124 return xdr_mapname (xdrs
, &objp
->map
);
126 libnsl_hidden_nolink_def (xdr_ypreq_nokey
, GLIBC_2_0
)
129 xdr_ypreq_xfr (XDR
*xdrs
, ypreq_xfr
*objp
)
131 if (!xdr_ypmap_parms (xdrs
, &objp
->map_parms
))
133 if (!xdr_u_int (xdrs
, &objp
->transid
))
135 if (!xdr_u_int (xdrs
, &objp
->prog
))
137 return xdr_u_int (xdrs
, &objp
->port
);
139 libnsl_hidden_nolink_def (xdr_ypreq_xfr
, GLIBC_2_0
)
142 xdr_ypresp_val (XDR
*xdrs
, ypresp_val
*objp
)
144 if (!xdr_ypstat (xdrs
, &objp
->stat
))
146 return xdr_valdat (xdrs
, &objp
->val
);
148 libnsl_hidden_nolink_def (xdr_ypresp_val
, GLIBC_2_0
)
151 xdr_ypresp_key_val (XDR
*xdrs
, ypresp_key_val
*objp
)
153 if (!xdr_ypstat (xdrs
, &objp
->stat
))
155 if (!xdr_valdat (xdrs
, &objp
->val
))
157 return xdr_keydat (xdrs
, &objp
->key
);
159 libnsl_hidden_nolink_def (xdr_ypresp_key_val
, GLIBC_2_0
)
162 xdr_ypresp_master (XDR
*xdrs
, ypresp_master
*objp
)
164 if (!xdr_ypstat (xdrs
, &objp
->stat
))
166 return xdr_peername (xdrs
, &objp
->peer
);
168 libnsl_hidden_nolink_def (xdr_ypresp_master
, GLIBC_2_0
)
171 xdr_ypresp_order (XDR
*xdrs
, ypresp_order
*objp
)
173 if (!xdr_ypstat (xdrs
, &objp
->stat
))
175 return xdr_u_int (xdrs
, &objp
->ordernum
);
177 libnsl_hidden_nolink_def (xdr_ypresp_order
, GLIBC_2_0
)
180 xdr_ypresp_all (XDR
*xdrs
, ypresp_all
*objp
)
182 if (!xdr_bool (xdrs
, &objp
->more
))
187 return xdr_ypresp_key_val (xdrs
, &objp
->ypresp_all_u
.val
);
195 libnsl_hidden_nolink_def (xdr_ypresp_all
, GLIBC_2_0
)
198 xdr_ypresp_xfr (XDR
*xdrs
, ypresp_xfr
*objp
)
200 if (!xdr_u_int (xdrs
, &objp
->transid
))
202 return xdr_ypxfrstat (xdrs
, &objp
->xfrstat
);
204 libnsl_hidden_nolink_def (xdr_ypresp_xfr
, GLIBC_2_0
)
207 xdr_ypmaplist (XDR
*xdrs
, ypmaplist
*objp
)
209 if (!xdr_mapname (xdrs
, &objp
->map
))
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
);
215 libnsl_hidden_nolink_def (xdr_ypmaplist
, GLIBC_2_0
)
218 xdr_ypresp_maplist (XDR
*xdrs
, ypresp_maplist
*objp
)
220 if (!xdr_ypstat (xdrs
, &objp
->stat
))
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
);
226 libnsl_hidden_nolink_def (xdr_ypresp_maplist
, GLIBC_2_0
)
229 xdr_yppush_status (XDR
*xdrs
, yppush_status
*objp
)
231 return xdr_enum (xdrs
, (enum_t
*) objp
);
233 libnsl_hidden_nolink_def (xdr_yppush_status
, GLIBC_2_0
)
236 xdr_yppushresp_xfr (XDR
*xdrs
, yppushresp_xfr
*objp
)
238 if (!xdr_u_int (xdrs
, &objp
->transid
))
240 return xdr_yppush_status (xdrs
, &objp
->status
);
242 libnsl_hidden_nolink_def (xdr_yppushresp_xfr
, GLIBC_2_0
)
245 xdr_ypbind_resptype (XDR
*xdrs
, ypbind_resptype
*objp
)
247 return xdr_enum (xdrs
, (enum_t
*) objp
);
249 libnsl_hidden_nolink_def (xdr_ypbind_resptype
, GLIBC_2_0
)
252 xdr_ypbind_binding (XDR
*xdrs
, ypbind_binding
*objp
)
254 if (!xdr_opaque (xdrs
, objp
->ypbind_binding_addr
, 4))
256 return xdr_opaque (xdrs
, objp
->ypbind_binding_port
, 2);
258 libnsl_hidden_nolink_def (xdr_ypbind_binding
, GLIBC_2_0
)
261 xdr_ypbind_resp (XDR
*xdrs
, ypbind_resp
*objp
)
263 if (!xdr_ypbind_resptype (xdrs
, &objp
->ypbind_status
))
265 switch (objp
->ypbind_status
)
267 case YPBIND_FAIL_VAL
:
268 return xdr_u_int (xdrs
, &objp
->ypbind_resp_u
.ypbind_error
);
269 case YPBIND_SUCC_VAL
:
270 return xdr_ypbind_binding (xdrs
, &objp
->ypbind_resp_u
.ypbind_bindinfo
);
274 libnsl_hidden_nolink_def (xdr_ypbind_resp
, GLIBC_2_0
)
277 xdr_ypbind_setdom (XDR
*xdrs
, ypbind_setdom
*objp
)
279 if (!xdr_domainname (xdrs
, &objp
->ypsetdom_domain
))
281 if (!xdr_ypbind_binding (xdrs
, &objp
->ypsetdom_binding
))
283 return xdr_u_int (xdrs
, &objp
->ypsetdom_vers
);
285 libnsl_hidden_nolink_def (xdr_ypbind_setdom
, GLIBC_2_0
)
288 xdr_ypall(XDR
*xdrs
, struct ypall_callback
*incallback
)
290 struct ypresp_key_val out
;
291 char key
[YPMAXRECORD
], val
[YPMAXRECORD
];
294 * Set up key/val struct to be used during the transaction.
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
);
305 /* Values pending? */
306 if (!xdr_bool(xdrs
, &more
))
307 return FALSE
; /* can't tell! */
309 return TRUE
; /* no more */
311 /* Transfer key/value pair. */
312 status
= xdr_ypresp_key_val(xdrs
, &out
);
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
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
,
330 libnsl_hidden_nolink_def (xdr_ypall
, GLIBC_2_2
)