static DisplayEntry * ReadDisplayEntry (FILE *file) { char *displayOrAlias; DisplayEntry *d; struct _display *display; HostEntry *h, **prev; tryagain: displayOrAlias = ReadWord (file, FALSE); if (!displayOrAlias) return NULL; d = malloc (sizeof (DisplayEntry)); d->notAllowed = 0; d->notBroadcast = 0; d->chooser = 0; if (*displayOrAlias == ALIAS_CHARACTER) { d->type = DISPLAY_ALIAS; d->entry.aliasName = strdup (displayOrAlias); if (!d->entry.aliasName) { free (d); return NULL; } } else if (!strcmp(displayOrAlias, LISTEN_STRING)) { d->type = DISPLAY_LISTEN; } else { if (*displayOrAlias == NEGATE_CHARACTER) { d->notAllowed = 1; ++displayOrAlias; } if (HasGlobCharacters (displayOrAlias)) { d->type = DISPLAY_PATTERN; d->entry.displayPattern = strdup (displayOrAlias); if (!d->entry.displayPattern) { free (d); return NULL; } } else { void *addr = NULL; size_t addr_length = 0; int addrtype = 0; # if defined(IPv6) && defined(AF_INET6) struct addrinfo *ai = NULL; if (getaddrinfo(displayOrAlias, NULL, NULL, &ai) == 0) { addrtype = ai->ai_addr->sa_family; if (addrtype == AF_INET) { addr = &((struct sockaddr_in *)ai->ai_addr)->sin_addr; addr_length = sizeof(struct in_addr); } else if (addrtype == AF_INET6) { addr = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; addr_length = sizeof(struct in6_addr); } } # else struct hostent *hostent; if ((hostent = gethostbyname (displayOrAlias)) != NULL) { Debug("ReadDisplayEntry: %s\n", displayOrAlias); addr = hostent->h_addr; addrtype = hostent->h_addrtype; addr_length = hostent->h_length; } # endif if (addr == NULL) { LogError ("Access file %s, display %s unknown\n", accessFile, displayOrAlias); free (d); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif goto tryagain; } d->type = DISPLAY_ADDRESS; display = &d->entry.displayAddress; if (!XdmcpAllocARRAY8 (&display->clientAddress, addr_length)) { free (d); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif return NULL; } memmove( display->clientAddress.data, addr, addr_length); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif switch (addrtype) { # ifdef AF_UNIX case AF_UNIX: display->connectionType = FamilyLocal; break; # endif # ifdef AF_INET case AF_INET: display->connectionType = FamilyInternet; break; # endif # if defined(IPv6) && defined(AF_INET6) case AF_INET6: display->connectionType = FamilyInternet6; break; # endif # ifdef AF_DECnet case AF_DECnet: display->connectionType = FamilyDECnet; break; # endif default: display->connectionType = FamilyLocal; break; } } } prev = &d->hosts; while ((h = ReadHostEntry (file))) { if (h->type == HOST_CHOOSER) { FreeHostEntry (h); d->chooser = 1; } else if (h->type == HOST_NOBROADCAST) { FreeHostEntry (h); d->notBroadcast = 1; } else if (h->type == HOST_ANYADDR) { if (d->type == DISPLAY_LISTEN) { *prev = h; prev = &h->next; } else { Debug("Wildcard host specified in Xaccess for type other than LISTEN -- ignoring\n"); FreeHostEntry (h); } } else { *prev = h; prev = &h->next; } } *prev = NULL; return d; }
static DisplayEntry * ReadDisplayEntry (FILE *file) { char *displayOrAlias; DisplayEntry *d; struct _display *display; HostEntry *h, **prev; struct hostent *hostent; displayOrAlias = ReadWord (file, FALSE); if (!displayOrAlias) return NULL; d = (DisplayEntry *) malloc (sizeof (DisplayEntry)); d->notAllowed = 0; d->notBroadcast = 0; d->chooser = 0; if (*displayOrAlias == ALIAS_CHARACTER) { d->type = DISPLAY_ALIAS; d->entry.aliasName = malloc (strlen (displayOrAlias) + 1); if (!d->entry.aliasName) { free ((char *) d); return NULL; } strcpy (d->entry.aliasName, displayOrAlias); } else { if (*displayOrAlias == NEGATE_CHARACTER) { d->notAllowed = 1; ++displayOrAlias; } if (HasGlobCharacters (displayOrAlias)) { d->type = DISPLAY_PATTERN; d->entry.displayPattern = malloc (strlen (displayOrAlias) + 1); if (!d->entry.displayPattern) { free ((char *) d); return NULL; } strcpy (d->entry.displayPattern, displayOrAlias); } else { if ((hostent = gethostbyname (displayOrAlias)) == NULL) { LogError ("Access file %s, display %s unknown\n", accessFile, displayOrAlias); free ((char *) d); return NULL; } d->type = DISPLAY_ADDRESS; display = &d->entry.displayAddress; if (!XdmcpAllocARRAY8 (&display->clientAddress, hostent->h_length)) { free ((char *) d); return NULL; } memmove( display->clientAddress.data, hostent->h_addr, hostent->h_length); switch (hostent->h_addrtype) { #ifdef AF_UNIX case AF_UNIX: display->connectionType = FamilyLocal; break; #endif #ifdef AF_INET case AF_INET: display->connectionType = FamilyInternet; break; #endif #ifdef AF_DECnet case AF_DECnet: display->connectionType = FamilyDECnet; break; #endif default: display->connectionType = FamilyLocal; break; } } } prev = &d->hosts; while ((h = ReadHostEntry (file))) { if (h->type == HOST_CHOOSER) { FreeHostEntry (h); d->chooser = 1; } else if (h->type == HOST_NOBROADCAST) { FreeHostEntry (h); d->notBroadcast = 1; } else { *prev = h; prev = &h->next; } } *prev = NULL; return d; }