4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * 4.3 BSD under license from the Regents of the University of
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * svc_auth.c, Server-side rpc authenticator interface.
45 #include <sys/types.h>
49 * svcauthsw is the bdevsw of server side authentication.
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
57 * flavorx_auth(rqst, msg)
58 * struct svc_req *rqst;
59 * struct rpc_msg *msg;
61 * The RPCSEC_GSS flavor is an exception. Its routine takes an
62 * additional boolean parameter that gets set to TRUE when the call
63 * is not to be dispatched to the server.
66 enum auth_stat
__svcauth_null(); /* no authentication */
67 enum auth_stat
__svcauth_sys(); /* (system) unix style (uid, gids) */
68 enum auth_stat
__svcauth_short(); /* short hand unix style */
69 enum auth_stat
__svcauth_des(); /* des style */
70 enum auth_stat
__svcauth_loopback(); /* (loopback) unix style (uid, gids) */
71 extern enum auth_stat
__svcrpcsec_gss(); /* GSS style */
73 /* declarations to allow servers to specify new authentication flavors */
76 enum auth_stat (*handler
)();
79 static struct authsvc
*Auths
= NULL
;
82 * The call rpc message, msg has been obtained from the wire. The msg contains
83 * the raw form of credentials and verifiers. no_dispatch is used and
84 * dereferenced in subsequent gss function calls. 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.
90 * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
91 * its length is set appropriately.
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.
97 * There is an assumption that any flavour less than AUTH_NULL is
101 __gss_authenticate(struct svc_req
*rqst
, struct rpc_msg
*msg
,
106 extern mutex_t authsvc_lock
;
108 /* VARIABLES PROTECTED BY authsvc_lock: asp, Auths */
110 rqst
->rq_cred
= msg
->rm_call
.cb_cred
;
111 rqst
->rq_xprt
->xp_verf
.oa_flavor
= _null_auth
.oa_flavor
;
112 rqst
->rq_xprt
->xp_verf
.oa_length
= 0;
113 cred_flavor
= rqst
->rq_cred
.oa_flavor
;
114 *no_dispatch
= FALSE
;
115 switch (cred_flavor
) {
117 return (__svcauth_null(rqst
, msg
));
119 return (__svcauth_sys(rqst
, msg
));
121 return (__svcauth_short(rqst
, msg
));
123 return (__svcauth_des(rqst
, msg
));
125 return (__svcauth_loopback(rqst
, msg
));
127 return (__svcrpcsec_gss(rqst
, msg
, no_dispatch
));
130 /* flavor doesn't match any of the builtin types, so try new ones */
131 (void) mutex_lock(&authsvc_lock
);
132 for (asp
= Auths
; asp
; asp
= asp
->next
) {
133 if (asp
->flavor
== cred_flavor
) {
136 as
= (*asp
->handler
)(rqst
, msg
);
137 (void) mutex_unlock(&authsvc_lock
);
141 (void) mutex_unlock(&authsvc_lock
);
143 return (AUTH_REJECTEDCRED
);
147 * The following function __authenticate(rqst, msg) is preserved for
148 * backward compatibility.
151 __authenticate(struct svc_req
*rqst
, struct rpc_msg
*msg
)
155 return (__gss_authenticate(rqst
, msg
, &no_dispatch
));
160 __svcauth_null(struct svc_req
*rqst
, struct rpc_msg
*msg
)
166 * Allow the rpc service to register new authentication types that it is
167 * prepared to handle. When an authentication flavor is registered,
168 * the flavor is checked against already registered values. If not
169 * registered, then a new Auths entry is added on the list.
171 * There is no provision to delete a registration once registered.
173 * This routine returns:
174 * 0 if registration successful
175 * 1 if flavor already registered
176 * -1 if can't register (errno set)
180 svc_auth_reg(int cred_flavor
, enum auth_stat (*handler
)())
183 extern mutex_t authsvc_lock
;
185 switch (cred_flavor
) {
192 /* already registered */
195 (void) mutex_lock(&authsvc_lock
);
196 for (asp
= Auths
; asp
; asp
= asp
->next
) {
197 if (asp
->flavor
== cred_flavor
) {
198 /* already registered */
199 (void) mutex_unlock(&authsvc_lock
);
204 /* this is a new one, so go ahead and register it */
205 asp
= malloc(sizeof (*asp
));
207 (void) mutex_unlock(&authsvc_lock
);
210 asp
->flavor
= cred_flavor
;
211 asp
->handler
= handler
;
214 (void) mutex_unlock(&authsvc_lock
);