[dovecot-cvs] dovecot/src/master imap-process.c,1.11,1.12 settings.c,1.27,1.28 settings.h,1.15,1.16

cras at procontrol.fi cras at procontrol.fi
Thu Dec 12 08:04:32 EET 2002


Update of /home/cvs/dovecot/src/master
In directory danu:/tmp/cvs-serv4349/src/master

Modified Files:
	imap-process.c settings.c settings.h 
Log Message:
New setting: default_mail_env which can be used to specify where to find
users mailbox. Default is still to use autodetection. Authentication process
can override this if needed, it's possible with passwd-file authentication.



Index: imap-process.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/imap-process.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- imap-process.c	1 Dec 2002 13:48:50 -0000	1.11
+++ imap-process.c	12 Dec 2002 06:04:30 -0000	1.12
@@ -2,6 +2,7 @@
 
 #include "common.h"
 #include "env-util.h"
+#include "temp-string.h"
 #include "restrict-access.h"
 #include "restrict-process-size.h"
 
@@ -62,6 +63,44 @@
 	return FALSE;
 }
 
+static const char *expand_mail_env(const char *env, const char *user,
+				   const char *home)
+{
+	TempString *str;
+	const char *p;
+
+	str = t_string_new(256);
+
+	/* it's either type:data or just data */
+	p = strchr(env, ':');
+	if (p != NULL) {
+		while (env != p) {
+			t_string_append_c(str, *env);
+			env++;
+		}
+
+		t_string_append_c(str, *env++);
+	}
+
+	if (env[0] == '~' && env[1] == '/') {
+		/* expand home */
+		t_string_append(str, home);
+		env++;
+	}
+
+	/* expand $U if found */
+	for (; *env != '\0'; env++) {
+		if (*env == '$' && env[1] == 'U') {
+			t_string_append(str, user);
+			env++;
+		} else {
+			t_string_append_c(str, *env);
+		}
+	}
+
+	return str->str;
+}
+
 MasterReplyResult create_imap_process(int socket, IPADDR *ip, const char *user,
 				      uid_t uid, gid_t gid, const char *home,
 				      int chroot, const char *env[])
@@ -69,7 +108,7 @@
 	static char *argv[] = { NULL, "-s", NULL, NULL };
 	char host[MAX_IP_LEN], title[1024];
 	pid_t pid;
-	int i, j, err;
+	int i, j, err, found_mail;
 
 	if (imap_process_count == set_max_imap_processes) {
 		i_error("Maximum number of imap processes exceeded");
@@ -111,9 +150,23 @@
 	(void)close(socket);
 
 	/* setup environment */
-	while (env[0] != NULL && env[1] != NULL) {
+        found_mail = FALSE;
+	for (; env[0] != NULL && env[1] != NULL; env += 2) {
+		if (strcmp(env[0], "MAIL") == 0) {
+			if (env[1] == NULL || *env[1] == '\0')
+				continue;
+
+			found_mail = TRUE;
+		}
+
 		env_put(t_strconcat(env[0], "=", env[1], NULL));
-		env += 2;
+	}
+
+	if (!found_mail) {
+		const char *mail;
+
+		mail = expand_mail_env(set_default_mail_env, user, home);
+		env_put(t_strconcat("MAIL=", mail, NULL));
 	}
 
 	env_put(t_strconcat("HOME=", home, NULL));

Index: settings.c
===================================================================
RCS file: /home/cvs/dovecot/src/master/settings.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- settings.c	6 Dec 2002 01:09:23 -0000	1.27
+++ settings.c	12 Dec 2002 06:04:30 -0000	1.28
@@ -59,6 +59,7 @@
 	{ "last_valid_uid",	SET_INT, &set_last_valid_uid },
 	{ "first_valid_gid",	SET_INT, &set_first_valid_gid },
 	{ "last_valid_gid",	SET_INT, &set_last_valid_gid },
+	{ "default_mail_env",	SET_STR, &set_default_mail_env },
 	{ "mail_cache_fields",	SET_STR, &set_mail_cache_fields },
 	{ "mail_never_cache_fields",
 				SET_STR, &set_mail_never_cache_fields },
@@ -124,6 +125,7 @@
 unsigned int set_first_valid_uid = 500, set_last_valid_uid = 0;
 unsigned int set_first_valid_gid = 1, set_last_valid_gid = 0;
 
+char *set_default_mail_env = NULL;
 char *set_mail_cache_fields = "MessagePart";
 char *set_mail_never_cache_fields = NULL;
 unsigned int set_mailbox_check_interval = 30;

Index: settings.h
===================================================================
RCS file: /home/cvs/dovecot/src/master/settings.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- settings.h	1 Dec 2002 13:48:50 -0000	1.15
+++ settings.h	12 Dec 2002 06:04:30 -0000	1.16
@@ -42,10 +42,12 @@
 extern unsigned int set_first_valid_uid, set_last_valid_uid;
 extern unsigned int set_first_valid_gid, set_last_valid_gid;
 
+extern char *set_default_mail_env;
 extern char *set_mail_cache_fields;
 extern char *set_mail_never_cache_fields;
 extern unsigned int set_mailbox_check_interval;
 extern int set_mail_save_crlf;
+extern int set_mail_read_mmaped;
 extern int set_mail_read_mmaped;
 extern int set_maildir_copy_with_hardlinks;
 extern int set_maildir_check_content_changes;




More information about the dovecot-cvs mailing list