8106 authloopback_marshal() can violate the RPC specification
[unleashed/tickless.git] / usr / src / uts / common / rpc / sec / authu_prot.c
blob8b0bf90a5dea85dbe1b96474aa7e59358ed57bd7
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 * under license from the Regents of the University of California.
35 * authunix_prot.c
36 * XDR for UNIX style authentication parameters for RPC
39 #include <sys/param.h>
40 #include <sys/time.h>
41 #include <sys/cred.h>
42 #include <sys/proc.h>
43 #include <sys/user.h>
44 #include <sys/utsname.h>
46 #include <rpc/types.h>
47 #include <rpc/rpc_sztypes.h>
48 #include <rpc/xdr.h>
49 #include <rpc/auth.h>
50 #include <rpc/auth_unix.h>
51 #include <rpc/clnt.h>
54 * XDR for unix authentication parameters.
56 bool_t
57 xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p)
59 if (xdr_u_int(xdrs, &p->aup_time) &&
60 xdr_string(xdrs, &p->aup_machname, MAX_MACHINE_NAME) &&
61 xdr_int(xdrs, (int *)&(p->aup_uid)) &&
62 xdr_int(xdrs, (int *)&(p->aup_gid)) &&
63 xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
64 &(p->aup_len), NGRPS, sizeof (int),
65 (xdrproc_t)xdr_int)) {
66 return (TRUE);
68 return (FALSE);
72 * XDR user id types (uid_t)
74 bool_t
75 xdr_uid_t(XDR *xdrs, uid_t *ip)
77 #ifdef lint
78 (void) (xdr_short(xdrs, (short *)ip));
79 return (xdr_int32(xdrs, (int32_t *)ip));
80 #else
81 if (sizeof (uid_t) == sizeof (int32_t)) {
82 return (xdr_int(xdrs, (int32_t *)ip));
83 } else {
84 return (xdr_short(xdrs, (short *)ip));
86 #endif
90 * XDR group id types (gid_t)
92 bool_t
93 xdr_gid_t(XDR *xdrs, gid_t *ip)
95 #ifdef lint
96 (void) (xdr_short(xdrs, (short *)ip));
97 return (xdr_int32(xdrs, (int32_t *)ip));
98 #else
99 if (sizeof (gid_t) == sizeof (int32_t)) {
100 return (xdr_int32(xdrs, (int32_t *)ip));
101 } else {
102 return (xdr_short(xdrs, (short *)ip));
104 #endif
108 * XDR kernel unix auth parameters.
109 * Goes out of the u struct directly.
110 * NOTE: this is an XDR_ENCODE only routine.
112 bool_t
113 xdr_authkern(XDR *xdrs, cred_t *cr)
115 uid_t uid;
116 gid_t gid;
117 uint_t len;
118 caddr_t groups;
119 char *name = uts_nodename();
120 time_t now;
122 if (xdrs->x_op != XDR_ENCODE)
123 return (FALSE);
125 uid = crgetuid(cr);
126 gid = crgetgid(cr);
127 len = crgetngroups(cr);
129 if (len > NGRPS)
130 len = NGRPS;
132 groups = (caddr_t)crgetgroups(cr);
133 now = gethrestime_sec();
134 if (xdr_uint32(xdrs, (uint32_t *)&now) &&
135 xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
136 xdr_uid_t(xdrs, &uid) &&
137 xdr_gid_t(xdrs, &gid) &&
138 xdr_array(xdrs, &groups, &len, NGRPS, sizeof (gid_t), xdr_gid_t))
139 return (TRUE);
140 return (FALSE);
144 * XDR loopback unix auth parameters.
145 * NOTE: this is an XDR_ENCODE only routine.
147 bool_t
148 xdr_authloopback(XDR *xdrs, cred_t *cr)
150 uid_t uid;
151 gid_t gid;
152 uint_t len;
153 caddr_t groups;
154 char *name = uts_nodename();
155 time_t now;
157 if (xdrs->x_op != XDR_ENCODE)
158 return (FALSE);
160 uid = crgetuid(cr);
161 gid = crgetgid(cr);
162 len = crgetngroups(cr);
163 groups = (caddr_t)crgetgroups(cr);
164 now = gethrestime_sec();
165 if (xdr_uint32(xdrs, (uint32_t *)&now) &&
166 xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
167 xdr_uid_t(xdrs, &uid) &&
168 xdr_gid_t(xdrs, &gid) &&
169 xdr_array(xdrs, &groups, &len, NGROUPS_UMAX, sizeof (gid_t),
170 xdr_gid_t))
171 return (TRUE);
172 return (FALSE);