1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley
* 4.3 BSD under license from the Regents of the University of
* California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Protocol for the local binder service, or pmap.
* All the pmap xdr routines here.
*/
#include "mt.h"
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_rmt.h>
bool_t
xdr_pmap(XDR *xdrs, struct pmap *objp)
{
rpc_inline_t *buf;
switch (xdrs->x_op) {
case XDR_ENCODE:
buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT);
if (buf == NULL) {
if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_prog))
return (FALSE);
if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_vers))
return (FALSE);
if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_prot))
return (FALSE);
if (!XDR_PUTINT32(xdrs, (int32_t *)&objp->pm_port))
return (FALSE);
} else {
IXDR_PUT_U_INT32(buf, objp->pm_prog);
IXDR_PUT_U_INT32(buf, objp->pm_vers);
IXDR_PUT_U_INT32(buf, objp->pm_prot);
IXDR_PUT_U_INT32(buf, objp->pm_port);
}
return (TRUE);
case XDR_DECODE:
buf = XDR_INLINE(xdrs, 4 * BYTES_PER_XDR_UNIT);
if (buf == NULL) {
if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_prog))
return (FALSE);
if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_vers))
return (FALSE);
if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_prot))
return (FALSE);
if (!XDR_GETINT32(xdrs, (int32_t *)&objp->pm_port))
return (FALSE);
} else {
objp->pm_prog = IXDR_GET_U_INT32(buf);
objp->pm_vers = IXDR_GET_U_INT32(buf);
objp->pm_prot = IXDR_GET_U_INT32(buf);
objp->pm_port = IXDR_GET_U_INT32(buf);
}
return (TRUE);
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* pmaplist_ptr implements a linked list. The RPCL definition from
* pmap_prot.x is:
*
* struct pm__list {
* pmap pml_map;
* struct pm__list *pml_next;
* };
* typedef pm__list *pmaplist_ptr;
*
* Recall that "pointers" in XDR are encoded as a boolean, indicating whether
* there's any data behind the pointer, followed by the data (if any exists).
* The boolean can be interpreted as ``more data follows me''; if FALSE then
* nothing follows the boolean; if TRUE then the boolean is followed by an
* actual struct pmap, and another pmaplist_ptr (declared in RPCL as "struct
* pmaplist *").
*
* This could be implemented via the xdr_pointer type, though this would
* result in one recursive call per element in the list. Rather than do that
* we can ``unwind'' the recursion into a while loop and use xdr_reference to
* serialize the pmap elements.
*/
bool_t
xdr_pmaplist_ptr(XDR *xdrs, pmaplist_ptr *rp)
{
/*
* more_elements is pre-computed in case the direction is
* XDR_ENCODE or XDR_FREE. more_elements is overwritten by
* xdr_bool when the direction is XDR_DECODE.
*/
bool_t more_elements;
int freeing = (xdrs->x_op == XDR_FREE);
pmaplist_ptr next;
pmaplist_ptr next_copy;
for (;;) {
more_elements = (bool_t)(*rp != NULL);
if (!xdr_bool(xdrs, &more_elements))
return (FALSE);
if (!more_elements)
return (TRUE); /* we are done */
/*
* the unfortunate side effect of non-recursion is that in
* the case of freeing we must remember the next object
* before we free the current object ...
*/
if (freeing)
next = (*rp)->pml_next;
if (!xdr_reference(xdrs, (caddr_t *)rp,
(uint_t)sizeof (struct pmaplist), (xdrproc_t)xdr_pmap))
return (FALSE);
if (freeing) {
next_copy = next;
rp = &next_copy;
/*
* Note that in the subsequent iteration, next_copy
* gets nulled out by the xdr_reference
* but next itself survives.
*/
} else {
rp = &((*rp)->pml_next);
}
}
/*NOTREACHED*/
}
/*
* xdr_pmaplist() is specified to take a PMAPLIST **, but is identical in
* functionality to xdr_pmaplist_ptr().
*/
bool_t
xdr_pmaplist(XDR *xdrs, PMAPLIST **rp)
{
return (xdr_pmaplist_ptr(xdrs, (pmaplist_ptr *)rp));
}
/*
* XDR remote call arguments
* written for XDR_ENCODE direction only
*/
bool_t
xdr_rmtcallargs(XDR *xdrs, struct p_rmtcallargs *cap)
{
uint_t lenposition, argposition, position;
rpc_inline_t *buf;
buf = XDR_INLINE(xdrs, 3 * BYTES_PER_XDR_UNIT);
if (buf == NULL) {
if (!xdr_u_int(xdrs, (uint_t *)&(cap->prog)) ||
!xdr_u_int(xdrs, (uint_t *)&(cap->vers)) ||
!xdr_u_int(xdrs, (uint_t *)&(cap->proc)))
return (FALSE);
} else {
IXDR_PUT_U_INT32(buf, cap->prog);
IXDR_PUT_U_INT32(buf, cap->vers);
IXDR_PUT_U_INT32(buf, cap->proc);
}
/*
* All the jugglery for just getting the size of the arguments
*/
lenposition = XDR_GETPOS(xdrs);
if (!xdr_u_int(xdrs, &(cap->args.args_len)))
return (FALSE);
argposition = XDR_GETPOS(xdrs);
if (!(*cap->xdr_args)(xdrs, cap->args.args_val))
return (FALSE);
position = XDR_GETPOS(xdrs);
cap->args.args_len = position - argposition;
XDR_SETPOS(xdrs, lenposition);
if (!xdr_u_int(xdrs, &(cap->args.args_len)))
return (FALSE);
XDR_SETPOS(xdrs, position);
return (TRUE);
}
/*
* XDR remote call results
* written for XDR_DECODE direction only
*/
bool_t
xdr_rmtcallres(XDR *xdrs, struct p_rmtcallres *crp)
{
if (xdr_u_int(xdrs, (uint_t *)&crp->port) &&
xdr_u_int(xdrs, &crp->res.res_len))
return ((*(crp->xdr_res))(xdrs, crp->res.res_val));
return (FALSE);
}
|