Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / rpc / sec / authu_prot.c
blob102f3fd94b100065edccce1cea6533f815674d7c
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 if (sizeof (uid_t) == sizeof (int32_t)) {
78 return (xdr_int(xdrs, (int32_t *)ip));
79 } else {
80 return (xdr_short(xdrs, (short *)ip));
85 * XDR group id types (gid_t)
87 bool_t
88 xdr_gid_t(XDR *xdrs, gid_t *ip)
90 if (sizeof (gid_t) == sizeof (int32_t)) {
91 return (xdr_int32(xdrs, (int32_t *)ip));
92 } else {
93 return (xdr_short(xdrs, (short *)ip));
98 * XDR kernel unix auth parameters.
99 * Goes out of the u struct directly.
100 * NOTE: this is an XDR_ENCODE only routine.
102 bool_t
103 xdr_authkern(XDR *xdrs, cred_t *cr)
105 uid_t uid;
106 gid_t gid;
107 uint_t len;
108 caddr_t groups;
109 char *name = uts_nodename();
110 time_t now;
112 if (xdrs->x_op != XDR_ENCODE)
113 return (FALSE);
115 uid = crgetuid(cr);
116 gid = crgetgid(cr);
117 len = crgetngroups(cr);
119 if (len > NGRPS)
120 len = NGRPS;
122 groups = (caddr_t)crgetgroups(cr);
123 now = gethrestime_sec();
124 if (xdr_uint32(xdrs, (uint32_t *)&now) &&
125 xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
126 xdr_uid_t(xdrs, &uid) &&
127 xdr_gid_t(xdrs, &gid) &&
128 xdr_array(xdrs, &groups, &len, NGRPS, sizeof (gid_t), xdr_gid_t))
129 return (TRUE);
130 return (FALSE);
134 * XDR loopback unix auth parameters.
135 * NOTE: this is an XDR_ENCODE only routine.
137 bool_t
138 xdr_authloopback(XDR *xdrs, cred_t *cr)
140 uid_t uid;
141 gid_t gid;
142 uint_t len;
143 caddr_t groups;
144 char *name = uts_nodename();
145 time_t now;
147 if (xdrs->x_op != XDR_ENCODE)
148 return (FALSE);
150 uid = crgetuid(cr);
151 gid = crgetgid(cr);
152 len = crgetngroups(cr);
153 groups = (caddr_t)crgetgroups(cr);
154 now = gethrestime_sec();
155 if (xdr_uint32(xdrs, (uint32_t *)&now) &&
156 xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
157 xdr_uid_t(xdrs, &uid) &&
158 xdr_gid_t(xdrs, &gid) &&
159 xdr_array(xdrs, &groups, &len, NGROUPS_UMAX, sizeof (gid_t),
160 xdr_gid_t))
161 return (TRUE);
162 return (FALSE);