]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Remove support for getting quota limits from quota backends
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 14 Aug 2024 07:18:46 +0000 (10:18 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
Previously using quota_rule = ?:... with Maildir++ quota would read the
limit from maildirsize file, if it existed. This feature wasn't really
even documented, so it's unlikely to be used, and it unnecessarily
complicates the code.

src/plugins/quota/quota-maildir.c
src/plugins/quota/quota-private.h
src/plugins/quota/quota-util.c
src/plugins/quota/quota.c

index fb501eeeecd0fa5c7311bfa4f3cb330672828a54..4bb37329fea1c96459f0c08126f5d8a32f3942e4 100644 (file)
@@ -344,11 +344,6 @@ static int maildirsize_recalculate_namespace(struct maildir_quota_root *root,
 
 static void maildirsize_rebuild_later(struct maildir_quota_root *root)
 {
-       if (!root->root.set->force_default_rule) {
-               /* FIXME: can't unlink(), because the limits would be lost. */
-               return;
-       }
-
        if (unlink(root->maildirsize_path) < 0 &&
            errno != ENOENT && errno != ESTALE)
                e_error(root->root.backend.event,
@@ -472,21 +467,10 @@ static int maildirsize_parse(struct maildir_quota_root *root,
        if (message_count_limit >= (1ULL << 63))
                message_count_limit = (1ULL << 63) - 1;
 
-       if (root->root.bytes_limit == (int64_t)message_bytes_limit &&
-           root->root.count_limit == (int64_t)message_count_limit) {
-               /* limits haven't changed */
-       } else if (root->root.set->force_default_rule) {
-               /* we know the limits and they've changed.
-                  the file must be rewritten. */
+       if (root->root.bytes_limit != (int64_t)message_bytes_limit ||
+           root->root.count_limit != (int64_t)message_count_limit) {
+               /* the limits have changed. the file must be rewritten. */
                return 0;
-       } else {
-               /* we're using limits from the file. */
-               root->root.bytes_limit = message_bytes_limit;
-               root->root.count_limit = message_count_limit;
-               quota_root_recalculate_relative_rules(_root->backend.event,
-                                                     root->root.set,
-                                                     message_bytes_limit,
-                                                     message_count_limit);
        }
 
        if (*lines == NULL) {
@@ -704,17 +688,6 @@ maildirquota_refresh(struct maildir_quota_root *root, bool *recalculated_r,
 
        ret = maildirquota_read_limits(root, error_r);
        if (ret == 0) {
-               if (root->root.bytes_limit == 0 &&
-                   root->root.count_limit == 0 &&
-                   root->root.set->default_rule.bytes_limit == 0 &&
-                   root->root.set->default_rule.count_limit == 0) {
-                       /* no quota */
-                       if (!root->root.set->force_default_rule)
-                               return 0;
-                       /* explicitly specified 0 as quota. keep the quota
-                          updated even if it's not enforced. */
-               }
-
                ret = maildirsize_recalculate(root, error_r);
                if (ret == 0)
                        *recalculated_r = TRUE;
index 373999c62e618de087c9dcfd97c4e23cf70347df..37dd6c46e04564026a0131eb713eb2a5489fbaf9 100644 (file)
@@ -105,8 +105,6 @@ struct quota_root_settings {
        uint64_t last_mail_max_extra_bytes;
        struct quota_rule grace_rule;
 
-       /* Limits in default_rule override backend's quota limits */
-       bool force_default_rule:1;
        /* TRUE if any of the warning_rules have reverse==TRUE */
        bool have_reverse_warnings:1;
 };
@@ -128,7 +126,7 @@ struct quota_root {
        const char *ns_prefix;
 
        /* initially the same as set->default_rule.*_limit, but some backends
-          may change these by reading the limits elsewhere (e.g. Maildir++,
+          may change these by reading the limits elsewhere (e.g. imapc,
           FS quota) */
        int64_t bytes_limit, count_limit;
 
index 03c9db8b65975b5bc5dbfe044f0372ffe1621324..3046dbb3888e98308e488a8ea4ea361fa1e795c8 100644 (file)
@@ -9,7 +9,6 @@
 #define QUOTA_DEFAULT_GRACE "10%"
 
 #define RULE_NAME_DEFAULT_FORCE "*"
-#define RULE_NAME_DEFAULT_NONFORCE "?"
 
 struct quota_rule *
 quota_root_rule_find(struct quota_root_settings *root_set, const char *name)
@@ -243,12 +242,9 @@ int quota_root_add_rule(struct event *event, pool_t pool,
 
        rule = quota_root_rule_find_exact(root_set, mailbox_mask);
        if (rule == NULL) {
-               if (strcmp(mailbox_mask, RULE_NAME_DEFAULT_NONFORCE) == 0)
+               if (strcmp(mailbox_mask, RULE_NAME_DEFAULT_FORCE) == 0)
                        rule = &root_set->default_rule;
-               else if (strcmp(mailbox_mask, RULE_NAME_DEFAULT_FORCE) == 0) {
-                       rule = &root_set->default_rule;
-                       root_set->force_default_rule = TRUE;
-               } else {
+               else {
                        rule = array_append_space(&root_set->rules);
                        rule->mailbox_mask = strcasecmp(mailbox_mask, "INBOX") == 0 ? "INBOX" :
                                p_strdup(pool, mailbox_mask);
index a048c5cfa5db98064f24f105a9667ba5c72f03a9..52519268078d4d9d41eff97c92e0039cdedcce35 100644 (file)
@@ -442,31 +442,16 @@ void quota_deinit(struct quota **_quota)
        i_free(quota);
 }
 
-static int quota_root_get_rule_limits(struct quota_root *root,
-                                     const char *mailbox_name,
-                                     uint64_t *bytes_limit_r,
-                                     uint64_t *count_limit_r,
-                                     bool *ignored_r,
-                                     const char **error_r)
+static void
+quota_root_get_rule_limits(struct quota_root *root, const char *mailbox_name,
+                          uint64_t *bytes_limit_r, uint64_t *count_limit_r,
+                          bool *ignored_r)
 {
        struct quota_rule *rule;
        int64_t bytes_limit, count_limit;
-       int ret;
 
        *ignored_r = FALSE;
 
-       if (!root->set->force_default_rule) {
-               if (root->backend.v.init_limits != NULL) {
-                       const char *error;
-                       if (root->backend.v.init_limits(root, &error) < 0) {
-                               *error_r = t_strdup_printf(
-                                       "Initializing limits failed for quota backend: %s",
-                                       error);
-                               return -1;
-                       }
-               }
-       }
-
        bytes_limit = root->bytes_limit;
        count_limit = root->count_limit;
 
@@ -476,10 +461,8 @@ static int quota_root_get_rule_limits(struct quota_root *root,
                (void)mail_namespace_find_unalias(root->quota->user->namespaces,
                                                  &mailbox_name);
                rule = quota_root_rule_find(root->set, mailbox_name);
-               ret = 1;
        } else {
                rule = NULL;
-               ret = 0;
        }
 
        if (rule != NULL) {
@@ -495,7 +478,6 @@ static int quota_root_get_rule_limits(struct quota_root *root,
 
        *bytes_limit_r = bytes_limit <= 0 ? 0 : bytes_limit;
        *count_limit_r = count_limit <= 0 ? 0 : count_limit;
-       return ret;
 }
 
 static bool
@@ -757,14 +739,8 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
                return ret;
        }
 
-       if (quota_root_get_rule_limits(root, mailbox_name,
-                                      &bytes_limit, &count_limit,
-                                      &ignored, &error) < 0) {
-               *error_r = t_strdup_printf(
-                       "Failed to get quota root rule limits for mailbox %s: %s",
-                       mailbox_name, error);
-               return QUOTA_GET_RESULT_INTERNAL_ERROR;
-       }
+       quota_root_get_rule_limits(root, mailbox_name,
+                                  &bytes_limit, &count_limit, &ignored);
 
        if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
                *limit_r = bytes_limit;
@@ -869,15 +845,10 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                        continue;
                else if (roots[i]->no_enforcing) {
                        ignored = FALSE;
-               } else if (quota_root_get_rule_limits(roots[i], mailbox_name,
-                                                     &bytes_limit, &count_limit,
-                                                     &ignored, &error) < 0) {
-                       ctx->failed = TRUE;
-                       *error_result_r = QUOTA_GET_RESULT_INTERNAL_ERROR;
-                       *error_r = t_strdup_printf(
-                               "Failed to get quota root rule limits for %s: %s",
-                               mailbox_name, error);
-                       return -1;
+               } else {
+                       quota_root_get_rule_limits(roots[i], mailbox_name,
+                                                  &bytes_limit, &count_limit,
+                                                  &ignored);
                }
                if (!ignored)
                        ctx->no_quota_updates = FALSE;
@@ -1338,7 +1309,6 @@ static enum quota_alloc_result quota_default_test_alloc(
        struct quota_root *const *roots;
        unsigned int i, count;
        bool ignore;
-       int ret;
 
        if (!quota_transaction_is_over(ctx, size))
                return QUOTA_ALLOC_RESULT_OK;
@@ -1360,17 +1330,10 @@ static enum quota_alloc_result quota_default_test_alloc(
                    roots[i]->no_enforcing)
                        continue;
 
-               const char *error;
-               ret = quota_root_get_rule_limits(roots[i],
-                                                mailbox_get_vname(ctx->box),
-                                                &bytes_limit, &count_limit,
-                                                &ignore, &error);
-               if (ret < 0) {
-                       *error_r = t_strdup_printf(
-                               "Failed to get quota root rule limits: %s",
-                               error);
-                       return QUOTA_ALLOC_RESULT_TEMPFAIL;
-               }
+               quota_root_get_rule_limits(roots[i],
+                                          mailbox_get_vname(ctx->box),
+                                          &bytes_limit, &count_limit,
+                                          &ignore);
 
                /* if size is bigger than any limit, then
                   it is bigger than the lowest limit */