home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / os / rpcauth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-27  |  3.8 KB  |  164 lines

  1. /*
  2.  * SUN-DES-1 authentication mechanism
  3.  *
  4.  * $XConsortium: rpcauth.c,v 1.3 91/02/28 09:36:18 rws Exp $
  5.  *
  6.  * Copyright 1991 Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of M.I.T. not be used in advertising or
  13.  * publicity pertaining to distribution of the software without specific,
  14.  * written prior permission.  M.I.T. makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * Author:  Mayank Choudhary, Sun Microsystems
  19.  */
  20.  
  21. #ifdef SECURE_RPC
  22. #include <rpc/rpc.h>
  23. #ifdef ultrix
  24. #include <time.h>
  25. #include <rpc/auth_des.h>
  26. #endif
  27. #include "Xauth.h"
  28. #include "misc.h"
  29. #include "X.h"
  30. #include "os.h"
  31.  
  32. static char * 
  33. authdes_ezdecode(inmsg, len)
  34. char *inmsg;
  35. int  len;
  36. {
  37.     enum auth_stat  why;
  38.     struct rpc_msg  msg;
  39.     char            cred_area[MAX_AUTH_BYTES];
  40.     char            verf_area[MAX_AUTH_BYTES];
  41.     char            *temp_inmsg;
  42.     struct svc_req  r;
  43.     bool_t          res0, res1;
  44.     XDR             xdr;
  45.     SVCXPRT         xprt;
  46.  
  47.     temp_inmsg = (char *) xalloc(len);
  48.     bcopy(inmsg, temp_inmsg, len);
  49.  
  50.     memset(&msg, 0, sizeof(msg));
  51.     memset(&r, 0, sizeof(r));
  52.     memset(cred_area, 0, sizeof(cred_area));
  53.     memset(verf_area, 0, sizeof(verf_area));
  54.  
  55.     msg.rm_call.cb_cred.oa_base = cred_area;
  56.     msg.rm_call.cb_verf.oa_base = verf_area;
  57.     why = AUTH_FAILED; 
  58.     xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
  59.  
  60.     if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
  61.         goto bad1;
  62.     r.rq_xprt = &xprt;
  63.  
  64.     /* decode into msg */
  65.     res0 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_cred)); 
  66.     res1 = xdr_opaque_auth(&xdr, &(msg.rm_call.cb_verf));
  67.     if ( ! (res0 && res1) )
  68.          goto bad2;
  69.  
  70.     /* do the authentication */
  71.  
  72.     r.rq_cred = msg.rm_call.cb_cred;        /* read by opaque stuff */
  73.     if (r.rq_cred.oa_flavor != AUTH_DES) {
  74.         why = AUTH_TOOWEAK;
  75.         goto bad2;
  76.     }
  77.     if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
  78.             goto bad2;
  79.     }
  80.     return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name); 
  81.  
  82. bad2:
  83.     Xfree(r.rq_clntcred);
  84. bad1:
  85.     return ((char *)0); /* ((struct authdes_cred *) NULL); */
  86. }
  87.  
  88. static XID  rpc_id = (XID) ~0L;
  89.  
  90. static Bool
  91. CheckNetName (addr, len, closure)
  92.     unsigned char    *addr;
  93.     int            len;
  94.     pointer        closure;
  95. {
  96.     return (len == strlen ((char *) closure) &&
  97.         strncmp ((char *) addr, (char *) closure, len) == 0);
  98. }
  99.  
  100. XID
  101. SecureRPCCheck (data_length, data)
  102. register unsigned short    data_length;
  103. char    *data;
  104. {
  105.     char *fullname;
  106.     
  107.     if (rpc_id != (XID) ~0L &&
  108.     (fullname = authdes_ezdecode(data, data_length)) != (char *)0)
  109.     {
  110.     if (ForEachHostInFamily (FamilyNetname, CheckNetName, (pointer) fullname))
  111.         return rpc_id;
  112.     }
  113.     return (XID) ~0L;
  114. }
  115.     
  116.  
  117. SecureRPCInit ()
  118. {
  119.     if (rpc_id == ~0L)
  120.     AddAuthorization (9, "SUN-DES-1", 0, (char *) 0);
  121. }
  122.  
  123. int
  124. SecureRPCAdd (data_length, data, id)
  125. unsigned short    data_length;
  126. char    *data;
  127. XID    id;
  128. {
  129.     if (data_length)
  130.     AddHost ((pointer) 0, FamilyNetname, data_length, data);
  131.     rpc_id = id;
  132. }
  133.  
  134. int
  135. SecureRPCReset ()
  136. {
  137.     rpc_id = (XID) ~0L;
  138. }
  139.  
  140. XID
  141. SecureRPCToID (data_length, data)
  142.     unsigned short    data_length;
  143.     char        *data;
  144. {
  145.     return rpc_id;
  146. }
  147.  
  148. SecureRPCFromID (id, data_lenp, datap)
  149.      XID id;
  150.      unsigned short    *data_lenp;
  151.      char    **datap;
  152. {
  153.     return 0;
  154. }
  155.  
  156. SecureRPCRemove (data_length, data)
  157.      unsigned short    data_length;
  158.      char    *data;
  159. {
  160.     return 0;
  161. }
  162. #endif SECURE_RPC
  163.  
  164.