From: Timo Sirainen Date: Thu, 17 Jun 2021 14:26:20 +0000 (+0300) Subject: lib-auth: Add auth_proxy_parse_redirect() X-Git-Tag: 2.4.0~4802 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e279f5aead1090304a7f019c3f75b033e664b15d;p=thirdparty%2Fdovecot%2Fcore.git lib-auth: Add auth_proxy_parse_redirect() --- diff --git a/src/lib-auth/auth-proxy.c b/src/lib-auth/auth-proxy.c index 29d075dcaf..b76ce3795b 100644 --- a/src/lib-auth/auth-proxy.c +++ b/src/lib-auth/auth-proxy.c @@ -76,3 +76,24 @@ int auth_proxy_settings_parse(struct auth_proxy_settings *set, pool_t pool, return 0; return 1; } + +bool auth_proxy_parse_redirect(const char *target, + const char **destuser_r, + const char **host_r, struct ip_addr *ip_r, + in_port_t *port_r) +{ + const char *p; + + p = strrchr(target, '@'); + if (p == NULL) + *destuser_r = NULL; + else { + *destuser_r = t_strdup_until(target, p); + target = p+1; + } + if (net_str2hostport(target, 0, host_r, port_r) < 0) + return FALSE; + if (net_addr2ip(*host_r, ip_r) < 0) + return FALSE; + return TRUE; +} diff --git a/src/lib-auth/auth-proxy.h b/src/lib-auth/auth-proxy.h index 90e5f655bf..57dcc264ef 100644 --- a/src/lib-auth/auth-proxy.h +++ b/src/lib-auth/auth-proxy.h @@ -59,4 +59,10 @@ int auth_proxy_settings_parse(struct auth_proxy_settings *set, pool_t pool, const char *key, const char *value, const char **error_r); +/* Parse [user@]ip[:port] string. Note that host must currently always be IP. */ +bool auth_proxy_parse_redirect(const char *target, + const char **destuser_r, + const char **host_r, struct ip_addr *ip_r, + in_port_t *port_r); + #endif