changeset 1328:0a524d229f50 HEAD

Added auth_default_realm (based on patch by Kristian Hoffmann)
author Timo Sirainen <tss@iki.fi>
date Wed, 02 Apr 2003 04:00:02 +0300
parents 36ba64c5dbb2
children ae229b7acb4c
files 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
diffstat 8 files changed, 29 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/dovecot-example.conf	Tue Apr 01 17:55:48 2003 +0300
+++ b/dovecot-example.conf	Wed Apr 02 04:00:02 2003 +0300
@@ -348,15 +348,15 @@
 #   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
--- a/src/auth/mech-digest-md5.c	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/auth/mech-digest-md5.c	Wed Apr 02 04:00:02 2003 +0300
@@ -551,7 +551,7 @@
 	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 @@
 				  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,
--- a/src/auth/mech-plain.c	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/auth/mech-plain.c	Wed Apr 02 04:00:02 2003 +0300
@@ -47,7 +47,15 @@
 		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 */
--- a/src/auth/mech.c	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/auth/mech.c	Wed Apr 02 04:00:02 2003 +0300
@@ -17,6 +17,7 @@
 
 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 @@
 		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
--- a/src/auth/mech.h	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/auth/mech.h	Wed Apr 02 04:00:02 2003 +0300
@@ -37,6 +37,7 @@
 
 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);
--- a/src/master/auth-process.c	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/master/auth-process.c	Wed Apr 02 04:00:02 2003 +0300
@@ -313,6 +313,7 @@
 	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));
 
--- a/src/master/master-settings.c	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/master/master-settings.c	Wed Apr 02 04:00:02 2003 +0300
@@ -106,6 +106,7 @@
 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),
--- a/src/master/master-settings.h	Tue Apr 01 17:55:48 2003 +0300
+++ b/src/master/master-settings.h	Wed Apr 02 04:00:02 2003 +0300
@@ -92,6 +92,7 @@
 	const char *name;
 	const char *mechanisms;
 	const char *realms;
+	const char *default_realm;
 	const char *userdb;
 	const char *passdb;
 	const char *executable;