home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume6 / rpc2 / part08 / rpc / rpclib / svc_auth_unix.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  4.1 KB  |  143 lines

  1. /*
  2.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3.  * unrestricted use provided that this legend is included on all tape
  4.  * media and as a part of the software program in whole or part.  Users
  5.  * may copy or modify Sun RPC without charge, but are not authorized
  6.  * to license or distribute it to anyone else except as part of a product or
  7.  * program developed by the user.
  8.  * 
  9.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12.  * 
  13.  * Sun RPC is provided with no support and without any obligation on the
  14.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15.  * modification or enhancement.
  16.  * 
  17.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19.  * OR ANY PART THEREOF.
  20.  * 
  21.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22.  * or profits or other special, indirect and consequential damages, even if
  23.  * Sun has been advised of the possibility of such damages.
  24.  * 
  25.  * Sun Microsystems, Inc.
  26.  * 2550 Garcia Avenue
  27.  * Mountain View, California  94043
  28.  */
  29. #ifndef lint
  30. static char sccsid[] = "@(#)svc_auth_unix.c 1.1 86/02/03 Copyr 1984 Sun Micro";
  31. #endif
  32.  
  33. /*
  34.  * svc_auth_unix.c
  35.  * Handles UNIX flavor authentication parameters on the service side of rpc.
  36.  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
  37.  * _svcauth_unix does full blown unix style uid,gid+gids auth,
  38.  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
  39.  * Note: the shorthand has been gutted for efficiency.
  40.  *
  41.  * Copyright (C) 1984, Sun Microsystems, Inc.
  42.  */
  43.  
  44. #include <stdio.h>
  45. #include "types.h"
  46. #include <sys/time.h>
  47. #include <netinet/in.h>
  48. #include "xdr.h"
  49. #include "auth.h"
  50. #include "clnt.h"
  51. #include "rpc_msg.h"
  52. #include "svc.h"
  53. #include "auth_unix.h"
  54. #include "svc_auth.h"
  55. char *mem_alloc();
  56.  
  57. #define    RNDUP(x)  ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
  58.            * BYTES_PER_XDR_UNIT)
  59.  
  60. /*
  61.  * Unix longhand authenticator
  62.  */
  63. enum auth_stat
  64. _svcauth_unix(rqst, msg)
  65.     register struct svc_req *rqst;
  66.     register struct rpc_msg *msg;
  67. {
  68.     register enum auth_stat stat;
  69.     XDR xdrs;
  70.     register struct authunix_parms *aup;
  71.     register long *buf;
  72.     struct area {
  73.         struct authunix_parms area_aup;
  74.         char area_machname[MAX_MACHINE_NAME];
  75.         int area_gids[NGRPS];
  76.     } *area;
  77.     u_int auth_len;
  78.     int str_len, gid_len;
  79.     register int i;
  80.  
  81.     area = (struct area *) rqst->rq_clntcred;
  82.     aup = &area->area_aup;
  83.     aup->aup_machname = area->area_machname;
  84.     aup->aup_gids = area->area_gids;
  85.     auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
  86.     xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
  87.     buf = XDR_INLINE(&xdrs, auth_len);
  88.     if (buf != NULL) {
  89.         aup->aup_time = IXDR_GET_LONG(buf);
  90.         str_len = IXDR_GET_U_LONG(buf);
  91.         bcopy(buf, aup->aup_machname, str_len);
  92.         aup->aup_machname[str_len] = 0;
  93.         str_len = RNDUP(str_len);
  94.         buf += str_len / sizeof (long);
  95.         aup->aup_uid = IXDR_GET_LONG(buf);
  96.         aup->aup_gid = IXDR_GET_LONG(buf);
  97.         gid_len = IXDR_GET_U_LONG(buf);
  98.         if (gid_len > NGRPS) {
  99.             stat = AUTH_BADCRED;
  100.             goto done;
  101.         }
  102.         aup->aup_len = gid_len;
  103.         for (i = 0; i < gid_len; i++) {
  104.             aup->aup_gids[i] = IXDR_GET_LONG(buf);
  105.         }
  106.         /*
  107.          * five is the smallest unix credentials structure -
  108.          * timestamp, hostname len (0), uid, gid, and gids len (0).
  109.          */
  110.         if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
  111.             printf("bad auth_len gid %d str %d auth %d\n",
  112.                    gid_len, auth_len, auth_len);
  113.             stat = AUTH_BADCRED;
  114.             goto done;
  115.         }
  116.     } else if (! xdr_authunix_parms(&xdrs, aup)) {
  117.         xdrs.x_op = XDR_FREE;
  118.         (void)xdr_authunix_parms(&xdrs, aup);
  119.         stat = AUTH_BADCRED;
  120.         goto done;
  121.     }
  122.     rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
  123.     rqst->rq_xprt->xp_verf.oa_length = 0;
  124.     stat = AUTH_OK;
  125. done:
  126.     XDR_DESTROY(&xdrs);
  127.     return (stat);
  128. }
  129.  
  130.  
  131. /*
  132.  * Shorthand unix authenticator
  133.  * Looks up longhand in a cache.
  134.  */
  135. /*ARGSUSED*/
  136. enum auth_stat 
  137. _svcauth_short(rqst, msg)
  138.     struct svc_req *rqst;
  139.     struct rpc_msg *msg;
  140. {
  141.     return (AUTH_REJECTEDCRED);
  142. }
  143.