# HG changeset patch # User Timo Sirainen # Date 1224938562 -10800 # Node ID c7d14e00c1583390e66fb9649ee4251662487321 # Parent a3df5b1eac6d2678986c1470927b135a47774c8b If a missing home directory is tried to be used, fail the namespace creation. 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 @@ 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 @@ 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 @@ /* */ 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,23 +156,29 @@ } 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; + } } if (set->index_dir != NULL && strcmp(set->index_dir, "MEMORY") == 0)