4eee78df32199c287496767f68e228e8638f95ca
[shibboleth/cpp-sp.git] / oncrpc / rpc_call.c
1 /*********************************************************************
2  * RPC for the Windows NT Operating System
3  * 1993 by Martin F. Gergeleit
4  * Users may use, copy or modify Sun RPC for the Windows NT Operating 
5  * System according to the Sun copyright below.
6  *
7  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
8  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
9  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10  *********************************************************************/
11 /* @(#)rpc_callmsg.c    2.1 88/07/29 4.0 RPCSRC */
12 /*
13  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
14  * unrestricted use provided that this legend is included on all tape
15  * media and as a part of the software program in whole or part.  Users
16  * may copy or modify Sun RPC without charge, but are not authorized
17  * to license or distribute it to anyone else except as part of a product or
18  * program developed by the user.
19  * 
20  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
21  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
23  * 
24  * Sun RPC is provided with no support and without any obligation on the
25  * part of Sun Microsystems, Inc. to assist in its use, correction,
26  * modification or enhancement.
27  * 
28  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
29  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
30  * OR ANY PART THEREOF.
31  * 
32  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
33  * or profits or other special, indirect and consequential damages, even if
34  * Sun has been advised of the possibility of such damages.
35  * 
36  * Sun Microsystems, Inc.
37  * 2550 Garcia Avenue
38  * Mountain View, California  94043
39  */
40 #if !defined(lint) && defined(SCCSIDS)
41 static char sccsid[] = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
42 #endif
43
44 /*
45  * rpc_callmsg.c
46  *
47  * Copyright (C) 1984, Sun Microsystems, Inc.
48  *
49  */
50
51 #ifndef WIN32
52 #include <sys/param.h>
53 #endif
54 #include <rpc/rpc.h>
55
56 /*
57  * XDR a call message
58  */
59 bool_t
60 xdr_callmsg(xdrs, cmsg)
61         register XDR *xdrs;
62         register struct rpc_msg *cmsg;
63 {
64         register long *buf;
65         register struct opaque_auth *oa;
66
67         if (xdrs->x_op == XDR_ENCODE) {
68                 if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
69                         return (FALSE);
70                 }
71                 if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
72                         return (FALSE);
73                 }
74                 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
75                         + RNDUP(cmsg->rm_call.cb_cred.oa_length)
76                         + 2 * BYTES_PER_XDR_UNIT
77                         + RNDUP(cmsg->rm_call.cb_verf.oa_length));
78                 if (buf != NULL) {
79                         IXDR_PUT_LONG(buf, cmsg->rm_xid);
80                         IXDR_PUT_ENUM(buf, cmsg->rm_direction);
81                         if (cmsg->rm_direction != CALL) {
82                                 return (FALSE);
83                         }
84                         IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
85                         if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
86                                 return (FALSE);
87                         }
88                         IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
89                         IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
90                         IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
91                         oa = &cmsg->rm_call.cb_cred;
92                         IXDR_PUT_ENUM(buf, oa->oa_flavor);
93                         IXDR_PUT_LONG(buf, oa->oa_length);
94                         if (oa->oa_length) {
95                                 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
96                                 buf += RNDUP(oa->oa_length) / sizeof (long);
97                         }
98                         oa = &cmsg->rm_call.cb_verf;
99                         IXDR_PUT_ENUM(buf, oa->oa_flavor);
100                         IXDR_PUT_LONG(buf, oa->oa_length);
101                         if (oa->oa_length) {
102                                 bcopy(oa->oa_base, (caddr_t)buf, oa->oa_length);
103                                 /* no real need....
104                                 buf += RNDUP(oa->oa_length) / sizeof (long);
105                                 */
106                         }
107                         return (TRUE);
108                 }
109         }
110         if (xdrs->x_op == XDR_DECODE) {
111                 buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
112                 if (buf != NULL) {
113                         cmsg->rm_xid = IXDR_GET_LONG(buf);
114                         cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
115                         if (cmsg->rm_direction != CALL) {
116                                 return (FALSE);
117                         }
118                         cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
119                         if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
120                                 return (FALSE);
121                         }
122                         cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
123                         cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
124                         cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
125                         oa = &cmsg->rm_call.cb_cred;
126                         oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
127                         oa->oa_length = IXDR_GET_LONG(buf);
128                         if (oa->oa_length) {
129                                 if (oa->oa_length > MAX_AUTH_BYTES) {
130                                         return (FALSE);
131                                 }
132                                 if (oa->oa_base == NULL) {
133                                         oa->oa_base = (caddr_t)
134                                                 mem_alloc(oa->oa_length);
135                                 }
136                                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
137                                 if (buf == NULL) {
138                                         if (xdr_opaque(xdrs, oa->oa_base,
139                                             oa->oa_length) == FALSE) {
140                                                 return (FALSE);
141                                         }
142                                 } else {
143                                         bcopy((caddr_t)buf, oa->oa_base,
144                                             oa->oa_length);
145                                         /* no real need....
146                                         buf += RNDUP(oa->oa_length) /
147                                                 sizeof (long);
148                                         */
149                                 }
150                         }
151                         oa = &cmsg->rm_call.cb_verf;
152                         buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
153                         if (buf == NULL) {
154                                 if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
155                                     xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
156                                         return (FALSE);
157                                 }
158                         } else {
159                                 oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
160                                 oa->oa_length = IXDR_GET_LONG(buf);
161                         }
162                         if (oa->oa_length) {
163                                 if (oa->oa_length > MAX_AUTH_BYTES) {
164                                         return (FALSE);
165                                 }
166                                 if (oa->oa_base == NULL) {
167                                         oa->oa_base = (caddr_t)
168                                                 mem_alloc(oa->oa_length);
169                                 }
170                                 buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
171                                 if (buf == NULL) {
172                                         if (xdr_opaque(xdrs, oa->oa_base,
173                                             oa->oa_length) == FALSE) {
174                                                 return (FALSE);
175                                         }
176                                 } else {
177                                         bcopy((caddr_t)buf, oa->oa_base,
178                                             oa->oa_length);
179                                         /* no real need...
180                                         buf += RNDUP(oa->oa_length) /
181                                                 sizeof (long);
182                                         */
183                                 }
184                         }
185                         return (TRUE);
186                 }
187         }
188         if (
189             xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
190             xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
191             (cmsg->rm_direction == CALL) &&
192             xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
193             (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
194             xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) &&
195             xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) &&
196             xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) &&
197             xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
198             return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
199         return (FALSE);
200 }
201