📄 access.c
字号:
/* $XConsortium: access.c /main/68 1996/12/15 22:57:09 rws $ *//* $XFree86: xc/programs/Xserver/os/access.c,v 3.18.2.4 1998/02/21 06:07:16 robin Exp $ *//***********************************************************Copyright (c) 1987 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************/#ifdef WIN32#include <X11/Xwinsock.h>#endif#include <stdio.h>#include <X11/Xtrans.h>#include <X11/Xauth.h>#include "X.h"#include "Xproto.h"#include "misc.h"#include "site.h"#include <errno.h>#include <sys/types.h>#ifndef WIN32#if !defined(AMOEBA) && !defined(MINIX)#ifdef ESIX#include <lan/socket.h>#else#ifndef Lynx#include <sys/socket.h>#else#include <socket.h>#endif#endif#include <sys/ioctl.h>#else#ifdef AMOEBA#define port am_port_t#include <amoeba.h>#include <cmdreg.h>#include <stdcom.h>#include <stderr.h>#include <ampolicy.h>#include <server/ip/hton.h>#include <server/ip/types.h>#include <server/ip/tcpip.h>#include <server/ip/tcp_io.h>#include <server/ip/gen/in.h>#include <server/ip/gen/tcp.h>#include <server/ip/gen/tcp_io.h>#include <server/ip/gen/socket.h>#undef port#endif#endif /* AMOEBA || MINIX */#include <ctype.h>#if defined(TCPCONN) || defined(STREAMSCONN) || defined(ISC) || defined(SCO)#include <netinet/in.h>#endif /* TCPCONN || STREAMSCONN || ISC || SCO */#ifdef DNETCONN#include <netdnet/dn.h>#include <netdnet/dnetdb.h>#endif#if !defined(AMOEBA)#ifdef hpux# include <sys/utsname.h># ifdef HAS_IFREQ# include <net/if.h># endif#else#if defined(SVR4) || (defined(SYSV) && defined(i386)) || defined(MINIX)# include <sys/utsname.h>#endif#if defined(SYSV) && defined(i386)# include <sys/stream.h># ifdef ISC# include <sys/stropts.h># include <sys/sioctl.h># endif /* ISC */#endif#ifdef ESIX# include <lan/if.h>#else#ifndef MINIX# include <net/if.h>#endif#endif#endif /* hpux */#endif /* !AMOEBA */#ifdef SVR4#ifndef SCO#include <sys/sockio.h>#endif#include <sys/stropts.h>#endif#ifdef ESIX#include <lan/netdb.h>#else#if !defined(AMOEBA) && !defined(MINIX)#include <netdb.h>#else#ifdef AMOEBA#include <server/ip/gen/netdb.h>#endif#ifdef MINIX#include <net/hton.h>#include <net/gen/netdb.h>#define INADDR_BROADCAST 0xFFFFFFFF#endif#endif /* AMOEBA || MINIX */#endif /* ESIX */#ifdef CSRG_BASED#include <sys/param.h>#if (BSD >= 199103)#define VARIABLE_IFREQ#endif#endif#if defined(Lynx) && defined(BSD44SOCKETS)#define VARIABLE_IFREQ#endif#endif /* WIN32 */#ifndef PATH_MAX#ifndef Lynx#include <sys/param.h>#else#include <param.h>#endif #ifndef PATH_MAX#ifdef MAXPATHLEN#define PATH_MAX MAXPATHLEN#else#define PATH_MAX 1024#endif#endif#endif #include "dixstruct.h"#include "osdep.h"#ifdef XCSECURITY#define _SECURITY_SERVER#include "extensions/security.h"#endifBool defeatAccessControl = FALSE;#define acmp(a1, a2, len) memcmp((char *)(a1), (char *)(a2), len)#define acopy(a1, a2, len) memmove((char *)(a2), (char *)(a1), len)#define addrEqual(fam, address, length, host) \ ((fam) == (host)->family &&\ (length) == (host)->len &&\ !acmp (address, (host)->addr, length))static int ConvertAddr(#if NeedFunctionPrototypes struct sockaddr */*saddr*/, int */*len*/, pointer */*addr*/#endif);static int CheckAddr(#if NeedFunctionPrototypes int /*family*/, pointer /*pAddr*/, unsigned /*length*/#endif);static Bool NewHost(#if NeedFunctionPrototypes int /*family*/, pointer /*addr*/, int /*len*/#endif);typedef struct _host { short family; short len; unsigned char *addr; struct _host *next;} HOST;#define MakeHost(h,l) (h)=(HOST *) xalloc(sizeof *(h)+(l));\ (h)->addr=(unsigned char *) ((h) + 1);#define FreeHost(h) xfree(h)static HOST *selfhosts = NULL;static HOST *validhosts = NULL;static int AccessEnabled = DEFAULT_ACCESS_CONTROL;static int LocalHostEnabled = FALSE;static int UsingXdmcp = FALSE;/* * called when authorization is not enabled to add the * local host to the access list */voidEnableLocalHost (){ if (!UsingXdmcp) { LocalHostEnabled = TRUE; AddLocalHosts (); }}/* * called when authorization is enabled to keep us secure */voidDisableLocalHost (){ HOST *self; LocalHostEnabled = FALSE; for (self = selfhosts; self; self = self->next) (void) RemoveHost ((ClientPtr)NULL, self->family, self->len, (pointer)self->addr);}/* * called at init time when XDMCP will be used; xdmcp always * adds local hosts manually when needed */voidAccessUsingXdmcp (){ UsingXdmcp = TRUE; LocalHostEnabled = FALSE;}#if ((defined(SVR4) && !defined(SCO325) && !defined(sun) && !defined(NCR)) || defined(ISC)) && defined(SIOCGIFCONF)/* Deal with different SIOCGIFCONF ioctl semantics on these OSs */static intifioctl (fd, cmd, arg) int fd; int cmd; char *arg;{ struct strioctl ioc; int ret; bzero((char *) &ioc, sizeof(ioc)); ioc.ic_cmd = cmd; ioc.ic_timout = 0; if (cmd == SIOCGIFCONF) { ioc.ic_len = ((struct ifconf *) arg)->ifc_len; ioc.ic_dp = ((struct ifconf *) arg)->ifc_buf;#ifdef ISC /* SIOCGIFCONF is somewhat brain damaged on ISC. The argument * buffer must contain the ifconf structure as header. Ifc_req * is also not a pointer but a one element array of ifreq * structures. On return this array is extended by enough * ifreq fields to hold all interfaces. The return buffer length * is placed in the buffer header. */ ((struct ifconf *) ioc.ic_dp)->ifc_len = ioc.ic_len - sizeof(struct ifconf);#endif } else { ioc.ic_len = sizeof(struct ifreq); ioc.ic_dp = arg; } ret = ioctl(fd, I_STR, (char *) &ioc); if (ret >= 0 && cmd == SIOCGIFCONF)#ifdef SVR4 ((struct ifconf *) arg)->ifc_len = ioc.ic_len;#endif#ifdef ISC { ((struct ifconf *) arg)->ifc_len = ((struct ifconf *)ioc.ic_dp)->ifc_len; ((struct ifconf *) arg)->ifc_buf = (caddr_t)((struct ifconf *)ioc.ic_dp)->ifc_req; }#endif return(ret);}#else /* ((SVR4 && !sun) || ISC) && SIOCGIFCONF */#define ifioctl ioctl#endif /* ((SVR4 && !sun) || ISC) && SIOCGIFCONF *//* * DefineSelf (fd): * * Define this host for access control. Find all the hosts the OS knows about * for this fd and add them to the selfhosts list. */#ifdef WINTCP /* NCR Wollongong based TCP */#include <sys/un.h>#include <stropts.h>#include <tiuser.h>#include <sys/stream.h>#include <net/if.h>#include <netinet/ip.h>#include <netinet/ip_var.h>#include <netinet/in.h>#include <netinet/in_var.h>voidDefineSelf (fd) int fd;{ /* * The Wolongong drivers used by NCR SVR4/MP-RAS don't understand the * socket IO calls that most other drivers seem to like. Because of * this, this routine must be special cased for NCR. Eventually, * this will be cleared up. */ struct ipb ifnet; struct in_ifaddr ifaddr; struct strioctl str; unsigned char *addr; register HOST *host; int family, len; if ((fd = open ("/dev/ip", O_RDWR, 0 )) < 0) Error ("Getting interface configuration (1)"); /* Indicate that we want to start at the begining */ ifnet.ib_next = (struct ipb *) 1; while (ifnet.ib_next) { str.ic_cmd = IPIOC_GETIPB; str.ic_timout = 0; str.ic_len = sizeof (struct ipb); str.ic_dp = (char *) &ifnet; if (ioctl (fd, (int) I_STR, (char *) &str) < 0) { close (fd); Error ("Getting interface configuration (2)"); } ifaddr.ia_next = (struct in_ifaddr *) ifnet.if_addrlist; str.ic_cmd = IPIOC_GETINADDR; str.ic_timout = 0; str.ic_len = sizeof (struct in_ifaddr); str.ic_dp = (char *) &ifaddr; if (ioctl (fd, (int) I_STR, (char *) &str) < 0) { close (fd); Error ("Getting interface configuration (3)"); } len = sizeof(struct sockaddr_in); family = ConvertAddr (IA_SIN(&ifaddr), &len, (pointer *)&addr); if (family == -1 || family == FamilyLocal) continue; for (host = selfhosts; host && !addrEqual (family, addr, len, host); host = host->next) ; if (host) continue; MakeHost(host,len) if (host) { host->family = family; host->len = len; acopy(addr, host->addr, len); host->next = selfhosts; selfhosts = host; }#ifdef XDMCP { struct sockaddr broad_addr; /* * If this isn't an Internet Address, don't register it. */ if (family != FamilyInternet) continue; /* * ignore 'localhost' entries as they're not useful * on the other end of the wire */ if (len == 4 && addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1) continue; XdmcpRegisterConnection (family, (char *)addr, len);#define IA_BROADADDR(ia) ((struct sockaddr_in *)(&((struct in_ifaddr *)ia)->ia_broadaddr)) XdmcpRegisterBroadcastAddress ( (struct sockaddr_in *) IA_BROADADDR(&ifaddr));#undef IA_BROADADDR }#endif /* XDMCP */ } close(fd); /* * add something of FamilyLocalHost */ for (host = selfhosts; host && !addrEqual(FamilyLocalHost, "", 0, host); host = host->next); if (!host)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -