- rediff
[packages/apache1-mod_rpaf.git] / mod_rpaf_degtine.patch
1 --- mod_rpaf-0.6/mod_rpaf-2.0.c 2008-01-01 05:05:40.000000000 +0200
2 +++ mod_rpaf-0.6-degtine/mod_rpaf-2.0.c 2008-01-14 12:47:44.248571877 +0200
3 @@ -152,6 +152,16 @@
4      return APR_SUCCESS;
5  }
6  
7 +static char* last_not_in_array(apr_array_header_t *forwarded_for,
8 +                              apr_array_header_t *proxy_ips) {
9 +    int i;
10 +    for (i = (forwarded_for->nelts)-1; i > 0; i--) {
11 +       if (!is_in_array(((char **)forwarded_for->elts)[i], proxy_ips))
12 +           break;
13 +    }
14 +    return ((char **)forwarded_for->elts)[i];
15 +}
16 +
17  static int change_remote_ip(request_rec *r) {
18      const char *fwdvalue;
19      char *val;
20 @@ -183,7 +193,7 @@
21              rcr->old_ip = apr_pstrdup(r->connection->pool, r->connection->remote_ip);
22              rcr->r = r;
23              apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null);
24 -            r->connection->remote_ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]);
25 +            r->connection->remote_ip = apr_pstrdup(r->connection->pool, last_not_in_array(arr, cfg->proxy_ips));
26              r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip);
27              if (cfg->sethostname) {
28                  const char *hostvalue;
29 --- mod_rpaf-0.6/mod_rpaf.c     2008-01-01 05:03:15.000000000 +0200
30 +++ mod_rpaf-0.6-degtine/mod_rpaf.c     2008-01-14 12:47:44.248571877 +0200
31 @@ -148,7 +148,25 @@
32  static void rpaf_cleanup(void *data) {
33      rpaf_cleanup_rec *rcr = (rpaf_cleanup_rec *)data;
34      rcr->r->connection->remote_ip   = ap_pstrdup(rcr->r->connection->pool, rcr->old_ip);
35 +#ifdef INET6
36 +       switch (rcr->r->connection->remote_addr.ss_family) {
37 +       case AF_INET:
38 +               inet_pton(AF_INET, rcr->r->connection->remote_ip, &((struct sockaddr_in*)&rcr->r->connection->remote_addr)->sin_addr.s_addr);
39 +               break;
40 +       }
41 +#else
42      rcr->r->connection->remote_addr.sin_addr.s_addr = inet_addr(rcr->r->connection->remote_ip);
43 +#endif
44 +}
45 +
46 +static char* last_not_in_array(array_header *forwarded_for,
47 +                              array_header *proxy_ips) {
48 +    int i;
49 +    for (i = (forwarded_for->nelts)-1; i > 0; i--) {
50 +       if (!is_in_array(((char **)forwarded_for->elts)[i], proxy_ips))
51 +           break;
52 +    }
53 +    return ((char **)forwarded_for->elts)[i];
54  }
55  
56  static int change_remote_ip(request_rec *r) {
57 @@ -182,8 +200,17 @@
58              rcr->old_ip = ap_pstrdup(r->connection->pool, r->connection->remote_ip);
59              rcr->r = r;
60              ap_register_cleanup(r->pool, (void *)rcr, rpaf_cleanup, ap_null_cleanup);
61 -            r->connection->remote_ip = ap_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]);
62 -            r->connection->remote_addr.sin_addr.s_addr = inet_addr(r->connection->remote_ip);
63 +            r->connection->remote_ip = ap_pstrdup(r->connection->pool, last_not_in_array(arr, cfg->proxy_ips));
64 +#ifdef INET6
65 +                       switch (r->connection->remote_addr.ss_family) {
66 +                       case AF_INET:
67 +                               inet_pton(AF_INET, r->connection->remote_ip, &((struct sockaddr_in*)&r->connection->remote_addr)->sin_addr.s_addr);
68 +                               break;
69 +                       }
70 +#else
71 +                       r->connection->remote_addr.sin_addr.s_addr = inet_addr(r->connection->remote_ip);
72 +#endif
73 +
74              if (cfg->sethostname) {
75                  const char *hostvalue;
76                  if (hostvalue = ap_table_get(r->headers_in, "X-Forwarded-Host")) {
This page took 0.036631 seconds and 3 git commands to generate.