dovecot-2.2: lib-storage: Removed mailbox list backend-specific ...

dovecot at dovecot.org dovecot at dovecot.org
Tue Sep 25 21:45:17 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/3e6048697365
changeset: 15104:3e6048697365
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Sep 25 21:45:00 2012 +0300
description:
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
The virtual name validity is independent of the backend. The physical name
is always used for paths in filesystem, so it can also be verified with
common code. Backend's mailbox_dir and storage's internal directories can
also be checked. There's nothing else left really.

diffstat:

 src/lib-storage/index/imapc/imapc-list.c    |   24 ---
 src/lib-storage/index/shared/shared-list.c  |   33 -----
 src/lib-storage/list/mailbox-list-fs.c      |   98 ---------------
 src/lib-storage/list/mailbox-list-fs.h      |    4 -
 src/lib-storage/list/mailbox-list-maildir.c |   91 --------------
 src/lib-storage/list/mailbox-list-maildir.h |    4 -
 src/lib-storage/list/mailbox-list-none.c    |   24 ---
 src/lib-storage/mail-storage.c              |  181 +++++++++++++++++----------
 src/lib-storage/mailbox-list-private.h      |    6 -
 src/lib-storage/mailbox-list.c              |   53 +++++++-
 10 files changed, 159 insertions(+), 359 deletions(-)

diffs (truncated from 754 to 300 lines):

diff -r fbc90337b48c -r 3e6048697365 src/lib-storage/index/imapc/imapc-list.c
--- a/src/lib-storage/index/imapc/imapc-list.c	Tue Sep 25 21:31:41 2012 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Tue Sep 25 21:45:00 2012 +0300
@@ -161,27 +161,6 @@
 					imapc_untagged_lsub);
 }
 
-static bool
-imapc_is_valid_pattern(struct mailbox_list *list ATTR_UNUSED,
-		       const char *pattern ATTR_UNUSED)
-{
-	return TRUE;
-}
-
-static bool
-imapc_is_valid_existing_name(struct mailbox_list *list ATTR_UNUSED,
-			     const char *name ATTR_UNUSED)
-{
-	return TRUE;
-}
-
-static bool
-imapc_is_valid_create_name(struct mailbox_list *list ATTR_UNUSED,
-			   const char *name ATTR_UNUSED)
-{
-	return TRUE;
-}
-
 static char imapc_list_get_hierarchy_sep(struct mailbox_list *_list)
 {
 	struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list;
@@ -700,9 +679,6 @@
 		imapc_list_alloc,
 		imapc_list_deinit,
 		NULL,
-		imapc_is_valid_pattern,
-		imapc_is_valid_existing_name,
-		imapc_is_valid_create_name,
 		imapc_list_get_hierarchy_sep,
 		imapc_list_get_vname,
 		imapc_list_get_storage_name,
diff -r fbc90337b48c -r 3e6048697365 src/lib-storage/index/shared/shared-list.c
--- a/src/lib-storage/index/shared/shared-list.c	Tue Sep 25 21:31:41 2012 +0300
+++ b/src/lib-storage/index/shared/shared-list.c	Tue Sep 25 21:45:00 2012 +0300
@@ -54,36 +54,6 @@
 	return 0;
 }
 
-static bool
-shared_is_valid_pattern(struct mailbox_list *list, const char *pattern)
-{
-	struct mail_namespace *ns = list->ns;
-
-	if (shared_storage_get_namespace(&ns, &pattern) < 0)
-		return FALSE;
-	return mailbox_list_is_valid_pattern(ns->list, pattern);
-}
-
-static bool
-shared_is_valid_existing_name(struct mailbox_list *list, const char *name)
-{
-	struct mail_namespace *ns = list->ns;
-
-	if (shared_storage_get_namespace(&ns, &name) < 0)
-		return FALSE;
-	return mailbox_list_is_valid_existing_name(ns->list, name);
-}
-
-static bool
-shared_is_valid_create_name(struct mailbox_list *list, const char *name)
-{
-	struct mail_namespace *ns = list->ns;
-
-	if (shared_storage_get_namespace(&ns, &name) < 0)
-		return FALSE;
-	return mailbox_list_is_valid_create_name(ns->list, name);
-}
-
 static char shared_list_get_hierarchy_sep(struct mailbox_list *list ATTR_UNUSED)
 {
 	return '/';
@@ -337,9 +307,6 @@
 		shared_list_alloc,
 		shared_list_deinit,
 		shared_get_storage,
-		shared_is_valid_pattern,
-		shared_is_valid_existing_name,
-		shared_is_valid_create_name,
 		shared_list_get_hierarchy_sep,
 		mailbox_list_default_get_vname,
 		mailbox_list_default_get_storage_name,
diff -r fbc90337b48c -r 3e6048697365 src/lib-storage/list/mailbox-list-fs.c
--- a/src/lib-storage/list/mailbox-list-fs.c	Tue Sep 25 21:31:41 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-fs.c	Tue Sep 25 21:45:00 2012 +0300
@@ -41,101 +41,6 @@
 	pool_unref(&list->list.pool);
 }
 
-static bool fs_list_is_valid_common(const char *name, size_t *len_r)
-{
-	*len_r = strlen(name);
-
-	if (name[0] == '\0' || name[*len_r-1] == '/')
-		return FALSE;
-	return TRUE;
-}
-
-static bool
-fs_list_is_valid_common_nonfs(struct mailbox_list *list, const char *name)
-{
-	bool ret, allow_internal_dirs;
-
-	/* make sure it's not absolute path */
-	if (*name == '/' || *name == '~')
-		return FALSE;
-
-	/* make sure the mailbox name doesn't contain any foolishness:
-	   "../" could give access outside the mailbox directory.
-	   "./" and "//" could fool ACL checks. */
-	allow_internal_dirs = list->v.is_internal_name == NULL ||
-		*list->set.maildir_name != '\0';
-	T_BEGIN {
-		const char *const *names;
-
-		names = t_strsplit(name, "/");
-		for (; *names != NULL; names++) {
-			const char *n = *names;
-
-			if (*n == '\0')
-				break; /* // */
-			if (*n == '.') {
-				if (n[1] == '\0')
-					break; /* ./ */
-				if (n[1] == '.' && n[2] == '\0')
-					break; /* ../ */
-			}
-			if (*list->set.maildir_name != '\0' &&
-			    strcmp(list->set.maildir_name, n) == 0) {
-				/* don't allow maildir_name to be used as part
-				   of the mailbox name */
-				break;
-			}
-			if (!allow_internal_dirs &&
-			    list->v.is_internal_name(list, n))
-				break;
-		}
-		ret = *names == NULL;
-	} T_END;
-
-	return ret;
-}
-
-static bool
-fs_is_valid_pattern(struct mailbox_list *list, const char *pattern)
-{
-	if (list->mail_set->mail_full_filesystem_access)
-		return TRUE;
-
-	return fs_list_is_valid_common_nonfs(list, pattern);
-}
-
-static bool
-fs_is_valid_existing_name(struct mailbox_list *list, const char *name)
-{
-	size_t len;
-
-	if (!fs_list_is_valid_common(name, &len))
-		return FALSE;
-
-	if (list->mail_set->mail_full_filesystem_access)
-		return TRUE;
-
-	return fs_list_is_valid_common_nonfs(list, name);
-}
-
-static bool
-fs_is_valid_create_name(struct mailbox_list *list, const char *name)
-{
-	size_t len;
-
-	if (!fs_list_is_valid_common(name, &len))
-		return FALSE;
-	if (len > FS_MAX_CREATE_MAILBOX_NAME_LENGTH)
-		return FALSE;
-
-	if (list->mail_set->mail_full_filesystem_access)
-		return TRUE;
-
-	if (mailbox_list_name_is_too_large(name, '/'))
-		return FALSE;
-	return fs_list_is_valid_common_nonfs(list, name);
-}
-
 static char fs_list_get_hierarchy_sep(struct mailbox_list *list ATTR_UNUSED)
 {
 	return '/';
@@ -605,9 +510,6 @@
 		fs_list_alloc,
 		fs_list_deinit,
 		NULL,
-		fs_is_valid_pattern,
-		fs_is_valid_existing_name,
-		fs_is_valid_create_name,
 		fs_list_get_hierarchy_sep,
 		mailbox_list_default_get_vname,
 		mailbox_list_default_get_storage_name,
diff -r fbc90337b48c -r 3e6048697365 src/lib-storage/list/mailbox-list-fs.h
--- a/src/lib-storage/list/mailbox-list-fs.h	Tue Sep 25 21:31:41 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-fs.h	Tue Sep 25 21:45:00 2012 +0300
@@ -3,10 +3,6 @@
 
 #include "mailbox-list-private.h"
 
-/* Don't allow creating too long mailbox names. They could start causing
-   problems when they reach the limit. */
-#define FS_MAX_CREATE_MAILBOX_NAME_LENGTH (MAILBOX_LIST_NAME_MAX_LENGTH/2)
-
 /* When doing deletion via renaming it first to trash directory, use this as
    the trash directory name */
 #define MAILBOX_LIST_FS_TRASH_DIR_NAME "..DOVECOT-TrasH"
diff -r fbc90337b48c -r 3e6048697365 src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c	Tue Sep 25 21:31:41 2012 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Tue Sep 25 21:45:00 2012 +0300
@@ -92,91 +92,6 @@
 					     p+1);
 }
 
-static bool
-maildir_list_is_valid_common(struct maildir_mailbox_list *list,
-			     const char *name, size_t *len_r)
-{
-	size_t len;
-
-	/* check that there are no adjacent hierarchy separators */
-	for (len = 0; name[len] != '\0'; len++) {
-		if (name[len] == list->sep &&
-		    name[len+1] == list->sep)
-			return FALSE;
-	}
-
-	if (len == 0 || name[len-1] == '/')
-		return FALSE;
-
-	if (name[0] == list->sep ||
-	    name[len-1] == list->sep)
-		return FALSE;
-
-	*len_r = len;
-	return TRUE;
-}
-
-static bool maildir_list_is_valid_common_nonfs(const char *name)
-{
-	if (*name == '~' || strchr(name, '/') != NULL)
-		return FALSE;
-
-	if (name[0] == '.' && (name[1] == '\0' ||
-			       (name[1] == '.' && name[2] == '\0'))) {
-		/* "." and ".." aren't allowed. */
-		return FALSE;
-	}
-	return TRUE;
-}
-
-static bool
-maildir_is_valid_existing_name(struct mailbox_list *_list, const char *name)
-{
-	struct maildir_mailbox_list *list =
-		(struct maildir_mailbox_list *)_list;
-	size_t len;
-
-	if (!maildir_list_is_valid_common(list, name, &len))
-		return FALSE;
-
-	if (_list->mail_set->mail_full_filesystem_access)
-		return TRUE;
-
-	return maildir_list_is_valid_common_nonfs(name);
-}
-
-static bool
-maildir_is_valid_pattern(struct mailbox_list *list, const char *pattern)
-{
-	/* maildir code itself doesn't care about this, but we may get here
-	   from listing subscriptions to LAYOUT=fs namespace containing
-	   entries for a subscriptions=no LAYOUT=maildir++ namespace */
-	return maildir_is_valid_existing_name(list, pattern);
-}
-
-static bool
-maildir_is_valid_create_name(struct mailbox_list *_list, const char *name)
-{
-	struct maildir_mailbox_list *list =
-		(struct maildir_mailbox_list *)_list;
-	size_t len;
-
-	if (!maildir_list_is_valid_common(list, name, &len))
-		return FALSE;
-	if (len > MAILDIR_MAX_CREATE_MAILBOX_NAME_LENGTH)
-		return FALSE;


More information about the dovecot-cvs mailing list