really matter. ignore silently. */
return;
}
- if (errno != EPERM)
+ if (!ENOACCESS(errno))
mail_index_file_set_syscall_error(index, path, "fchown()");
else {
mail_index_set_error(index, "%s",
umask(old_mode);
if (log->fd == -1) {
- if (errno != EACCES)
+ if (!ENOACCESS(errno))
e_error(log->event, "creat(%s) failed: %m",
log->filepath);
else
return -1;
}
if (fchown(log->fd, (uid_t)-1, log->gid) < 0) {
- if (errno != EPERM)
+ if (!ENOACCESS(errno))
e_error(log->event, "fchown(%s) failed: %m",
log->filepath);
else {
/* try the primary path first */
path = file->primary_path;
while ((file->fd = open(path, flags)) == -1) {
- if (errno == EACCES && flags == O_RDWR) {
+ if (ENOACCESS(errno) && flags == O_RDWR) {
flags = O_RDONLY;
continue;
}
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
return -1;
- } else if (errno == EACCES) {
+ } else if (ENOACCESS(errno)) {
mailbox_set_critical(box, "%s",
mail_error_eacces_msg("stat", box_path));
return -1;
}
if (unlink(file->cur_path) < 0) {
dbox_file_set_syscall_error(file, "unlink()");
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
/* configuration problem? revert the write */
i_unlink(dest_path);
}
/* we could handle the EEXIST condition by changing the
filename, but it practically never happens so just fallback
to standard copying for the rare cases when it does. */
- if (errno == EACCES || ECANTLINK(errno) || errno == EEXIST)
+ if (ENOACCESS(errno) || ECANTLINK(errno) || errno == EEXIST)
return 1;
mailbox_set_critical(&mbox->box, "link(%s, %s) failed: %m",
if (errno == ENOENT)
return 0;
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_set_critical(&mbox->box, "%s",
mail_error_eacces_msg("open", path));
} else {
if (errno == ENOENT)
return 0;
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_set_critical(&mbox->box, "%s",
mail_error_eacces_msg("stat", path));
} else {
} else if (errno == ENOENT) {
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
"Mailbox was deleted while it was being created");
- } else if (errno == EACCES) {
+ } else if (ENOACCESS(errno)) {
if (box->list->ns->type == MAIL_NAMESPACE_TYPE_SHARED) {
/* shared namespace, don't log permission errors */
mail_storage_set_error(box->storage, MAIL_ERROR_PERM,
if (stat(path, &st) < 0) {
if (errno == ENOENT || errno == ENAMETOOLONG)
return 0;
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mail_storage_set_critical(storage, "%s",
mail_error_eacces_msg("stat", path));
return -1;
mbox->backend_readonly_set = TRUE;
if (i_faccessat2(AT_FDCWD, t_strconcat(box_path, "/cur", NULL), W_OK, AT_EACCESS) < 0 &&
- errno == EACCES)
+ ENOACCESS(errno))
mbox->backend_readonly = TRUE;
}
return mbox->backend_readonly;
if (rename(path, newpath) < 0) {
if (errno == ENOENT)
return 0;
- if (!ENOSPACE(errno) && errno != EACCES) {
+ if (!ENOSPACE(errno) && !ENOACCESS(errno)) {
mailbox_set_critical(box,
"rename(%s, %s) failed: %m",
path, newpath);
break;
if (errno != ENOENT || i == MAILDIR_DELETE_RETRY_COUNT) {
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_set_critical(&ctx->mbox->box, "%s",
eacces_error_get("opendir", path));
} else {
move_count++;
flags |= MAILDIR_UIDLIST_REC_FLAG_MOVED |
MAILDIR_UIDLIST_REC_FLAG_RECENT;
- } else if (ENOSPACE(errno) || errno == EACCES) {
+ } else if (ENOSPACE(errno) || ENOACCESS(errno)) {
/* not enough disk space / read-only maildir,
leave here */
flags |= MAILDIR_UIDLIST_REC_FLAG_NEW_DIR;
return 0;
}
if (errno != ENOENT || i == MAILDIR_DELETE_RETRY_COUNT) {
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_set_critical(box, "%s",
eacces_error_get_creating("file_dotlock_create", path));
} else {
if (uidlist->fd == -1) {
fd = nfs_safe_open(uidlist->path, O_RDWR);
- if (fd == -1 && errno == EACCES) {
+ if (fd == -1 && ENOACCESS(errno)) {
fd = nfs_safe_open(uidlist->path, O_RDONLY);
readonly = TRUE;
}
}
uidlist->fd = nfs_safe_open(uidlist->path, O_RDWR);
- if (uidlist->fd == -1 && errno == EACCES) {
+ if (uidlist->fd == -1 && ENOACCESS(errno)) {
uidlist->fd = nfs_safe_open(uidlist->path, O_RDONLY);
uidlist->recreate_on_change = TRUE;
}
fd = open(mailbox_get_path(&mbox->box),
mbox_is_backend_readonly(mbox) ? O_RDONLY : O_RDWR);
- if (fd == -1 && errno == EACCES && !mbox->backend_readonly) {
+ if (fd == -1 && ENOACCESS(errno) && !mbox->backend_readonly) {
mbox->backend_readonly = TRUE;
fd = open(mailbox_get_path(&mbox->box), O_RDONLY);
}
buf.actime = buf.modtime - 1;
/* EPERM can happen with shared mailboxes */
if (utime(mailbox_get_path(&mbox->box), &buf) < 0 &&
- errno != EPERM)
+ !ENOACCESS(errno))
mbox_set_syscall_error(mbox, "utime()");
}
}
ret = file_dotlock_create(set, fname, 0, &mbox->mbox_dotlock);
if (ret > 0)
mbox->mbox_used_privileges = TRUE;
- else if (ret < 0 && errno == EACCES) {
+ else if (ret < 0 && ENOACCESS(errno)) {
const char *errmsg =
eacces_error_get_creating("file_dotlock_create",
fname);
&mbox->mbox_dotlock);
if (ret >= 0) {
/* success / timeout */
- } else if (errno == EACCES && restrict_access_have_priv_gid() &&
+ } else if (ENOACCESS(errno) && restrict_access_have_priv_gid() &&
mbox->mbox_privileged_locking) {
/* try again, this time with extra privileges */
ret = mbox_dotlock_privileged_op(mbox, &set,
MBOX_DOTLOCK_OP_LOCK);
- } else if (errno == EACCES)
+ } else if (ENOACCESS(errno))
mbox_dotlock_log_eacces_error(mbox, mailbox_get_path(&mbox->box));
else
mbox_set_syscall_error(mbox, "file_dotlock_create()");
if (ret < 0) {
- if ((ENOSPACE(errno) || errno == EACCES) && try)
+ if ((ENOSPACE(errno) || ENOACCESS(errno)) && try)
return 1;
return -1;
}
while (lockf(ctx->mbox->mbox_fd, lock_type, 0) < 0) {
if (errno != EINTR) {
- if ((errno == EACCES || errno == EAGAIN) &&
+ if ((ENOACCESS(errno) || errno == EAGAIN) &&
max_wait_time == 0) {
/* non-blocking lock trying failed */
return 0;
while (fcntl(ctx->mbox->mbox_fd, wait_type, &fl) < 0) {
if (errno != EINTR) {
- if ((errno == EACCES || errno == EAGAIN) &&
+ if ((ENOACCESS(errno) || errno == EAGAIN) &&
wait_type == F_SETLK) {
/* non-blocking lock trying failed */
return 0;
buf.modtime = st.st_mtime;
buf.actime = ctx->orig_atime;
if (utime(mailbox_get_path(&mbox->box), &buf) < 0 &&
- errno != EPERM)
+ !ENOACCESS(errno))
mbox_set_syscall_error(mbox, "utime()");
}
inbox_path = mailbox_get_path(box);
fd = open(inbox_path, O_RDWR | O_CREAT | O_EXCL, 0660);
- if (fd == -1 && errno == EACCES) {
+ if (fd == -1 && ENOACCESS(errno)) {
/* try again with increased privileges */
(void)restrict_access_use_priv_gid();
fd = open(inbox_path, O_RDWR | O_CREAT | O_EXCL, 0660);
if (fd != -1) {
i_close_fd(&fd);
return 0;
- } else if (errno == EACCES) {
+ } else if (ENOACCESS(errno)) {
mailbox_set_critical(box, "%s",
mail_error_create_eacces_msg("open", inbox_path));
return -1;
if (!mbox->backend_readonly_set) {
mbox->backend_readonly_set = TRUE;
if (i_faccessat2(AT_FDCWD, mailbox_get_path(&mbox->box), R_OK | W_OK, AT_EACCESS) < 0 &&
- errno == EACCES)
+ ENOACCESS(errno))
mbox->backend_readonly = TRUE;
}
return mbox->backend_readonly;
buf.modtime = st.st_mtime;
buf.actime = sync_ctx.orig_atime;
if (utime(mailbox_get_path(&mbox->box), &buf) < 0 &&
- errno != EPERM)
+ !ENOACCESS(errno))
mbox_set_syscall_error(mbox, "utime()");
}
}
deleting the mailbox. */
return 0;
}
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
/* ignore permission errors */
return 0;
}
mailbox_list_set_error(oldlist, MAIL_ERROR_NOTPOSSIBLE,
"Target mailbox doesn't allow inferior mailboxes");
return -1;
- } else if (errno != ENOENT && errno != EACCES) {
+ } else if (errno != ENOENT && !ENOACCESS(errno)) {
mailbox_list_set_critical(oldlist, "lstat(%s) failed: %m",
newpath);
return -1;
dirp = opendir(ctx->dir);
if (dirp == NULL) {
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_list_set_critical(list, "%s",
mail_error_eacces_msg("opendir", ctx->dir));
} else if (errno != ENOENT) {
static void subsread_set_syscall_error(struct mailbox_list *list,
const char *function, const char *path)
{
- if (errno == EACCES && !event_want_debug_log(list->ns->user->event)) {
+ if (ENOACCESS(errno) && !event_want_debug_log(list->ns->user->event)) {
mailbox_list_set_error(list, MAIL_ERROR_PERM,
"No permission to read subscriptions");
} else {
static void subswrite_set_syscall_error(struct mailbox_list *list,
const char *function, const char *path)
{
- if (errno == EACCES && !event_want_debug_log(list->ns->user->event)) {
+ if (ENOACCESS(errno) && !event_want_debug_log(list->ns->user->event)) {
mailbox_list_set_error(list, MAIL_ERROR_PERM,
"No permission to modify subscriptions");
} else {
if (chdir("/") < 0)
e_error(user->event, "chdir(/) failed: %m");
} else if (chdir(chdir_path) < 0) {
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
e_error(user->event, "%s",
eacces_error_get("chdir",
t_strconcat(chdir_path, "/", NULL)));
*error_r = t_strdup_printf(
"Root mail directory is a file: %s", root_dir);
return -1;
- } else if (errno == EACCES) {
+ } else if (ENOACCESS(errno)) {
*error_r = mail_error_eacces_msg("stat", root_dir);
return -1;
} else if (errno != ENOENT) {
struct stat st;
if (stat(path, &st) < 0) {
- if (errno == EACCES) {
+ if (ENOACCESS(errno)) {
mailbox_list_set_critical(list, "%s",
mail_error_eacces_msg("stat", path));
} else if (!ENOTFOUND(errno)) {
/* get the first existing parent directory's permissions */
if (stat_first_parent(expanded, &root_dir, &st) < 0) {
- *error_r = errno == EACCES ?
+ *error_r = ENOACCESS(errno) ?
mail_error_eacces_msg("stat", root_dir) :
t_strdup_printf("stat(%s) failed: %m", root_dir);
return -1;
perm.file_create_gid,
perm.file_create_gid_origin) < 0 &&
errno != EEXIST) {
- if (errno == EACCES)
+ if (ENOACCESS(errno))
*error_r = mail_error_create_eacces_msg("mkdir", path);
else
*error_r = t_strdup_printf("mkdir(%s) failed: %m", path);