⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 access.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,and the Massachusetts Institute of Technology, Cambridge, 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 names of Digital or MIT 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.******************************************************************//* $XConsortium: access.c,v 1.26 88/09/06 15:51:03 jim Exp $ */#ifdef ISOCONN#include <math.h>/* * i'm sorry, i'm sorry * * By Analogy with per host auth, we keep all the TSAPaddr but * do access control on NSAPaddr part only... */#endif /* ISOCONN */#include "X.h"#include "Xproto.h"#include "misc.h"#include "site.h"#include <errno.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/ioctl.h>#ifdef hpux#include <sys/utsname.h>#else#include <net/if.h>#endif /* hpux */#include <netdb.h>#ifdef TCPCONN#include <netinet/in.h>#endif /* TCPCONN */#ifdef DNETCONN#include <netdnet/dn.h>#include <netdnet/dnetdb.h>#endif#ifdef ISOCONN#include <isode/psap.h>#include <isode/tsap.h>#include <isode/isoservent.h>#endif#undef NULL#include <stdio.h>#include "dixstruct.h"#include "osdep.h"#define acmp(a1, a2, len) bcmp((char *)(a1), (char *)(a2), len)#define acopy(a1, a2, len) bcopy((char *)(a1), (char *)(a2), len)#define DONT_CHECK -1extern char	*index();typedef struct _host {	short		family;	short		len;#ifdef ISOCONN	struct TSAPaddr addr; 		/* and so it is!! */#else /* ISOCONN */	unsigned char	addr[4];	/* will need to be bigger eventually */#endif /* ISOCONN */	struct _host *next;} HOST;static HOST *selfhosts = NULL;static HOST *validhosts = NULL;static int AccessEnabled = DEFAULT_ACCESS_CONTROL;typedef struct {    int af, xf;} FamilyMap;static FamilyMap familyMap[] = {#ifdef ISOCONN /* * This has to be visible to the protocol via X.h... */    {AF_OSI, FamilyIso},#endif /* ISOCONN */#ifdef     AF_DECnet    {AF_DECnet, FamilyDECnet},#endif /* AF_DECnet */#ifdef     AF_CHAOS    {AF_CHAOS, FamilyChaos},#endif /* AF_CHAOS */#ifdef    AF_INET    {AF_INET, FamilyInternet}#endif};#define FAMILIES ((sizeof familyMap)/(sizeof familyMap[0]))#ifdef hpux/* Define this host for access control.  Find all the hosts the OS knows about  * for this fd and add them to the selfhosts list. * HPUX version - hpux does not have SIOCGIFCONF ioctl; */DefineSelf (fd)    int fd;{    register int n;    int	len;    caddr_t	addr;    int		family;    register HOST	*host;    struct utsname name;    register struct hostent  *hp;    union {	struct  sockaddr   sa;	struct  sockaddr_in  in;    } saddr;	    struct	sockaddr_in	*inetaddr;    /* Why not use gethostname()?  Well, at least on my system, I've had to     * make an ugly kernel patch to get a name longer than 8 characters, and     * uname() lets me access to the whole string (it smashes release, you     * see), whereas gethostname() kindly truncates it for me.     */    uname(&name);    hp = gethostbyname (name.nodename);    if (hp != NULL) {	saddr.sa.sa_family = hp->h_addrtype;	inetaddr = (struct sockaddr_in *) (&(saddr.sa));	acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length);	family = ConvertAddr ( &(saddr.sa), &len, &addr);	if ( family > 0) {	    for (host = selfhosts;		 host && ( family != host->family ||			  acmp ( addr, host->addr, len));		 host = host->next) ;	    if (!host) {		/* add this host to the host list.	*/		host = (HOST *) xalloc (sizeof (HOST));		host->family = family;		host->len = len;		acopy ( addr, host->addr, len);		host->next = selfhosts;		selfhosts = host;	    }	}    }}#else/* Define this host for access control.  Find all the hosts the OS knows about  * for this fd and add them to the selfhosts list. */DefineSelf (fd)    int fd;{    char		buf[2048];    struct ifconf	ifc;    register int	n;    int 		len;    pointer 		addr;    int 		family;    register HOST 	*host;    register struct ifreq *ifr;#ifdef ISOCONN    AEI			aei;    struct PSAPaddr    *pa;#endif /* ISOCONN */    #ifdef TCPCONN || UNIXCONN || DNETCONN    ifc.ifc_len = sizeof (buf);    ifc.ifc_buf = buf;    if (ioctl (fd, (int) SIOCGIFCONF, (pointer) &ifc) < 0)        Error ("Getting interface configuration");    for (ifr = ifc.ifc_req, n = ifc.ifc_len / sizeof (struct ifreq); --n >= 0;     ifr++)    {#ifdef DNETCONN	/*	 * this is ugly but SIOCGIFCONF returns decnet addresses in	 * a different form from other decnet calls	 */	if (ifr->ifr_addr.sa_family == AF_DECnet) {		len = sizeof (struct dn_naddr);		addr = (pointer)ifr->ifr_addr.sa_data;		family = AF_DECnet;	} else#endif /* DNETCONN */        if ((family = ConvertAddr (&ifr->ifr_addr, &len, &addr)) <= 0)	    continue;        for (host = selfhosts; host && (family != host->family ||	  acmp (addr, host->addr, len)); host = host->next)	    ;        if (host)	    continue;        host = (HOST *) xalloc (sizeof (HOST));        host->family = family;        host->len = len;        acopy(addr, host->addr, len);        host->next = selfhosts;        selfhosts = host;    }#endif TCPCONN#ifdef ISOCONN/*  * This is dubious - we should be able to take an fd (transport * descriptor) and get the list of possible transport interfaces... * * Well strictly, for this TSAP, a list of NSAPs that are valid */	host = (HOST *)xalloc (sizeof (HOST));        host->family = AF_OSI;	aei = str2aei(TLocalHostName(), DEFAULTTSERVICE);	if (aei == NULLAEI) {		Error("Unknown Display\n");		return;	}	if ((pa = aei2addr (aei)) == NULLPA) {		fprintf (stderr, "address translation failed");		return;	}	acopy(&(pa->pa_addr.sa_addr), &(host->addr), sizeof(struct TSAPaddr));	host->len = NASIZE;	host->next = selfhosts;	selfhosts = host;#ifdef ISODEBUG	if (isodexbug) {		int i; char *hp = (char *)&(host->addr);		fprintf(stderr, "Self: ");		for(i=0; i<host->len; i++)			fprintf(stderr, "%x ", (*hp++)&0xff);		fprintf(stderr, "\n");	}#endif /* ISODEBUG */#endif /* ISOCONN */}#endif hpux/* Reset access control list to initial hosts */ResetHosts (display)    char *display;{    register HOST	*host, *self;    char 		hostname[120];    char		fname[32];    FILE		*fd;    char		*ptr;    union {        struct sockaddr	sa;#ifdef TCPCONN        struct sockaddr_in in;#endif /* TCPCONN */#ifdef DNETCONN        struct sockaddr_dn dn;#endif#ifdef ISOCONN	struct TSAPaddr ta;#endif /* ISOCONN */    } 			saddr;#ifdef DNETCONN    struct nodeent 	*np;    struct dn_naddr 	dnaddr, *dnaddrp, *dnet_addr();#endif    int			family;    int			len;    pointer		addr;    register struct hostent *hp;    AccessEnabled = DEFAULT_ACCESS_CONTROL;    while (host = validhosts)    {        validhosts = host->next;        xfree (host);    }    for (self = selfhosts; self; self = self->next)    {        host = (HOST *) xalloc (sizeof (HOST));        *host = *self;        host->next = validhosts;        validhosts = host;    }    strcpy (fname, "/etc/X");    strcat (fname, display);    strcat (fname, ".hosts");    if (fd = fopen (fname, "r"))     {        while (fgets (hostname, sizeof (hostname), fd))	{    	if (ptr = index (hostname, '\n'))    	    *ptr = 0;#ifdef DNETCONN    	if ((ptr = index (hostname, ':')) && (*(ptr + 1) == ':'))	{    	    /* node name (DECnet names end in "::") */    	    *ptr = 0;    	    if (dnaddrp = dnet_addr(hostname))	    {    		    /* allow nodes to be specified by address */    		    NewHost ((short) AF_DECnet, (pointer) dnaddrp);    	    }	    else	    {    		if (np = getnodebyname (hostname))		{    		    /* node was specified by name */    		    saddr.sa.sa_family = np->n_addrtype;    		    if ((family = ConvertAddr (&saddr.sa, &len, &addr)) ==		      AF_DECnet)		    {    			bzero ((pointer) &dnaddr, sizeof (dnaddr));    			dnaddr.a_len = np->n_length;    			acopy (np->n_addr, dnaddr.a_addr, np->n_length);    			NewHost (family, (pointer) &dnaddr);    		    }    		}    	    }    	}	else	{#endif /* DNETCONN */#ifdef ISOCONN/* * ISO displays are host:T-Namedisplay number * only AEI are allowed (i.e. no raw addrs)  * XXX Fix to allow T/X and other T-Names... */	if ((ptr = index (hostname, ':')) && 		((*(ptr + 1) == 'X') || (*(ptr + 1) == 'T')))	{		AEI aei;		struct PSAPaddr *pa;		*ptr++ = '\0';		if (ptr)			aei = str2aei(hostname, ptr);		else			aei = str2aei(hostname, DEFAULTTSERVICE);		if (aei == NULLAEI) {			fprintf (stderr, "%s %s Unknown Display\n",				hostname, ptr);			continue;		}		if ((pa = aei2addr (aei)) == NULLPA) {			fprintf (stderr, "address translation failed");			continue;        	}		family = AF_OSI;		NewHost(family, pa);	}#endif ISOCONN#ifdef TCPCONN    	    /* host name */    	    if (hp = gethostbyname (hostname))	    {    		saddr.sa.sa_family = hp->h_addrtype;    		if ((family = ConvertAddr (&saddr.sa, &len, &addr)) > 0)#ifdef NEW_HEADER_WITH_OLD_LIBRARY    		    NewHost (family, (pointer)hp->h_addr_list);#else    		    NewHost (family, (pointer)hp->h_addr);#endif    	    }#endif /* TCPCONN */#ifdef DNETCONN     	}	#endif /* DNETCONN */        }        fclose (fd);    }}static BoolAuthorizedClient(client)    ClientPtr client;{    int    		alen, family;#ifndef ISOCONN    struct sockaddr	from;#endif    pointer		addr;    register HOST	*host;#ifdef ISOCONN    struct TSAPaddr	from;#endif /* ISOCONN */#ifdef ISOCONN/* * XXXXXXXXXXXXXXXXX * Just til I fix the X.25 calling addr stuff */return TRUE;#endif /* ISOCONN */    alen = sizeof (from);#ifdef ISOCONN    if (!SGetPeerName (((OsCommPtr)client->osPrivate)->fd, &from, &alen))#else /* ISOCONN */    if (!getpeername (((OsCommPtr)client->osPrivate)->fd, &from, &alen))#endif /* ISOCONN */    {        if ((family = ConvertAddr (&from, &alen, &addr)) >= 0)	{	    if (family == 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -