3 * Copyright (c) 2009, Sun Microsystems, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * - Neither the name of Sun Microsystems, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
34 * svc_auth.c, Server-side rpc authenticator interface.
38 #include <reentrant.h>
39 #include <sys/types.h>
44 * svcauthsw is the bdevsw of server side authentication.
46 * Server side authenticators are called from authenticate by
47 * using the client auth struct flavor field to index into svcauthsw.
48 * The server auth flavors must implement a routine that looks
52 * flavorx_auth(rqst, msg)
53 * struct svc_req *rqst;
54 * struct rpc_msg *msg;
58 /* declarations to allow servers to specify new authentication flavors */
61 enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *);
64 static struct authsvc *Auths = NULL;
67 * The call rpc message, msg has been obtained from the wire. The msg contains
68 * the raw form of credentials and verifiers. authenticate returns AUTH_OK
69 * if the msg is successfully authenticated. If AUTH_OK then the routine also
70 * does the following things:
71 * set rqst->rq_xprt->verf to the appropriate response verifier;
72 * sets rqst->rq_client_cred to the "cooked" form of the credentials.
74 * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
75 * its length is set appropriately.
77 * The caller still owns and is responsible for msg->u.cmb.cred and
78 * msg->u.cmb.verf. The authentication system retains ownership of
79 * rqst->rq_client_cred, the cooked credentials.
81 * There is an assumption that any flavour less than AUTH_NULL is
85 _gss_authenticate(rqst, msg, no_dispatch)
93 extern mutex_t authsvc_lock;
95 /* VARIABLES PROTECTED BY authsvc_lock: asp, Auths */
97 rqst->rq_cred = msg->rm_call.cb_cred;
98 rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
99 rqst->rq_xprt->xp_verf.oa_length = 0;
100 cred_flavor = rqst->rq_cred.oa_flavor;
101 *no_dispatch = FALSE;
102 switch (cred_flavor) {
104 dummy = _svcauth_none(rqst, msg);
107 dummy = _svcauth_unix(rqst, msg);
110 dummy = _svcauth_short(rqst, msg);
114 dummy = _svcauth_des(rqst, msg);
117 #ifdef HAVE_RPCSEC_GSS
119 dummy = _svcauth_gss(rqst, msg, no_dispatch);
126 /* flavor doesn't match any of the builtin types, so try new ones */
127 mutex_lock(&authsvc_lock);
128 for (asp = Auths; asp; asp = asp->next) {
129 if (asp->flavor == cred_flavor) {
132 as = (*asp->handler)(rqst, msg);
133 mutex_unlock(&authsvc_lock);
137 mutex_unlock(&authsvc_lock);
139 return (AUTH_REJECTEDCRED);
143 _authenticate(struct svc_req *rqst, struct rpc_msg *msg)
146 return _gss_authenticate(rqst, msg, &no_dispatch);
150 * Allow the rpc service to register new authentication types that it is
151 * prepared to handle. When an authentication flavor is registered,
152 * the flavor is checked against already registered values. If not
153 * registered, then a new Auths entry is added on the list.
155 * There is no provision to delete a registration once registered.
157 * This routine returns:
158 * 0 if registration successful
159 * 1 if flavor already registered
160 * -1 if can't register (errno set)
164 svc_auth_reg(cred_flavor, handler)
166 enum auth_stat (*handler)(struct svc_req *, struct rpc_msg *);
169 extern mutex_t authsvc_lock;
171 switch (cred_flavor) {
178 #ifdef HAVE_RPCSEC_GSS
181 /* already registered */
185 mutex_lock(&authsvc_lock);
186 for (asp = Auths; asp; asp = asp->next) {
187 if (asp->flavor == cred_flavor) {
188 /* already registered */
189 mutex_unlock(&authsvc_lock);
194 /* this is a new one, so go ahead and register it */
195 asp = mem_alloc(sizeof (*asp));
197 mutex_unlock(&authsvc_lock);
200 asp->flavor = cred_flavor;
201 asp->handler = handler;
204 mutex_unlock(&authsvc_lock);