gnif/mod_rpaf — pull request #16 by mpdude (2014-09-02 13:36:00+00:00)
Title: Apache 2.4 compatibility

Currently, this module does not compile for Apache 2.4 - but I would like to see support for it! :+1:

mod_rpaf has a unique selling point, namely the ability to read the X-Forwarded-Port/X-Forwarded-Proto headers. That allows to use Amazon EC2's Elastic Load Balancers for transparent SSL termination: http://www.webfactory.de/blog/transparent-ssl-termination-on-amazon-elb-with-mod-rpaf

mod_remoteip seems to be the favored solution contained in the Apache core, but it is not capable of handling this setup.

Here are the API changes: http://httpd.apache.org/docs/2.4/developer/new_api_2_4.html

The following patch at least allows me to compile the module, but I haven't yet had the possiblity to test it in any way...

```c
diff --git a/mod_rpaf.c b/mod_rpaf.c
index 5ce4071..9973c2c 100644
--- a/mod_rpaf.c
+++ b/mod_rpaf.c
@@ -166,8 +166,8 @@ static int is_in_array(apr_pool_t *pool, const char *remote_ip, apr_array_header

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);
+ rcr->r->connection->client_ip = apr_pstrdup(rcr->r->connection->pool, rcr->old_ip);
+ rcr->r->connection->client_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(rcr->r->connection->client_ip);
return APR_SUCCESS;
}

@@ -191,7 +191,7 @@ static int change_remote_ip(request_rec *r) {
if (!cfg->enable)
return DECLINED;

- if (is_in_array(r->pool, r->connection->remote_ip, cfg->proxy_ips) == 1) {
+ if (is_in_array(r->pool, r->connection->client_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))) {
@@ -210,11 +210,11 @@ static int change_remote_ip(request_rec *r) {
if (*fwdvalue != '\0')
++fwdvalue;
}
- rcr->old_ip = apr_pstrdup(r->connection->pool, r->connection->remote_ip);
+ rcr->old_ip = apr_pstrdup(r->connection->pool, r->connection->client_ip);
rcr->r = r;
apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null);
- r->connection->remote_ip = apr_pstrdup(r->connection->pool, last_not_in_array(r->pool, arr, cfg->proxy_ips));
- r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip);
+ r->connection->client_ip = apr_pstrdup(r->connection->pool, last_not_in_array(r->pool, arr, cfg->proxy_ips));
+ r->connection->client_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->client_ip);

if (cfg->sethostname) {
const char *hostvalue;
`````