From: Karl Fleischmann Date: Fri, 10 Dec 2021 10:04:06 +0000 (+0100) Subject: login-common: Use base index for aliases X-Git-Tag: 2.3.18~71 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ad1a92aa5e590b1b9274c717e1abc5296118512;p=thirdparty%2Fdovecot%2Fcore.git login-common: Use base index for aliases 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. --- diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 2bf3b4361d..c86a764e7f 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -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);