Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_play / rpc / svc_auth_unix.c
1 #ifndef lint
2 static char sfs_svc_auth_unix_id[] = "@(#)svc_auth_unix.c     2.1     97/10/23";
3 #endif
4 /* @(#)svc_auth_unix.c  2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Manassas, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
53 #endif
54
55 /*
56  * svc_auth_unix.c
57  * Handles UNIX flavor authentication parameters on the service side of rpc.
58  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
59  * _svcauth_unix does full blown unix style uid,gid+gids auth,
60  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
61  * Note: the shorthand has been gutted for efficiency.
62  *
63  * Copyright (C) 1984, Sun Microsystems, Inc.
64  */
65
66 #include <stdio.h>
67 #include <string.h>
68 #include "rpc/rpc.h"
69
70 /*
71  * Unix longhand authenticator
72  */
73 enum auth_stat
74 _svcauth_unix(
75         struct svc_req *rqst,
76         struct rpc_msg *msg)
77 {
78         enum auth_stat stat;
79         XDR xdrs;
80         struct authunix_parms *aup;
81         int32_t *buf;
82         struct area {
83                 struct authunix_parms area_aup;
84                 char area_machname[MAX_MACHINE_NAME+1];
85                 int area_gids[NGRPS];
86         } *area;
87         uint_t auth_len;
88         int str_len, gid_len;
89         int i;
90
91         area = (struct area *) rqst->rq_clntcred;
92         aup = &area->area_aup;
93         aup->aup_machname = area->area_machname;
94         aup->aup_gids = area->area_gids;
95         auth_len = (uint_t)msg->rm_call.cb_cred.oa_length;
96         xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
97         buf = XDR_INLINE(&xdrs, auth_len);
98         if (buf != NULL) {
99                 aup->aup_time = IXDR_GET_LONG(buf);
100                 str_len = IXDR_GET_U_LONG(buf);
101                 if (str_len > MAX_MACHINE_NAME) {
102                         stat = AUTH_BADCRED;
103                         goto done;
104                 }
105                 memmove(aup->aup_machname, (void *)buf, (uint_t)str_len);
106                 aup->aup_machname[str_len] = 0;
107                 str_len = RNDUP(str_len);
108                 buf += str_len / sizeof (int32_t);
109                 aup->aup_uid = IXDR_GET_LONG(buf);
110                 aup->aup_gid = IXDR_GET_LONG(buf);
111                 gid_len = IXDR_GET_U_LONG(buf);
112                 if (gid_len > NGRPS) {
113                         stat = AUTH_BADCRED;
114                         goto done;
115                 }
116                 aup->aup_len = gid_len;
117                 for (i = 0; i < gid_len; i++) {
118                         aup->aup_gids[i] = IXDR_GET_LONG(buf);
119                 }
120                 /*
121                  * five is the smallest unix credentials structure -
122                  * timestamp, hostname len (0), uid, gid, and gids len (0).
123                  */
124                 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
125                         (void) printf("bad auth_len gid %d str %d auth %d\n",
126                             gid_len, str_len, auth_len);
127                         stat = AUTH_BADCRED;
128                         goto done;
129                 }
130         } else if (! xdr_authunix_parms(&xdrs, aup)) {
131                 xdrs.x_op = XDR_FREE;
132                 (void)xdr_authunix_parms(&xdrs, aup);
133                 stat = AUTH_BADCRED;
134                 goto done;
135         }
136         rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
137         rqst->rq_xprt->xp_verf.oa_length = 0;
138         stat = AUTH_OK;
139 done:
140         XDR_DESTROY(&xdrs);
141         return (stat);
142 }
143
144
145 /*
146  * Shorthand unix authenticator
147  * Looks up longhand in a cache.
148  */
149 /*ARGSUSED*/
150 enum auth_stat 
151 _svcauth_short(
152         struct svc_req *rqst,
153         struct rpc_msg *msg)
154 {
155         return (AUTH_REJECTEDCRED);
156 }