main (int argc, char *argv[]) { int expect; int res; int c; int i; progname = *argv; for ( i = 0; ex[i].a; i++ ) { expect = ex[i].res; if ( expect < 0 ) c = '<'; else if ( expect > 0 ) c = '>'; else c = '='; printf ("%-20s %-20s ==> %c 0 ", ex[i].a, ex[i].b, c); fflush (stdout); res = domaincmp (ex[i].a, ex[i].b); printf ("%3d ", res); if ( res < 0 && expect < 0 || res > 0 && expect > 0 || res == 0 && expect == 0 ) puts ("ok"); else puts ("not ok"); } }
struct gateway * forward_url(struct http_request *http, struct client_state *csp) { struct file_list *fl; struct forward_spec *b; struct url_spec url[1]; if(((fl = csp->flist) == NULL) || ((b = fl->f) == NULL)) { return(gw_default); } *url = dsplit(http->host); /* if splitting the domain fails, punt */ if(url->dbuf == NULL) return(gw_default); for(b = b->next; b ; b = b->next) { if((b->url->port == 0) || (b->url->port == http->port)) { if((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0)) { if((b->url->path == NULL) || #ifdef REGEX (regexec(b->url->preg, http->path, 0, NULL, 0) == 0) #else (strncmp(b->url->path, http->path, b->url->pathlen) == 0) #endif ) { freez(url->dbuf); freez(url->dvec); return(b->gw); } } } } freez(url->dbuf); freez(url->dvec); return(gw_default); }
int clone_proxy::operator&(const clone_proxy &c) { return !domaincmp(user->host, c.user->host, 2); }
char * block_url(struct http_request *http, struct client_state *csp) { struct file_list *fl; struct block_spec *b; struct url_spec url[1]; char *p; char *hostport, *path, *spec; int n; if(((fl = csp->blist) == NULL) || ((b = fl->f) == NULL)) { return(NULL); } *url = dsplit(http->host); /* if splitting the domain fails, punt */ if(url->dbuf == NULL) return(NULL); for(b = b->next; b ; b = b->next) { if((b->url->port == 0) || (b->url->port == http->port)) { if((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0)) { if((b->url->path == NULL) || #ifdef REGEX (regexec(b->url->preg, http->path, 0, NULL, 0) == 0) #else (strncmp(b->url->path, http->path, b->url->pathlen) == 0) #endif ) { freez(url->dbuf); freez(url->dvec); if(b->reject == 0) return(NULL); hostport = URL(http->hostport); path = URL(http->path); spec = URL(b->url->spec); /* Modified by Kiewitz */ n = strlen(CBLOCK); /* n += strlen(hostport); n += strlen(path); n += strlen(spec); */ p = malloc(n); sprintf(p, CBLOCK); /* , hostport, path, spec); */ freez(hostport); freez(path); freez(spec); return(p); } } } } freez(url->dbuf); freez(url->dvec); return(NULL); }
char * trust_url(struct http_request *http, struct client_state *csp) { struct file_list *fl; struct block_spec *b; struct url_spec url[1], **tl, *t; char *p, *h; char *hostport, *path, *referrer; struct http_request rhttp[1]; int n; if(((fl = csp->tlist) == NULL) || ((b = fl->f) == NULL)) { return(NULL); } *url = dsplit(http->host); /* if splitting the domain fails, punt */ if(url->dbuf == NULL) return(NULL); memset(rhttp, '\0', sizeof(*rhttp)); for(b = b->next; b ; b = b->next) { if((b->url->port == 0) || (b->url->port == http->port)) { if((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0)) { if((b->url->path == NULL) || #ifdef REGEX (regexec(b->url->preg, http->path, 0, NULL, 0) == 0) #else (strncmp(b->url->path, http->path, b->url->pathlen) == 0) #endif ) { freez(url->dbuf); freez(url->dvec); if(b->reject == 0) return(NULL); hostport = URL(http->hostport); path = URL(http->path); if(csp->referrer) { referrer = URL(csp->referrer); } else { referrer = URL("undefined"); } n = strlen(CTRUST); n += strlen(hostport); n += strlen(path); n += strlen(referrer); p = malloc(n); sprintf(p, CTRUST, hostport, path, referrer); freez(hostport); freez(path); freez(referrer); return(p); } } } } freez(url->dbuf); freez(url->dvec); if((csp->referrer == NULL)|| (strlen(csp->referrer) <= 9)) { /* no referrer was supplied */ goto trust_url_not_trusted; } /* forge a URL from the referrer so we can use * convert_url() to parse it into its components. */ p = NULL; p = strsav(p, "GET "); p = strsav(p, csp->referrer + 9); /* skip over "Referer: " */ p = strsav(p, " HTTP/1.0"); parse_http_request(p, rhttp, csp); if(rhttp->cmd == NULL) { freez(p); goto trust_url_not_trusted; } freez(p); *url = dsplit(rhttp->host); /* if splitting the domain fails, punt */ if(url->dbuf == NULL) goto trust_url_not_trusted; for(tl = trust_list; (t = *tl) ; tl++) { if((t->port == 0) || (t->port == rhttp->port)) { if((t->domain[0] == '\0') || domaincmp(t, url) == 0) { if((t->path == NULL) || #ifdef REGEX (regexec(t->preg, rhttp->path, 0, NULL, 0) == 0) #else (strncmp(t->path, rhttp->path, t->pathlen) == 0) #endif ) { /* if the URL's referrer is from a trusted referrer, then * add the target spec to the trustfile as an unblocked * domain and return NULL (which means it's OK). */ FILE *fp; freez(url->dbuf); freez(url->dvec); if((fp = fopen(trustfile, "a"))) { h = NULL; h = strsav(h, "~"); h = strsav(h, http->hostport); p = http->path; if((*p++ == '/') && (*p++ == '~')) { /* since this path points into a user's home space * be sure to include this spec in the trustfile. */ if((p = strchr(p, '/'))) { *p = '\0'; h = strsav(h, http->path); h = strsav(h, "/"); } } free_http_request(rhttp); fprintf(fp, "%s\n", h); freez(h); fclose(fp); } return(NULL); } } } } trust_url_not_trusted: free_http_request(rhttp); hostport = URL(http->hostport); path = URL(http->path); if(csp->referrer) { referrer = URL(csp->referrer); } else { referrer = URL("undefined"); } n = strlen(CTRUST); n += strlen(hostport); n += strlen(path); n += strlen(referrer); p = malloc(n); sprintf(p, CTRUST, hostport, path, referrer); freez(hostport); freez(path); freez(referrer); return(p); }