home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp-sdk / src / rpclib / svc_auth_unix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  3.0 KB  |  113 lines

  1. /*
  2.  *      $Id: svc_auth_unix.c,v 4.2 1994/09/29 23:48:50 jraja Exp $
  3.  *
  4.  *      Handles UNIX flavor authentication parameters on the service
  5.  *      side of rpc.
  6.  *
  7.  *      Copyright © 1994 AmiTCP/IP Group,
  8.  *                       Network Solutions Development Inc.
  9.  *                       All rights reserved. 
  10.  */
  11.  
  12. /* @(#)svc_auth_unix.c    2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
  13. #if !defined(lint) && defined(SCCSIDS)
  14. static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
  15. #endif
  16.  
  17. /*
  18.  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
  19.  * _svcauth_unix does full blown unix style uid,gid+gids auth,
  20.  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
  21.  * Note: the shorthand has been gutted for efficiency.
  22.  *
  23.  * Copyright (C) 1984, Sun Microsystems, Inc.
  24.  */
  25.  
  26. #include <sys/param.h>
  27. #include <stdio.h>
  28. #include <rpc/rpc.h>
  29.  
  30. /*
  31.  * Unix longhand authenticator
  32.  */
  33. enum auth_stat
  34. _svcauth_unix(register struct svc_req *rqst, register struct rpc_msg *msg)
  35. {
  36.     register enum auth_stat stat;
  37.     XDR xdrs;
  38.     register struct authunix_parms *aup;
  39.     register long *buf;
  40.     struct area {
  41.         struct authunix_parms area_aup;
  42.         char area_machname[MAX_MACHINE_NAME+1];
  43.         gid_t area_gids[NGRPS];
  44.     } *area;
  45.     u_int auth_len;
  46.     int str_len, gid_len;
  47.     register int i;
  48.  
  49.     area = (struct area *) rqst->rq_clntcred;
  50.     aup = &area->area_aup;
  51.     aup->aup_machname = area->area_machname;
  52.     aup->aup_gids = area->area_gids;
  53.     auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
  54.     xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
  55.     buf = XDR_INLINE(&xdrs, auth_len);
  56.     if (buf != NULL) {
  57.         aup->aup_time = IXDR_GET_LONG(buf);
  58.         str_len = IXDR_GET_U_LONG(buf);
  59.         if (str_len > MAX_MACHINE_NAME) {
  60.             stat = AUTH_BADCRED;
  61.             goto done;
  62.         }
  63.         bcopy((caddr_t)buf, aup->aup_machname, (u_int)str_len);
  64.         aup->aup_machname[str_len] = 0;
  65.         str_len = RNDUP(str_len);
  66.         buf += str_len / sizeof (long);
  67.         aup->aup_uid = IXDR_GET_LONG(buf);
  68.         aup->aup_gid = IXDR_GET_LONG(buf);
  69.         gid_len = IXDR_GET_U_LONG(buf);
  70.         if (gid_len > NGRPS) {
  71.             stat = AUTH_BADCRED;
  72.             goto done;
  73.         }
  74.         aup->aup_len = gid_len;
  75.         for (i = 0; i < gid_len; i++) {
  76.             aup->aup_gids[i] = IXDR_GET_LONG(buf);
  77.         }
  78.         /*
  79.          * five is the smallest unix credentials structure -
  80.          * timestamp, hostname len (0), uid, gid, and gids len (0).
  81.          */
  82.         if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
  83.             (void) fprintf(stderr, "bad auth_len gid %ld str %ld auth %ld\n",
  84.                 gid_len, str_len, auth_len);
  85.             stat = AUTH_BADCRED;
  86.             goto done;
  87.         }
  88.     } else if (! xdr_authunix_parms(&xdrs, aup)) {
  89.         xdrs.x_op = XDR_FREE;
  90.         (void)xdr_authunix_parms(&xdrs, aup);
  91.         stat = AUTH_BADCRED;
  92.         goto done;
  93.     }
  94.     rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
  95.     rqst->rq_xprt->xp_verf.oa_length = 0;
  96.     stat = AUTH_OK;
  97. done:
  98.     XDR_DESTROY(&xdrs);
  99.     return (stat);
  100. }
  101.  
  102.  
  103. /*
  104.  * Shorthand unix authenticator
  105.  * Looks up longhand in a cache.
  106.  */
  107. /*ARGSUSED*/
  108. enum auth_stat 
  109. _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg)
  110. {
  111.     return (AUTH_REJECTEDCRED);
  112. }
  113.