Blame sunrpc/svc_auth.c

Packit 6c4009
/*
Packit 6c4009
 * svc_auth.c, Server-side rpc authenticator interface.
Packit 6c4009
 *
Packit 6c4009
 * Copyright (c) 2010, Oracle America, Inc.
Packit 6c4009
 *
Packit 6c4009
 * Redistribution and use in source and binary forms, with or without
Packit 6c4009
 * modification, are permitted provided that the following conditions are
Packit 6c4009
 * met:
Packit 6c4009
 *
Packit 6c4009
 *     * Redistributions of source code must retain the above copyright
Packit 6c4009
 *       notice, this list of conditions and the following disclaimer.
Packit 6c4009
 *     * Redistributions in binary form must reproduce the above
Packit 6c4009
 *       copyright notice, this list of conditions and the following
Packit 6c4009
 *       disclaimer in the documentation and/or other materials
Packit 6c4009
 *       provided with the distribution.
Packit 6c4009
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit 6c4009
 *       contributors may be used to endorse or promote products derived
Packit 6c4009
 *       from this software without specific prior written permission.
Packit 6c4009
 *
Packit 6c4009
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 6c4009
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 6c4009
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit 6c4009
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit 6c4009
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit 6c4009
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 6c4009
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit 6c4009
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 6c4009
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit 6c4009
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 6c4009
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 6c4009
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <rpc/rpc.h>
Packit 6c4009
#include <rpc/svc.h>
Packit 6c4009
#include <rpc/svc_auth.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * svcauthsw is the bdevsw of server side authentication.
Packit 6c4009
 *
Packit 6c4009
 * Server side authenticators are called from authenticate by
Packit 6c4009
 * using the client auth struct flavor field to index into svcauthsw.
Packit 6c4009
 * The server auth flavors must implement a routine that looks
Packit 6c4009
 * like:
Packit 6c4009
 *
Packit 6c4009
 *      enum auth_stat
Packit 6c4009
 *      flavorx_auth(rqst, msg)
Packit 6c4009
 *              register struct svc_req *rqst;
Packit 6c4009
 *              register struct rpc_msg *msg;
Packit 6c4009
 *
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
static enum auth_stat _svcauth_null (struct svc_req *, struct rpc_msg *);
Packit 6c4009
				/* no authentication */
Packit 6c4009
extern enum auth_stat _svcauth_unix (struct svc_req *, struct rpc_msg *);
Packit 6c4009
				/* unix style (uid, gids) */
Packit 6c4009
extern enum auth_stat _svcauth_short (struct svc_req *, struct rpc_msg *);
Packit 6c4009
				/* short hand unix style */
Packit 6c4009
extern enum auth_stat _svcauth_des (struct svc_req *, struct rpc_msg *);
Packit 6c4009
				/* des style */
Packit 6c4009
Packit 6c4009
static const struct
Packit 6c4009
  {
Packit 6c4009
    enum auth_stat (*authenticator) (struct svc_req *, struct rpc_msg *);
Packit 6c4009
  }
Packit 6c4009
svcauthsw[] =
Packit 6c4009
{
Packit 6c4009
  { _svcauth_null },		/* AUTH_NULL */
Packit 6c4009
  { _svcauth_unix },		/* AUTH_UNIX */
Packit 6c4009
  { _svcauth_short },		/* AUTH_SHORT */
Packit 6c4009
  { _svcauth_des }		/* AUTH_DES */
Packit 6c4009
};
Packit 6c4009
#define	AUTH_MAX	3	/* HIGHEST AUTH NUMBER */
Packit 6c4009
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * The call rpc message, msg has been obtained from the wire.  The msg contains
Packit 6c4009
 * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
Packit 6c4009
 * if the msg is successfully authenticated.  If AUTH_OK then the routine also
Packit 6c4009
 * does the following things:
Packit 6c4009
 * set rqst->rq_xprt->verf to the appropriate response verifier;
Packit 6c4009
 * sets rqst->rq_client_cred to the "cooked" form of the credentials.
Packit 6c4009
 *
Packit 6c4009
 * NB: rqst->rq_cxprt->verf must be pre-allocated;
Packit 6c4009
 * its length is set appropriately.
Packit 6c4009
 *
Packit 6c4009
 * The caller still owns and is responsible for msg->u.cmb.cred and
Packit 6c4009
 * msg->u.cmb.verf.  The authentication system retains ownership of
Packit 6c4009
 * rqst->rq_client_cred, the cooked credentials.
Packit 6c4009
 *
Packit 6c4009
 * There is an assumption that any flavour less than AUTH_NULL is
Packit 6c4009
 * invalid.
Packit 6c4009
 */
Packit 6c4009
enum auth_stat
Packit 6c4009
_authenticate (register struct svc_req *rqst, struct rpc_msg *msg)
Packit 6c4009
{
Packit 6c4009
  register int cred_flavor;
Packit 6c4009
Packit 6c4009
  rqst->rq_cred = msg->rm_call.cb_cred;
Packit 6c4009
  rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
Packit 6c4009
  rqst->rq_xprt->xp_verf.oa_length = 0;
Packit 6c4009
  cred_flavor = rqst->rq_cred.oa_flavor;
Packit 6c4009
  if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL))
Packit 6c4009
    return (*(svcauthsw[cred_flavor].authenticator)) (rqst, msg);
Packit 6c4009
Packit 6c4009
  return AUTH_REJECTEDCRED;
Packit 6c4009
}
Packit 6c4009
libc_hidden_nolink_sunrpc (_authenticate, GLIBC_2_1)
Packit 6c4009
Packit 6c4009
static enum auth_stat
Packit 6c4009
_svcauth_null (struct svc_req *rqst, struct rpc_msg *msg)
Packit 6c4009
{
Packit 6c4009
  return AUTH_OK;
Packit 6c4009
}