From 14eae55fef492c3491a6abca0d3dd05c91ab737a Mon Sep 17 00:00:00 2001 From: Valen Blanco Date: Fri, 7 Oct 2016 11:09:50 +0200 Subject: [PATCH] Changed Upstream config directive to support receiving a Base64 string --- src/conf.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/conf.c b/src/conf.c index c003627..4f9e55f 100644 --- a/src/conf.c +++ b/src/conf.c @@ -254,8 +254,8 @@ struct { BEGIN "(no" WS "upstream)" WS STR END, handle_upstream_no, NULL }, { - BEGIN "(upstream)" WS "(" IP "|" ALNUM ")" ":" INT "(" WS STR - ")?" END, handle_upstream, NULL + BEGIN "(upstream)" WS "(" STR "@" ")?" "(" IP "|" ALNUM ")" ":" + INT "(" WS STR ")?" END, handle_upstream, NULL }, #endif /* loglevel */ @@ -1075,22 +1075,31 @@ static HANDLE_FUNC (handle_upstream) char *ip; int port; char *domain; + char *basic_auth = NULL; /* optional, Base64 basic auth */ - ip = get_string_arg (line, &match[2]); + if (match[3].rm_so != -1) { + /* Basic auth is set for upstream proxy. */ + basic_auth = get_string_arg (line, &match[3]); + } + + ip = get_string_arg (line, &match[4]); if (!ip) return -1; - port = (int) get_long_arg (line, &match[7]); + port = (int) get_long_arg (line, &match[9]); - if (match[10].rm_so != -1) { - domain = get_string_arg (line, &match[10]); + if (match[12].rm_so != -1) { + domain = get_string_arg (line, &match[12]); if (domain) { - upstream_add (ip, port, domain, &conf->upstream_list); + upstream_bauth_add (ip, port, basic_auth, domain, + &conf->upstream_list); safefree (domain); } } else { - upstream_add (ip, port, NULL, &conf->upstream_list); + upstream_bauth_add (ip, port, basic_auth, NULL, + &conf->upstream_list); } + safefree (basic_auth); safefree (ip); return 0;