]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added auth_default_realm (based on patch by Kristian Hoffmann)
authorTimo Sirainen <tss@iki.fi>
Wed, 2 Apr 2003 01:00:02 +0000 (04:00 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 2 Apr 2003 01:00:02 +0000 (04:00 +0300)
--HG--
branch : HEAD

dovecot-example.conf
src/auth/mech-digest-md5.c
src/auth/mech-plain.c
src/auth/mech.c
src/auth/mech.h
src/master/auth-process.c
src/master/master-settings.c
src/master/master-settings.h

index 6393bd5b4ba9ef75bf66a2f05853e2075deb3979..0178e17eb2eefa788ca6fd028f4f3305ab4f8650 100644 (file)
@@ -348,15 +348,15 @@ auth = default
 #   plain digest-md5
 auth_mechanisms = plain
 
-# Space separated list of realms with authentication methods that need them.
-# This is usually empty or the host name of the server (eg.
-# mail.mycompany.com).
-#  - plain auth checks the password from all realms specified in here
-#  - digest-md5 must have the password added for each realm separately, and
-#    many clients simply use the first realm listed here. so if you really
-#    need to add more realms, add them to end of the list.
+# Space separated list of realms for SASL authentication mechanisms that need
+# them. You can leave it empty if you don't want to support multiple realms.
+# Many clients simply use the first one listed here, so keep the default realm
+# first.
 #auth_realms =
 
+# Default realm to use if none was specified.
+#auth_default_realm = 
+
 # Where user database is kept:
 #   passwd: /etc/passwd or similiar, using getpwnam()
 #   passwd-file <path>: passwd-like file with specified location
index 9c7844f352f60b7ce24c668154a2fafe3a47cfd5..ab8e506ed17e1d64b4e5783bd1cfeccbe600e2a1 100644 (file)
@@ -551,7 +551,7 @@ mech_digest_md5_auth_continue(struct auth_request *auth_request,
        struct digest_auth_request *auth =
                (struct digest_auth_request *)auth_request;
        struct auth_login_reply reply;
-       const char *error;
+       const char *error, *realm;
 
        /* initialize reply */
        mech_init_login_reply(&reply);
@@ -568,13 +568,14 @@ mech_digest_md5_auth_continue(struct auth_request *auth_request,
                                  request->data_size, &error)) {
                auth_request->callback = callback;
 
-               if (auth->realm == NULL) {
+               realm = auth->realm != NULL ? auth->realm : default_realm;
+               if (realm == NULL) {
                        auth_request->user = p_strdup(auth_request->pool,
                                                      auth->username);
                } else {
                        auth_request->user = p_strconcat(auth_request->pool,
                                                         auth->username, "@",
-                                                        auth->realm, NULL);
+                                                        realm, NULL);
                }
 
                passdb->lookup_credentials(&auth->auth_request,
index 87549c1e1fec38044ec98755d5961b9111a8f2a4..4f92105b6fa2cfb3170d7ae619208c81f07e1afa 100644 (file)
@@ -47,7 +47,15 @@ mech_plain_auth_continue(struct auth_request *auth_request,
                mech_auth_finish(auth_request, NULL, 0, FALSE);
        } else {
                /* split and save user/realm */
-               auth_request->user = p_strdup(auth_request->pool, authenid);
+               if (strchr(authenid, '@') == NULL && default_realm != NULL) {
+                       auth_request->user = p_strconcat(auth_request->pool,
+                                                        authenid, "@",
+                                                        default_realm, NULL);
+               } else {
+                       auth_request->user = p_strdup(auth_request->pool,
+                                                     authenid);
+               }
+
                passdb->verify_plain(auth_request, pass, verify_callback);
 
                /* make sure it's cleared */
index e57809575b1c4e26a3c98ba24b0db0e724071b15..8a0688692a6de778c1765a753ecafdcafca1d7f2 100644 (file)
@@ -17,6 +17,7 @@ struct mech_module_list {
 
 enum auth_mech auth_mechanisms;
 const char *const *auth_realms;
+const char *default_realm;
 
 static int set_use_cyrus_sasl;
 static struct mech_module_list *mech_modules;
@@ -229,6 +230,10 @@ void mech_init(void)
                env = "";
        auth_realms = t_strsplit(env, " ");
 
+       default_realm = getenv("DEFAULT_REALM");
+       if (default_realm != NULL && *default_realm == '\0')
+               default_realm = NULL;
+
        set_use_cyrus_sasl = getenv("USE_CYRUS_SASL") != NULL;
 
 #ifdef USE_CYRUS_SASL2
index c0616327ba7a0b4e3854784515f40048c6008200..1f5024e4aa09f331411949546fc707060d21892a 100644 (file)
@@ -37,6 +37,7 @@ struct mech_module {
 
 extern enum auth_mech auth_mechanisms;
 extern const char *const *auth_realms;
+extern const char *default_realm;
 
 void mech_register_module(struct mech_module *module);
 void mech_unregister_module(struct mech_module *module);
index 327cc30aac4ad9f8a6909223e5101692a5ccd049..882924bbf20de8902dfe262f12e39a3e28f00b13 100644 (file)
@@ -313,6 +313,7 @@ static pid_t create_auth_process(struct auth_process_group *group)
        env_put(t_strconcat("AUTH_PROCESS=", dec2str(getpid()), NULL));
        env_put(t_strconcat("MECHANISMS=", group->set->mechanisms, NULL));
        env_put(t_strconcat("REALMS=", group->set->realms, NULL));
+       env_put(t_strconcat("DEFAULT_REALM=", group->set->default_realm, NULL));
        env_put(t_strconcat("USERDB=", group->set->userdb, NULL));
        env_put(t_strconcat("PASSDB=", group->set->passdb, NULL));
 
index cfdcf09f12ea6ef8382795f455951f67c262382d..8b8f72c86ff444c3e8cebc53799f54b36cf92bdf 100644 (file)
@@ -106,6 +106,7 @@ static struct setting_def login_setting_defs[] = {
 static struct setting_def auth_setting_defs[] = {
        DEF(SET_STR, mechanisms),
        DEF(SET_STR, realms),
+       DEF(SET_STR, default_realm),
        DEF(SET_STR, userdb),
        DEF(SET_STR, passdb),
        DEF(SET_STR, executable),
index 4edbc6176a3e3e7c9bde252f0d962f2c3998e7dd..b8975531fc1012df7bc0f43219a1fda496f74b82 100644 (file)
@@ -92,6 +92,7 @@ struct auth_settings {
        const char *name;
        const char *mechanisms;
        const char *realms;
+       const char *default_realm;
        const char *userdb;
        const char *passdb;
        const char *executable;