Path: blob/main/crypto/krb5/src/lib/rpc/svc_auth.c
39536 views
/* lib/rpc/svc_auth.c */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/3334/*35* svc_auth_nodes.c, Server-side rpc authenticator interface,36* *WITHOUT* DES authentication.37*/3839#include <gssrpc/rpc.h>4041/*42* Server side authenticators are called from authenticate by43* using the client auth struct flavor field to index into svcauthsw.44* The server auth flavors must implement a routine that looks45* like:46*47* enum auth_stat48* flavorx_auth(rqst, msg)49* struct svc_req *rqst;50* struct rpc_msg *msg;51*52*/5354static struct svcauthsw_type {55enum_t flavor;56enum auth_stat (*authenticator)(struct svc_req *, struct rpc_msg *,57bool_t *);58} svcauthsw[] = {59{AUTH_GSSAPI, gssrpc__svcauth_gssapi}, /* AUTH_GSSAPI */60{AUTH_NONE, gssrpc__svcauth_none}, /* AUTH_NONE */61{AUTH_UNIX, gssrpc__svcauth_unix}, /* AUTH_UNIX */62{AUTH_SHORT, gssrpc__svcauth_short}, /* AUTH_SHORT */63{RPCSEC_GSS, gssrpc__svcauth_gss} /* RPCSEC_GSS */64};65static int svcauthnum = sizeof(svcauthsw) / sizeof(struct svcauthsw_type);6667/*68* The call rpc message, msg has been obtained from the wire. The msg contains69* the raw form of credentials and verifiers. authenticate returns AUTH_OK70* if the msg is successfully authenticated. If AUTH_OK then the routine also71* does the following things:72* set rqst->rq_xprt->verf to the appropriate response verifier;73* sets rqst->rq_client_cred to the "cooked" form of the credentials.74*75* NB: rqst->rq_cxprt->verf must be pre-alloctaed;76* its length is set appropriately.77*78* The caller still owns and is responsible for msg->u.cmb.cred and79* msg->u.cmb.verf. The authentication system retains ownership of80* rqst->rq_client_cred, the cooked credentials.81*/82enum auth_stat83gssrpc__authenticate(84struct svc_req *rqst,85struct rpc_msg *msg,86bool_t *no_dispatch)87{88int cred_flavor, i;8990rqst->rq_cred = msg->rm_call.cb_cred;91rqst->rq_xprt->xp_verf.oa_flavor = gssrpc__null_auth.oa_flavor;92rqst->rq_xprt->xp_verf.oa_length = 0;93cred_flavor = rqst->rq_cred.oa_flavor;94*no_dispatch = FALSE;95for (i = 0; i < svcauthnum; i++) {96if (cred_flavor == svcauthsw[i].flavor &&97svcauthsw[i].authenticator != NULL) {98return ((*(svcauthsw[i].authenticator))(rqst,99msg,100no_dispatch));101}102}103104return (AUTH_REJECTEDCRED);105}106107108