]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-auth: Add auth_proxy_parse_redirect()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 17 Jun 2021 14:26:20 +0000 (17:26 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
src/lib-auth/auth-proxy.c
src/lib-auth/auth-proxy.h

index 29d075dcafb53ff23c48766252ce01348cd78416..b76ce3795b5950e672c9fdf9264e563e30bf39a1 100644 (file)
@@ -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;
+}
index 90e5f655bfd7df274b503de8df0631b843cdd948..57dcc264ef5b1865e5bd3158de7ebc6621c2e9c7 100644 (file)
@@ -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