]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Replace EACCES with ENOACCESS
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 4 Jul 2023 13:06:16 +0000 (13:06 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 6 Oct 2023 16:00:06 +0000 (16:00 +0000)
23 files changed:
src/lib-index/mail-index.c
src/lib-index/mailbox-log.c
src/lib-storage/index/dbox-common/dbox-file.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-single/sdbox-file.c
src/lib-storage/index/maildir/maildir-copy.c
src/lib-storage/index/maildir/maildir-mail.c
src/lib-storage/index/maildir/maildir-storage.c
src/lib-storage/index/maildir/maildir-sync-index.c
src/lib-storage/index/maildir/maildir-sync.c
src/lib-storage/index/maildir/maildir-uidlist.c
src/lib-storage/index/mbox/mbox-file.c
src/lib-storage/index/mbox/mbox-lock.c
src/lib-storage/index/mbox/mbox-save.c
src/lib-storage/index/mbox/mbox-storage.c
src/lib-storage/index/mbox/mbox-sync.c
src/lib-storage/list/mailbox-list-fs-iter.c
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir-iter.c
src/lib-storage/list/subscription-file.c
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c

index a2fec7acba350ee9e5eceeadfcdc3ce43f7e707b..1a1caa748394c22dace4fa3d6d0e34a87a36d8c3 100644 (file)
@@ -1015,7 +1015,7 @@ void mail_index_fchown(struct mail_index *index, int fd, const char *path)
                   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",
index 444308f6db363e707c11221aeff1549776fa5d15..c158eb9c1ced83426dbcf430ace1bd455e948279 100644 (file)
@@ -105,7 +105,7 @@ static int mailbox_log_open(struct mailbox_log *log)
        umask(old_mode);
 
        if (log->fd == -1) {
-               if (errno != EACCES)
+               if (!ENOACCESS(errno))
                        e_error(log->event, "creat(%s) failed: %m",
                                log->filepath);
                else
@@ -114,7 +114,7 @@ static int mailbox_log_open(struct mailbox_log *log)
                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 {
index e447b2070d5542444401adc977c20a76f1d92cff..a407e19396a379eb936bf192481df711ca39618f 100644 (file)
@@ -177,7 +177,7 @@ static int dbox_file_open_fd(struct dbox_file *file, bool try_altpath)
        /* 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;
                }
index 7c693b805e857bd4d5b20279117a4f738e17f285..3acaac46b5af86267f46789c0000714aa98429a5 100644 (file)
@@ -274,7 +274,7 @@ int dbox_mailbox_check_existence(struct mailbox *box)
                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;
index 28eebe6121074af07b3de2daedbf5b73c611a3d0..0237ae3df8d69dc4589ebcd588cb46c7cb60f325 100644 (file)
@@ -380,7 +380,7 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path)
        }
        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);
                }
index 1645ddb455266d68e977650e27cdddefd526fcad..1f3a8365135ea5aa30aeed3bbf65bbdb0c59faf5 100644 (file)
@@ -42,7 +42,7 @@ static int do_hardlink(struct maildir_mailbox *mbox, const char *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",
index a093c522399e1f4a0e2c8d7b87452bdd4fb78bfd..e8130e1f15a5f9a0771cb4025d22a6e48888932b 100644 (file)
@@ -31,7 +31,7 @@ do_open(struct maildir_mailbox *mbox, const char *path,
        if (errno == ENOENT)
                return 0;
 
-       if (errno == EACCES) {
+       if (ENOACCESS(errno)) {
                mailbox_set_critical(&mbox->box, "%s",
                        mail_error_eacces_msg("open", path));
        } else {
@@ -49,7 +49,7 @@ do_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st)
        if (errno == ENOENT)
                return 0;
 
-       if (errno == EACCES) {
+       if (ENOACCESS(errno)) {
                mailbox_set_critical(&mbox->box, "%s",
                        mail_error_eacces_msg("stat", path));
        } else {
index a9d6fe5ec7f42c6e28e827c431abcf66fb1c297e..91dbf2b2afda47c98e9d59200c532febb59e73d3 100644 (file)
@@ -187,7 +187,7 @@ mkdir_verify(struct mailbox *box, const char *dir, bool verify)
        } 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,
@@ -213,7 +213,7 @@ static int maildir_check_tmp(struct mail_storage *storage, const char *dir)
        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;
@@ -713,7 +713,7 @@ bool maildir_is_backend_readonly(struct maildir_mailbox *mbox)
 
                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;
index 98ed927b455a51b0be2e067348ef5ac03a887244..7c1fb28817f1f39c331c212e661a77836e0a5be1 100644 (file)
@@ -143,7 +143,7 @@ static int maildir_sync_flags(struct maildir_mailbox *mbox, const char *path,
                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);
index 075429f06acba98e7a135d451d4e48cd2eb40bee..13b64c8aab745b1704118933ee8b0cac1a60d8ef 100644 (file)
@@ -423,7 +423,7 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final,
                        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 {
@@ -506,7 +506,7 @@ maildir_scan_dir(struct maildir_sync_context *ctx, bool new_dir, bool final,
                                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;
index 3766e34d21183e3ad78dea94919cde3f73bdf57b..5c14c57b3e45bc658cc1d951af6c1280589c74b5 100644 (file)
@@ -170,7 +170,7 @@ static int maildir_uidlist_lock_timeout(struct maildir_uidlist *uidlist,
                        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 {
@@ -712,7 +712,7 @@ maildir_uidlist_update_read(struct maildir_uidlist *uidlist,
 
        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;
                }
@@ -932,7 +932,7 @@ static int maildir_uidlist_open_latest(struct maildir_uidlist *uidlist)
        }
 
        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;
        }
index b71abb835037f411b227cd56470ecc5e167fe6e2..6366ce9004f643c779d5fe7b067e8cf1dcbfa694 100644 (file)
@@ -27,7 +27,7 @@ int mbox_file_open(struct mbox_mailbox *mbox)
 
        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);
        }
@@ -115,7 +115,7 @@ static void mbox_file_fix_atime(struct mbox_mailbox *mbox)
                        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()");
                }
        }
index 7c4202367ec5c0567fdcd84808b308ec4aa7c92f..032eeb548a26213f43f550b262b7e6154cfadaf3 100644 (file)
@@ -300,7 +300,7 @@ mbox_dotlock_privileged_op(struct mbox_mailbox *mbox,
                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);
@@ -418,18 +418,18 @@ mbox_lock_dotlock_int(struct mbox_lock_context *ctx, int lock_type, bool try)
                                  &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;
        }
@@ -552,7 +552,7 @@ static int mbox_lock_lockf(struct mbox_lock_context *ctx, int lock_type,
 
        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;
@@ -619,7 +619,7 @@ static int mbox_lock_fcntl(struct mbox_lock_context *ctx, int lock_type,
 
        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;
index 40e3a6ba7b1e54482e774a4491097886e34db018..1734d44c620e1cea812bad99c2447d0e2290c28c 100644 (file)
@@ -782,7 +782,7 @@ int mbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
                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()");
        }
 
index 7a7f5fc86e765ca35fb1c13dbe8ce5c9852f8442..42ca124444d72c976b786616a736555c87d52234 100644 (file)
@@ -542,7 +542,7 @@ static int create_inbox(struct mailbox *box)
        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);
@@ -551,7 +551,7 @@ static int create_inbox(struct mailbox *box)
        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;
@@ -812,7 +812,7 @@ bool mbox_is_backend_readonly(struct mbox_mailbox *mbox)
        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;
index 8e887dd187ba5af8f902ba51358f673f2420ec81..52a0e7a623e49c9ee4bb30c6df293407b5112d8d 100644 (file)
@@ -1989,7 +1989,7 @@ again:
                        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()");
                }
        }
index 436934f59491323c9f1547ce4fd6f6eff6ed4dab..1b859e07f15988d1a5e87ce4ff471d2ea61a4d8c 100644 (file)
@@ -299,7 +299,7 @@ fs_list_dir_read(struct fs_list_iterate_context *ctx,
                           deleting the mailbox. */
                        return 0;
                }
-               if (errno == EACCES) {
+               if (ENOACCESS(errno)) {
                        /* ignore permission errors */
                        return 0;
                }
index 8e4640647ee5d71e755688a1314e2705ca2fbd7b..eb1bed5c23477654e1313a3750d70368c6d8a57b 100644 (file)
@@ -503,7 +503,7 @@ static int fs_list_rename_mailbox(struct mailbox_list *oldlist,
                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;
index d63555480db8165a2096883f677cdf338ce6a394..3b97dc7c422c3151a79120ff1799a10b32570525 100644 (file)
@@ -379,7 +379,7 @@ maildir_fill_readdir(struct maildir_list_iterate_context *ctx,
 
        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) {
index 4c5094a40ca490f4eafe84d59e23284bc4709fcd..ef2bb9723505a730871370c11b2973801d784c61 100644 (file)
@@ -33,7 +33,7 @@ static const char version2_header[] = "V\t2\n\n";
 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 {
@@ -46,7 +46,7 @@ static void subsread_set_syscall_error(struct mailbox_list *list,
 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 {
index a93cc4a44268a7f0239cd3c5c6efab96e2980f84..4e968fdff3eb559d1bbdd2de2a8784fe5078d1ad 100644 (file)
@@ -758,7 +758,7 @@ mail_storage_service_init_post(struct mail_storage_service_ctx *ctx,
                        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)));
index 0e22438ba2f93b9218fe29a1a7050e5a792c96d5..1ed9bf371644c0491acd0356a0b1bc50ab97164f 100644 (file)
@@ -255,7 +255,7 @@ mail_storage_verify_root(const char *root_dir, const char *dir_type,
                *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) {
index 8a3e95eccf117a939675b9837c5d7e0b2c9cfe6c..a8a83568ba7170daa026a0d19b74fe3e1cf6aaa4 100644 (file)
@@ -932,7 +932,7 @@ mailbox_list_get_permissions_stat(struct mailbox_list *list, const char *path,
        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)) {
@@ -1173,7 +1173,7 @@ mailbox_list_try_mkdir_root_parent(struct mailbox_list *list,
 
        /* 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;
@@ -1259,7 +1259,7 @@ int mailbox_list_try_mkdir_root(struct mailbox_list *list, const char *path,
                                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);