dovecot-2.0: auth: Moved some variables generated from settings ...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Mar 13 16:53:44 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/9675d9a54ac9
changeset: 10892:9675d9a54ac9
user: Timo Sirainen <tss at iki.fi>
date: Sat Mar 13 16:52:50 2010 +0200
description:
auth: Moved some variables generated from settings to struct auth_settings.
diffstat:
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(-)
diffs (182 lines):
diff -r f2b9387ba047 -r 9675d9a54ac9 src/auth/auth-request.c
--- a/src/auth/auth-request.c Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/auth-request.c Sat Mar 13 16:52:50 2010 +0200
@@ -782,21 +782,22 @@
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 @@
}
}
- 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 @@
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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/auth-settings.c
--- a/src/auth/auth-settings.c Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/auth-settings.c Sat Mar 13 16:52:50 2010 +0200
@@ -231,15 +231,33 @@
};
/* <settings checks> */
-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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/auth-settings.h
--- a/src/auth/auth-settings.h Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/auth-settings.h Sat Mar 13 16:52:50 2010 +0200
@@ -43,6 +43,11 @@
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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/auth.c
--- a/src/auth/auth.c Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/auth.c Sat Mar 13 16:52:50 2010 +0200
@@ -206,7 +206,6 @@
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 @@
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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/auth.h
--- a/src/auth/auth.h Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/auth.h Sat Mar 13 16:52:50 2010 +0200
@@ -40,10 +40,6 @@
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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/mech-digest-md5.c
--- a/src/auth/mech-digest-md5.c Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/mech-digest-md5.c Sat Mar 13 16:52:50 2010 +0200
@@ -84,12 +84,12 @@
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 -r f2b9387ba047 -r 9675d9a54ac9 src/auth/mech-rpa.c
--- a/src/auth/mech-rpa.c Sat Mar 13 15:25:44 2010 +0200
+++ b/src/auth/mech-rpa.c Sat Mar 13 16:52:50 2010 +0200
@@ -337,7 +337,7 @@
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);
}
More information about the dovecot-cvs
mailing list