From: Timo Sirainen Date: Mon, 18 Oct 2010 14:07:02 +0000 (+0100) Subject: lib-storage: Log a debug message if shared user's storage root doesn't exist with... X-Git-Tag: 2.0.6~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9789e1f8a8f50c8620c771817b3f0f74fc02a2e6;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes --- diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 7e5afa510e..4c18c438ad 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -181,41 +181,66 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver, } return NULL; } + static int -mail_storage_create_root(struct mailbox_list *list, - enum mail_storage_flags flags, const char **error_r) +mail_storage_verify_root(const char *root_dir, bool autocreate, + const char **error_r) { - const char *root_dir, *origin; struct stat st; - mode_t mode; - gid_t gid; - if ((flags & MAIL_STORAGE_FLAG_NO_AUTOVERIFY) != 0) - return 0; - - root_dir = mailbox_list_get_path(list, NULL, - MAILBOX_LIST_PATH_TYPE_MAILBOX); - if (root_dir == NULL) { - /* storage doesn't use directories (e.g. shared root) */ - return 0; - } if (stat(root_dir, &st) == 0) { - /* ok */ - return 0; + /* exists */ + return 1; } else if (errno == EACCES) { *error_r = mail_error_eacces_msg("stat", root_dir); return -1; } else if (errno != ENOENT && errno != ENOTDIR) { *error_r = t_strdup_printf("stat(%s) failed: %m", root_dir); return -1; - } else if (list->ns->type == NAMESPACE_SHARED) { - /* can't create a new user, but we don't want to fail - the storage creation. */ - } else if ((flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) { + } else if (!autocreate) { *error_r = t_strdup_printf( "Root mail directory doesn't exist: %s", root_dir); return -1; + } else { + /* doesn't exist */ + return 0; } +} + +static int +mail_storage_create_root(struct mailbox_list *list, + enum mail_storage_flags flags, const char **error_r) +{ + const char *root_dir, *origin, *error; + mode_t mode; + gid_t gid; + bool autocreate; + int ret; + + root_dir = mailbox_list_get_path(list, NULL, + MAILBOX_LIST_PATH_TYPE_MAILBOX); + if (root_dir == NULL) { + /* storage doesn't use directories (e.g. shared root) */ + return 0; + } + + if ((flags & MAIL_STORAGE_FLAG_NO_AUTOVERIFY) != 0) { + if (!list->mail_set->mail_debug) + return 0; + + /* we don't need to verify, but since debugging is + enabled, check and log if the root doesn't exist */ + if (mail_storage_verify_root(root_dir, FALSE, &error) < 0) { + i_debug("Namespace %s: Creating storage despite: %s", + list->ns->prefix, error); + } + return 0; + } + + autocreate = (flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) == 0; + ret = mail_storage_verify_root(root_dir, autocreate, error_r); + if (ret != 0) + return ret; /* we need to create the root directory. */ mailbox_list_get_dir_permissions(list, NULL, &mode, &gid, &origin);