home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / os / access.c.orig < prev    next >
Encoding:
Text File  |  1991-07-09  |  18.0 KB  |  796 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* $XConsortium: access.c,v 1.51 91/07/09 15:13:16 rws Exp $ */
  26.  
  27. #include "Xos.h"
  28. #include "X.h"
  29. #include "Xproto.h"
  30. #include "misc.h"
  31. #include "site.h"
  32. #include <errno.h>
  33. #include <sys/socket.h>
  34. #include <sys/ioctl.h>
  35. #include <X11/Xauth.h>
  36.  
  37. #ifdef TCPCONN
  38. #include <netinet/in.h>
  39. #endif /* TCPCONN */
  40. #ifdef DNETCONN
  41. #include <netdnet/dn.h>
  42. #include <netdnet/dnetdb.h>
  43. #endif
  44.  
  45. #ifdef hpux
  46. # include <sys/utsname.h>
  47. # ifdef HAS_IFREQ
  48. #  include <net/if.h>
  49. # endif
  50. #else
  51. #if defined(SVR4) || defined(SYSV386)
  52. # include <sys/utsname.h>
  53. #endif
  54. #if defined(SYSV) && defined(SYSV386)
  55. # include <sys/stream.h>
  56. #endif
  57. # include <net/if.h>
  58. #endif /* hpux */
  59.  
  60. #include <netdb.h>
  61. #undef NULL
  62. #include <stdio.h>
  63. #include "dixstruct.h"
  64. #include "osdep.h"
  65.  
  66. #define acmp(a1, a2, len) bcmp((char *)(a1), (char *)(a2), len)
  67. #define acopy(a1, a2, len) bcopy((char *)(a1), (char *)(a2), len)
  68. #define addrEqual(fam, address, length, host) \
  69.              ((fam) == (host)->family &&\
  70.               (length) == (host)->len &&\
  71.               !acmp (address, (host)->addr, length))
  72.  
  73. #ifdef hpux
  74. #define getpeername(fd, from, fromlen)    hpux_getpeername(fd, from, fromlen)
  75. #endif
  76.  
  77. static int ConvertAddr(), CheckAddr();
  78. static Bool NewHost();
  79.  
  80. typedef struct _host {
  81.     short        family;
  82.     short        len;
  83.     unsigned char    *addr;
  84.     struct _host *next;
  85. } HOST;
  86.  
  87. #define MakeHost(h,l)    (h)=(HOST *) xalloc(sizeof *(h)+(l));\
  88.             (h)->addr=(unsigned char *) ((h) + 1);
  89. #define FreeHost(h)    xfree(h)
  90. static HOST *selfhosts = NULL;
  91. static HOST *validhosts = NULL;
  92. static int AccessEnabled = DEFAULT_ACCESS_CONTROL;
  93. static int LocalHostEnabled = FALSE;
  94. static int UsingXdmcp = FALSE;
  95.  
  96. /*
  97.  * called when authorization is not enabled to add the
  98.  * local host to the access list
  99.  */
  100.  
  101. EnableLocalHost ()
  102. {
  103.     if (!UsingXdmcp)
  104.     {
  105.     LocalHostEnabled = TRUE;
  106.     AddLocalHosts ();
  107.     }
  108. }
  109.  
  110. /*
  111.  * called at init time when XDMCP will be used; xdmcp always
  112.  * adds local hosts manually when needed
  113.  */
  114.  
  115. AccessUsingXdmcp ()
  116. {
  117.     UsingXdmcp = TRUE;
  118.     LocalHostEnabled = FALSE;
  119. }
  120.  
  121. #if defined(SVR4) || defined (SYSV386) || (defined (hpux) && ! defined (HAS_IFREQ))
  122. /* Define this host for access control.  Find all the hosts the OS knows about 
  123.  * for this fd and add them to the selfhosts list.
  124.  * hpux, SVR4, and SYSV386 do not have SIOCGIFCONF ioctl;
  125.  */
  126. DefineSelf (fd)
  127.     int fd;
  128. {
  129.     register int n;
  130.     int    len;
  131.     caddr_t    addr;
  132.     int        family;
  133.     register HOST    *host;
  134.  
  135.     struct utsname name;
  136.     register struct hostent  *hp;
  137.  
  138.     union {
  139.     struct  sockaddr   sa;
  140.     struct  sockaddr_in  in;
  141.     } saddr;
  142.     
  143.     struct    sockaddr_in    *inetaddr;
  144.  
  145.     /* Why not use gethostname()?  Well, at least on my system, I've had to
  146.      * make an ugly kernel patch to get a name longer than 8 characters, and
  147.      * uname() lets me access to the whole string (it smashes release, you
  148.      * see), whereas gethostname() kindly truncates it for me.
  149.      */
  150.     uname(&name);
  151.     hp = gethostbyname (name.nodename);
  152.     if (hp != NULL)
  153.     {
  154.     saddr.sa.sa_family = hp->h_addrtype;
  155.     inetaddr = (struct sockaddr_in *) (&(saddr.sa));
  156.     acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length);
  157.     len = sizeof(saddr.sa);
  158.     family = ConvertAddr ( &(saddr.sa), &len, &addr);
  159.     if ( family != -1 && family != FamilyLocal )
  160.     {
  161.         for (host = selfhosts;
  162.          host && !addrEqual (family, addr, len, host);
  163.          host = host->next) ;
  164.         if (!host)
  165.         {
  166.         /* add this host to the host list.    */
  167.         MakeHost(host,len)
  168.         if (host)
  169.         {
  170.             host->family = family;
  171.             host->len = len;
  172.             acopy ( addr, host->addr, len);
  173.             host->next = selfhosts;
  174.             selfhosts = host;
  175.         }
  176.         }
  177.     }
  178.     }
  179. }
  180.  
  181. #else
  182. /* Define this host for access control.  Find all the hosts the OS knows about 
  183.  * for this fd and add them to the selfhosts list.
  184.  */
  185. DefineSelf (fd)
  186.     int fd;
  187. {
  188.     char        buf[2048];
  189.     struct ifconf    ifc;
  190.     register int    n;
  191.     int         len;
  192.     pointer         addr;
  193.     int         family;
  194.     register HOST     *host;
  195.     register struct ifreq *ifr;
  196.     
  197. #ifdef DNETCONN
  198.     struct dn_naddr *dnaddr = getnodeadd(0);
  199.     /*
  200.      * AF_DECnet may not be listed in the interface list.  Instead use
  201.      * the supported library call to find out the local address (if any).
  202.      */
  203.     if (dnaddr)
  204.     {    
  205.     addr = (pointer) dnaddr;
  206.     len = dnaddr->a_len + sizeof(dnaddr->a_len);
  207.     family = AF_DECnet;
  208.     for (host = selfhosts;
  209.          host && !addrEqual (family, addr, len, host);
  210.          host = host->next)
  211.         ;
  212.         if (!host)
  213.     {
  214.         MakeHost(host,len)
  215.         if (host)
  216.         {
  217.         host->family = family;
  218.         host->len = len;
  219.         acopy(addr, host->addr, len);
  220.         host->next = selfhosts;
  221.         selfhosts = host;
  222.         }
  223.     }
  224.     }
  225. #endif
  226.     ifc.ifc_len = sizeof (buf);
  227.     ifc.ifc_buf = buf;
  228.     if (ioctl (fd, (int) SIOCGIFCONF, (pointer) &ifc) < 0)
  229.         Error ("Getting interface configuration");
  230.     for (ifr = ifc.ifc_req, n = ifc.ifc_len / sizeof (struct ifreq); --n >= 0;
  231.      ifr++)
  232.     {
  233.     len = sizeof(ifr->ifr_addr);
  234. #ifdef DNETCONN
  235.     /*
  236.      * DECnet was handled up above.
  237.      */
  238.     if (ifr->ifr_addr.sa_family == AF_DECnet)
  239.         continue;
  240. #endif /* DNETCONN */
  241.     family = ConvertAddr (&ifr->ifr_addr, &len, &addr);
  242.         if (family == -1 || family == FamilyLocal)
  243.         continue;
  244.         for (host = selfhosts;
  245.           host && !addrEqual (family, addr, len, host);
  246.          host = host->next)
  247.         ;
  248.         if (host)
  249.         continue;
  250.     MakeHost(host,len)
  251.     if (host)
  252.     {
  253.         host->family = family;
  254.         host->len = len;
  255.         acopy(addr, host->addr, len);
  256.         host->next = selfhosts;
  257.         selfhosts = host;
  258.     }
  259. #ifdef XDMCP
  260.     {
  261.         struct sockaddr broad_addr;
  262.  
  263.         /*
  264.          * If this isn't an Internet Address, don't register it.
  265.          */
  266.         if (family != FamilyInternet)
  267.         continue;
  268.  
  269.         XdmcpRegisterConnection (family, (char *)addr, len);
  270.         broad_addr = ifr->ifr_addr;
  271.         ((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
  272.         htonl (INADDR_BROADCAST);
  273. #ifdef SIOCGIFBRDADDR
  274.         {
  275.             struct ifreq    broad_req;
  276.     
  277.             broad_req = *ifr;
  278.         if (ioctl (fd, SIOCGIFFLAGS, (char *) &broad_req) != -1 &&
  279.             (broad_req.ifr_flags & IFF_BROADCAST) &&
  280.             (broad_req.ifr_flags & IFF_UP)
  281.             )
  282.         {
  283.             broad_req = *ifr;
  284.             if (ioctl (fd, SIOCGIFBRDADDR, &broad_req) != -1)
  285.             broad_addr = broad_req.ifr_addr;
  286.             else
  287.             continue;
  288.         }
  289.         else
  290.             continue;
  291.         }
  292. #endif
  293.         XdmcpRegisterBroadcastAddress ((struct sockaddr_in *) &broad_addr);
  294.     }
  295. #endif
  296.     }
  297. }
  298. #endif /* hpux && !HAS_IFREQ */
  299.  
  300. #ifdef XDMCP
  301. void
  302. AugmentSelf(fd)
  303.     int fd;
  304. {
  305.     int len;
  306.     struct sockaddr from;
  307.     int family;
  308.     pointer addr;
  309.     register HOST *host;
  310.  
  311.     len = sizeof(from);
  312.     if (getpeername(fd, &from, &len))
  313.     return;
  314.     family = ConvertAddr(&from, &len, &addr);
  315.     if (family == -1 || family == FamilyLocal)
  316.     return;
  317.     for (host = selfhosts; host; host = host->next)
  318.     {
  319.     if (addrEqual(family, addr, len, host))
  320.         return;
  321.     }
  322.     MakeHost(host,len)
  323.     if (!host)
  324.     return;
  325.     host->family = family;
  326.     host->len = len;
  327.     acopy(addr, host->addr, len);
  328.     host->next = selfhosts;
  329.     selfhosts = host;
  330. }
  331. #endif
  332.  
  333. AddLocalHosts ()
  334. {
  335.     HOST    *self;
  336.  
  337.     for (self = selfhosts; self; self = self->next)
  338.     (void) NewHost (self->family, self->addr, self->len);
  339. }
  340.  
  341. /* Reset access control list to initial hosts */
  342. ResetHosts (display)
  343.     char *display;
  344. {
  345.     register HOST    *host;
  346.     char         hostname[120];
  347.     char        fname[32];
  348.     FILE        *fd;
  349.     char        *ptr;
  350.     union {
  351.         struct sockaddr    sa;
  352. #ifdef TCPCONN
  353.         struct sockaddr_in in;
  354. #endif /* TCPCONN */
  355. #ifdef DNETCONN
  356.         struct sockaddr_dn dn;
  357. #endif
  358.     }             saddr;
  359. #ifdef DNETCONN
  360.     struct nodeent     *np;
  361.     struct dn_naddr     dnaddr, *dnaddrp, *dnet_addr();
  362. #endif
  363.     int            family;
  364.     int            len;
  365.     pointer        addr;
  366.     register struct hostent *hp;
  367.  
  368.     AccessEnabled = DEFAULT_ACCESS_CONTROL;
  369.     LocalHostEnabled = FALSE;
  370.     while (host = validhosts)
  371.     {
  372.         validhosts = host->next;
  373.         FreeHost (host);
  374.     }
  375.     strcpy (fname, "/etc/X");
  376.     strcat (fname, display);
  377.     strcat (fname, ".hosts");
  378.     if (fd = fopen (fname, "r")) 
  379.     {
  380.         while (fgets (hostname, sizeof (hostname), fd))
  381.     {
  382.         if (ptr = index (hostname, '\n'))
  383.             *ptr = 0;
  384. #ifdef DNETCONN
  385.         if ((ptr = index (hostname, ':')) && (*(ptr + 1) == ':'))
  386.     {
  387.             /* node name (DECnet names end in "::") */
  388.             *ptr = 0;
  389.         dnaddrp = dnet_addr(hostname);
  390.             if (!dnaddrp && (np = getnodebyname (hostname)))
  391.         {
  392.         /* node was specified by name */
  393.         saddr.sa.sa_family = np->n_addrtype;
  394.         len = sizeof(saddr.sa);
  395.         if (ConvertAddr (&saddr.sa, &len, &addr) == FamilyDECnet)
  396.         {
  397.             bzero ((char *) &dnaddr, sizeof (dnaddr));
  398.             dnaddr.a_len = np->n_length;
  399.             acopy (np->n_addr, dnaddr.a_addr, np->n_length);
  400.             dnaddrp = &dnaddr;
  401.         }
  402.             }
  403.         if (dnaddrp)
  404.         (void) NewHost((short)FamilyDECnet, (pointer)dnaddrp,
  405.             (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len)));
  406.         }
  407.     else
  408. #endif /* DNETCONN */
  409. #ifdef SECURE_RPC
  410.     if (index (hostname, '@'))
  411.     {
  412.         SecureRPCInit ();
  413.         (void) NewHost (FamilyNetname, hostname, strlen (hostname));
  414.     }
  415.     else
  416. #endif /* SECURE_RPC */
  417. #ifdef TCPCONN
  418.     {
  419.             /* host name */
  420.             if (hp = gethostbyname (hostname))
  421.         {
  422.             saddr.sa.sa_family = hp->h_addrtype;
  423.         len = sizeof(saddr.sa);
  424.             if ((family = ConvertAddr (&saddr.sa, &len, &addr)) != -1)
  425.         {
  426. #ifdef h_addr                /* new 4.3bsd version of gethostent */
  427.             char **list;
  428.  
  429.             /* iterate over the addresses */
  430.             for (list = hp->h_addr_list; *list; list++)
  431.             (void) NewHost (family, (pointer)*list, len);
  432. #else
  433.                 (void) NewHost (family, (pointer)hp->h_addr, len);
  434. #endif
  435.         }
  436.             }
  437.         }    
  438. #endif /* TCPCONN */
  439.         }
  440.         fclose (fd);
  441.     }
  442. }
  443.  
  444. static Bool
  445. AuthorizedClient(client)
  446.     ClientPtr client;
  447. {
  448.     int            alen, family;
  449.     struct sockaddr    from;
  450.     pointer        addr;
  451.     register HOST    *host;
  452.  
  453.     if (!client)
  454.     return TRUE;
  455.     alen = sizeof (from);
  456.     if (!getpeername (((OsCommPtr)client->osPrivate)->fd, &from, &alen))
  457.     {
  458.     family = ConvertAddr (&from, &alen, &addr);
  459.     if (family == -1)
  460.         return FALSE;
  461.     if (family == FamilyLocal)
  462.         return TRUE;
  463.     for (host = selfhosts; host; host = host->next)
  464.     {
  465.         if (addrEqual (family, addr, alen, host))
  466.         return TRUE;
  467.     }
  468.     }
  469.     return FALSE;
  470. }
  471.  
  472. /* Add a host to the access control list.  This is the external interface
  473.  * called from the dispatcher */
  474.  
  475. int
  476. AddHost (client, family, length, pAddr)
  477.     ClientPtr        client;
  478.     int                 family;
  479.     unsigned            length;        /* of bytes in pAddr */
  480.     pointer             pAddr;
  481. {
  482.     int            len;
  483.     register HOST    *host;
  484.     int                 unixFamily;
  485.  
  486.     if (!AuthorizedClient(client))
  487.     return(BadAccess);
  488.     switch (family) {
  489. #ifdef SECURE_RPC
  490.     case FamilyNetname:
  491.     len = length;
  492.     SecureRPCInit ();
  493.     break;
  494. #endif
  495.     case FamilyInternet:
  496.     case FamilyDECnet:
  497.     case FamilyChaos:
  498.     if ((len = CheckAddr (family, pAddr, length)) < 0)
  499.     {
  500.         client->errorValue = length;
  501.         return (BadValue);
  502.     }
  503.     break;
  504.     case FamilyLocal:
  505.     default:
  506.     client->errorValue = family;
  507.     return (BadValue);
  508.     }
  509.     if (NewHost (family, pAddr, len))
  510.     return Success;
  511.     return BadAlloc;
  512. }
  513.  
  514. Bool
  515. ForEachHostInFamily (family, func, closure)
  516.     int        family;
  517.     Bool    (*func)();
  518.     pointer closure;
  519. {
  520.     HOST    *host;
  521.  
  522.     for (host = validhosts; host; host = host->next)
  523.     if (family == host->family && func (host->addr, host->len, closure))
  524.         return TRUE;
  525.     return FALSE;
  526. }
  527.  
  528. /* Add a host to the access control list. This is the internal interface 
  529.  * called when starting or resetting the server */
  530. static Bool
  531. NewHost (family, addr, len)
  532.     short    family;
  533.     pointer    addr;
  534.     int        len;
  535. {
  536.     register HOST *host;
  537.  
  538.     for (host = validhosts; host; host = host->next)
  539.     {
  540.         if (addrEqual (family, addr, len, host))
  541.         return TRUE;
  542.     }
  543.     MakeHost(host,len)
  544.     if (!host)
  545.     return FALSE;
  546.     host->family = family;
  547.     host->len = len;
  548.     acopy(addr, host->addr, len);
  549.     host->next = validhosts;
  550.     validhosts = host;
  551.     return TRUE;
  552. }
  553.  
  554. /* Remove a host from the access control list */
  555.  
  556. int
  557. RemoveHost (client, family, length, pAddr)
  558.     ClientPtr        client;
  559.     int                 family;
  560.     unsigned            length;        /* of bytes in pAddr */
  561.     pointer             pAddr;
  562. {
  563.     int            len;
  564.     register HOST    *host, **prev;
  565.  
  566.     if (!AuthorizedClient(client))
  567.     return(BadAccess);
  568.     switch (family) {
  569. #ifdef SECURE_RPC
  570.     case FamilyNetname:
  571.     len = length;
  572.     break;
  573. #endif
  574.     case FamilyInternet:
  575.     case FamilyDECnet:
  576.     case FamilyChaos:
  577.         if ((len = CheckAddr (family, pAddr, length)) < 0)
  578.         {
  579.         client->errorValue = length;
  580.             return(BadValue);
  581.         }
  582.     break;
  583.     case FamilyLocal:
  584.     default:
  585.     client->errorValue = family;
  586.         return(BadValue);
  587.     }
  588.     for (prev = &validhosts;
  589.          (host = *prev) && (!addrEqual (family, pAddr, len, host));
  590.          prev = &host->next)
  591.         ;
  592.     if (host)
  593.     {
  594.         *prev = host->next;
  595.         FreeHost (host);
  596.     }
  597.     return (Success);
  598. }
  599.  
  600. /* Get all hosts in the access control list */
  601. int
  602. GetHosts (data, pnHosts, pLen, pEnabled)
  603.     pointer        *data;
  604.     int            *pnHosts;
  605.     int            *pLen;
  606.     BOOL        *pEnabled;
  607. {
  608.     int            len;
  609.     register int     n = 0;
  610.     register pointer    ptr;
  611.     register HOST    *host;
  612.     int            nHosts = 0;
  613.     int            *lengths = (int *) NULL;
  614.     int            *newlens;
  615.  
  616.     *pEnabled = AccessEnabled ? EnableAccess : DisableAccess;
  617.     for (host = validhosts; host; host = host->next)
  618.     {
  619.     newlens = (int *) xrealloc(lengths, (nHosts + 1) * sizeof(int));
  620.     if (!newlens)
  621.     {
  622.         xfree(lengths);
  623.         return(BadAlloc);
  624.     }
  625.     lengths = newlens;
  626.     lengths[nHosts++] = host->len;
  627.     n += (((host->len + 3) >> 2) << 2) + sizeof(xHostEntry);
  628.     }
  629.     if (n)
  630.     {
  631.         *data = ptr = (pointer) xalloc (n);
  632.     if (!ptr)
  633.     {
  634.         xfree(lengths);
  635.         return(BadAlloc);
  636.     }
  637.     nHosts = 0;
  638.         for (host = validhosts; host; host = host->next)
  639.     {
  640.  
  641.         len = lengths[nHosts++];
  642.         ((xHostEntry *)ptr)->family = host->family;
  643.         ((xHostEntry *)ptr)->length = len;
  644.         ptr += sizeof(xHostEntry);
  645.         acopy (host->addr, ptr, len);
  646.         ptr += ((len + 3) >> 2) << 2;
  647.         }
  648.     } else {
  649.     *data = NULL;
  650.     }
  651.     *pnHosts = nHosts;
  652.     *pLen = n;
  653.     xfree(lengths);
  654.     return(Success);
  655. }
  656.  
  657. /* Check for valid address family and length, and return address length. */
  658.  
  659. /*ARGSUSED*/
  660. static int
  661. CheckAddr (family, pAddr, length)
  662.     int            family;
  663.     pointer        pAddr;
  664.     unsigned        length;
  665. {
  666.     int    len;
  667.  
  668.     switch (family)
  669.     {
  670. #ifdef TCPCONN
  671.       case FamilyInternet:
  672.     if (length == sizeof (struct in_addr))
  673.         len = length;
  674.     else
  675.         len = -1;
  676.         break;
  677. #endif 
  678. #ifdef DNETCONN
  679.       case FamilyDECnet:
  680.         {
  681.         struct dn_naddr *dnaddr = (struct dn_naddr *) pAddr;
  682.  
  683.         if ((length < sizeof(dnaddr->a_len)) ||
  684.         (length < dnaddr->a_len + sizeof(dnaddr->a_len)))
  685.         len = -1;
  686.         else
  687.         len = dnaddr->a_len + sizeof(dnaddr->a_len);
  688.         if (len > sizeof(struct dn_naddr))
  689.         len = -1;
  690.     }
  691.         break;
  692. #endif
  693.       default:
  694.         len = -1;
  695.     }
  696.     return (len);
  697. }
  698.  
  699. /* Check if a host is not in the access control list. 
  700.  * Returns 1 if host is invalid, 0 if we've found it. */
  701.  
  702. InvalidHost (saddr, len)
  703.     register struct sockaddr    *saddr;
  704.     int                len;
  705. {
  706.     int             family;
  707.     pointer            addr;
  708.     register HOST         *selfhost, *host;
  709.  
  710.     if (!AccessEnabled)   /* just let them in */
  711.         return(0);    
  712.     family = ConvertAddr (saddr, &len, &addr);
  713.     if (family == -1)
  714.         return 1;
  715.     if (family == FamilyLocal)
  716.     {
  717.     if (!LocalHostEnabled)
  718.      {
  719.         /*
  720.          * check to see if any local address is enabled.  This 
  721.          * implicitly enables local connections.
  722.          */
  723.         for (selfhost = selfhosts; selfhost; selfhost=selfhost->next)
  724.          {
  725.         for (host = validhosts; host; host=host->next)
  726.         {
  727.             if (addrEqual (selfhost->family, selfhost->addr,
  728.                    selfhost->len, host))
  729.             return 0;
  730.         }
  731.         }
  732.         return 1;
  733.     } else
  734.         return 0;
  735.     }
  736.     for (host = validhosts; host; host = host->next)
  737.     {
  738.         if (addrEqual (family, addr, len, host))
  739.             return (0);
  740.     }
  741.     return (1);
  742. }
  743.  
  744. static int
  745. ConvertAddr (saddr, len, addr)
  746.     register struct sockaddr    *saddr;
  747.     int                *len;
  748.     pointer            *addr;
  749. {
  750.     if (*len == 0)
  751.         return (FamilyLocal);
  752.     switch (saddr->sa_family)
  753.     {
  754.     case AF_UNSPEC:
  755. #ifdef UNIXCONN
  756.     case AF_UNIX:
  757. #endif
  758.         return FamilyLocal;
  759. #ifdef TCPCONN
  760.     case AF_INET:
  761.         *len = sizeof (struct in_addr);
  762.         *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr);
  763.         return FamilyInternet;
  764. #endif
  765. #ifdef DNETCONN
  766.     case AF_DECnet:
  767.     {
  768.         struct sockaddr_dn *sdn = (struct sockaddr_dn *) saddr;
  769.         *len = sdn->sdn_nodeaddrl + sizeof(sdn->sdn_nodeaddrl);
  770.         *addr = (pointer) &(sdn->sdn_add);
  771.     }
  772.         return FamilyDECnet;
  773. #endif
  774. #ifdef CHAOSCONN
  775.     case AF_CHAOS:
  776.     {
  777.         not implemented
  778.     }
  779.     return FamilyChaos;
  780. #endif
  781.     default:
  782.         return -1;
  783.     }
  784. }
  785.  
  786. int
  787. ChangeAccessControl(client, fEnabled)
  788.     ClientPtr client;
  789.     int fEnabled;
  790. {
  791.     if (!AuthorizedClient(client))
  792.     return BadAccess;
  793.     AccessEnabled = fEnabled;
  794.     return Success;
  795. }
  796.