static apr_status_t rpaf_cleanup(void *data) { rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)data; rcr->r->connection->remote_ip = (char *)rcr->old_ip; rcr->r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(rcr->r->connection->remote_ip); rcr->r->connection->remote_addr->sa.sin.sin_family = rcr->old_family; return APR_SUCCESS; }
static int change_remote_ip(request_rec *r) { const char *fwdvalue; char *val; rpaf_server_cfg *cfg = (rpaf_server_cfg *)ap_get_module_config(r->server->module_config, &rpaf_module); if (!cfg->enable) return DECLINED; if (cfg->remote_addr_env) { apr_table_set(r->subprocess_env, cfg->remote_addr_env, r->connection->remote_ip); } if (is_in_array(r->connection->remote_ip, cfg->proxy_ips) == 1) { /* check if cfg->headername is set and if it is use that instead of X-Forwarded-For by default */ if (cfg->headername && (fwdvalue = apr_table_get(r->headers_in, cfg->headername))) { // } else if ((fwdvalue = apr_table_get(r->headers_in, "X-Forwarded-For"))) { // } else { return DECLINED; } if (fwdvalue) { rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)apr_pcalloc(r->pool, sizeof(rpaf_cleanup_rec)); apr_array_header_t *arr = apr_array_make(r->pool, 0, sizeof(char*)); while (*fwdvalue && (val = ap_get_token(r->pool, &fwdvalue, 1))) { *(char **)apr_array_push(arr) = apr_pstrdup(r->pool, val); if (*fwdvalue != '\0') ++fwdvalue; } rcr->old_ip = r->connection->remote_ip; rcr->old_family = r->connection->remote_addr->sa.sin.sin_family; rcr->r = r; apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null); r->connection->remote_ip = apr_pstrdup(r->pool, extract_ip(arr, cfg->proxy_ips, cfg->recursive)); r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip); r->connection->remote_addr->sa.sin.sin_family = AF_INET; if (cfg->sethostname) { const char *hostvalue; if ((hostvalue = apr_table_get(r->headers_in, "X-Forwarded-Host"))) { /* 2.0 proxy frontend or 1.3 => 1.3.25 proxy frontend */ apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue)); r->hostname = apr_pstrdup(r->pool, hostvalue); ap_update_vhost_from_headers(r); } else if ((hostvalue = apr_table_get(r->headers_in, "X-Host"))) { /* 1.3 proxy frontend with mod_proxy_add_forward */ apr_table_set(r->headers_in, "Host", apr_pstrdup(r->pool, hostvalue)); r->hostname = apr_pstrdup(r->pool, hostvalue); ap_update_vhost_from_headers(r); } } } } return DECLINED; }
static apr_status_t rpaf_cleanup(void *data) { rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)data; rcr->r->connection->remote_ip = apr_pstrdup(rcr->r->connection->pool, rcr->old_ip); rcr->r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(rcr->r->connection->remote_ip); return APR_SUCCESS; }