2352630649219e47dfbaaeac3d48c042a89de26c
[bluesky.git] / TBBT / trace_play / rpc / svc_auth.c
1 #ifndef lint
2 static char sfs_svc_auth_id[] = "@(#)svc_auth.c     2.1     97/10/23";
3 #endif
4 #if !defined(lint) && defined(SCCSIDS)
5 static char sccsid[] = "@(#)svc_auth.c  2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
6 #endif
7 /*
8  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
9  *      All rights reserved.
10  *              Standard Performance Evaluation Corporation (SPEC)
11  *              6585 Merchant Place, Suite 100
12  *              Warrenton, VA 20187
13  *
14  *      This product contains benchmarks acquired from several sources who
15  *      understand and agree with SPEC's goal of creating fair and objective
16  *      benchmarks to measure computer performance.
17  *
18  *      This copyright notice is placed here only to protect SPEC in the
19  *      event the source is misused in any manner that is contrary to the
20  *      spirit, the goals and the intent of SPEC.
21  *
22  *      The source code is provided to the user or company under the license
23  *      agreement for the SPEC Benchmark Suite for this product.
24  */
25 /*
26  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
27  * unrestricted use provided that this legend is included on all tape
28  * media and as a part of the software program in whole or part.  Users
29  * may copy or modify Sun RPC without charge, but are not authorized
30  * to license or distribute it to anyone else except as part of a product or
31  * program developed by the user.
32  * 
33  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
34  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
35  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
36  * 
37  * Sun RPC is provided with no support and without any obligation on the
38  * part of Sun Microsystems, Inc. to assist in its use, correction,
39  * modification or enhancement.
40  *
41  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
42  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
43  * OR ANY PART THEREOF.
44  *
45  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
46  * or profits or other special, indirect and consequential damages, even if
47  * Sun has been advised of the possibility of such damages.
48  *
49  * Sun Microsystems, Inc.
50  * 2550 Garcia Avenue
51  * Mountain View, California  94043
52  */
53
54 /*
55  * svc_auth_nodes.c, Server-side rpc authenticator interface,
56  * *WITHOUT* DES authentication.
57  *
58  * Copyright (C) 1984, Sun Microsystems, Inc.
59  */
60
61 #include "rpc/rpc.h"
62
63 /*
64  * svcauthsw is the bdevsw of server side authentication. 
65  * 
66  * Server side authenticators are called from authenticate by
67  * using the client auth struct flavor field to index into svcauthsw.
68  * The server auth flavors must implement a routine that looks  
69  * like: 
70  * 
71  *      enum auth_stat
72  *      flavorx_auth(rqst, msg)
73  *              register struct svc_req *rqst; 
74  *              register struct rpc_msg *msg;
75  *
76  */
77
78 extern enum auth_stat _svcauth_null(struct svc_req *, struct rpc_msg *);
79 extern enum auth_stat _svcauth_unix(struct svc_req *, struct rpc_msg *);
80 extern enum auth_stat _svcauth_short(struct svc_req *, struct rpc_msg *);
81
82 static struct {
83         enum auth_stat (*authenticator)(struct svc_req *, struct rpc_msg *);
84 } svcauthsw[] = {
85         _svcauth_null,                  /* AUTH_NULL */
86         _svcauth_unix,                  /* AUTH_UNIX */
87         _svcauth_short,                 /* AUTH_SHORT */
88 };
89 #define AUTH_MAX        2               /* HIGHEST AUTH NUMBER */
90
91
92 /*
93  * The call rpc message, msg has been obtained from the wire.  The msg contains
94  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
95  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
96  * does the following things:
97  * set rqst->rq_xprt->verf to the appropriate response verifier;
98  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
99  *
100  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
101  * its length is set appropriately.
102  *
103  * The caller still owns and is responsible for msg->u.cmb.cred and
104  * msg->u.cmb.verf.  The authentication system retains ownership of
105  * rqst->rq_client_cred, the cooked credentials.
106  *
107  * There is an assumption that any flavour less than AUTH_NULL is
108  * invalid.
109  */
110 enum auth_stat
111 _authenticate(
112         struct svc_req *rqst,
113         struct rpc_msg *msg)
114 {
115         register int cred_flavor;
116
117         rqst->rq_cred = msg->rm_call.cb_cred;
118         rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
119         rqst->rq_xprt->xp_verf.oa_length = 0;
120         cred_flavor = rqst->rq_cred.oa_flavor;
121         if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
122                 return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
123         }
124
125         return (AUTH_REJECTEDCRED);
126 }
127
128 /* ARGSUSED */
129 enum auth_stat
130 _svcauth_null(
131         struct svc_req *rqst,
132         struct rpc_msg *msg)
133 {
134
135         return (AUTH_OK);
136 }