Skip to content

Commit

Permalink
Add support for ipv6
Browse files Browse the repository at this point in the history
fix logs

FIX ident
  • Loading branch information
Steffen Greber committed Jun 4, 2021
1 parent a25093a commit 0c7f5c2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,27 @@ static const char* oidc_get_current_url_scheme(const request_rec *r) {
return scheme_str;
}

/*
* get the Port part that is currently being accessed
*/
static const char* oidc_get_port_from_host( const char *host_hdr){
char *p = NULL;
char *i = NULL;

if (host_hdr) {
if (host_hdr[0]=='[') {
i = strchr(host_hdr, ']');
p = strchr(i, OIDC_CHAR_COLON);
} else {
p = strchr(host_hdr, OIDC_CHAR_COLON);
}
}
if (p)
return p;
else
return NULL;
}

/*
* get the URL port that is currently being accessed
*/
Expand All @@ -407,7 +428,7 @@ static const char* oidc_get_current_url_port(const request_rec *r,
*/
const char *host_hdr = oidc_util_hdr_in_x_forwarded_host_get(r);
if (host_hdr) {
port_str = strchr(host_hdr, OIDC_CHAR_COLON);
port_str = oidc_get_port_from_host(host_hdr);
if (port_str)
port_str++;
return port_str;
Expand All @@ -419,7 +440,7 @@ static const char* oidc_get_current_url_port(const request_rec *r,
*/
host_hdr = oidc_util_hdr_in_host_get(r);
if (host_hdr) {
port_str = strchr(host_hdr, OIDC_CHAR_COLON);
port_str = oidc_get_port_from_host(host_hdr);
if (port_str) {
port_str++;
return port_str;
Expand Down Expand Up @@ -452,13 +473,22 @@ static const char* oidc_get_current_url_port(const request_rec *r,
*/
const char* oidc_get_current_url_host(request_rec *r) {
const char *host_str = oidc_util_hdr_in_x_forwarded_host_get(r);
char *p = NULL;
char *i = NULL;
if (host_str == NULL)
host_str = oidc_util_hdr_in_host_get(r);
if (host_str) {
host_str = apr_pstrdup(r->pool, host_str);
char *p = strchr(host_str, OIDC_CHAR_COLON);
if (p != NULL)
*p = '\0';

if (host_str[0] == '[') {
i= strchr(host_str, ']');
p = strchr(i, OIDC_CHAR_COLON);
} else {
p = strchr(host_str, OIDC_CHAR_COLON);
}

if (p != NULL)
*p = '\0';
} else {
/* no Host header, HTTP 1.0 */
host_str = ap_get_server_name(r);
Expand Down
10 changes: 10 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,16 @@ static char * test_current_url(request_rec *r) {
TST_ASSERT_STR("test_current_url (8)", url,
"http://remotehost:8380/private/?foo=bar&param1=value1");

apr_table_set(r->headers_in, "Host", "[fd04:41b1:1170:28:16b0:446b:9fb7:7118]:8380");
url = oidc_get_current_url(r);
TST_ASSERT_STR("test_current_url (9)", url,
"http://[fd04:41b1:1170:28:16b0:446b:9fb7:7118]:8380/private/?foo=bar&param1=value1");

apr_table_set(r->headers_in, "Host", "[fd04:41b1:1170:28:16b0:446b:9fb7:7118]");
url = oidc_get_current_url(r);
TST_ASSERT_STR("test_current_url (10)", url,
"http://[fd04:41b1:1170:28:16b0:446b:9fb7:7118]/private/?foo=bar&param1=value1");

return 0;
}

Expand Down

0 comments on commit 0c7f5c2

Please sign in to comment.