ReactOS 0.4.15-dev-5667-ged97270
rpc_callmsg.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
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 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.
15 *
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.
27 */
28
29/*
30 * rpc_callmsg.c
31 *
32 * Copyright (C) 1984, Sun Microsystems, Inc.
33 *
34 */
35
36#include <wintirpc.h>
37#include <assert.h>
38#include <stdlib.h>
39#include <string.h>
40
41#include <rpc/rpc.h>
42#include <rpc/xdr.h>
43
44//#include <sys/select.h>
45
46/*
47 * XDR a call message
48 */
50xdr_callmsg(xdrs, cmsg)
51 XDR *xdrs;
52 struct rpc_msg *cmsg;
53{
54 int32_t *buf;
55 struct opaque_auth *oa;
56
57 assert(xdrs != NULL);
58 assert(cmsg != NULL);
59
60 if (xdrs->x_op == XDR_ENCODE) {
61 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
62 return (FALSE);
63 }
64 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
65 return (FALSE);
66 }
68 + RNDUP(cmsg->rm_call.cb_cred.oa_length)
70 + RNDUP(cmsg->rm_call.cb_verf.oa_length));
71 if (buf != NULL) {
74 if (cmsg->rm_direction != CALL) {
75 return (FALSE);
76 }
77 IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
78 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
79 return (FALSE);
80 }
81 IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
82 IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
83 IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
84 oa = &cmsg->rm_call.cb_cred;
87 if (oa->oa_length) {
88 memmove(buf, oa->oa_base, oa->oa_length);
89 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
90 }
91 oa = &cmsg->rm_call.cb_verf;
94 if (oa->oa_length) {
95 memmove(buf, oa->oa_base, oa->oa_length);
96 /* no real need....
97 buf += RNDUP(oa->oa_length) / sizeof (int32_t);
98 */
99 }
100 return (TRUE);
101 }
102 }
103 if (xdrs->x_op == XDR_DECODE) {
104 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
105 if (buf != NULL) {
106 cmsg->rm_xid = IXDR_GET_U_INT32(buf);
107 cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
108 if (cmsg->rm_direction != CALL) {
109 return (FALSE);
110 }
111 cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf);
112 if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
113 return (FALSE);
114 }
115 cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf);
116 cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf);
117 cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf);
118 oa = &cmsg->rm_call.cb_cred;
121 if (oa->oa_length) {
122 if (oa->oa_length > MAX_AUTH_BYTES) {
123 return (FALSE);
124 }
125 if (oa->oa_base == NULL) {
126 oa->oa_base = (caddr_t)
127 mem_alloc(oa->oa_length);
128 if (oa->oa_base == NULL)
129 return (FALSE);
130 }
131 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
132 if (buf == NULL) {
133 if (xdr_opaque(xdrs, oa->oa_base,
134 oa->oa_length) == FALSE) {
135 return (FALSE);
136 }
137 } else {
138 memmove(oa->oa_base, buf,
139 oa->oa_length);
140 /* no real need....
141 buf += RNDUP(oa->oa_length) /
142 sizeof (int32_t);
143 */
144 }
145 }
146 oa = &cmsg->rm_call.cb_verf;
147 buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
148 if (buf == NULL) {
149 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
150 xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
151 return (FALSE);
152 }
153 } else {
156 }
157 if (oa->oa_length) {
158 if (oa->oa_length > MAX_AUTH_BYTES) {
159 return (FALSE);
160 }
161 if (oa->oa_base == NULL) {
162 oa->oa_base = (caddr_t)
163 mem_alloc(oa->oa_length);
164 if (oa->oa_base == NULL)
165 return (FALSE);
166 }
167 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
168 if (buf == NULL) {
169 if (xdr_opaque(xdrs, oa->oa_base,
170 oa->oa_length) == FALSE) {
171 return (FALSE);
172 }
173 } else {
174 memmove(oa->oa_base, buf,
175 oa->oa_length);
176 /* no real need...
177 buf += RNDUP(oa->oa_length) /
178 sizeof (int32_t);
179 */
180 }
181 }
182 return (TRUE);
183 }
184 }
185 if (
186 xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
187 xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
188 (cmsg->rm_direction == CALL) &&
189 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
190 (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
191 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
192 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
193 xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
194 xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
195 return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
196 return (FALSE);
197}
bool_t xdr_u_int(XDR *xdrs, u_int *up)
Definition: xdr.c:133
bool_t xdr_u_int32_t(XDR *xdrs, u_int32_t *u_int32_p)
Definition: xdr.c:239
bool_t xdr_opaque(XDR *xdrs, caddr_t cp, u_int cnt)
Definition: xdr.c:484
bool_t xdr_enum(XDR *xdrs, enum_t *ep)
Definition: xdr.c:458
bool_t xdr_opaque_auth()
#define caddr_t
Definition: ftp.c:24
#define MAX_AUTH_BYTES
Definition: auth.h:77
UINT32 u_int
Definition: types.h:82
#define NULL
Definition: types.h:112
#define mem_alloc(bsize)
Definition: types.h:123
int32_t bool_t
Definition: types.h:101
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
INT32 int32_t
Definition: types.h:71
int32_t enum_t
Definition: types.h:102
#define assert(x)
Definition: debug.h:53
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define int32_t
Definition: nsiface.idl:56
bool_t xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg)
Definition: rpc_callmsg.c:50
#define RPC_MSG_VERSION
Definition: rpc_msg.h:66
msg_type
Definition: rpc_msg.h:77
@ CALL
Definition: rpc_msg.h:78
#define IXDR_PUT_INT32(buf, v)
Definition: rpcb_prot.h:15
#define IXDR_GET_U_INT32(buf)
Definition: rpcb_prot.h:18
Definition: xdr.h:103
enum xdr_op x_op
Definition: xdr.h:104
u_int oa_length
Definition: auth.h:198
caddr_t oa_base
Definition: auth.h:197
enum_t oa_flavor
Definition: auth.h:196
enum msg_type rm_direction
Definition: rpc_msg.h:174
u_int32_t rm_xid
Definition: rpc_msg.h:173
#define IXDR_PUT_ENUM(buf, v)
Definition: xdr.h:282
#define XDR_INLINE(xdrs, len)
Definition: xdr.h:209
@ XDR_DECODE
Definition: xdr.h:86
@ XDR_ENCODE
Definition: xdr.h:85
#define IXDR_GET_ENUM(buf, t)
Definition: xdr.h:276
#define BYTES_PER_XDR_UNIT
Definition: xdr.h:93
#define RNDUP(x)
Definition: xdr.h:94