|
Lines 86-91
Link Here
|
| 86 |
request_rec *r; |
86 |
request_rec *r; |
| 87 |
} rpaf_cleanup_rec; |
87 |
} rpaf_cleanup_rec; |
|
|
88 |
inline apr_sockaddr_t * client_addr(conn_rec *c) { |
| 89 |
#if AP_SERVER_MAJORVERSION_NUMBER >= 2 && AP_SERVER_MINORVERSION_NUMBER >= 4 |
| 90 |
return c->client_addr; |
| 91 |
#else |
| 92 |
return c->remote_addr; |
| 93 |
#endif |
| 94 |
} |
| 95 |
|
| 96 |
inline char * client_ip(conn_rec *c) { |
| 97 |
#if AP_SERVER_MAJORVERSION_NUMBER >= 2 && AP_SERVER_MINORVERSION_NUMBER >= 4 |
| 98 |
return c->client_ip; |
| 99 |
#else |
| 100 |
return c->remote_ip; |
| 101 |
#endif |
| 102 |
} |
| 103 |
|
| 104 |
|
| 88 |
static void *rpaf_create_server_cfg(apr_pool_t *p, server_rec *s) { |
105 |
static void *rpaf_create_server_cfg(apr_pool_t *p, server_rec *s) { |
| 89 |
rpaf_server_cfg *cfg = (rpaf_server_cfg *)apr_pcalloc(p, sizeof(rpaf_server_cfg)); |
106 |
rpaf_server_cfg *cfg = (rpaf_server_cfg *)apr_pcalloc(p, sizeof(rpaf_server_cfg)); |
| 90 |
if (!cfg) |
107 |
if (!cfg) |
|
Lines 147-154
Link Here
|
| 147 |
static apr_status_t rpaf_cleanup(void *data) { |
164 |
static apr_status_t rpaf_cleanup(void *data) { |
| 148 |
rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)data; |
165 |
rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)data; |
| 149 |
rcr->r->connection->remote_ip = apr_pstrdup(rcr->r->connection->pool, rcr->old_ip); |
166 |
char *ip = client_ip(rcr->r->connection); |
| 150 |
rcr->r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(rcr->r->connection->remote_ip); |
167 |
ip = apr_pstrdup(rcr->r->connection->pool, rcr->old_ip); |
|
|
168 |
client_addr(rcr->r->connection)->sa.sin.sin_addr.s_addr = apr_inet_addr(ip); |
| 151 |
return APR_SUCCESS; |
169 |
return APR_SUCCESS; |
| 152 |
} |
170 |
} |
|
Lines 161-167
Link Here
|
| 161 |
if (!cfg->enable) |
179 |
if (!cfg->enable) |
| 162 |
return DECLINED; |
180 |
return DECLINED; |
| 163 |
if (is_in_array(r->connection->remote_ip, cfg->proxy_ips) == 1) { |
181 |
if (is_in_array(client_ip(r->connection), cfg->proxy_ips) == 1) { |
| 164 |
/* check if cfg->headername is set and if it is use |
182 |
/* check if cfg->headername is set and if it is use |
| 165 |
that instead of X-Forwarded-For by default */ |
183 |
that instead of X-Forwarded-For by default */ |
| 166 |
if (cfg->headername && (fwdvalue = apr_table_get(r->headers_in, cfg->headername))) { |
184 |
if (cfg->headername && (fwdvalue = apr_table_get(r->headers_in, cfg->headername))) { |
|
Lines 180-190
Link Here
|
| 180 |
if (*fwdvalue != '\0') |
198 |
if (*fwdvalue != '\0') |
| 181 |
++fwdvalue; |
199 |
++fwdvalue; |
| 182 |
} |
200 |
} |
| 183 |
rcr->old_ip = apr_pstrdup(r->connection->pool, r->connection->remote_ip); |
201 |
rcr->old_ip = apr_pstrdup(r->connection->pool, client_ip(r->connection)); |
| 184 |
rcr->r = r; |
202 |
rcr->r = r; |
| 185 |
apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null); |
203 |
apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null); |
| 186 |
r->connection->remote_ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]); |
204 |
char *ip = client_ip(r->connection); |
| 187 |
r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip); |
205 |
ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]); |
|
|
206 |
client_addr(r->connection)->sa.sin.sin_addr.s_addr = apr_inet_addr(client_ip(r->connection)); |
| 188 |
if (cfg->sethostname) { |
207 |
if (cfg->sethostname) { |
| 189 |
const char *hostvalue; |
208 |
const char *hostvalue; |
| 190 |
if (hostvalue = apr_table_get(r->headers_in, "X-Forwarded-Host")) { |
209 |
if (hostvalue = apr_table_get(r->headers_in, "X-Forwarded-Host")) { |