Blame sunrpc/svc_authux.c

Packit Service 82fcde
/*
Packit Service 82fcde
 * svc_auth_unix.c
Packit Service 82fcde
 * Handles UNIX flavor authentication parameters on the service side of rpc.
Packit Service 82fcde
 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
Packit Service 82fcde
 * _svcauth_unix does full blown unix style uid,gid+gids auth,
Packit Service 82fcde
 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
Packit Service 82fcde
 * Note: the shorthand has been gutted for efficiency.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Copyright (c) 2010, Oracle America, Inc.
Packit Service 82fcde
 *
Packit Service 82fcde
 * Redistribution and use in source and binary forms, with or without
Packit Service 82fcde
 * modification, are permitted provided that the following conditions are
Packit Service 82fcde
 * met:
Packit Service 82fcde
 *
Packit Service 82fcde
 *     * Redistributions of source code must retain the above copyright
Packit Service 82fcde
 *       notice, this list of conditions and the following disclaimer.
Packit Service 82fcde
 *     * Redistributions in binary form must reproduce the above
Packit Service 82fcde
 *       copyright notice, this list of conditions and the following
Packit Service 82fcde
 *       disclaimer in the documentation and/or other materials
Packit Service 82fcde
 *       provided with the distribution.
Packit Service 82fcde
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit Service 82fcde
 *       contributors may be used to endorse or promote products derived
Packit Service 82fcde
 *       from this software without specific prior written permission.
Packit Service 82fcde
 *
Packit Service 82fcde
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 82fcde
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 82fcde
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit Service 82fcde
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit Service 82fcde
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit Service 82fcde
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 82fcde
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit Service 82fcde
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit Service 82fcde
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit Service 82fcde
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit Service 82fcde
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 82fcde
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 82fcde
 */
Packit Service 82fcde
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <rpc/rpc.h>
Packit Service 82fcde
#include <rpc/svc.h>
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * Unix longhand authenticator
Packit Service 82fcde
 */
Packit Service 82fcde
enum auth_stat
Packit Service 82fcde
_svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg)
Packit Service 82fcde
{
Packit Service 82fcde
  enum auth_stat stat;
Packit Service 82fcde
  XDR xdrs;
Packit Service 82fcde
  struct authunix_parms *aup;
Packit Service 82fcde
  int32_t *buf;
Packit Service 82fcde
  struct area
Packit Service 82fcde
    {
Packit Service 82fcde
      struct authunix_parms area_aup;
Packit Service 82fcde
      char area_machname[MAX_MACHINE_NAME + 1];
Packit Service 82fcde
      gid_t area_gids[NGRPS];
Packit Service 82fcde
    }
Packit Service 82fcde
   *area;
Packit Service 82fcde
  u_int auth_len;
Packit Service 82fcde
  u_int str_len, gid_len;
Packit Service 82fcde
  u_int i;
Packit Service 82fcde
Packit Service 82fcde
  area = (struct area *) rqst->rq_clntcred;
Packit Service 82fcde
  aup = &area->area_aup;
Packit Service 82fcde
  aup->aup_machname = area->area_machname;
Packit Service 82fcde
  aup->aup_gids = area->area_gids;
Packit Service 82fcde
  auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
Packit Service 82fcde
  xdrmem_create (&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, XDR_DECODE);
Packit Service 82fcde
  buf = XDR_INLINE (&xdrs, auth_len);
Packit Service 82fcde
  if (buf != NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      aup->aup_time = IXDR_GET_LONG (buf);
Packit Service 82fcde
      str_len = IXDR_GET_U_INT32 (buf);
Packit Service 82fcde
      if (str_len > MAX_MACHINE_NAME)
Packit Service 82fcde
	{
Packit Service 82fcde
	  stat = AUTH_BADCRED;
Packit Service 82fcde
	  goto done;
Packit Service 82fcde
	}
Packit Service 82fcde
      memcpy (aup->aup_machname, (caddr_t) buf, (u_int) str_len);
Packit Service 82fcde
      aup->aup_machname[str_len] = 0;
Packit Service 82fcde
      str_len = RNDUP (str_len);
Packit Service 82fcde
      buf = (int32_t *) ((char *) buf + str_len);
Packit Service 82fcde
      aup->aup_uid = IXDR_GET_LONG (buf);
Packit Service 82fcde
      aup->aup_gid = IXDR_GET_LONG (buf);
Packit Service 82fcde
      gid_len = IXDR_GET_U_INT32 (buf);
Packit Service 82fcde
      if (gid_len > NGRPS)
Packit Service 82fcde
	{
Packit Service 82fcde
	  stat = AUTH_BADCRED;
Packit Service 82fcde
	  goto done;
Packit Service 82fcde
	}
Packit Service 82fcde
      aup->aup_len = gid_len;
Packit Service 82fcde
      for (i = 0; i < gid_len; i++)
Packit Service 82fcde
	{
Packit Service 82fcde
	  aup->aup_gids[i] = IXDR_GET_LONG (buf);
Packit Service 82fcde
	}
Packit Service 82fcde
      /*
Packit Service 82fcde
       * five is the smallest unix credentials structure -
Packit Service 82fcde
       * timestamp, hostname len (0), uid, gid, and gids len (0).
Packit Service 82fcde
       */
Packit Service 82fcde
      if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
Packit Service 82fcde
	{
Packit Service 82fcde
	  stat = AUTH_BADCRED;
Packit Service 82fcde
	  goto done;
Packit Service 82fcde
	}
Packit Service 82fcde
    }
Packit Service 82fcde
  else if (!xdr_authunix_parms (&xdrs, aup))
Packit Service 82fcde
    {
Packit Service 82fcde
      xdrs.x_op = XDR_FREE;
Packit Service 82fcde
      (void) xdr_authunix_parms (&xdrs, aup);
Packit Service 82fcde
      stat = AUTH_BADCRED;
Packit Service 82fcde
      goto done;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  /* get the verifier */
Packit Service 82fcde
  if ((u_int)msg->rm_call.cb_verf.oa_length)
Packit Service 82fcde
    {
Packit Service 82fcde
      rqst->rq_xprt->xp_verf.oa_flavor =
Packit Service 82fcde
	msg->rm_call.cb_verf.oa_flavor;
Packit Service 82fcde
      rqst->rq_xprt->xp_verf.oa_base =
Packit Service 82fcde
	msg->rm_call.cb_verf.oa_base;
Packit Service 82fcde
      rqst->rq_xprt->xp_verf.oa_length =
Packit Service 82fcde
	msg->rm_call.cb_verf.oa_length;
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    {
Packit Service 82fcde
      rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
Packit Service 82fcde
      rqst->rq_xprt->xp_verf.oa_length = 0;
Packit Service 82fcde
    }
Packit Service 82fcde
  stat = AUTH_OK;
Packit Service 82fcde
done:
Packit Service 82fcde
  XDR_DESTROY (&xdrs);
Packit Service 82fcde
  return stat;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/*
Packit Service 82fcde
 * Shorthand unix authenticator
Packit Service 82fcde
 * Looks up longhand in a cache.
Packit Service 82fcde
 */
Packit Service 82fcde
/*ARGSUSED */
Packit Service 82fcde
enum auth_stat
Packit Service 82fcde
_svcauth_short (struct svc_req *rqst, struct rpc_msg *msg)
Packit Service 82fcde
{
Packit Service 82fcde
  return AUTH_REJECTEDCRED;
Packit Service 82fcde
}