From 59ec5dc69fc6719c445155bca1259ad96fc9ae1e Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Wed, 4 Dec 2002 17:36:48 +0000 Subject: (strip_username_password): New function to remove any username/password part from the host URI. (extract_http_url), (extract_ssl_url): Use the new strip_username_password function to remove any non-host information from the URI. --- src/reqs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/reqs.c b/src/reqs.c index d2fd7e3..1f3a9f1 100644 --- a/src/reqs.c +++ b/src/reqs.c @@ -1,4 +1,4 @@ -/* $Id: reqs.c,v 1.88 2002-12-04 17:06:13 rjkaes Exp $ +/* $Id: reqs.c,v 1.89 2002-12-04 17:36:48 rjkaes Exp $ * * This is where all the work in tinyproxy is actually done. Incoming * connections have a new child created for them. The child then @@ -189,6 +189,26 @@ free_request_struct(struct request_s *request) safefree(request); } +/* + * Take a host string and if there is a username/password part, strip + * it off. + */ +static void +strip_username_password(char* host) +{ + char *ptr1, *ptr2; + + if ((ptr1 = strchr(host, '@')) != NULL) { + ptr1++; /* move to one past the @ symbol */ + ptr2 = host; + + /* copy the bytes up to the NUL */ + while (*ptr1) + *ptr2++ = *ptr1++; + *ptr2 = '\0'; + } +} + /* * Pull the information out of the URL line. This will handle both HTTP * and FTP (proxied) URLs. @@ -218,6 +238,9 @@ extract_http_url(const char *url, struct request_s *request) goto ERROR_EXIT; } + /* Remove the username/password if they're present */ + strip_username_password(request->host); + return 0; ERROR_EXIT: @@ -249,6 +272,9 @@ extract_ssl_url(const char *url, struct request_s *request) return -1; } + /* Remove the username/password if they're present */ + strip_username_password(request->host); + return 0; } -- cgit v1.2.3