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>
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. */
40 #define XDRMAXNAME 1024
41 #define XDRMAXRECORD (16 * 1024 * 1024)
44 xdr_ypstat (XDR
*xdrs
, ypstat
*objp
)
46 return xdr_enum (xdrs
, (enum_t
*) objp
);
48 libnsl_hidden_def (xdr_ypstat
)
51 xdr_ypxfrstat (XDR
*xdrs
, ypxfrstat
*objp
)
53 return xdr_enum (xdrs
, (enum_t
*) objp
);
55 libnsl_hidden_def (xdr_ypxfrstat
)
58 xdr_domainname (XDR
*xdrs
, domainname
*objp
)
60 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
62 libnsl_hidden_def (xdr_domainname
)
65 xdr_mapname (XDR
*xdrs
, mapname
*objp
)
67 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
69 libnsl_hidden_def (xdr_mapname
)
72 xdr_peername (XDR
*xdrs
, peername
*objp
)
74 return xdr_string (xdrs
, objp
, XDRMAXNAME
);
76 libnsl_hidden_def (xdr_peername
)
79 xdr_keydat (XDR
*xdrs
, keydat
*objp
)
81 return xdr_bytes (xdrs
, (char **) &objp
->keydat_val
,
82 (u_int
*) &objp
->keydat_len
, XDRMAXRECORD
);
84 libnsl_hidden_def (xdr_keydat
)
87 xdr_valdat (XDR
*xdrs
, valdat
*objp
)
89 return xdr_bytes (xdrs
, (char **) &objp
->valdat_val
,
90 (u_int
*) &objp
->valdat_len
, XDRMAXRECORD
);
92 libnsl_hidden_def (xdr_valdat
)
95 xdr_ypmap_parms (XDR
*xdrs
, ypmap_parms
*objp
)
97 if (!xdr_domainname (xdrs
, &objp
->domain
))
99 if (!xdr_mapname (xdrs
, &objp
->map
))
101 if (!xdr_u_int (xdrs
, &objp
->ordernum
))
103 return xdr_peername (xdrs
, &objp
->peer
);
105 libnsl_hidden_def (xdr_ypmap_parms
)
108 xdr_ypreq_key (XDR
*xdrs
, ypreq_key
*objp
)
110 if (!xdr_domainname (xdrs
, &objp
->domain
))
112 if (!xdr_mapname (xdrs
, &objp
->map
))
114 return xdr_keydat (xdrs
, &objp
->key
);
116 libnsl_hidden_def (xdr_ypreq_key
)
119 xdr_ypreq_nokey (XDR
*xdrs
, ypreq_nokey
*objp
)
121 if (!xdr_domainname (xdrs
, &objp
->domain
))
123 return xdr_mapname (xdrs
, &objp
->map
);
125 libnsl_hidden_def (xdr_ypreq_nokey
)
128 xdr_ypreq_xfr (XDR
*xdrs
, ypreq_xfr
*objp
)
130 if (!xdr_ypmap_parms (xdrs
, &objp
->map_parms
))
132 if (!xdr_u_int (xdrs
, &objp
->transid
))
134 if (!xdr_u_int (xdrs
, &objp
->prog
))
136 return xdr_u_int (xdrs
, &objp
->port
);
140 xdr_ypresp_val (XDR
*xdrs
, ypresp_val
*objp
)
142 if (!xdr_ypstat (xdrs
, &objp
->stat
))
144 return xdr_valdat (xdrs
, &objp
->val
);
146 libnsl_hidden_def (xdr_ypresp_val
)
149 xdr_ypresp_key_val (XDR
*xdrs
, ypresp_key_val
*objp
)
151 if (!xdr_ypstat (xdrs
, &objp
->stat
))
153 if (!xdr_valdat (xdrs
, &objp
->val
))
155 return xdr_keydat (xdrs
, &objp
->key
);
157 libnsl_hidden_def (xdr_ypresp_key_val
)
160 xdr_ypresp_master (XDR
*xdrs
, ypresp_master
*objp
)
162 if (!xdr_ypstat (xdrs
, &objp
->stat
))
164 return xdr_peername (xdrs
, &objp
->peer
);
166 libnsl_hidden_def (xdr_ypresp_master
)
169 xdr_ypresp_order (XDR
*xdrs
, ypresp_order
*objp
)
171 if (!xdr_ypstat (xdrs
, &objp
->stat
))
173 return xdr_u_int (xdrs
, &objp
->ordernum
);
175 libnsl_hidden_def (xdr_ypresp_order
)
178 xdr_ypresp_all (XDR
*xdrs
, ypresp_all
*objp
)
180 if (!xdr_bool (xdrs
, &objp
->more
))
185 return xdr_ypresp_key_val (xdrs
, &objp
->ypresp_all_u
.val
);
193 libnsl_hidden_def (xdr_ypresp_all
)
196 xdr_ypresp_xfr (XDR
*xdrs
, ypresp_xfr
*objp
)
198 if (!xdr_u_int (xdrs
, &objp
->transid
))
200 return xdr_ypxfrstat (xdrs
, &objp
->xfrstat
);
204 xdr_ypmaplist (XDR
*xdrs
, ypmaplist
*objp
)
206 if (!xdr_mapname (xdrs
, &objp
->map
))
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
);
212 libnsl_hidden_def (xdr_ypmaplist
)
215 xdr_ypresp_maplist (XDR
*xdrs
, ypresp_maplist
*objp
)
217 if (!xdr_ypstat (xdrs
, &objp
->stat
))
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
);
223 libnsl_hidden_def (xdr_ypresp_maplist
)
226 xdr_yppush_status (XDR
*xdrs
, yppush_status
*objp
)
228 return xdr_enum (xdrs
, (enum_t
*) objp
);
230 libnsl_hidden_def (xdr_yppush_status
)
233 xdr_yppushresp_xfr (XDR
*xdrs
, yppushresp_xfr
*objp
)
235 if (!xdr_u_int (xdrs
, &objp
->transid
))
237 return xdr_yppush_status (xdrs
, &objp
->status
);
241 xdr_ypbind_resptype (XDR
*xdrs
, ypbind_resptype
*objp
)
243 return xdr_enum (xdrs
, (enum_t
*) objp
);
245 libnsl_hidden_def (xdr_ypbind_resptype
)
248 xdr_ypbind_binding (XDR
*xdrs
, ypbind_binding
*objp
)
250 if (!xdr_opaque (xdrs
, objp
->ypbind_binding_addr
, 4))
252 return xdr_opaque (xdrs
, objp
->ypbind_binding_port
, 2);
254 libnsl_hidden_def (xdr_ypbind_binding
)
257 xdr_ypbind_resp (XDR
*xdrs
, ypbind_resp
*objp
)
259 if (!xdr_ypbind_resptype (xdrs
, &objp
->ypbind_status
))
261 switch (objp
->ypbind_status
)
263 case YPBIND_FAIL_VAL
:
264 return xdr_u_int (xdrs
, &objp
->ypbind_resp_u
.ypbind_error
);
265 case YPBIND_SUCC_VAL
:
266 return xdr_ypbind_binding (xdrs
, &objp
->ypbind_resp_u
.ypbind_bindinfo
);
270 libnsl_hidden_def (xdr_ypbind_resp
)
273 xdr_ypbind_setdom (XDR
*xdrs
, ypbind_setdom
*objp
)
275 if (!xdr_domainname (xdrs
, &objp
->ypsetdom_domain
))
277 if (!xdr_ypbind_binding (xdrs
, &objp
->ypsetdom_binding
))
279 return xdr_u_int (xdrs
, &objp
->ypsetdom_vers
);
283 xdr_ypall(XDR
*xdrs
, struct ypall_callback
*incallback
)
285 struct ypresp_key_val out
;
286 char key
[YPMAXRECORD
], val
[YPMAXRECORD
];
289 * Set up key/val struct to be used during the transaction.
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
);
300 /* Values pending? */
301 if (!xdr_bool(xdrs
, &more
))
302 return FALSE
; /* can't tell! */
304 return TRUE
; /* no more */
306 /* Transfer key/value pair. */
307 status
= xdr_ypresp_key_val(xdrs
, &out
);
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
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
,