📄 access.c
字号:
return TRUE; for (host = selfhosts; host; host = host->next) {#ifdef ISOCONN if (family == host->family && !acmp (addr, &(host->addr), alen))#else /* ISOCONN */ if (family == host->family && !acmp (addr, host->addr, alen))#endif /* ISOCONN */ return TRUE; } } } return FALSE;}/* Add a host to the access control list. This is the external interface * called from the dispatcher */intAddHost (client, family, length, pAddr) ClientPtr client; int family; unsigned length; /* of bytes in pAddr */ pointer pAddr;{ int len; register HOST *host; int unixFamily; if (!AuthorizedClient(client)) return(BadAccess); unixFamily = UnixFamily(family); if ((len = CheckFamily (DONT_CHECK, unixFamily)) < 0) { client->errorValue = family; return(-len); } if (len != length) { client->errorValue = length; return(BadValue); } for (host = validhosts; host; host = host->next) {#ifdef ISOCONN if (unixFamily == host->family && !acmp (pAddr, &(host->addr), len)) return (Success);#else /* ISOCONN */ if (unixFamily == host->family && !acmp (pAddr, host->addr, len)) return (Success);#endif /* ISOCONN */ } host = (HOST *) xalloc (sizeof (HOST)); host->family = unixFamily; host->len = len;#ifdef ISOCONN acopy(pAddr, &(host->addr), len);#else /* ISOCONN */ acopy(pAddr, host->addr, len);#endif /* ISOCONN */ host->next = validhosts; validhosts = host; return (Success);}/* Add a host to the access control list. This is the internal interface * called when starting or resetting the server */NewHost (family, addr) short family; pointer addr;{ int len; register HOST *host; if ((len = CheckFamily (DONT_CHECK, family)) < 0) return; for (host = validhosts; host; host = host->next) {#ifdef ISOCONN if (family == host->family && !acmp (addr, &(host->addr), len)) return;#else /* ISOCONN */ if (family == host->family && !acmp (addr, host->addr, len)) return;#endif /* ISOCONN */ } host = (HOST *) xalloc (sizeof (HOST)); host->family = family; host->len = len;#ifdef ISOCONN acopy(addr, &(host->addr), len);#else /* ISOCONN */ acopy(addr, host->addr, len);#endif /* ISOCONN */ host->next = validhosts; validhosts = host;}/* Remove a host from the access control list */intRemoveHost (client, family, length, pAddr) ClientPtr client; int family; unsigned length; /* of bytes in pAddr */ pointer pAddr;{ int len, unixFamily; register HOST *host, **prev; if (!AuthorizedClient(client)) return(BadAccess); unixFamily = UnixFamily(family); if ((len = CheckFamily (DONT_CHECK, unixFamily)) < 0) { client->errorValue = family; return(-len); } if (len != length) { client->errorValue = length; return(BadValue); } for (prev = &validhosts; (host = *prev) && (unixFamily != host->family ||#ifdef ISOCONN acmp (pAddr, &(host->addr), len));#else /* ISOCONN */ acmp (pAddr, host->addr, len));#endif /* ISOCONN */ prev = &host->next) ; if (host) { *prev = host->next; xfree (host); } return (Success);}/* Get all hosts in the access control list */intGetHosts (data, pnHosts, pEnabled) pointer *data; int *pnHosts; BOOL *pEnabled;{ int len; register int n = 0; register pointer ptr; register HOST *host; int nHosts = 0; int *lengths = (int *) NULL; *pEnabled = AccessEnabled ? EnableAccess : DisableAccess; for (host = validhosts; host; host = host->next) { if ((len = CheckFamily (DONT_CHECK, host->family)) < 0) return (-1); lengths = (int *) xrealloc(lengths, (nHosts + 1) * sizeof(int)); lengths[nHosts++] = len; n += (((len + 3) >> 2) << 2) + sizeof(xHostEntry); } if (n) { *data = ptr = (pointer) xalloc (n); nHosts = 0; for (host = validhosts; host; host = host->next) {#ifdef ISOCONN#ifdef ISODEBUG if (isodexbug) { int i; char *hp = (char *)(&host->addr); fprintf(stderr, "List(%d): ", host->family); for(i=0; i<len; i++) fprintf(stderr, "%x ", (*hp++)&0xff); fprintf(stderr, "\n"); }#endif ISODEBUG#endif /* ISOCONN */ len = lengths[nHosts++]; ((xHostEntry *)ptr)->family = XFamily(host->family); ((xHostEntry *)ptr)->length = len; ptr += sizeof(xHostEntry);#ifdef ISOCONN acopy (&host->addr, ptr, len);#else /* ISOCONN */ acopy (host->addr, ptr, len);#endif /* ISOCONN */ ptr += ((len + 3) >> 2) << 2; } } *pnHosts = nHosts; xfree(lengths); return (n);}/* Check for valid address family, and for local host if client modification. * Return address length. */CheckFamily (connection, family) int connection; int family;{#ifdef ISOCONN struct TSAPaddr from;#else /* ISOCONN */ struct sockaddr from;#endif /* ISOCONN */ int alen; pointer addr; register HOST *host; int len; switch (family) {#ifdef TCPCONN case AF_INET: len = sizeof (struct in_addr); break;#endif #ifdef DNETCONN case AF_DECnet: len = sizeof (struct dn_naddr); break;#endif#ifdef ISOCONN case AF_OSI: len = NASIZE; break;#endif /* ISOCONN */ default: return (-BadValue); } if (connection == DONT_CHECK) return (len);#ifdef ISOCONN alen = NASIZE; if (!SGetPeerName(connection, &from, &alen))#else /* ISOCONN */ alen = sizeof (from); if (!getpeername (connection, &from, &alen))#endif /* ISOCONN */ { if ((family = ConvertAddr (&from, &alen, &addr)) >= 0) { if (family == 0) return (len); for (host = selfhosts; host; host = host->next) { if (family == host->family &&#ifdef ISOCONN !acmp (addr, &(host->addr), alen))#else /* ISOCONN */ !acmp (addr, host->addr, alen))#endif /* ISOCONN */ return (len); } } } /* Bad Access */ return (-1);}/* Check if a host is not in the access control list. * Returns 1 if host is invalid, 0 if we've found it. */InvalidHost (saddr, len)#ifdef ISOCONN register struct TSAPaddr *saddr;#else /* ISOCONN */ register struct sockaddr *saddr;#endif /* ISOCONN */ int len;{ int family; pointer addr; register HOST *host;#ifdef ISOCONN len = NASIZE;#endif /* ISOCONN */ if ((family = ConvertAddr (saddr, len ? &len : 0, &addr)) < 0) return (1);#ifdef ISOCONN#ifdef ISODEBUG if (isodexbug) { int i; char *hp = (char *)(addr); fprintf(stderr, "Other(%d): ", family); for(i=0; i<len; i++) fprintf(stderr, "%x ", (*hp++)&0xff); fprintf(stderr, "\n"); }#endif /* ISODEBUG */#endif /* ISOCONN */ if (family == 0) return (0);#ifdef ISOCONN/* * XXXXXXXXXXXXXXXXX * Just til I fix the X.25 calling addr stuff */return 0;#endif if (!AccessEnabled) /* just let them in */ return(0); for (host = validhosts; host; host = host->next) {#ifdef ISOCONN#ifdef ISODEBUG if (isodexbug) { int i; char *hp = (char *)&(host->addr); fprintf(stderr, "List(%d): ", host->family); for(i=0; i<host->len; i++) fprintf(stderr, "%x ", (*hp++)&0xff); fprintf(stderr, "\n"); }#endif /* ISODEBUG */ if (family == host->family && !acmp (addr, &(host->addr), len))#else /* ISOCONN */ if (family == host->family && !acmp (addr, host->addr, len))#endif /* ISOCONN */ return (0); } return (1);}ConvertAddr (saddr, len, addr)#ifdef ISOCONN register struct TSAPaddr *saddr;#else /* ISOCONN */ register struct sockaddr *saddr;#endif /* ISOCONN */ int *len; pointer *addr;{ if (len == 0) return (0);#ifdef ISOCONN/* * NULL ish type acttion, but maybe later we'd change this to * use AEIs as the thing for access ctl, and need to get from * transport descriptor to T-SAPs to AEI... */ *len = NASIZE; *addr = (pointer)saddr; return (AF_OSI);#else /* ISOCONN */ switch (saddr->sa_family) { case AF_UNSPEC:#ifndef hpux case AF_UNIX:#endif return (0); case AF_INET:#ifdef TCPCONN *len = sizeof (struct in_addr); *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr); return (AF_INET);#else break;#endif#ifdef DNETCONN case AF_DECnet: *len = sizeof (struct dn_naddr); *addr = (pointer) &(((struct sockaddr_dn *) saddr)->sdn_add); return (AF_DECnet);#else break;#endif default: break; } return (-1);#endif /* ISOCONN */}intChangeAccessControl(client, fEnabled) ClientPtr client; int fEnabled;{ if (!AuthorizedClient(client)) return BadAccess; AccessEnabled = fEnabled; return Success;}static int XFamily(af) int af;{ int i; for (i = 0; i < FAMILIES; i++) if (familyMap[i].af == af) return familyMap[i].xf; return -1;}static int UnixFamily(xf) int xf;{ int i; for (i = 0; i < FAMILIES; i++) if (familyMap[i].xf == xf) return familyMap[i].af; return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -