rpc: Fix xdr_* macros and limit buffer sizes.
[dragonfly.git] / lib / libc / rpc / rpcb_st_xdr.c
blob9058c44769b37834a434fb921f1df4428a3a8509
1 /*-
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * $NetBSD: rpcb_st_xdr.c,v 1.3 2000/07/14 08:40:42 fvdl Exp $
29 * $FreeBSD: src/lib/libc/rpc/rpcb_st_xdr.c,v 1.4 2007/11/20 01:51:20 jb Exp $
32 * Copyright 1991 Sun Microsystems, Inc.
33 * rpcb_stat_xdr.c
37 * This file was generated from rpcb_prot.x, but includes only those
38 * routines used with the rpcbind stats facility.
41 #include "namespace.h"
42 #include <rpc/rpc.h>
43 #include <rpc/rpc_com.h>
44 #include "un-namespace.h"
46 /* Link list of all the stats about getport and getaddr */
48 bool_t
49 xdr_rpcbs_addrlist(XDR *xdrs, rpcbs_addrlist *objp)
51 struct rpcbs_addrlist **pnext;
53 if (!xdr_rpcprog(xdrs, &objp->prog)) {
54 return (FALSE);
56 if (!xdr_rpcvers(xdrs, &objp->vers)) {
57 return (FALSE);
59 if (!xdr_int(xdrs, &objp->success)) {
60 return (FALSE);
62 if (!xdr_int(xdrs, &objp->failure)) {
63 return (FALSE);
65 if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
66 return (FALSE);
69 pnext = &objp->next;
71 if (!xdr_pointer(xdrs, (char **) pnext,
72 sizeof (rpcbs_addrlist),
73 (xdrproc_t)xdr_rpcbs_addrlist)) {
74 return (FALSE);
77 return (TRUE);
80 /* Link list of all the stats about rmtcall */
82 bool_t
83 xdr_rpcbs_rmtcalllist(XDR *xdrs, rpcbs_rmtcalllist *objp)
85 int32_t *buf;
87 if (xdrs->x_op == XDR_ENCODE) {
88 buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
89 if (buf == NULL) {
90 if (!xdr_rpcvers(xdrs, &objp->prog)) {
91 return (FALSE);
93 if (!xdr_rpcvers(xdrs, &objp->vers)) {
94 return (FALSE);
96 if (!xdr_rpcproc(xdrs, &objp->proc)) {
97 return (FALSE);
99 if (!xdr_int(xdrs, &objp->success)) {
100 return (FALSE);
102 if (!xdr_int(xdrs, &objp->failure)) {
103 return (FALSE);
105 if (!xdr_int(xdrs, &objp->indirect)) {
106 return (FALSE);
108 } else {
109 IXDR_PUT_U_INT32(buf, objp->prog);
110 IXDR_PUT_U_INT32(buf, objp->vers);
111 IXDR_PUT_U_INT32(buf, objp->proc);
112 IXDR_PUT_INT32(buf, objp->success);
113 IXDR_PUT_INT32(buf, objp->failure);
114 IXDR_PUT_INT32(buf, objp->indirect);
116 if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
117 return (FALSE);
119 if (!xdr_pointer(xdrs, (char **)&objp->next,
120 sizeof (rpcbs_rmtcalllist),
121 (xdrproc_t)xdr_rpcbs_rmtcalllist)) {
122 return (FALSE);
124 return (TRUE);
125 } else if (xdrs->x_op == XDR_DECODE) {
126 buf = XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
127 if (buf == NULL) {
128 if (!xdr_rpcprog(xdrs, &objp->prog)) {
129 return (FALSE);
131 if (!xdr_rpcvers(xdrs, &objp->vers)) {
132 return (FALSE);
134 if (!xdr_rpcproc(xdrs, &objp->proc)) {
135 return (FALSE);
137 if (!xdr_int(xdrs, &objp->success)) {
138 return (FALSE);
140 if (!xdr_int(xdrs, &objp->failure)) {
141 return (FALSE);
143 if (!xdr_int(xdrs, &objp->indirect)) {
144 return (FALSE);
146 } else {
147 objp->prog = (rpcprog_t)IXDR_GET_U_INT32(buf);
148 objp->vers = (rpcvers_t)IXDR_GET_U_INT32(buf);
149 objp->proc = (rpcproc_t)IXDR_GET_U_INT32(buf);
150 objp->success = (int)IXDR_GET_INT32(buf);
151 objp->failure = (int)IXDR_GET_INT32(buf);
152 objp->indirect = (int)IXDR_GET_INT32(buf);
154 if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
155 return (FALSE);
157 if (!xdr_pointer(xdrs, (char **)&objp->next,
158 sizeof (rpcbs_rmtcalllist),
159 (xdrproc_t)xdr_rpcbs_rmtcalllist)) {
160 return (FALSE);
162 return (TRUE);
164 if (!xdr_rpcprog(xdrs, &objp->prog)) {
165 return (FALSE);
167 if (!xdr_rpcvers(xdrs, &objp->vers)) {
168 return (FALSE);
170 if (!xdr_rpcproc(xdrs, &objp->proc)) {
171 return (FALSE);
173 if (!xdr_int(xdrs, &objp->success)) {
174 return (FALSE);
176 if (!xdr_int(xdrs, &objp->failure)) {
177 return (FALSE);
179 if (!xdr_int(xdrs, &objp->indirect)) {
180 return (FALSE);
182 if (!xdr_string(xdrs, &objp->netid, RPC_MAXDATASIZE)) {
183 return (FALSE);
185 if (!xdr_pointer(xdrs, (char **)&objp->next,
186 sizeof (rpcbs_rmtcalllist),
187 (xdrproc_t)xdr_rpcbs_rmtcalllist)) {
188 return (FALSE);
190 return (TRUE);
193 bool_t
194 xdr_rpcbs_proc(XDR *xdrs, rpcbs_proc objp)
196 if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBSTAT_HIGHPROC,
197 sizeof (int), (xdrproc_t)xdr_int)) {
198 return (FALSE);
200 return (TRUE);
203 bool_t
204 xdr_rpcbs_addrlist_ptr(XDR *xdrs, rpcbs_addrlist_ptr *objp)
206 if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_addrlist),
207 (xdrproc_t)xdr_rpcbs_addrlist)) {
208 return (FALSE);
210 return (TRUE);
213 bool_t
214 xdr_rpcbs_rmtcalllist_ptr(XDR *xdrs, rpcbs_rmtcalllist_ptr *objp)
216 if (!xdr_pointer(xdrs, (char **)objp, sizeof (rpcbs_rmtcalllist),
217 (xdrproc_t)xdr_rpcbs_rmtcalllist)) {
218 return (FALSE);
220 return (TRUE);
223 bool_t
224 xdr_rpcb_stat(XDR *xdrs, rpcb_stat *objp)
227 if (!xdr_rpcbs_proc(xdrs, objp->info)) {
228 return (FALSE);
230 if (!xdr_int(xdrs, &objp->setinfo)) {
231 return (FALSE);
233 if (!xdr_int(xdrs, &objp->unsetinfo)) {
234 return (FALSE);
236 if (!xdr_rpcbs_addrlist_ptr(xdrs, &objp->addrinfo)) {
237 return (FALSE);
239 if (!xdr_rpcbs_rmtcalllist_ptr(xdrs, &objp->rmtinfo)) {
240 return (FALSE);
242 return (TRUE);
246 * One rpcb_stat structure is returned for each version of rpcbind
247 * being monitored.
249 bool_t
250 xdr_rpcb_stat_byvers(XDR *xdrs, rpcb_stat_byvers objp)
252 if (!xdr_vector(xdrs, (char *)(void *)objp, RPCBVERS_STAT,
253 sizeof (rpcb_stat), (xdrproc_t)xdr_rpcb_stat)) {
254 return (FALSE);
256 return (TRUE);