changeset 809:27554afad17e HEAD

Limit the mailbox path. A few cleanups.
author Timo Sirainen <tss@iki.fi>
date Thu, 19 Dec 2002 03:53:19 +0200
parents 574a18ea05d6
children 30f6811f4952
files src/imap/commands-util.c src/lib-storage/index/mbox/mbox-list.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-storage.c
diffstat 4 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/commands-util.c	Thu Dec 19 03:04:02 2002 +0200
+++ b/src/imap/commands-util.c	Thu Dec 19 03:53:19 2002 +0200
@@ -5,6 +5,12 @@
 #include "commands-util.h"
 #include "imap-util.h"
 
+/* Maximum length for mailbox name, including it's path. This isn't fully
+   exact since the user can create folder hierarchy with small names, then
+   rename them to larger names. Mail storages should set more strict limits
+   to them, mbox/maildir currently allow paths only up to PATH_MAX. */
+#define MAILBOX_MAX_NAME_LEN 512
+
 int client_verify_mailbox_name(Client *client, const char *mailbox,
 			       int should_exist, int should_not_exist)
 {
@@ -28,6 +34,11 @@
 		}
 	}
 
+	if (strlen(mailbox) > MAILBOX_MAX_NAME_LEN) {
+		client_send_tagline(client, "NO Mailbox name too long.");
+		return FALSE;
+	}
+
 	/* check what our storage thinks of it */
 	if (!client->storage->get_mailbox_name_status(client->storage, mailbox,
 						      &mailbox_status)) {
--- a/src/lib-storage/index/mbox/mbox-list.c	Thu Dec 19 03:04:02 2002 +0200
+++ b/src/lib-storage/index/mbox/mbox-list.c	Thu Dec 19 03:53:19 2002 +0200
@@ -98,7 +98,7 @@
 			break;
 		}
 
-		if (stat(fullpath, &st) != 0) {
+		if (stat(fullpath, &st) < 0) {
 			if (errno == ENOENT)
 				continue; /* just deleted, ignore */
 
--- a/src/lib-storage/index/mbox/mbox-save.c	Thu Dec 19 03:04:02 2002 +0200
+++ b/src/lib-storage/index/mbox/mbox-save.c	Thu Dec 19 03:53:19 2002 +0200
@@ -91,7 +91,7 @@
 			name = my_hostname;
 		}
 
-		strocpy(my_hostdomain, name, 256);
+		strocpy(my_hostdomain, name, sizeof(my_hostdomain));
 	}
 
 	sender = t_strconcat(storage->user, "@", my_hostdomain, NULL);
--- a/src/lib-storage/index/mbox/mbox-storage.c	Thu Dec 19 03:04:02 2002 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Thu Dec 19 03:53:19 2002 +0200
@@ -107,12 +107,10 @@
 
 static int mbox_is_valid_name(MailStorage *storage, const char *name)
 {
-	if (name[0] == '\0' || name[0] == storage->hierarchy_sep ||
-	    name[strlen(name)-1] == storage->hierarchy_sep ||
-	    strchr(name, '*') != NULL || strchr(name, '%') != NULL)
-		return FALSE;
-
-	return mbox_is_valid_mask(name);
+	return name[0] != '\0' && name[0] != storage->hierarchy_sep &&
+		name[strlen(name)-1] != storage->hierarchy_sep &&
+		strchr(name, '*') == NULL && strchr(name, '%') == NULL &&
+		mbox_is_valid_mask(name);
 }
 
 static const char *mbox_get_index_dir(const char *mbox_path)
@@ -121,7 +119,7 @@
 
 	p = strrchr(mbox_path, '/');
 	if (p == NULL)
-		return t_strconcat(".imap/", mbox_path);
+		return t_strconcat(".imap/", mbox_path, NULL);
 	else {
 		rootpath = t_strdup_until(mbox_path, p);
 		return t_strconcat(rootpath, "/.imap/", p+1, NULL);