Also moved the code to mail-error.c and used it when listing mailboxes.
--HG--
branch : HEAD
"Root mail directory doesn't exist: %s",
list_set.root_dir);
} else if (errno == EACCES) {
- *error_r = mail_storage_eacces_msg("stat",
+ *error_r = mail_error_eacces_msg("stat",
list_set.root_dir);
} else {
*error_r = t_strdup_printf(
} else if (mkdir_parents(list_set.root_dir,
CREATE_MODE) == 0 || errno == EEXIST) {
} else if (errno == EACCES) {
- *error_r = mail_storage_eacces_msg("mkdir", list_set.root_dir);
+ *error_r = mail_error_eacces_msg("mkdir", list_set.root_dir);
return -1;
} else {
*error_r = t_strdup_printf("mkdir(%s) failed: %m",
T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
} else if (errno == EACCES) {
mail_storage_set_critical(_storage, "%s",
- mail_storage_eacces_msg("stat", path));
+ mail_error_eacces_msg("stat", path));
} else {
mail_storage_set_critical(_storage, "stat(%s) failed: %m",
path);
"Root mail directory doesn't exist: %s",
list_set.root_dir);
} else if (errno == EACCES) {
- *error_r = mail_storage_eacces_msg("stat",
+ *error_r = mail_error_eacces_msg("stat",
list_set.root_dir);
} else {
*error_r = t_strdup_printf(
CREATE_MODE) == 0 || errno == EEXIST) {
} else if (errno == EACCES) {
if (_storage->ns->type != NAMESPACE_SHARED) {
- *error_r = mail_storage_eacces_msg("mkdir",
- list_set.root_dir);
+ *error_r = mail_error_eacces_msg("mkdir",
+ list_set.root_dir);
return -1;
}
/* can't create a new user, but we don't want to fail
T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
} else if (errno == EACCES) {
mail_storage_set_critical(_storage, "%s",
- mail_storage_eacces_msg("stat", path));
+ mail_error_eacces_msg("stat", path));
} else {
mail_storage_set_critical(_storage, "stat(%s) failed: %m",
path);
}
if (errno == EACCES) {
mail_storage_set_critical(storage, "%s",
- mail_storage_eacces_msg("stat", index_dir));
+ mail_error_eacces_msg("stat", index_dir));
return NULL;
}
if (stat(list_set.root_dir, &st) == 0) {
/* ok */
} else if (errno == EACCES) {
- *error_r = mail_storage_eacces_msg("stat",
- list_set.root_dir);
+ *error_r = mail_error_eacces_msg("stat",
+ list_set.root_dir);
return -1;
} else if (errno == ENOENT) {
*error_r = t_strdup_printf(
return 0;
if (errno == EACCES) {
mail_storage_set_critical(storage, "%s",
- mail_storage_eacces_msg("stat", path));
+ mail_error_eacces_msg("stat", path));
return -1;
}
mail_storage_set_critical(storage, "stat(%s) failed: %m", path);
if (lstat(list_set->root_dir, &st) == 0) {
/* yep, go ahead */
} else if (errno == EACCES) {
- *error_r = mail_storage_eacces_msg("lstat",
- list_set->root_dir);
+ *error_r = mail_error_eacces_msg("lstat",
+ list_set->root_dir);
return -1;
} else if (errno != ENOENT && errno != ENOTDIR) {
*error_r = t_strdup_printf("lstat(%s) failed: %m",
return -1;
} else if (errno == EACCES) {
mail_storage_set_critical(storage, "%s",
- mail_storage_eacces_msg("open", inbox_path));
+ mail_error_eacces_msg("open", inbox_path));
return -1;
} else if (errno != EEXIST) {
mail_storage_set_critical(storage,
dirp = opendir(ctx->dir);
if (dirp == NULL) {
- if (errno != ENOENT) {
+ if (errno == EACCES) {
+ mailbox_list_set_critical(ctx->ctx.list, "%s",
+ mail_error_eacces_msg("opendir", ctx->dir));
+ } else if (errno != ENOENT) {
mailbox_list_set_critical(ctx->ctx.list,
"opendir(%s) failed: %m", ctx->dir);
return -1;
/* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "str.h"
#include "mail-error.h"
+#include <sys/stat.h>
+#include <unistd.h>
+#include <pwd.h>
+#include <grp.h>
+
bool mail_error_from_errno(enum mail_error *error_r,
const char **error_string_r)
{
}
return TRUE;
}
+
+const char *mail_error_eacces_msg(const char *func, const char *path)
+{
+ const char *prev_path = path, *dir = "/", *p;
+ const struct passwd *pw;
+ const struct group *group;
+ string_t *errmsg;
+ struct stat st;
+ int ret = -1;
+
+ errmsg = t_str_new(256);
+ str_printfa(errmsg, "%s(%s) failed: Permission denied (euid=%s",
+ func, path, dec2str(geteuid()));
+
+ pw = getpwuid(geteuid());
+ if (pw != NULL)
+ str_printfa(errmsg, "(%s)", pw->pw_name);
+
+ str_printfa(errmsg, " egid=%s", dec2str(getegid()));
+ group = getgrgid(getegid());
+ if (group != NULL)
+ str_printfa(errmsg, "(%s)", group->gr_name);
+
+ while ((p = strrchr(prev_path, '/')) != NULL) {
+ dir = t_strdup_until(prev_path, p);
+ ret = stat(dir, &st);
+ if (ret == 0 || errno != EACCES)
+ break;
+ prev_path = dir;
+ dir = "/";
+ }
+
+ if (ret == 0) {
+ if (access(dir, X_OK) < 0 && errno == EACCES)
+ str_printfa(errmsg, " missing +x perm: %s", dir);
+ else if (prev_path == path &&
+ access(path, R_OK) < 0 && errno == EACCES)
+ str_printfa(errmsg, " missing +r perm: %s", path);
+ }
+ str_append_c(errmsg, ')');
+ return str_c(errmsg);
+}
bool mail_error_from_errno(enum mail_error *error_r,
const char **error_string_r);
+/* Build a helpful error message for a failed EACCESS syscall. */
+const char *mail_error_eacces_msg(const char *func, const char *path);
+
#endif
void mail_set_expunged(struct mail *mail);
void mailbox_set_deleted(struct mailbox *box);
-const char *mail_storage_eacces_msg(const char *func, const char *path);
-
enum mailbox_list_flags
mail_storage_get_list_flags(enum mail_storage_flags storage_flags);
#include "lib.h"
#include "ioloop.h"
#include "array.h"
-#include "str.h"
#include "var-expand.h"
#include "mail-index-private.h"
#include "mailbox-list-private.h"
#include "mailbox-search-result-private.h"
#include <stdlib.h>
-#include <time.h>
#include <ctype.h>
#define DEFAULT_MAX_KEYWORD_LENGTH 50
"Mailbox was deleted under us");
box->mailbox_deleted = TRUE;
}
-
-const char *mail_storage_eacces_msg(const char *func, const char *path)
-{
- const char *prev_path = path, *dir = "/", *p;
- string_t *errmsg = t_str_new(256);
- struct stat st;
- int ret = -1;
-
- str_printfa(errmsg, "%s(%s) failed: Permission denied (euid=%s egid=%s",
- func, path, dec2str(geteuid()), dec2str(getegid()));
- while ((p = strrchr(prev_path, '/')) != NULL) {
- dir = t_strdup_until(prev_path, p);
- ret = stat(dir, &st);
- if (ret == 0 || errno != EACCES)
- break;
- prev_path = dir;
- dir = "/";
- }
-
- if (ret == 0) {
- if (access(dir, X_OK) < 0 && errno == EACCES)
- str_printfa(errmsg, " missing +x perm: %s", dir);
- else if (prev_path == path &&
- access(path, R_OK) < 0 && errno == EACCES)
- str_printfa(errmsg, " missing +r perm: %s", path);
- }
- str_append_c(errmsg, ')');
- return str_c(errmsg);
-}