branch Attitude Adjustment packages
[12.09/packages.git] / net / tinyproxy / patches / 040-fix_url_filter_in_transparent_mode.patch
1 From e0cf6d4b0c84da6273c127a8c87076aac3b51588 Mon Sep 17 00:00:00 2001
2 From: Daniel Egger <daniel.egger@sphairon.com>
3 Date: Mon, 16 Aug 2010 22:36:20 +0200
4 Subject: [PATCH 3/3] Pass a pointer to a char pointer to do_transparent_proxy so the reassembled URL
5  will actually end up back in the caller where it is needed for filtering
6  decisions. This fixes the problem that a tinyproxy configured with the
7  transparent proxy functionality and "FilterURLs Yes" would filter on everything
8  but the domain.
9
10 Signed-off-by: daniel.egger@sphairon.com
11 ---
12  src/reqs.c              |    2 +-
13  src/transparent-proxy.c |   20 ++++++++++----------
14  src/transparent-proxy.h |    2 +-
15  3 files changed, 12 insertions(+), 12 deletions(-)
16
17 --- a/src/reqs.c
18 +++ b/src/reqs.c
19 @@ -418,7 +418,7 @@ BAD_REQUEST_ERROR:
20          } else {
21  #ifdef TRANSPARENT_PROXY
22                  if (!do_transparent_proxy
23 -                    (connptr, hashofheaders, request, &config, url)) {
24 +                    (connptr, hashofheaders, request, &config, &url)) {
25                          goto fail;
26                  }
27  #else
28 --- a/src/transparent-proxy.c
29 +++ b/src/transparent-proxy.c
30 @@ -55,11 +55,11 @@ static int build_url (char **url, const 
31  int
32  do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
33                        struct request_s *request, struct config_s *conf,
34 -                      char *url)
35 +                      char **url)
36  {
37          socklen_t length;
38          char *data;
39 -        size_t ulen = strlen (url);
40 +        size_t ulen = strlen (*url);
41  
42          length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
43          if (length <= 0) {
44 @@ -73,7 +73,7 @@ do_transparent_proxy (struct conn_s *con
45                                       connptr->client_fd);
46                          indicate_http_error (connptr, 400, "Bad Request",
47                                               "detail", "Unknown destination",
48 -                                             "url", url, NULL);
49 +                                             "url", *url, NULL);
50                          return 0;
51                  }
52  
53 @@ -83,15 +83,15 @@ do_transparent_proxy (struct conn_s *con
54                  request->port = ntohs (dest_addr.sin_port);
55  
56                  request->path = (char *) safemalloc (ulen + 1);
57 -                strlcpy (request->path, url, ulen + 1);
58 +                strlcpy (request->path, *url, ulen + 1);
59  
60                  /* url overwritten by the call below is the url passed
61                   * to this function, and is not the url variable in the
62                   * caller. */
63 -                build_url (&url, request->host, request->port, request->path);
64 +                build_url (url, request->host, request->port, request->path);
65                  log_message (LOG_INFO,
66                               "process_request: trans IP %s %s for %d",
67 -                             request->method, url, connptr->client_fd);
68 +                             request->method, *url, connptr->client_fd);
69          } else {
70                  request->host = (char *) safemalloc (length + 1);
71                  if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
72 @@ -101,15 +101,15 @@ do_transparent_proxy (struct conn_s *con
73                  }
74  
75                  request->path = (char *) safemalloc (ulen + 1);
76 -                strlcpy (request->path, url, ulen + 1);
77 +                strlcpy (request->path, *url, ulen + 1);
78  
79                  /* url overwritten by the call below is the url passed
80                   * to this function, and is not the url variable in the
81                   * caller. */
82 -                build_url (&url, request->host, request->port, request->path);
83 +                build_url (url, request->host, request->port, request->path);
84                  log_message (LOG_INFO,
85                               "process_request: trans Host %s %s for %d",
86 -                             request->method, url, connptr->client_fd);
87 +                             request->method, *url, connptr->client_fd);
88          }
89          if (conf->ipAddr && strcmp (request->host, conf->ipAddr) == 0) {
90                  log_message (LOG_ERR,
91 @@ -118,7 +118,7 @@ do_transparent_proxy (struct conn_s *con
92                  indicate_http_error (connptr, 400, "Bad Request",
93                                       "detail",
94                                       "You tried to connect to the machine "
95 -                                     "the proxy is running on", "url", url,
96 +                                     "the proxy is running on", "url", *url,
97                                       NULL);
98                  return 0;
99          }
100 --- a/src/transparent-proxy.h
101 +++ b/src/transparent-proxy.h
102 @@ -32,7 +32,7 @@
103  extern int do_transparent_proxy (struct conn_s *connptr,
104                                   hashmap_t hashofheaders,
105                                   struct request_s *request,
106 -                                 struct config_s *config, char *url);
107 +                                 struct config_s *config, char **url);
108  
109  #endif
110