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