static void *Realloc(void *ptr, size_t size) { void *ret; if(!(ret = realloc(ptr, size)) && size) LogOutOfMem(); return ret; }
void *Malloc(size_t size) { void *ret; if(!(ret = malloc(size))) LogOutOfMem(); return ret; }
void *Calloc(size_t nmemb, size_t size) { void *ret; if(!(ret = calloc(nmemb, size))) LogOutOfMem(); return ret; }
static HostEntry * ReadHostEntry (FILE *file) { char *hostOrAlias; HostEntry *h; struct hostent *hostent; tryagain: hostOrAlias = ReadWord (file, TRUE); if (!hostOrAlias) return NULL; h = (HostEntry *) malloc (sizeof (DisplayEntry)); if (*hostOrAlias == ALIAS_CHARACTER) { h->type = HOST_ALIAS; h->entry.aliasName = malloc (strlen (hostOrAlias) + 1); if (!h->entry.aliasName) { free ((char *) h); return NULL; } strcpy (h->entry.aliasName, hostOrAlias); } else if (!strcmp (hostOrAlias, CHOOSER_STRING)) { h->type = HOST_CHOOSER; } else if (!strcmp (hostOrAlias, BROADCAST_STRING)) { h->type = HOST_BROADCAST; } else if (!strcmp (hostOrAlias, NOBROADCAST_STRING)) { h->type = HOST_NOBROADCAST; } else { h->type = HOST_ADDRESS; hostent = gethostbyname (hostOrAlias); if (!hostent) { Debug ("No such host %s\n", hostOrAlias); LogError ("Access file \"%s\", host \"%s\" not found\n", accessFile, hostOrAlias); free ((char *) h); goto tryagain; } if (!XdmcpAllocARRAY8 (&h->entry.hostAddress, hostent->h_length)) { LogOutOfMem ("ReadHostEntry\n"); free ((char *) h); return NULL; } memmove( h->entry.hostAddress.data, hostent->h_addr, hostent->h_length); } return h; }
void ForEachListenAddr ( ListenFunc listenfunction, ListenFunc mcastfunction, void **closure) { DisplayEntry *d; HostEntry *h; int listenFound = 0; for (d = database; d != NULL ; d = d->next) { if (d->type == DISPLAY_LISTEN) { listenFound = 1; h = d->hosts; if (h != NULL) { (*listenfunction) (&h->entry.hostAddress, closure); for (h = h->next; h != NULL; h = h->next) { (*mcastfunction) (&h->entry.hostAddress, closure); } } } } if (!listenFound) { (*listenfunction) (NULL, closure); # if defined(IPv6) && defined(AF_INET6) && defined(XDM_DEFAULT_MCAST_ADDR6) { /* Join default IPv6 Multicast Group */ static ARRAY8 defaultMcastAddress; if (defaultMcastAddress.length == 0) { struct in6_addr addr6; if (inet_pton(AF_INET6,XDM_DEFAULT_MCAST_ADDR6,&addr6) == 1) { if (!XdmcpAllocARRAY8 (&defaultMcastAddress, sizeof(struct in6_addr))) { LogOutOfMem ("ReadHostEntry\n"); defaultMcastAddress.length = -1; } else { memcpy(defaultMcastAddress.data, &addr6, sizeof(struct in6_addr)); } } else { defaultMcastAddress.length = -1; } } if ( defaultMcastAddress.length == sizeof(struct in6_addr) ) { (*mcastfunction) (&defaultMcastAddress, closure); } } # endif } }
static char * makeEnv (char *name, char *value) { char *result; result = malloc ((unsigned) (strlen (name) + strlen (value) + 2)); if (!result) { LogOutOfMem ("makeEnv"); return 0; } sprintf (result, "%s=%s", name, value); return result; }
/*ARGSUSED*/ static void SetSessionArgument ( Widget ctxw, XEvent *event, String *params, Cardinal *num_params) { LoginWidget ctx = (LoginWidget)ctxw; RemoveFail (ctx); if (ctx->login.sessionArg) XtFree (ctx->login.sessionArg); ctx->login.sessionArg = 0; if (*num_params > 0) { ctx->login.sessionArg = XtMalloc (strlen (params[0]) + 1); if (ctx->login.sessionArg) strcpy (ctx->login.sessionArg, params[0]); else LogOutOfMem ("set session argument"); } }
static HostEntry * ReadHostEntry (FILE *file) { char *hostOrAlias; HostEntry *h; tryagain: hostOrAlias = ReadWord (file, TRUE); if (!hostOrAlias) return NULL; h = malloc (sizeof (DisplayEntry)); h->hopCount = 1; if (*hostOrAlias == ALIAS_CHARACTER) { h->type = HOST_ALIAS; h->entry.aliasName = strdup (hostOrAlias); if (!h->entry.aliasName) { free (h); return NULL; } } else if (!strcmp (hostOrAlias, CHOOSER_STRING)) { h->type = HOST_CHOOSER; } else if (!strcmp (hostOrAlias, BROADCAST_STRING)) { h->type = HOST_BROADCAST; } else if (!strcmp (hostOrAlias, NOBROADCAST_STRING)) { h->type = HOST_NOBROADCAST; } else if (!strcmp (hostOrAlias, WILDCARD_STRING)) { h->type = HOST_ANYADDR; h->entry.hostAddress.length = 0; } else { void *addr=NULL; size_t addr_length=0; # if defined(IPv6) && defined(AF_INET6) struct addrinfo *ai = NULL; # else struct hostent *hostent = gethostbyname (hostOrAlias); # endif char *hops = strrchr(hostOrAlias, '/'); if (hops) { *(hops++) = '\0'; h->hopCount = strtol(hops, NULL, 10); if (h->hopCount < 1) h->hopCount = 1; } # if defined(IPv6) && defined(AF_INET6) if (getaddrinfo(hostOrAlias, NULL, NULL, &ai) == 0) { if (ai->ai_addr->sa_family == AF_INET) { addr = &((struct sockaddr_in *)ai->ai_addr)->sin_addr; addr_length = sizeof(struct in_addr); } else if (ai->ai_addr->sa_family == AF_INET6) { addr = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr; addr_length = sizeof(struct in6_addr); } } # else if (hostent) { addr = hostent->h_addr; addr_length = hostent->h_length; } # endif h->type = HOST_ADDRESS; if (!addr) { Debug ("No such host %s\n", hostOrAlias); LogError ("Access file \"%s\", host \"%s\" not found\n", accessFile, hostOrAlias); free (h); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif goto tryagain; } if (!XdmcpAllocARRAY8 (&h->entry.hostAddress, addr_length)) { LogOutOfMem ("ReadHostEntry\n"); free (h); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif return NULL; } memmove( h->entry.hostAddress.data, addr, addr_length); # if defined(IPv6) && defined(AF_INET6) if (ai) freeaddrinfo(ai); # endif } return h; }