dovecot-1.2: If a missing home directory is tried to be used, fa...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 25 15:42:48 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/c7d14e00c158
changeset: 8329:c7d14e00c158
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 25 15:42:42 2008 +0300
description:
If a missing home directory is tried to be used, fail the namespace creation.

diffstat:

1 file changed, 26 insertions(+), 11 deletions(-)
src/lib-storage/mailbox-list.c |   37 ++++++++++++++++++++++++++-----------

diffs (81 lines):

diff -r a3df5b1eac6d -r c7d14e00c158 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Sat Oct 25 15:42:03 2008 +0300
+++ b/src/lib-storage/mailbox-list.c	Sat Oct 25 15:42:42 2008 +0300
@@ -108,13 +108,17 @@ int mailbox_list_alloc(const char *drive
 	return 0;
 }
 
-static const char *fix_path(struct mail_namespace *ns, const char *path)
+static int fix_path(struct mail_namespace *ns, const char *path,
+		    const char **path_r)
 {
 	size_t len = strlen(path);
 
 	if (len > 1 && path[len-1] == '/')
 		path = t_strndup(path, len-1);
-	return mail_user_home_expand(ns->user, path);
+	if (mail_user_try_home_expand(ns->user, &path) < 0)
+		return -1;
+	*path_r = path;
+	return 0;
 }
 
 int mailbox_list_settings_parse(const char *data,
@@ -123,7 +127,7 @@ int mailbox_list_settings_parse(const ch
 				const char **layout, const char **alt_dir_r,
 				const char **error_r)
 {
-	const char *const *tmp, *key, *value;
+	const char *const *tmp, *key, *value, **dest;
 
 	i_assert(*data != '\0');
 
@@ -133,7 +137,12 @@ int mailbox_list_settings_parse(const ch
 
 	/* <root dir> */
 	tmp = t_strsplit(data, ":");
-	set->root_dir = fix_path(ns, *tmp);
+	if (fix_path(ns, *tmp, &set->root_dir) < 0) {
+		*error_r = t_strdup_printf(
+			"Home directory not set, can't expand ~/ for "
+			"mail root dir in: %s", data);
+		return -1;
+	}
 	tmp++;
 
 	for (; *tmp != NULL; tmp++) {
@@ -147,21 +156,27 @@ int mailbox_list_settings_parse(const ch
 		}
 
 		if (strcmp(key, "INBOX") == 0)
-			set->inbox_path = fix_path(ns, value);
+			dest = &set->inbox_path;
 		else if (strcmp(key, "INDEX") == 0)
-			set->index_dir = fix_path(ns, value);
+			dest = &set->index_dir;
 		else if (strcmp(key, "CONTROL") == 0)
-			set->control_dir = fix_path(ns, value);
+			dest = &set->control_dir;
 		else if (strcmp(key, "ALT") == 0 && alt_dir_r != NULL)
-			*alt_dir_r = fix_path(ns, value);
+			dest = alt_dir_r;
 		else if (strcmp(key, "LAYOUT") == 0)
-			*layout = value;
+			dest = layout;
 		else if (strcmp(key, "SUBSCRIPTIONS") == 0)
-			set->subscription_fname = fix_path(ns, value);
+			dest = &set->subscription_fname;
 		else if (strcmp(key, "DIRNAME") == 0)
-			set->maildir_name = value;
+			dest = &set->maildir_name;
 		else {
 			*error_r = t_strdup_printf("Unknown setting: %s", key);
+			return -1;
+		}
+		if (fix_path(ns, value, dest) < 0) {
+			*error_r = t_strdup_printf(
+				"Home directory not set, can't expand ~/ for "
+				"%s in: %s", key, data);
 			return -1;
 		}
 	}


More information about the dovecot-cvs mailing list