]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-common: Use base index for aliases
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Fri, 10 Dec 2021 10:04:06 +0000 (11:04 +0100)
committerKarl Fleischmann <karl.fleischmann@open-xchange.com>
Thu, 16 Dec 2021 11:28:35 +0000 (12:28 +0100)
Define a base index for aliases in the login variable table. Assign
values via offset of that base index. This allows adding more values
later without updating any subsequent index.

src/login-common/client-common.c

index 2bf3b4361d0340e92e41887555b1507091f90170..c86a764e7fcf77295d109ae467b586eb7ca6ceb2 100644 (file)
@@ -770,6 +770,10 @@ const char *client_get_session_id(struct client *client)
        return client->session_id;
 }
 
+/* increment index if new proper login variables are added
+ * make sure the aliases stay in the current order */
+#define VAR_EXPAND_ALIAS_INDEX_START 27
+
 static struct var_expand_table login_var_expand_empty_tab[] = {
        { 'u', NULL, "user" },
        { 'n', NULL, "username" },
@@ -843,13 +847,18 @@ get_var_expand_table(struct client *client)
                get_var_expand_users(tab, client->virtual_user);
        tab[3].value = login_binary->protocol;
        tab[4].value = getenv("HOME");
-       tab[27].value = tab[5].value = net_ip2addr(&client->local_ip);
-       tab[28].value = tab[6].value = net_ip2addr(&client->ip);
+       tab[VAR_EXPAND_ALIAS_INDEX_START].value = tab[5].value =
+               net_ip2addr(&client->local_ip);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 1].value = tab[6].value =
+               net_ip2addr(&client->ip);
        tab[7].value = my_pid;
-       tab[35].value = tab[8].value = client->auth_mech_name == NULL ? NULL :
-               str_sanitize(client->auth_mech_name, MAX_MECH_NAME);
-       tab[29].value = tab[9].value = dec2str(client->local_port);
-       tab[30].value = tab[10].value = dec2str(client->remote_port);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 8].value = tab[8].value =
+               client->auth_mech_name == NULL ? NULL :
+                       str_sanitize(client->auth_mech_name, MAX_MECH_NAME);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 2].value = tab[9].value =
+               dec2str(client->local_port);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 3].value = tab[10].value =
+               dec2str(client->remote_port);
        if (!client->tls) {
                tab[11].value = client->secured ? "secured" : NULL;
                tab[12].value = "";
@@ -871,16 +880,20 @@ get_var_expand_table(struct client *client)
        tab[13].value = client->mail_pid == 0 ? "" :
                dec2str(client->mail_pid);
        tab[14].value = client_get_session_id(client);
-       tab[31].value = tab[15].value = net_ip2addr(&client->real_local_ip);
-       tab[32].value = tab[16].value = net_ip2addr(&client->real_remote_ip);
-       tab[33].value = tab[17].value = dec2str(client->real_local_port);
-       tab[34].value = tab[18].value = dec2str(client->real_remote_port);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 4].value = tab[15].value =
+               net_ip2addr(&client->real_local_ip);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 5].value = tab[16].value =
+               net_ip2addr(&client->real_remote_ip);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 6].value = tab[17].value =
+               dec2str(client->real_local_port);
+       tab[VAR_EXPAND_ALIAS_INDEX_START + 7].value = tab[18].value =
+               dec2str(client->real_remote_port);
        if (client->virtual_user_orig != NULL)
                get_var_expand_users(tab+19, client->virtual_user_orig);
        else {
-               tab[36].value = tab[19].value = tab[0].value;
-               tab[37].value = tab[20].value = tab[1].value;
-               tab[38].value = tab[21].value = tab[2].value;
+               tab[VAR_EXPAND_ALIAS_INDEX_START + 9].value = tab[19].value = tab[0].value;
+               tab[VAR_EXPAND_ALIAS_INDEX_START + 10].value = tab[20].value = tab[1].value;
+               tab[VAR_EXPAND_ALIAS_INDEX_START + 11].value = tab[21].value = tab[2].value;
        }
        if (client->virtual_auth_user != NULL)
                get_var_expand_users(tab+22, client->virtual_auth_user);