Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libcr / yp / xdryp.c
1 /*
2  * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote
14  *    products derived from this software without specific prior written
15  *    permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/lib/libc/yp/xdryp.c,v 1.9.2.1 2002/02/15 00:46:53 des Exp $
30  * $DragonFly: src/lib/libcr/yp/Attic/xdryp.c,v 1.2 2003/06/17 04:26:47 dillon Exp $
31  */
32
33 #include <rpc/rpc.h>
34 #include <rpcsvc/yp.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 extern int (*ypresp_allfn)();
39 extern void *ypresp_data;
40
41 /*
42  * I'm leaving the xdr_datum() function in purely for backwards
43  * compatibility. yplib.c doesn't actually use it, but it's listed
44  * in yp_prot.h as being available, so it's probably a good idea to
45  * leave it in in case somebody goes looking for it.
46  */
47 typedef struct {
48         char *dptr;
49         int  dsize;
50 } datum;
51
52 bool_t
53 xdr_datum(xdrs, objp)
54 XDR *xdrs;
55 datum *objp;
56 {
57         if (!xdr_bytes(xdrs, (char **)&objp->dptr, (u_int *)&objp->dsize, YPMAXRECORD)) {
58                 return (FALSE);
59         }
60         return (TRUE);
61 }
62
63 bool_t
64 xdr_ypresp_all_seq(xdrs, objp)
65 XDR *xdrs;
66 u_long *objp;
67 {
68         struct ypresp_all out;
69         u_long status;
70         char *key, *val;
71         int r;
72
73         bzero(&out, sizeof out);
74         while (1) {
75                 if (!xdr_ypresp_all(xdrs, &out)) {
76                         xdr_free(xdr_ypresp_all, (char *)&out);
77                         *objp = YP_YPERR;
78                         return (FALSE);
79                 }
80                 if (out.more == 0) {
81                         xdr_free(xdr_ypresp_all, (char *)&out);
82                         *objp = YP_NOMORE;
83                         return (TRUE);
84                 }
85                 status = out.ypresp_all_u.val.stat;
86                 switch (status) {
87                 case YP_TRUE:
88                         key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1);
89                         bcopy(out.ypresp_all_u.val.key.keydat_val, key,
90                                 out.ypresp_all_u.val.key.keydat_len);
91                         key[out.ypresp_all_u.val.key.keydat_len] = '\0';
92                         val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1);
93                         bcopy(out.ypresp_all_u.val.val.valdat_val, val,
94                                 out.ypresp_all_u.val.val.valdat_len);
95                         val[out.ypresp_all_u.val.val.valdat_len] = '\0';
96                         xdr_free(xdr_ypresp_all, (char *)&out);
97
98                         r = (*ypresp_allfn)(status,
99                                 key, out.ypresp_all_u.val.key.keydat_len,
100                                 val, out.ypresp_all_u.val.val.valdat_len,
101                                 ypresp_data);
102                         *objp = status;
103                         free(key);
104                         free(val);
105                         if (r)
106                                 return (TRUE);
107                         break;
108                 case YP_NOMORE:
109                         xdr_free(xdr_ypresp_all, (char *)&out);
110                         *objp = YP_NOMORE;
111                         return (TRUE);
112                 default:
113                         xdr_free(xdr_ypresp_all, (char *)&out);
114                         *objp = status;
115                         return (TRUE);
116                 }
117         }
118 }