Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4168:3f27bf7832a2 HEAD
Added auth_username_format setting.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 12 Apr 2006 17:36:58 +0300 |
parents | 32dd28f96dce |
children | 8686345192e8 |
files | dovecot-example.conf src/auth/auth-request.c src/auth/auth.c src/auth/auth.h src/master/auth-process.c src/master/master-settings.c src/master/master-settings.h |
diffstat | 7 files changed, 42 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Wed Apr 12 17:04:55 2006 +0300 +++ b/dovecot-example.conf Wed Apr 12 17:36:58 2006 +0300 @@ -617,6 +617,12 @@ # that '#' and '/' characters are translated to '@'. #auth_username_translation = +# Username formatting before it's looked up from databases. You can use +# the standard variables here, eg. %Lu would lowercase the username, %n would +# drop away the domain if it was given, or "%n-AT-%d" would change the '@' into +# "-AT-". This translation is done after auth_username_translation changes. +#auth_username_format = + # If you want to allow master users to log in by specifying the master # username within the normal username string (ie. not using SASL mechanism's # support for it), you can specify the separator character here. The format
--- a/src/auth/auth-request.c Wed Apr 12 17:04:55 2006 +0300 +++ b/src/auth/auth-request.c Wed Apr 12 17:36:58 2006 +0300 @@ -7,6 +7,7 @@ #include "str.h" #include "safe-memset.h" #include "str-sanitize.h" +#include "strescape.h" #include "var-expand.h" #include "auth-request.h" #include "auth-client-connection.h" @@ -554,7 +555,29 @@ *error_r = "Username contains disallowed characters"; return NULL; } - } + } + + if (request->auth->username_format != NULL) { + /* username format given, put it through variable expansion. + we'll have to temporarily replace request->user to get + %u to be the wanted username */ + const struct var_expand_table *table; + char *old_username; + string_t *dest; + + old_username = request->user; + request->user = user; + + t_push(); + dest = t_str_new(256); + table = auth_request_get_var_expand_table(request, str_escape); + var_expand(dest, request->auth->username_format, table); + user = p_strdup(request->pool, str_c(dest)); + t_pop(); + + request->user = old_username; + } + return user; }
--- a/src/auth/auth.c Wed Apr 12 17:04:55 2006 +0300 +++ b/src/auth/auth.c Wed Apr 12 17:36:58 2006 +0300 @@ -225,9 +225,9 @@ env = ""; auth->auth_realms = t_strsplit_spaces(env, " "); - auth->default_realm = getenv("DEFAULT_REALM"); - if (auth->default_realm != NULL && *auth->default_realm == '\0') - auth->default_realm = NULL; + env = getenv("DEFAULT_REALM"); + if (env != NULL && *env != '\0') + auth->default_realm = env; env = getenv("USERNAME_CHARS"); if (env == NULL || *env == '\0') { @@ -244,6 +244,10 @@ auth->username_translation[(int)(uint8_t)*env] = env[1]; } + env = getenv("USERNAME_FORMAT"); + if (env != NULL && *env != '\0') + auth->username_format = env; + env = getenv("MASTER_USER_SEPARATOR"); if (env != NULL) auth->master_user_separator = env[0];
--- a/src/auth/auth.h Wed Apr 12 17:04:55 2006 +0300 +++ b/src/auth/auth.h Wed Apr 12 17:36:58 2006 +0300 @@ -43,6 +43,7 @@ const char *const *auth_realms; const char *default_realm; const char *anonymous_username; + const char *username_format; char username_chars[256]; char username_translation[256]; char master_user_separator;
--- a/src/master/auth-process.c Wed Apr 12 17:04:55 2006 +0300 +++ b/src/master/auth-process.c Wed Apr 12 17:36:58 2006 +0300 @@ -420,8 +420,7 @@ env_put(t_strconcat("USERNAME_CHARS=", set->username_chars, NULL)); env_put(t_strconcat("USERNAME_TRANSLATION=", set->username_translation, NULL)); - env_put(t_strconcat("USERNAME_TRANSLATION=", - set->username_translation, NULL)); + env_put(t_strconcat("USERNAME_FORMAT=", set->username_format, NULL)); env_put(t_strconcat("MASTER_USER_SEPARATOR=", set->master_user_separator, NULL)); env_put(t_strdup_printf("CACHE_SIZE=%u", set->cache_size));
--- a/src/master/master-settings.c Wed Apr 12 17:04:55 2006 +0300 +++ b/src/master/master-settings.c Wed Apr 12 17:36:58 2006 +0300 @@ -169,6 +169,7 @@ DEF(SET_STR, chroot), DEF(SET_STR, username_chars), DEF(SET_STR, username_translation), + DEF(SET_STR, username_format), DEF(SET_STR, master_user_separator), DEF(SET_STR, anonymous_username), DEF(SET_STR, krb5_keytab), @@ -380,6 +381,7 @@ MEMBER(chroot) NULL, MEMBER(username_chars) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@", MEMBER(username_translation) "", + MEMBER(username_format) "", MEMBER(master_user_separator) NULL, MEMBER(anonymous_username) "anonymous", MEMBER(krb5_keytab) NULL,
--- a/src/master/master-settings.h Wed Apr 12 17:04:55 2006 +0300 +++ b/src/master/master-settings.h Wed Apr 12 17:36:58 2006 +0300 @@ -174,6 +174,7 @@ const char *chroot; const char *username_chars; const char *username_translation; + const char *username_format; const char *master_user_separator; const char *anonymous_username; const char *krb5_keytab;