Blame sunrpc/svc_authux.c

Packit 6c4009
/*
Packit 6c4009
 * svc_auth_unix.c
Packit 6c4009
 * Handles UNIX flavor authentication parameters on the service side of rpc.
Packit 6c4009
 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
Packit 6c4009
 * _svcauth_unix does full blown unix style uid,gid+gids auth,
Packit 6c4009
 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
Packit 6c4009
 * Note: the shorthand has been gutted for efficiency.
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 <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <rpc/rpc.h>
Packit 6c4009
#include <rpc/svc.h>
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Unix longhand authenticator
Packit 6c4009
 */
Packit 6c4009
enum auth_stat
Packit 6c4009
_svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg)
Packit 6c4009
{
Packit 6c4009
  enum auth_stat stat;
Packit 6c4009
  XDR xdrs;
Packit 6c4009
  struct authunix_parms *aup;
Packit 6c4009
  int32_t *buf;
Packit 6c4009
  struct area
Packit 6c4009
    {
Packit 6c4009
      struct authunix_parms area_aup;
Packit 6c4009
      char area_machname[MAX_MACHINE_NAME + 1];
Packit 6c4009
      gid_t area_gids[NGRPS];
Packit 6c4009
    }
Packit 6c4009
   *area;
Packit 6c4009
  u_int auth_len;
Packit 6c4009
  u_int str_len, gid_len;
Packit 6c4009
  u_int i;
Packit 6c4009
Packit 6c4009
  area = (struct area *) rqst->rq_clntcred;
Packit 6c4009
  aup = &area->area_aup;
Packit 6c4009
  aup->aup_machname = area->area_machname;
Packit 6c4009
  aup->aup_gids = area->area_gids;
Packit 6c4009
  auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
Packit 6c4009
  xdrmem_create (&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, XDR_DECODE);
Packit 6c4009
  buf = XDR_INLINE (&xdrs, auth_len);
Packit 6c4009
  if (buf != NULL)
Packit 6c4009
    {
Packit 6c4009
      aup->aup_time = IXDR_GET_LONG (buf);
Packit 6c4009
      str_len = IXDR_GET_U_INT32 (buf);
Packit 6c4009
      if (str_len > MAX_MACHINE_NAME)
Packit 6c4009
	{
Packit 6c4009
	  stat = AUTH_BADCRED;
Packit 6c4009
	  goto done;
Packit 6c4009
	}
Packit 6c4009
      memcpy (aup->aup_machname, (caddr_t) buf, (u_int) str_len);
Packit 6c4009
      aup->aup_machname[str_len] = 0;
Packit 6c4009
      str_len = RNDUP (str_len);
Packit 6c4009
      buf = (int32_t *) ((char *) buf + str_len);
Packit 6c4009
      aup->aup_uid = IXDR_GET_LONG (buf);
Packit 6c4009
      aup->aup_gid = IXDR_GET_LONG (buf);
Packit 6c4009
      gid_len = IXDR_GET_U_INT32 (buf);
Packit 6c4009
      if (gid_len > NGRPS)
Packit 6c4009
	{
Packit 6c4009
	  stat = AUTH_BADCRED;
Packit 6c4009
	  goto done;
Packit 6c4009
	}
Packit 6c4009
      aup->aup_len = gid_len;
Packit 6c4009
      for (i = 0; i < gid_len; i++)
Packit 6c4009
	{
Packit 6c4009
	  aup->aup_gids[i] = IXDR_GET_LONG (buf);
Packit 6c4009
	}
Packit 6c4009
      /*
Packit 6c4009
       * five is the smallest unix credentials structure -
Packit 6c4009
       * timestamp, hostname len (0), uid, gid, and gids len (0).
Packit 6c4009
       */
Packit 6c4009
      if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
Packit 6c4009
	{
Packit 6c4009
	  stat = AUTH_BADCRED;
Packit 6c4009
	  goto done;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
  else if (!xdr_authunix_parms (&xdrs, aup))
Packit 6c4009
    {
Packit 6c4009
      xdrs.x_op = XDR_FREE;
Packit 6c4009
      (void) xdr_authunix_parms (&xdrs, aup);
Packit 6c4009
      stat = AUTH_BADCRED;
Packit 6c4009
      goto done;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* get the verifier */
Packit 6c4009
  if ((u_int)msg->rm_call.cb_verf.oa_length)
Packit 6c4009
    {
Packit 6c4009
      rqst->rq_xprt->xp_verf.oa_flavor =
Packit 6c4009
	msg->rm_call.cb_verf.oa_flavor;
Packit 6c4009
      rqst->rq_xprt->xp_verf.oa_base =
Packit 6c4009
	msg->rm_call.cb_verf.oa_base;
Packit 6c4009
      rqst->rq_xprt->xp_verf.oa_length =
Packit 6c4009
	msg->rm_call.cb_verf.oa_length;
Packit 6c4009
    }
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
Packit 6c4009
      rqst->rq_xprt->xp_verf.oa_length = 0;
Packit 6c4009
    }
Packit 6c4009
  stat = AUTH_OK;
Packit 6c4009
done:
Packit 6c4009
  XDR_DESTROY (&xdrs);
Packit 6c4009
  return stat;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * Shorthand unix authenticator
Packit 6c4009
 * Looks up longhand in a cache.
Packit 6c4009
 */
Packit 6c4009
/*ARGSUSED */
Packit 6c4009
enum auth_stat
Packit 6c4009
_svcauth_short (struct svc_req *rqst, struct rpc_msg *msg)
Packit 6c4009
{
Packit 6c4009
  return AUTH_REJECTEDCRED;
Packit 6c4009
}