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