c563d12c1e6e7b379c8d50a21ac25b4c379e3d58
[shibboleth/cpp-sp.git] / oncrpc / svc_auth.c
1 /*********************************************************************
2  * RPC for the Windows NT Operating System
3  * 1993 by Martin F. Gergeleit
4  * Users may use, copy or modify Sun RPC for the Windows NT Operating 
5  * System according to the Sun copyright below.
6  *
7  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
8  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
9  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10  *********************************************************************/
11
12 #if !defined(lint) && defined(SCCSIDS)
13 static char sccsid[] = "@(#)svc_auth.c  2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
14 #endif
15 /*
16  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
17  * unrestricted use provided that this legend is included on all tape
18  * media and as a part of the software program in whole or part.  Users
19  * may copy or modify Sun RPC without charge, but are not authorized
20  * to license or distribute it to anyone else except as part of a product or
21  * program developed by the user.
22  * 
23  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
24  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
26  * 
27  * Sun RPC is provided with no support and without any obligation on the
28  * part of Sun Microsystems, Inc. to assist in its use, correction,
29  * modification or enhancement.
30  *
31  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
32  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
33  * OR ANY PART THEREOF.
34  *
35  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
36  * or profits or other special, indirect and consequential damages, even if
37  * Sun has been advised of the possibility of such damages.
38  *
39  * Sun Microsystems, Inc.
40  * 2550 Garcia Avenue
41  * Mountain View, California  94043
42  */
43
44 /*
45  * svc_auth_nodes.c, Server-side rpc authenticator interface,
46  * *WITHOUT* DES authentication.
47  *
48  * Copyright (C) 1984, Sun Microsystems, Inc.
49  */
50
51 #include <rpc/rpc.h>
52
53 /*
54  * svcauthsw is the bdevsw of server side authentication. 
55  * 
56  * Server side authenticators are called from authenticate by
57  * using the client auth struct flavor field to index into svcauthsw.
58  * The server auth flavors must implement a routine that looks  
59  * like: 
60  * 
61  *      enum auth_stat
62  *      flavorx_auth(rqst, msg)
63  *              register struct svc_req *rqst; 
64  *              register struct rpc_msg *msg;
65  *
66  */
67
68 enum auth_stat _svcauth_null();         /* no authentication */
69 enum auth_stat _svcauth_unix();         /* unix style (uid, gids) */
70 enum auth_stat _svcauth_short();        /* short hand unix style */
71
72 static struct {
73         enum auth_stat (*authenticator)();
74 } svcauthsw[] = {
75         _svcauth_null,                  /* AUTH_NULL */
76         _svcauth_unix,                  /* AUTH_UNIX */
77         _svcauth_short,                 /* AUTH_SHORT */
78 };
79 #define AUTH_MAX        2               /* HIGHEST AUTH NUMBER */
80
81
82 /*
83  * The call rpc message, msg has been obtained from the wire.  The msg contains
84  * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
85  * if the msg is successfully authenticated.  If AUTH_OK then the routine also
86  * does the following things:
87  * set rqst->rq_xprt->verf to the appropriate response verifier;
88  * sets rqst->rq_client_cred to the "cooked" form of the credentials.
89  *
90  * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
91  * its length is set appropriately.
92  *
93  * The caller still owns and is responsible for msg->u.cmb.cred and
94  * msg->u.cmb.verf.  The authentication system retains ownership of
95  * rqst->rq_client_cred, the cooked credentials.
96  *
97  * There is an assumption that any flavour less than AUTH_NULL is
98  * invalid.
99  */
100 enum auth_stat
101 _authenticate(rqst, msg)
102         register struct svc_req *rqst;
103         struct rpc_msg *msg;
104 {
105         register int cred_flavor;
106
107         rqst->rq_cred = msg->rm_call.cb_cred;
108         rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
109         rqst->rq_xprt->xp_verf.oa_length = 0;
110         cred_flavor = rqst->rq_cred.oa_flavor;
111         if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
112                 return ((*(svcauthsw[cred_flavor].authenticator))(rqst, msg));
113         }
114
115         return (AUTH_REJECTEDCRED);
116 }
117
118 enum auth_stat
119 _svcauth_null(/*rqst, msg*/)
120         /*struct svc_req *rqst;
121         struct rpc_msg *msg;*/
122 {
123
124         return (AUTH_OK);
125 }