.
[glibc/history.git] / nis / yp_xdr.c
blob0ee80126e8a52a04aed36831e48bfb94e0023a8f
1 /*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
30 #include <rpcsvc/yp.h>
31 #include <rpcsvc/ypclnt.h>
33 bool_t
34 xdr_ypstat (XDR *xdrs, ypstat *objp)
36 return xdr_enum (xdrs, (enum_t *) objp);
38 libnsl_hidden_def (xdr_ypstat)
40 bool_t
41 xdr_ypxfrstat (XDR *xdrs, ypxfrstat *objp)
43 return xdr_enum (xdrs, (enum_t *) objp);
45 libnsl_hidden_def (xdr_ypxfrstat)
47 bool_t
48 xdr_domainname (XDR *xdrs, domainname *objp)
50 return xdr_string (xdrs, objp, ~0);
52 libnsl_hidden_def (xdr_domainname)
54 bool_t
55 xdr_mapname (XDR *xdrs, mapname *objp)
57 return xdr_string (xdrs, objp, ~0);
59 libnsl_hidden_def (xdr_mapname)
61 bool_t
62 xdr_peername (XDR *xdrs, peername *objp)
64 return xdr_string (xdrs, objp, ~0);
66 libnsl_hidden_def (xdr_peername)
68 bool_t
69 xdr_keydat (XDR *xdrs, keydat *objp)
71 return xdr_bytes (xdrs, (char **) &objp->keydat_val,
72 (u_int *) &objp->keydat_len, ~0);
74 libnsl_hidden_def (xdr_keydat)
76 bool_t
77 xdr_valdat (XDR *xdrs, valdat *objp)
79 return xdr_bytes (xdrs, (char **) &objp->valdat_val,
80 (u_int *) &objp->valdat_len, ~0);
82 libnsl_hidden_def (xdr_valdat)
84 bool_t
85 xdr_ypmap_parms (XDR *xdrs, ypmap_parms *objp)
87 if (!xdr_domainname (xdrs, &objp->domain))
88 return FALSE;
89 if (!xdr_mapname (xdrs, &objp->map))
90 return FALSE;
91 if (!xdr_u_int (xdrs, &objp->ordernum))
92 return FALSE;
93 return xdr_peername (xdrs, &objp->peer);
95 libnsl_hidden_def (xdr_ypmap_parms)
97 bool_t
98 xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
100 if (!xdr_domainname (xdrs, &objp->domain))
101 return FALSE;
102 if (!xdr_mapname (xdrs, &objp->map))
103 return FALSE;
104 return xdr_keydat (xdrs, &objp->key);
107 bool_t
108 xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
110 if (!xdr_domainname (xdrs, &objp->domain))
111 return FALSE;
112 return xdr_mapname (xdrs, &objp->map);
115 bool_t
116 xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp)
118 if (!xdr_ypmap_parms (xdrs, &objp->map_parms))
119 return FALSE;
120 if (!xdr_u_int (xdrs, &objp->transid))
121 return FALSE;
122 if (!xdr_u_int (xdrs, &objp->prog))
123 return FALSE;
124 return xdr_u_int (xdrs, &objp->port);
127 bool_t
128 xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
130 if (!xdr_ypstat (xdrs, &objp->stat))
131 return FALSE;
132 return xdr_valdat (xdrs, &objp->val);
135 bool_t
136 xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
138 if (!xdr_ypstat (xdrs, &objp->stat))
139 return FALSE;
140 if (!xdr_valdat (xdrs, &objp->val))
141 return FALSE;
142 return xdr_keydat (xdrs, &objp->key);
144 libnsl_hidden_def (xdr_ypresp_key_val)
146 bool_t
147 xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
149 if (!xdr_ypstat (xdrs, &objp->stat))
150 return FALSE;
151 return xdr_peername (xdrs, &objp->peer);
154 bool_t
155 xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
157 if (!xdr_ypstat (xdrs, &objp->stat))
158 return FALSE;
159 return xdr_u_int (xdrs, &objp->ordernum);
162 bool_t
163 xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
165 if (!xdr_bool (xdrs, &objp->more))
166 return FALSE;
167 switch (objp->more)
169 case TRUE:
170 return xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val);
171 case FALSE:
172 break;
173 default:
174 return FALSE;
176 return TRUE;
178 libnsl_hidden_def (xdr_ypresp_all)
180 bool_t
181 xdr_ypresp_xfr (XDR *xdrs, ypresp_xfr *objp)
183 if (!xdr_u_int (xdrs, &objp->transid))
184 return FALSE;
185 return xdr_ypxfrstat (xdrs, &objp->xfrstat);
188 bool_t
189 xdr_ypmaplist (XDR *xdrs, ypmaplist *objp)
191 if (!xdr_mapname (xdrs, &objp->map))
192 return FALSE;
193 return xdr_pointer (xdrs, (char **) &objp->next, sizeof (ypmaplist),
194 (xdrproc_t) xdr_ypmaplist);
197 bool_t
198 xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
200 if (!xdr_ypstat (xdrs, &objp->stat))
201 return FALSE;
202 return xdr_pointer (xdrs, (char **) &objp->maps, sizeof (ypmaplist),
203 (xdrproc_t) xdr_ypmaplist);
206 bool_t
207 xdr_yppush_status (XDR *xdrs, yppush_status *objp)
209 return xdr_enum (xdrs, (enum_t *) objp);
211 libnsl_hidden_def (xdr_yppush_status)
213 bool_t
214 xdr_yppushresp_xfr (XDR *xdrs, yppushresp_xfr *objp)
216 if (!xdr_u_int (xdrs, &objp->transid))
217 return FALSE;
218 return xdr_yppush_status (xdrs, &objp->status);
221 bool_t
222 xdr_ypbind_resptype (XDR *xdrs, ypbind_resptype *objp)
224 return xdr_enum (xdrs, (enum_t *) objp);
226 libnsl_hidden_def (xdr_ypbind_resptype)
228 bool_t
229 xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp)
231 if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4))
232 return FALSE;
233 return xdr_opaque (xdrs, objp->ypbind_binding_port, 2);
235 libnsl_hidden_def (xdr_ypbind_binding)
237 bool_t
238 xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp)
240 if (!xdr_ypbind_resptype (xdrs, &objp->ypbind_status))
241 return FALSE;
242 switch (objp->ypbind_status)
244 case YPBIND_FAIL_VAL:
245 return xdr_u_int (xdrs, &objp->ypbind_resp_u.ypbind_error);
246 case YPBIND_SUCC_VAL:
247 return xdr_ypbind_binding (xdrs, &objp->ypbind_resp_u.ypbind_bindinfo);
249 return FALSE;
252 bool_t
253 xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
255 if (!xdr_domainname (xdrs, &objp->ypsetdom_domain))
256 return FALSE;
257 if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding))
258 return FALSE;
259 return xdr_u_int (xdrs, &objp->ypsetdom_vers);
262 bool_t
263 xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
265 struct ypresp_key_val out;
266 char key[YPMAXRECORD], val[YPMAXRECORD];
269 * Set up key/val struct to be used during the transaction.
271 memset(&out, 0, sizeof out);
272 out.key.keydat_val = key;
273 out.key.keydat_len = sizeof(key);
274 out.val.valdat_val = val;
275 out.val.valdat_len = sizeof(val);
277 for (;;) {
278 bool_t more, status;
280 /* Values pending? */
281 if (!xdr_bool(xdrs, &more))
282 return FALSE; /* can't tell! */
283 if (!more)
284 return TRUE; /* no more */
286 /* Transfer key/value pair. */
287 status = xdr_ypresp_key_val(xdrs, &out);
290 * If we succeeded, call the callback function.
291 * The callback will return TRUE when it wants
292 * no more values. If we fail, indicate the
293 * error.
295 if (status) {
296 if ((*incallback->foreach)(out.stat,
297 (char *)out.key.keydat_val, out.key.keydat_len,
298 (char *)out.val.valdat_val, out.val.valdat_len,
299 incallback->data))
300 return TRUE;
301 } else
302 return FALSE;