1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
From: Toni Uhlig <matzeton@googlemail.com>
Date: Thu, 18 Jan 2018 19:46:58 +0100
Subject: Add support for used defined base URI
* fixed two possible memory leaks in htc
* fixed compiler warning in hts for uid
Applied-Upstream: commit:f440dcb3c341d22428898952c343ad9fa6e9e7f5
---
common.h | 1 +
htc.c | 21 +++++++++++++++++++--
hts.c | 2 +-
http.c | 2 +-
http.h | 1 +
tunnel.c | 28 ++++++++++++++++++++++++++++
tunnel.h | 6 ++++++
7 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/common.h b/common.h
index 745bcfd..5c2d376 100644
--- a/common.h
+++ b/common.h
@@ -27,6 +27,7 @@ Copyright (C) 1999 Lars Brinkhoff. See COPYING for terms and conditions.
#define DEFAULT_CONTENT_LENGTH (100 * 1024) /* bytes */
#define DEFAULT_KEEP_ALIVE 5 /* seconds */
#define DEFAULT_MAX_CONNECTION_AGE 300 /* seconds */
+#define DEFAULT_BASE_URI "/index.html?crap="
#define BUG_REPORT_EMAIL "bug-httptunnel@gnu.org"
#ifndef TRUE
diff --git a/htc.c b/htc.c
index 2fdd301..97d9b04 100644
--- a/htc.c
+++ b/htc.c
@@ -41,6 +41,7 @@ typedef struct
int max_connection_age;
char *proxy_authorization;
char *user_agent;
+ const char *base_uri;
} Arguments;
#define NO_PROXY_BUFFER 0
@@ -84,13 +85,15 @@ usage (FILE *f, const char *me)
" -T, --timeout TIME timeout, in milliseconds, before sending\n"
" padding to a buffering proxy\n"
" -U, --user-agent STRING specify User-Agent value in HTTP requests\n"
+" -R, --base-uri STRING specify a URI value for all HTTP requests\n"
+" (default is \"%s\")\n"
" -V, --version output version information and exit\n"
" -w, --no-daemon don't fork into the background\n"
"\n"
"Report bugs to %s.\n",
me, DEFAULT_HOST_PORT, DEFAULT_KEEP_ALIVE,
DEFAULT_MAX_CONNECTION_AGE, DEFAULT_PROXY_PORT,
- BUG_REPORT_EMAIL);
+ DEFAULT_BASE_URI, BUG_REPORT_EMAIL);
}
static int
@@ -132,6 +135,7 @@ parse_arguments (int argc, char **argv, Arguments *arg)
arg->max_connection_age = DEFAULT_CONNECTION_MAX_TIME;
arg->proxy_authorization = NULL;
arg->user_agent = NULL;
+ arg->base_uri = DEFAULT_BASE_URI;
for (;;)
{
@@ -151,6 +155,7 @@ parse_arguments (int argc, char **argv, Arguments *arg)
{ "timeout", required_argument, 0, 'T' },
{ "keep-alive", required_argument, 0, 'k' },
{ "user-agent", required_argument, 0, 'U' },
+ { "base-uri", required_argument, 0, 'R' },
{ "forward-port", required_argument, 0, 'F' },
{ "content-length", required_argument, 0, 'c' },
{ "strict-content-length", no_argument, 0, 'S' },
@@ -161,7 +166,7 @@ parse_arguments (int argc, char **argv, Arguments *arg)
{ 0, 0, 0, 0 }
};
- static const char *short_options = "A:B:c:d:F:hk:M:P:sST:U:Vwz:"
+ static const char *short_options = "A:B:c:d:F:hk:M:P:sST:U:R:Vwz:"
#ifdef DEBUG_MODE
"D:l:"
#endif
@@ -257,6 +262,10 @@ parse_arguments (int argc, char **argv, Arguments *arg)
arg->user_agent = optarg;
break;
+ case 'R':
+ arg->base_uri = optarg;
+ break;
+
case 'V':
printf ("htc (%s) %s\n", PACKAGE, VERSION);
exit (0);
@@ -435,6 +444,7 @@ main (int argc, char **argv)
log_notice (" proxy_authorization = %s",
arg.proxy_authorization ? arg.proxy_authorization : "(null)");
log_notice (" user_agent = %s", arg.user_agent ? arg.user_agent : "(null)");
+ log_notice (" base_uri = %s", arg.base_uri ? arg.base_uri : "(null)");
log_notice (" debug_level = %d", debug_level);
@@ -582,6 +592,13 @@ main (int argc, char **argv)
strerror (errno));
}
+ if (arg.base_uri != NULL)
+ {
+ if (tunnel_setopt (tunnel, "base_uri", (void *)arg.base_uri) == -1)
+ log_error ("tunnel_setopt base_uri error: %s",
+ strerror (errno));
+ }
+
if (tunnel_connect (tunnel) == -1)
{
log_error ("couldn't open tunnel: %s", strerror (errno));
diff --git a/hts.c b/hts.c
index 1d7ef3a..b0ae68b 100644
--- a/hts.c
+++ b/hts.c
@@ -298,7 +298,7 @@ main (int argc, char **argv)
Arguments arg;
Tunnel *tunnel;
FILE *pid_file;
- uid_t uid;
+ uid_t uid = 0;
gid_t gid;
parse_arguments (argc, argv, &arg);
diff --git a/http.c b/http.c
index ec153b7..ef2833e 100644
--- a/http.c
+++ b/http.c
@@ -31,7 +31,7 @@ http_method (int fd, Http_destination *dest,
n = 0;
if (dest->proxy_name != NULL)
n = sprintf (str, "http://%s:%d", dest->host_name, dest->host_port);
- sprintf (str + n, "/index.html?crap=%ld", time (NULL));
+ sprintf (str + n, "%s%ld", dest->base_uri, time (NULL));
request = http_create_request (method, str, 1, 1);
if (request == NULL)
diff --git a/http.h b/http.h
index bb7188a..a4053f0 100644
--- a/http.h
+++ b/http.h
@@ -53,6 +53,7 @@ typedef struct
int proxy_port;
const char *proxy_authorization;
const char *user_agent;
+ const char *base_uri;
} Http_destination;
extern ssize_t http_get (int fd, Http_destination *dest);
diff --git a/tunnel.c b/tunnel.c
index 370bfc0..304ba59 100644
--- a/tunnel.c
+++ b/tunnel.c
@@ -1322,6 +1322,7 @@ tunnel_new_client (const char *host, int host_port,
tunnel->dest.proxy_port = proxy_port;
tunnel->dest.proxy_authorization = NULL;
tunnel->dest.user_agent = NULL;
+ tunnel->dest.base_uri = NULL;
/* -1 to allow for TUNNEL_DISCONNECT */
tunnel->content_length = content_length - 1;
tunnel->buf_ptr = tunnel->buf;
@@ -1363,6 +1364,15 @@ tunnel_destroy (Tunnel *tunnel)
if (tunnel->server_socket != -1)
close (tunnel->server_socket);
+ if (tunnel->dest.proxy_authorization)
+ free ((char *)tunnel->dest.proxy_authorization);
+
+ if (tunnel->dest.user_agent)
+ free ((char *)tunnel->dest.user_agent);
+
+ if (tunnel->dest.base_uri)
+ free ((char *)tunnel->dest.base_uri);
+
free (tunnel);
}
@@ -1426,6 +1436,24 @@ tunnel_opt (Tunnel *tunnel, const char *opt, void *data, int get_flag)
return -1;
}
}
+ else if (strcmp (opt, "base_uri") == 0)
+ {
+ if (get_flag)
+ {
+ if (tunnel->dest.base_uri == NULL)
+ *(char **)data = NULL;
+ else
+ *(char **)data = strdup (tunnel->dest.base_uri);
+ }
+ else
+ {
+ if (tunnel->dest.base_uri != NULL)
+ free ((char *)tunnel->dest.base_uri);
+ tunnel->dest.base_uri = strdup ((char *)data);
+ if (tunnel->dest.base_uri == NULL)
+ return -1;
+ }
+ }
else
{
errno = EINVAL;
diff --git a/tunnel.h b/tunnel.h
index 8e770f8..f9e7c4e 100644
--- a/tunnel.h
+++ b/tunnel.h
@@ -91,6 +91,12 @@ int tunnel_getopt (Tunnel *tunnel, const char *opt, void *data);
copied into a newly malloced memory region which the caller must
accept responsibility to manage.
+ * base_uri
+
+ DATA must be a pointer to a char pointer. The char pointer
+ specifies the base URI for every tunnel requests/responses. When
+ this option is not set, the default value is used.
+
int tunnel_close (Tunnel *tunnel);
Close the tunnel.
|