source: rtems-libbsd/freebsd/lib/libc/rpc/rpc_callmsg.c @ f41a394

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since f41a394 was 60b1d40, checked in by Sebastian Huber <sebastian.huber@…>, on 06/09/16 at 08:23:57

RPC(3): Import from FreeBSD

  • Property mode set to 100644
File size: 6.4 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*      $NetBSD: rpc_callmsg.c,v 1.16 2000/07/14 08:40:42 fvdl Exp $    */
4
5/*-
6 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright notice,
12 *   this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright notice,
14 *   this list of conditions and the following disclaimer in the documentation
15 *   and/or other materials provided with the distribution.
16 * - Neither the name of Sun Microsystems, Inc. nor the names of its
17 *   contributors may be used to endorse or promote products derived
18 *   from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char *sccsid2 = "@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
35static char *sccsid = "@(#)rpc_callmsg.c        2.1 88/07/29 4.0 RPCSRC";
36#endif
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD$");
39
40/*
41 * rpc_callmsg.c
42 *
43 * Copyright (C) 1984, Sun Microsystems, Inc.
44 *
45 */
46
47#include "namespace.h"
48#include <assert.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include <rpc/rpc.h>
53#include "un-namespace.h"
54
55/*
56 * XDR a call message
57 */
58bool_t
59xdr_callmsg(xdrs, cmsg)
60        XDR *xdrs;
61        struct rpc_msg *cmsg;
62{
63        enum msg_type *prm_direction;
64        int32_t *buf;
65        struct opaque_auth *oa;
66
67        assert(xdrs != NULL);
68        assert(cmsg != NULL);
69
70        if (xdrs->x_op == XDR_ENCODE) {
71                if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
72                        return (FALSE);
73                }
74                if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
75                        return (FALSE);
76                }
77                buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
78                        + RNDUP(cmsg->rm_call.cb_cred.oa_length)
79                        + 2 * BYTES_PER_XDR_UNIT
80                        + RNDUP(cmsg->rm_call.cb_verf.oa_length));
81                if (buf != NULL) {
82                        IXDR_PUT_INT32(buf, cmsg->rm_xid);
83                        IXDR_PUT_ENUM(buf, cmsg->rm_direction);
84                        if (cmsg->rm_direction != CALL) {
85                                return (FALSE);
86                        }
87                        IXDR_PUT_INT32(buf, cmsg->rm_call.cb_rpcvers);
88                        if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
89                                return (FALSE);
90                        }
91                        IXDR_PUT_INT32(buf, cmsg->rm_call.cb_prog);
92                        IXDR_PUT_INT32(buf, cmsg->rm_call.cb_vers);
93                        IXDR_PUT_INT32(buf, cmsg->rm_call.cb_proc);
94                        oa = &cmsg->rm_call.cb_cred;
95                        IXDR_PUT_ENUM(buf, oa->oa_flavor);
96                        IXDR_PUT_INT32(buf, oa->oa_length);
97                        if (oa->oa_length) {
98                                memmove(buf, oa->oa_base, oa->oa_length);
99                                buf += RNDUP(oa->oa_length) / sizeof (int32_t);
100                        }
101                        oa = &cmsg->rm_call.cb_verf;
102                        IXDR_PUT_ENUM(buf, oa->oa_flavor);
103                        IXDR_PUT_INT32(buf, oa->oa_length);
104                        if (oa->oa_length) {
105                                memmove(buf, oa->oa_base, oa->oa_length);
106                                /* no real need....
107                                buf += RNDUP(oa->oa_length) / sizeof (int32_t);
108                                */
109                        }
110                        return (TRUE);
111                }
112        }
113        if (xdrs->x_op == XDR_DECODE) {
114                buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
115                if (buf != NULL) {
116                        cmsg->rm_xid = IXDR_GET_U_INT32(buf);
117                        cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);
118                        if (cmsg->rm_direction != CALL) {
119                                return (FALSE);
120                        }
121                        cmsg->rm_call.cb_rpcvers = IXDR_GET_U_INT32(buf);
122                        if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
123                                return (FALSE);
124                        }
125                        cmsg->rm_call.cb_prog = IXDR_GET_U_INT32(buf);
126                        cmsg->rm_call.cb_vers = IXDR_GET_U_INT32(buf);
127                        cmsg->rm_call.cb_proc = IXDR_GET_U_INT32(buf);
128                        oa = &cmsg->rm_call.cb_cred;
129                        oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
130                        oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
131                        if (oa->oa_length) {
132                                if (oa->oa_length > MAX_AUTH_BYTES) {
133                                        return (FALSE);
134                                }
135                                if (oa->oa_base == NULL) {
136                                        oa->oa_base = (caddr_t)
137                                            mem_alloc(oa->oa_length);
138                                        if (oa->oa_base == NULL)
139                                                return (FALSE);
140                                }
141                                buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
142                                if (buf == NULL) {
143                                        if (xdr_opaque(xdrs, oa->oa_base,
144                                            oa->oa_length) == FALSE) {
145                                                return (FALSE);
146                                        }
147                                } else {
148                                        memmove(oa->oa_base, buf,
149                                            oa->oa_length);
150                                        /* no real need....
151                                        buf += RNDUP(oa->oa_length) /
152                                                sizeof (int32_t);
153                                        */
154                                }
155                        }
156                        oa = &cmsg->rm_call.cb_verf;
157                        buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
158                        if (buf == NULL) {
159                                if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
160                                    xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
161                                        return (FALSE);
162                                }
163                        } else {
164                                oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
165                                oa->oa_length = (u_int)IXDR_GET_U_INT32(buf);
166                        }
167                        if (oa->oa_length) {
168                                if (oa->oa_length > MAX_AUTH_BYTES) {
169                                        return (FALSE);
170                                }
171                                if (oa->oa_base == NULL) {
172                                        oa->oa_base = (caddr_t)
173                                            mem_alloc(oa->oa_length);
174                                        if (oa->oa_base == NULL)
175                                                return (FALSE);
176                                }
177                                buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
178                                if (buf == NULL) {
179                                        if (xdr_opaque(xdrs, oa->oa_base,
180                                            oa->oa_length) == FALSE) {
181                                                return (FALSE);
182                                        }
183                                } else {
184                                        memmove(oa->oa_base, buf,
185                                            oa->oa_length);
186                                        /* no real need...
187                                        buf += RNDUP(oa->oa_length) /
188                                                sizeof (int32_t);
189                                        */
190                                }
191                        }
192                        return (TRUE);
193                }
194        }
195        prm_direction = &cmsg->rm_direction;
196        if (
197            xdr_u_int32_t(xdrs, &(cmsg->rm_xid)) &&
198            xdr_enum(xdrs, (enum_t *) prm_direction) &&
199            (cmsg->rm_direction == CALL) &&
200            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
201            (cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
202            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) &&
203            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)) &&
204            xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_proc)) &&
205            xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)) )
206                return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
207        return (FALSE);
208}
Note: See TracBrowser for help on using the repository browser.