]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Drop username and domain %variable variants
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 10 Oct 2024 11:36:38 +0000 (14:36 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
These can be generated with %{user|username} and %{user|domain}

src/auth/auth-cache.c
src/auth/auth-request-var-expand.c
src/auth/auth-request-var-expand.h
src/auth/auth.c
src/auth/test-auth-cache.c
src/auth/test-auth-request-var-expand.c

index d6790aab253b8ccc23b0d39d45739be3933143a5..156d4fc5c89bd69d8d409e44f029dd714b596804 100644 (file)
@@ -99,18 +99,8 @@ static char *auth_cache_parse_key_exclude(pool_t pool, const char *query,
                }
        }
 
-       if (key_seen[AUTH_REQUEST_VAR_TAB_USERNAME_IDX] &&
-           key_seen[AUTH_REQUEST_VAR_TAB_DOMAIN_IDX]) {
-               /* %n and %d both used -> replace with %u */
-               key_seen[AUTH_REQUEST_VAR_TAB_USER_IDX] = TRUE;
-               key_seen[AUTH_REQUEST_VAR_TAB_USERNAME_IDX] = FALSE;
-               key_seen[AUTH_REQUEST_VAR_TAB_DOMAIN_IDX] = FALSE;
-       }
-
        /* we rely on these being at the beginning */
        i_assert(AUTH_REQUEST_VAR_TAB_USER_IDX == 0);
-       i_assert(AUTH_REQUEST_VAR_TAB_USERNAME_IDX == 1);
-       i_assert(AUTH_REQUEST_VAR_TAB_DOMAIN_IDX == 2);
 
        extra_vars = t_strdup(str_c(str));
        str_truncate(str, 0);
index 5cd6b7e2d026e50de32faf16284102a054bb5a86..77753ff6ed81b5686acbce6a315848cd352daf80 100644 (file)
@@ -14,8 +14,6 @@ struct auth_request_var_expand_ctx {
 const struct var_expand_table
 auth_request_var_expand_static_tab[] = {
        { .key = "user", .value = NULL },
-       { .key = "username", .value = NULL },
-       { .key = "domain", .value = NULL },
        { .key = "protocol", .value = NULL },
        { .key = "home", .value = NULL },
        { .key = "local_ip", .value = NULL },
@@ -29,8 +27,6 @@ auth_request_var_expand_static_tab[] = {
        { .key = "remote_port", .value = NULL },
        { .key = "cert", .value = NULL },
        { .key = "login_user", .value = NULL },
-       { .key = "login_username", .value = NULL },
-       { .key = "login_domain", .value = NULL },
        { .key = "session", .value = NULL },
        { .key = "real_local_ip", .value = NULL },
        { .key = "real_remote_ip", .value = NULL },
@@ -41,11 +37,7 @@ auth_request_var_expand_static_tab[] = {
        { .key = "master_user", .value = NULL },
        { .key = "session_pid", .value = NULL },
        { .key = "original_user", .value = NULL },
-       { .key = "original_username", .value = NULL },
-       { .key = "original_domain", .value = NULL },
        { .key = "auth_user", .value = NULL },
-       { .key = "auth_username", .value = NULL },
-       { .key = "auth_domain", .value = NULL },
        { .key = "local_name", .value = NULL },
        { .key = "client_id", .value = NULL },
        { .key = "ssl_ja3_hash", .value = NULL },
@@ -95,8 +87,6 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request,
                username = "";
 
        var_expand_table_set_value(tab, "user", username);
-       var_expand_table_set_value(tab, "username", t_strcut(username, '@'));
-       var_expand_table_set_value(tab, "domain", i_strchr_to_next(username, '@'));
        var_expand_table_set_value(tab, "protocol", fields->protocol);
        /* tab['home'] = we have no home dir */
        if (fields->local_ip.family != 0) {
@@ -138,15 +128,7 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request,
        var_expand_table_set_value(tab, "cert",
                        fields->valid_client_cert ? "valid" : "");
 
-       if (fields->requested_login_user != NULL) {
-               const char *login_user = fields->requested_login_user;
-
-               var_expand_table_set_value(tab, "login_user", login_user);
-               var_expand_table_set_value(tab, "login_username",
-                                          t_strcut(login_user, '@'));
-               var_expand_table_set_value(tab, "login_domain",
-                                          i_strchr_to_next(login_user, '@'));
-       }
+       var_expand_table_set_value(tab, "login_user", fields->requested_login_user);
 
        var_expand_table_set_value(tab, "session", fields->session_id);
        if (fields->real_local_ip.family != 0) {
@@ -180,18 +162,10 @@ auth_request_get_var_expand_table_full(const struct auth_request *auth_request,
        orig_user = fields->original_username != NULL ?
                fields->original_username : username;
        var_expand_table_set_value(tab, "original_user", orig_user);
-       var_expand_table_set_value(tab, "original_username",
-                                  t_strcut(orig_user, '@'));
-       var_expand_table_set_value(tab, "original_domain",
-                                  i_strchr_to_next(orig_user, '@'));
 
        auth_user = fields->master_user != NULL ?
                fields->master_user : orig_user;
        var_expand_table_set_value(tab, "auth_user", auth_user);
-       var_expand_table_set_value(tab, "auth_username",
-                                  t_strcut(auth_user, '@'));
-       var_expand_table_set_value(tab, "auth_domain",
-                                  i_strchr_to_next(auth_user, '@'));
        var_expand_table_set_value(tab, "local_name", fields->local_name);
        var_expand_table_set_value(tab, "client_id", fields->client_id);
        var_expand_table_set_value(tab, "ssl_ja3_hash", fields->ssl_ja3_hash);
index 9708372fc5187f965bf3721de90aafb593343345..3f4a39400366c7f7c16171d26bb327b7b4bfefb1 100644 (file)
@@ -6,9 +6,7 @@ auth_request_escape_func_t(const char *string,
                           const struct auth_request *auth_request);
 
 #define AUTH_REQUEST_VAR_TAB_USER_IDX 0
-#define AUTH_REQUEST_VAR_TAB_USERNAME_IDX 1
-#define AUTH_REQUEST_VAR_TAB_DOMAIN_IDX 2
-#define AUTH_REQUEST_VAR_TAB_COUNT 37
+#define AUTH_REQUEST_VAR_TAB_COUNT 29
 extern const struct var_expand_table
 auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT+1];
 
index c73dcb27c28f26915f5b3b01a2178bc642b2b59c..e3ae4db347c3c3a19b4297a3ed84234c2773e4dc 100644 (file)
@@ -475,8 +475,6 @@ void auths_init(void)
 
        /* sanity checks */
        i_assert(*auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_USER_IDX].key == 'u');
-       i_assert(*auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_USERNAME_IDX].key == 'u');
-       i_assert(*auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_DOMAIN_IDX].key == 'd');
        i_assert(auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT].key == NULL);
        i_assert(auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT-1].key != NULL);
 
index c1075bdb629563a2dccad50cfbffa45752df9e5e..f7bb5a7d1f7eddfd05ac7397dc28a253e65968f1 100644 (file)
@@ -8,10 +8,7 @@
 
 const struct var_expand_table
 auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT + 1] = {
-       /* these 3 must be in this order */
        { .key = "user", .value = NULL },
-       { .key = "username", .value = NULL },
-       { .key = "domain", .value = NULL },
 
        { .key = "a", .value = NULL },
        { .key = "b", .value = NULL },
@@ -73,11 +70,8 @@ static void test_auth_cache_parse_key(void)
        static const struct {
                const char *in, *out;
        } tests[] = {
-               { "%{username}@%{domain}", "%{user}" },
-               { "%{username}@%{domain}", "%{user}" },
-               { "%{username}%{domain}%{user}", "%{user}" },
-               { "%{username}", "%{username}" },
-               { "%{domain}", "%{domain}" },
+               { "%{user|username}", "%{user}" },
+               { "%{user|domain}", "%{user}" },
                { "%{a}%{b}%{user}", "%{user}\t%{a}\t%{b}" },
 
                { "foo%{a | substr(5, 5) }bar", "%{a}" },
index 9cf26397f3446c7df24eb83944ad0f4c3c0ac21a..6a4ba82a705ed15283d595bae56c85b97b562c30 100644 (file)
@@ -85,7 +85,7 @@ static bool test_empty_request(string_t *str, const char *input)
 static void test_auth_request_var_expand_keys(void)
 {
        static const char *test_input_long =
-               "%{user}\n%{username}\n%{domain}\n%{protocol}\n%{home}\n"
+               "%{user}\n%{user | username}\n%{user | domain}\n%{protocol}\n%{home}\n"
                "%{local_ip}\n%{remote_ip}\n"
                "%{client_pid}\n%{password}\n%{mechanism}\n%{secured}\n"
                "%{local_port}\n%{remote_port}\n%{cert}\n";
@@ -151,11 +151,11 @@ static void test_auth_request_var_expand_flags(void)
 static void test_auth_request_var_expand_long(void)
 {
        static const char *test_input =
-               "%{login_user}\n%{login_username}\n%{login_domain}\n%{session}\n"
+               "%{login_user}\n%{login_user | username}\n%{login_user | domain}\n%{session}\n"
                "%{real_local_ip}\n%{real_remote_ip}\n"
                "%{real_local_port}\n%{real_remote_port}\n"
                "%{master_user}\n%{session_pid}\n"
-               "%{original_user}\n%{original_username}\n%{original_domain}\n";
+               "%{original_user}\n%{original_user | username}\n%{original_user | domain}\n";
        static const char *test_output =
                "+loginuser@+logindomain1@+logindomain2\n+loginuser\n+logindomain1@+logindomain2\n+session\n"
                "13.81.174.20\n13.81.174.21\n"
@@ -190,7 +190,7 @@ static void test_auth_request_var_expand_usernames(void)
                { "-foo@-domain1@-domain2", "+foo\n+domain1@+domain2\n+domain1\n+domain2\n+foo@+domain1@+domain2" }
        };
        static const char *test_input =
-               "%{username}\n%{domain}\n%{domain_first}\n%{domain_last}\n%{user}";
+               "%{user | username}\n%{user | domain}\n%{domain_first}\n%{domain_last}\n%{user}";
        string_t *str = t_str_new(64);
        const char *error;
        unsigned int i;