[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-list.c,1.12,1.13 mbox-storage.c,1.35,1.36
cras at procontrol.fi
cras at procontrol.fi
Tue Feb 11 21:37:18 EET 2003
Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory danu:/tmp/cvs-serv1541/src/lib-storage/index/mbox
Modified Files:
mbox-list.c mbox-storage.c
Log Message:
Added mail_full_filesystem_access setting. Some of the setting variable
types were declared wrong and caused Dovecot to crash if they were set in
config file.
Index: mbox-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-list.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- mbox-list.c 31 Jan 2003 05:18:16 -0000 1.12
+++ mbox-list.c 11 Feb 2003 19:37:16 -0000 1.13
@@ -6,6 +6,7 @@
#include "subscription-file/subscription-file.h"
#include "mbox-index.h"
#include "mbox-storage.h"
+#include "home-expand.h"
#include <dirent.h>
#include <sys/stat.h>
@@ -15,10 +16,16 @@
void *context;
};
-static int mbox_find_path(struct mail_storage *storage,
- struct imap_match_glob *glob,
- mailbox_list_callback_t callback, void *context,
- const char *relative_dir)
+struct list_context {
+ struct mail_storage *storage;
+ struct imap_match_glob *glob;
+ mailbox_list_callback_t *callback;
+ void *context;
+
+ const char *rootdir;
+};
+
+static int mbox_find_path(struct list_context *ctx, const char *relative_dir)
{
DIR *dirp;
struct dirent *d;
@@ -31,11 +38,14 @@
t_push();
if (relative_dir == NULL)
- dir = storage->dir;
+ dir = ctx->rootdir;
+ else if (*ctx->rootdir == '\0' && *relative_dir != '\0')
+ dir = relative_dir;
else {
if (str_path(fulldir, sizeof(fulldir),
- storage->dir, relative_dir) < 0) {
- mail_storage_set_critical(storage, "Path too long: %s",
+ ctx->rootdir, relative_dir) < 0) {
+ mail_storage_set_critical(ctx->storage,
+ "Path too long: %s",
relative_dir);
return FALSE;
}
@@ -43,6 +53,7 @@
dir = fulldir;
}
+ dir = home_expand(dir);
dirp = opendir(dir);
if (dirp == NULL) {
t_pop();
@@ -54,7 +65,16 @@
return TRUE;
}
- mail_storage_set_critical(storage,
+ if (errno == EACCES) {
+ if (relative_dir != NULL) {
+ /* subfolder, ignore */
+ return TRUE;
+ }
+ mail_storage_set_error(ctx->storage, "Access denied");
+ return FALSE;
+ }
+
+ mail_storage_set_critical(ctx->storage,
"opendir(%s) failed: %m", dir);
return FALSE;
}
@@ -78,7 +98,7 @@
else {
if (str_path(path, sizeof(path),
relative_dir, fname) < 0) {
- mail_storage_set_critical(storage,
+ mail_storage_set_critical(ctx->storage,
"Path too long: %s/%s",
relative_dir, fname);
failed = TRUE;
@@ -87,12 +107,12 @@
listpath = path;
}
- if ((match = imap_match(glob, listpath)) < 0)
+ if ((match = imap_match(ctx->glob, listpath)) < 0)
continue;
/* see if it's a directory */
if (str_path(fullpath, sizeof(fullpath), dir, fname) < 0) {
- mail_storage_set_critical(storage,
+ mail_storage_set_critical(ctx->storage,
"Path too long: %s/%s",
dir, fname);
failed = TRUE;
@@ -103,8 +123,9 @@
if (errno == ENOENT)
continue; /* just deleted, ignore */
- mail_storage_set_critical(storage, "stat(%s) failed: "
- "%m", fullpath);
+ mail_storage_set_critical(ctx->storage,
+ "stat(%s) failed: %m",
+ fullpath);
failed = TRUE;
break;
}
@@ -112,22 +133,23 @@
if (S_ISDIR(st.st_mode)) {
/* subdirectory, scan it too */
t_push();
- callback(storage, listpath, MAILBOX_NOSELECT, context);
+ ctx->callback(ctx->storage, listpath, MAILBOX_NOSELECT,
+ ctx->context);
t_pop();
- if (!mbox_find_path(storage, glob, callback,
- context, listpath)) {
+ if (!mbox_find_path(ctx, listpath)) {
failed = TRUE;
break;
}
} else if (match > 0 &&
- strcmp(fullpath, storage->inbox_file) != 0 &&
+ strcmp(fullpath, ctx->storage->inbox_file) != 0 &&
strcasecmp(listpath, "INBOX") != 0) {
/* don't match any INBOX here, it's added later.
we might also have ~/mail/inbox, ~/mail/Inbox etc.
Just ignore them for now. */
t_push();
- callback(storage, listpath, MAILBOX_NOINFERIORS, context);
+ ctx->callback(ctx->storage, listpath,
+ MAILBOX_NOINFERIORS, ctx->context);
t_pop();
}
}
@@ -148,12 +170,13 @@
last_dir = p;
}
- return last_dir != NULL ? t_strdup_until(mask, last_dir) : NULL;
+ return last_dir == NULL ? NULL : t_strdup_until(mask, last_dir);
}
int mbox_find_mailboxes(struct mail_storage *storage, const char *mask,
mailbox_list_callback_t callback, void *context)
{
+ struct list_context ctx;
struct imap_match_glob *glob;
const char *relative_dir;
@@ -175,7 +198,31 @@
callback(storage, "INBOX", MAILBOX_NOINFERIORS, context);
}
- if (!mbox_find_path(storage, glob, callback, context, relative_dir))
+ memset(&ctx, 0, sizeof(ctx));
+ ctx.storage = storage;
+ ctx.glob = glob;
+ ctx.callback = callback;
+ ctx.context = context;
+
+ if (!full_filesystem_access || relative_dir == NULL ||
+ (*relative_dir != '/' && *relative_dir != '~' &&
+ *relative_dir != '\0'))
+ ctx.rootdir = storage->dir;
+ else
+ ctx.rootdir = "";
+
+ if (relative_dir != NULL) {
+ const char *matchdir = t_strconcat(relative_dir, "/", NULL);
+
+ if (imap_match(ctx.glob, matchdir) > 0) {
+ t_push();
+ ctx.callback(ctx.storage, matchdir, MAILBOX_NOSELECT,
+ ctx.context);
+ t_pop();
+ }
+ }
+
+ if (!mbox_find_path(&ctx, relative_dir))
return FALSE;
return TRUE;
Index: mbox-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- mbox-storage.c 8 Feb 2003 13:13:12 -0000 1.35
+++ mbox-storage.c 11 Feb 2003 19:37:16 -0000 1.36
@@ -220,6 +220,13 @@
const char *p;
int newdir;
+ if (full_filesystem_access)
+ return TRUE;
+
+ /* make sure it's not absolute path */
+ if (*mask == '/' || *mask == '\\' || *mask == '~')
+ return FALSE;
+
/* make sure there's no "../" or "..\" stuff */
newdir = TRUE;
for (p = mask; *p != '\0'; p++) {
More information about the dovecot-cvs
mailing list