xdryp.c revision 1.1 1 #ifdef YP
2
3 #include <sys/param.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <stdio.h>
7 #include <ctype.h>
8 #include <rpc/rpc.h>
9 #include <rpc/xdr.h>
10 #include <rpcsvc/yp_prot.h>
11 #include <rpcsvc/ypclnt.h>
12
13 extern int (*ypresp_allfn)();
14 extern void *ypresp_data;
15
16 struct ypresp_all {
17 bool_t more;
18 union {
19 struct ypresp_key_val val;
20 } ypresp_all_u;
21 };
22
23 bool_t
24 xdr_domainname(xdrs, objp)
25 XDR *xdrs;
26 char *objp;
27 {
28 if (!xdr_string(xdrs, &objp, YPMAXDOMAIN)) {
29 return (FALSE);
30 }
31 return (TRUE);
32 }
33
34 bool_t
35 xdr_peername(xdrs, objp)
36 XDR *xdrs;
37 char *objp;
38 {
39 if (!xdr_string(xdrs, &objp, YPMAXPEER)) {
40 return (FALSE);
41 }
42 return (TRUE);
43 }
44
45 bool_t
46 xdr_datum(xdrs, objp)
47 XDR *xdrs;
48 datum *objp;
49 {
50 if (!xdr_bytes(xdrs, (char **)&objp->dptr, (u_int *)&objp->dsize, YPMAXRECORD)) {
51 return (FALSE);
52 }
53 return (TRUE);
54 }
55
56 bool_t
57 xdr_mapname(xdrs, objp)
58 XDR *xdrs;
59 char *objp;
60 {
61 if (!xdr_string(xdrs, &objp, YPMAXMAP)) {
62 return (FALSE);
63 }
64 return (TRUE);
65 }
66
67 bool_t
68 xdr_ypreq_key(xdrs, objp)
69 XDR *xdrs;
70 struct ypreq_key *objp;
71 {
72 if (!xdr_domainname(xdrs, objp->domain)) {
73 return (FALSE);
74 }
75 if (!xdr_mapname(xdrs, objp->map)) {
76 return (FALSE);
77 }
78 if (!xdr_datum(xdrs, &objp->keydat)) {
79 return (FALSE);
80 }
81 return (TRUE);
82 }
83
84 bool_t
85 xdr_ypreq_nokey(xdrs, objp)
86 XDR *xdrs;
87 struct ypreq_nokey *objp;
88 {
89 if (!xdr_domainname(xdrs, objp->domain)) {
90 return (FALSE);
91 }
92 if (!xdr_mapname(xdrs, objp->map)) {
93 return (FALSE);
94 }
95 return (TRUE);
96 }
97
98 bool_t
99 xdr_yp_inaddr(xdrs, objp)
100 XDR *xdrs;
101 struct in_addr *objp;
102 {
103 if (!xdr_opaque(xdrs, &objp->s_addr, sizeof objp->s_addr)) {
104 return (FALSE);
105 }
106 return (TRUE);
107 }
108
109 bool_t
110 xdr_ypbind_binding(xdrs, objp)
111 XDR *xdrs;
112 struct ypbind_binding *objp;
113 {
114 if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr)) {
115 return (FALSE);
116 }
117 if (!xdr_opaque(xdrs, &objp->ypbind_binding_port,
118 sizeof objp->ypbind_binding_port)) {
119 return (FALSE);
120 }
121 return (TRUE);
122 }
123
124 bool_t
125 xdr_ypbind_resptype(xdrs, objp)
126 XDR *xdrs;
127 enum ypbind_resptype *objp;
128 {
129 if (!xdr_enum(xdrs, (enum_t *)objp)) {
130 return (FALSE);
131 }
132 return (TRUE);
133 }
134
135 bool_t
136 xdr_ypstat(xdrs, objp)
137 XDR *xdrs;
138 enum ypbind_resptype *objp;
139 {
140 if (!xdr_enum(xdrs, (enum_t *)objp)) {
141 return (FALSE);
142 }
143 return (TRUE);
144 }
145
146 bool_t
147 xdr_ypbind_resp(xdrs, objp)
148 XDR *xdrs;
149 struct ypbind_resp *objp;
150 {
151 if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) {
152 return (FALSE);
153 }
154 switch (objp->ypbind_status) {
155 case YPBIND_FAIL_VAL:
156 if (!xdr_u_int(xdrs, &objp->ypbind_respbody.ypbind_error)) {
157 return (FALSE);
158 }
159 break;
160 case YPBIND_SUCC_VAL:
161 if (!xdr_ypbind_binding(xdrs, &objp->ypbind_respbody.ypbind_bindinfo)) {
162 return (FALSE);
163 }
164 break;
165 default:
166 return (FALSE);
167 }
168 return (TRUE);
169 }
170
171 bool_t
172 xdr_ypresp_val(xdrs, objp)
173 XDR *xdrs;
174 struct ypresp_val *objp;
175 {
176 if (!xdr_ypstat(xdrs, &objp->status)) {
177 return (FALSE);
178 }
179 if (!xdr_datum(xdrs, &objp->valdat)) {
180 return (FALSE);
181 }
182 return (TRUE);
183 }
184
185 bool_t
186 xdr_ypbind_setdom(xdrs, objp)
187 XDR *xdrs;
188 struct ypbind_setdom *objp;
189 {
190 if (!xdr_domainname(xdrs, objp->ypsetdom_domain)) {
191 return (FALSE);
192 }
193 if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) {
194 return (FALSE);
195 }
196 if (!xdr_u_short(xdrs, &objp->ypsetdom_vers)) {
197 return (FALSE);
198 }
199 return (TRUE);
200 }
201
202 bool_t
203 xdr_ypresp_key_val(xdrs, objp)
204 XDR *xdrs;
205 struct ypresp_key_val *objp;
206 {
207 if (!xdr_ypstat(xdrs, &objp->status)) {
208 return (FALSE);
209 }
210 if (!xdr_datum(xdrs, &objp->valdat)) {
211 return (FALSE);
212 }
213 if (!xdr_datum(xdrs, &objp->keydat)) {
214 return (FALSE);
215 }
216 return (TRUE);
217 }
218
219 bool_t
220 xdr_ypresp_all(xdrs, objp)
221 XDR *xdrs;
222 struct ypresp_all *objp;
223 {
224 if (!xdr_bool(xdrs, &objp->more)) {
225 return (FALSE);
226 }
227 switch (objp->more) {
228 case TRUE:
229 if (!xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) {
230 return (FALSE);
231 }
232 break;
233 case FALSE:
234 break;
235 default:
236 return (FALSE);
237 }
238 return (TRUE);
239 }
240
241 bool_t
242 xdr_ypresp_all_seq(xdrs, objp)
243 XDR *xdrs;
244 u_long *objp;
245 {
246 struct ypresp_all out;
247 u_long status;
248 char *key, *val;
249 int r;
250
251 bzero(&out, sizeof out);
252 while(1) {
253 if( !xdr_ypresp_all(xdrs, &out)) {
254 xdr_free(xdr_ypresp_all, &out);
255 *objp = YP_YPERR;
256 return FALSE;
257 }
258 if(out.more == 0) {
259 xdr_free(xdr_ypresp_all, &out);
260 return FALSE;
261 }
262 status = out.ypresp_all_u.val.status;
263 switch(status) {
264 case YP_TRUE:
265 key = (char *)malloc(out.ypresp_all_u.val.keydat.dsize + 1);
266 bcopy(out.ypresp_all_u.val.keydat.dptr, key,
267 out.ypresp_all_u.val.keydat.dsize);
268 key[out.ypresp_all_u.val.keydat.dsize] = '\0';
269 val = (char *)malloc(out.ypresp_all_u.val.valdat.dsize + 1);
270 bcopy(out.ypresp_all_u.val.valdat.dptr, val,
271 out.ypresp_all_u.val.valdat.dsize);
272 val[out.ypresp_all_u.val.valdat.dsize] = '\0';
273 xdr_free(xdr_ypresp_all, &out);
274
275 r = (*ypresp_allfn)(status,
276 key, out.ypresp_all_u.val.keydat.dsize,
277 val, out.ypresp_all_u.val.valdat.dsize,
278 ypresp_data);
279 *objp = status;
280 free(key);
281 free(val);
282 if(r)
283 return TRUE;
284 break;
285 case YP_NOMORE:
286 xdr_free(xdr_ypresp_all, &out);
287 return TRUE;
288 default:
289 xdr_free(xdr_ypresp_all, &out);
290 *objp = status;
291 return TRUE;
292 }
293 }
294 }
295
296 bool_t
297 xdr_ypresp_master(xdrs, objp)
298 XDR *xdrs;
299 struct ypresp_master *objp;
300 {
301 if (!xdr_ypstat(xdrs, &objp->status)) {
302 return (FALSE);
303 }
304 if (!xdr_string(xdrs, &objp->master, YPMAXPEER)) {
305 return (FALSE);
306 }
307 return (TRUE);
308 }
309
310 bool_t
311 xdr_ypmaplist_str(xdrs, objp)
312 XDR *xdrs;
313 char *objp;
314 {
315 if (!xdr_string(xdrs, &objp, YPMAXMAP+1)) {
316 return (FALSE);
317 }
318 return (TRUE);
319 }
320
321 bool_t
322 xdr_ypmaplist(xdrs, objp)
323 XDR *xdrs;
324 struct ypmaplist *objp;
325 {
326 if (!xdr_ypmaplist_str(xdrs, objp->ypml_name)) {
327 return (FALSE);
328 }
329 if (!xdr_pointer(xdrs, &objp->ypml_next, sizeof(struct ypmaplist), xdr_ypmaplist)) {
330 return (FALSE);
331 }
332 return (TRUE);
333 }
334
335 bool_t
336 xdr_ypresp_maplist(xdrs, objp)
337 XDR *xdrs;
338 struct ypresp_maplist *objp;
339 {
340 if (!xdr_ypstat(xdrs, &objp->status)) {
341 return (FALSE);
342 }
343 if (!xdr_pointer(xdrs, &objp->list, sizeof(struct ypmaplist), xdr_ypmaplist)) {
344 return (FALSE);
345 }
346 return (TRUE);
347 }
348
349 bool_t
350 xdr_ypresp_order(xdrs, objp)
351 XDR *xdrs;
352 struct ypresp_order *objp;
353 {
354 if (!xdr_ypstat(xdrs, &objp->status)) {
355 return (FALSE);
356 }
357 if (!xdr_u_long(xdrs, &objp->ordernum)) {
358 return (FALSE);
359 }
360 return (TRUE);
361 }
362
363 #endif /* YP */
364