list = strdup(allow_list);
int len = strlen(allow_list); if (allow_once) { len += strlen(allow_once) + 2; } list = malloc(len); list[0] = '\0'; strcat(list, allow_list); if (allow_once) { strcat(list, ","); strcat(list, allow_once); }
static int check_access(char *addr) {	int allowed = 0;	char *p, *list;	if (allow_list == NULL || *allow_list == '\0') {		return 1;	}	if (addr == NULL || *addr == '\0') {		rfbLog("check_access: denying empty host IP address string.\n");		return 0;	}	if (strchr(allow_list, '/')) {		/* a file of IP addresess or prefixes */		int len;		struct stat sbuf;		FILE *in;		char line[1024], *q;		if (stat(allow_list, &sbuf) != 0) {			rfbLog("check_access: failure stating file: %s\n",			    allow_list);			rfbLogPerror("stat");			clean_up_exit(1);		}		len = sbuf.st_size + 1;	/* 1 more for '\0' at end */		list = malloc(len);		list[0] = '\0';				in = fopen(allow_list, "r");		if (in == NULL) {			rfbLog("check_access: cannot open: %s\n", allow_list);			rfbLogPerror("fopen");			clean_up_exit(1);		}		while (fgets(line, 1024, in) != NULL) {			if ( (q = strchr(line, '#')) != NULL) {				*q = '\0';			}			if (strlen(list) + strlen(line) >= len) {				break;			}			strcat(list, line);		}		fclose(in);	} else {		list = strdup(allow_list);	}		p = strtok(list, ", \t\n\r");	while (p) {		char *q;		if (*p == '\0') {			continue;			}		q = strstr(addr, p);		if (q == addr) {			rfbLog("check_access: client %s matches pattern %s\n",			    addr, p);			allowed = 1;		} else if(!strcmp(p,"localhost") && !strcmp(addr,"127.0.0.1")) {			allowed = 1;		}		p = strtok(NULL, ", \t\n\r");	}	free(list);	return allowed;}