*** mod_proxy.c Fri Apr 7 21:17:37 2006 --- mod_proxy.c.johnc Tue Apr 11 16:06:55 2006 *************** *** 451,456 **** --- 451,461 ---- ps->cache.cache_completion = (float)DEFAULT_CACHE_COMPLETION; ps->cache.cache_completion_set = 0; + /* johnc@grok.org.uk - setup AllowReferer and AllowUserAgent */ + ps->allowedrefs = ap_make_array(p, 10, sizeof(struct allowedrefs_entry)); + ps->alloweduas = ap_make_array(p, 10, sizeof(struct alloweduas_entry)); + ps->allowedaccepts = ap_make_array(p, 10, sizeof(struct allowedaccepts_entry)); + return ps; } *************** *** 487,492 **** --- 492,502 ---- ps->cache.dirlength = (overrides->cache.dirlength_set == 0) ? base->cache.dirlength : overrides->cache.dirlength; ps->cache.cache_completion = (overrides->cache.cache_completion_set == 0) ? base->cache.cache_completion : overrides->cache.cache_completion; + /* johnc@grok.org.uk - setup AllowReferer and AllowUserAgent*/ + ps->allowedrefs = ap_append_arrays(p, base->allowedrefs, overrides->allowedrefs); + ps->alloweduas = ap_append_arrays(p, base->alloweduas, overrides->alloweduas); + ps->allowedaccepts = ap_append_arrays(p, base->allowedaccepts, overrides->allowedaccepts); + return ps; } *************** *** 842,848 **** --- 852,958 ---- return NULL; } + static const char * + set_allowed_referer(cmd_parms *parms, void *dummy, char *arg) + { + server_rec *s = parms->server; + proxy_server_conf *conf = ap_get_module_config(s->module_config, &proxy_module); + struct allowedrefs_entry *new; + struct allowedrefs_entry *list = (struct allowedrefs_entry *) conf->allowedrefs->elts; + struct hostent hp; + int found = 0; + int i; + + /* Don't duplicate entries */ + for (i = 0; i < conf->allowedrefs->nelts; i++) { + if (strcasecmp(arg, list[i].name) == 0) /* ignore case for host names */ + found = 1; + } + + if (!found) { + new = ap_push_array(conf->allowedrefs); + new->name = arg; + /* Don't do name lookups on things that aren't dotted */ + if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL) + /* + * @@@FIXME: This copies only the first of (possibly many) IP + * addrs + */ + memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr)); + else + new->addr.s_addr = 0; + } + return NULL; + } + static const char * + set_allowed_useragent(cmd_parms *parms, void *dummy, char *arg) + { + server_rec *s = parms->server; + proxy_server_conf *conf = ap_get_module_config(s->module_config, &proxy_module); + struct alloweduas_entry *new; + struct alloweduas_entry *list = (struct alloweduas_entry *) conf->alloweduas->elts; + struct hostent hp; + int found = 0; + int i; + + /* Don't duplicate entries */ + for (i = 0; i < conf->alloweduas->nelts; i++) { + if (strcasecmp(arg, list[i].name) == 0) /* ignore case for host names */ + found = 1; + } + + if (!found) { + new = ap_push_array(conf->alloweduas); + new->name = arg; + /* Don't do name lookups on things that aren't dotted */ + if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL) + /* + * @@@FIXME: This copies only the first of (possibly many) IP + * addrs + */ + memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr)); + else + new->addr.s_addr = 0; + } + return NULL; + } + + static const char * + set_allowed_accept(cmd_parms *parms, void *dummy, char *arg) + { + server_rec *s = parms->server; + proxy_server_conf *conf = ap_get_module_config(s->module_config, &proxy_module); + struct allowedaccepts_entry *new; + struct allowedaccepts_entry *list = (struct allowedaccepts_entry *) conf->allowedaccepts->elts; + struct hostent hp; + int found = 0; + int i; + + /* Don't duplicate entries */ + for (i = 0; i < conf->allowedaccepts->nelts; i++) { + if (strcasecmp(arg, list[i].name) == 0) /* ignore case for host names */ + found = 1; + } + + if (!found) { + new = ap_push_array(conf->allowedaccepts); + new->name = arg; + /* Don't do name lookups on things that aren't dotted */ + if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL) + /* + * @@@FIXME: This copies only the first of (possibly many) IP + * addrs + */ + memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr)); + else + new->addr.s_addr = 0; + } + return NULL; + } + + + static const char * set_recv_buffer_size(cmd_parms *parms, void *dummy, char *arg) { proxy_server_conf *psf = *************** *** 960,965 **** --- 1070,1081 ---- "Force a http cache completion after this percentage is loaded"}, {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1, "Configure Via: proxy header header to one of: on | off | block | full"}, + {"AllowReferer", set_allowed_referer, NULL, RSRC_CONF, ITERATE, + "A list of names, hosts or domains for which referers are provided"}, + {"AllowUserAgent", set_allowed_useragent, NULL, RSRC_CONF, ITERATE, + "A list of names, hosts or domains for which user agents are provided"}, + {"AllowAccept", set_allowed_accept, NULL, RSRC_CONF, ITERATE, + "A list of names, hosts or domains for which Accept-* headers are provided"}, {NULL} };