From 7289c5600711b45f30fe289ab5b0293b51d87041 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 13 Mar 2010 16:52:50 +0200 Subject: [PATCH] auth: Moved some variables generated from settings to struct auth_settings. --HG-- branch : HEAD --- src/auth/auth-request.c | 17 +++++++++-------- src/auth/auth-settings.c | 20 +++++++++++++++++++- src/auth/auth-settings.h | 5 +++++ src/auth/auth.c | 18 ------------------ src/auth/auth.h | 4 ---- src/auth/mech-digest-md5.c | 4 ++-- src/auth/mech-rpa.c | 2 +- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index df0cc2e052..bec6fbcb56 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -782,21 +782,22 @@ static char * auth_request_fix_username(struct auth_request *request, const char *username, const char **error_r) { + const struct auth_settings *set = request->auth->set; unsigned char *p; - char *user; + char *user; - if (*request->auth->set->default_realm != '\0' && + if (*set->default_realm != '\0' && strchr(username, '@') == NULL) { user = p_strconcat(request->pool, username, "@", - request->auth->set->default_realm, NULL); + set->default_realm, NULL); } else { user = p_strdup(request->pool, username); } for (p = (unsigned char *)user; *p != '\0'; p++) { - if (request->auth->username_translation[*p & 0xff] != 0) - *p = request->auth->username_translation[*p & 0xff]; - if (request->auth->username_chars[*p & 0xff] == 0) { + if (set->username_translation_map[*p & 0xff] != 0) + *p = set->username_translation_map[*p & 0xff]; + if (set->username_chars_map[*p & 0xff] == 0) { *error_r = t_strdup_printf( "Username contains disallowed character: " "0x%02x", *p); @@ -804,7 +805,7 @@ auth_request_fix_username(struct auth_request *request, const char *username, } } - if (*request->auth->set->username_format != '\0') { + if (*set->username_format != '\0') { /* username format given, put it through variable expansion. we'll have to temporarily replace request->user to get %u to be the wanted username */ @@ -817,7 +818,7 @@ auth_request_fix_username(struct auth_request *request, const char *username, dest = t_str_new(256); table = auth_request_get_var_expand_table(request, NULL); - var_expand(dest, request->auth->set->username_format, table); + var_expand(dest, set->username_format, table); user = p_strdup(request->pool, str_c(dest)); request->user = old_username; diff --git a/src/auth/auth-settings.c b/src/auth/auth-settings.c index e7636d3547..d50cd77dfe 100644 --- a/src/auth/auth-settings.c +++ b/src/auth/auth-settings.c @@ -231,15 +231,33 @@ const struct setting_parser_info auth_setting_parser_info = { }; /* */ -static bool auth_settings_check(void *_set, pool_t pool ATTR_UNUSED, +static bool auth_settings_check(void *_set, pool_t pool, const char **error_r ATTR_UNUSED) { struct auth_settings *set = _set; + const char *p; if (set->debug_passwords) set->debug = TRUE; if (set->debug) set->verbose = TRUE; + + if (*set->username_chars == '\0') { + /* all chars are allowed */ + memset(set->username_chars_map, 1, + sizeof(set->username_chars_map)); + } else { + for (p = set->username_chars_map; *p != '\0'; p++) + set->username_chars_map[(int)(uint8_t)*p] = 1; + } + + if (*set->username_translation != '\0') { + p = set->username_translation; + for (; *p != '\0' && p[1] != '\0'; p += 2) + set->username_translation_map[(int)(uint8_t)*p] = p[1]; + } + set->realms_arr = + (const char *const *)p_strsplit_spaces(pool, set->realms, " "); return TRUE; } diff --git a/src/auth/auth-settings.h b/src/auth/auth-settings.h index ca144870b3..3972bb14ec 100644 --- a/src/auth/auth-settings.h +++ b/src/auth/auth-settings.h @@ -43,6 +43,11 @@ struct auth_settings { ARRAY_DEFINE(passdbs, struct auth_passdb_settings *); ARRAY_DEFINE(userdbs, struct auth_userdb_settings *); + + /* generated: */ + char username_chars_map[256]; + char username_translation_map[256]; + const char *const *realms_arr; }; struct auth_settings *auth_settings_read(struct master_service *service); diff --git a/src/auth/auth.c b/src/auth/auth.c index a0da771002..f616b27c7e 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -206,7 +206,6 @@ void auth_init(struct auth *auth) struct auth_userdb *userdb; const struct mech_module *mech; const char *const *mechanisms; - const char *p; for (passdb = auth->masterdbs; passdb != NULL; passdb = passdb->next) passdb_init(passdb); @@ -242,23 +241,6 @@ void auth_init(struct auth *auth) if (auth->mech_modules == NULL) i_fatal("No authentication mechanisms configured"); auth_mech_list_verify_passdb(auth); - - auth->auth_realms = (const char *const *) - p_strsplit_spaces(auth->pool, auth->set->realms, " "); - - if (*auth->set->username_chars == '\0') { - /* all chars are allowed */ - memset(auth->username_chars, 1, sizeof(auth->username_chars)); - } else { - for (p = auth->set->username_chars; *p != '\0'; p++) - auth->username_chars[(int)(uint8_t)*p] = 1; - } - - if (*auth->set->username_translation != '\0') { - p = auth->set->username_translation; - for (; *p != '\0' && p[1] != '\0'; p += 2) - auth->username_translation[(int)(uint8_t)*p] = p[1]; - } } void auth_deinit(struct auth **_auth) diff --git a/src/auth/auth.h b/src/auth/auth.h index a91d8be04a..9e2e28750d 100644 --- a/src/auth/auth.h +++ b/src/auth/auth.h @@ -40,10 +40,6 @@ struct auth { struct auth_passdb *passdbs; struct auth_userdb *userdbs; struct auth_penalty *penalty; - - const char *const *auth_realms; - char username_chars[256]; - char username_translation[256]; }; const string_t *auth_mechanisms_get_list(struct auth *auth); diff --git a/src/auth/mech-digest-md5.c b/src/auth/mech-digest-md5.c index 480d77058c..07976f9293 100644 --- a/src/auth/mech-digest-md5.c +++ b/src/auth/mech-digest-md5.c @@ -84,12 +84,12 @@ static string_t *get_digest_challenge(struct digest_auth_request *request) request->nonce = p_strdup(request->pool, buf.data); str = t_str_new(256); - if (*auth->auth_realms == NULL) { + if (*auth->set->realms_arr == NULL) { /* If no realms are given, at least Cyrus SASL client defaults to destination host name */ str_append(str, "realm=\"\","); } else { - for (tmp = auth->auth_realms; *tmp != NULL; tmp++) + for (tmp = auth->set->realms_arr; *tmp != NULL; tmp++) str_printfa(str, "realm=\"%s\",", *tmp); } diff --git a/src/auth/mech-rpa.c b/src/auth/mech-rpa.c index 0c0c194b50..4977995e4d 100644 --- a/src/auth/mech-rpa.c +++ b/src/auth/mech-rpa.c @@ -337,7 +337,7 @@ mech_rpa_build_token2(struct rpa_auth_request *request, size_t *size) const char *const *tmp; realms = t_str_new(64); - for (tmp = auth->auth_realms; *tmp != NULL; tmp++) { + for (tmp = auth->set->realms_arr; *tmp != NULL; tmp++) { rpa_add_realm(realms, *tmp, request->auth_request.service); } -- 2.47.3