From: Timo Sirainen Date: Thu, 15 Aug 2024 21:13:02 +0000 (+0300) Subject: quota, imap_quota: quota_get_resource() - Changed mailbox_name parameter to struct... X-Git-Tag: 2.4.0~398 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25a92924c75afb1b9af1e01bbeeae78dad83a61b;p=thirdparty%2Fdovecot%2Fcore.git quota, imap_quota: quota_get_resource() - Changed mailbox_name parameter to struct mailbox --- diff --git a/src/plugins/imap-quota/imap-quota-plugin.c b/src/plugins/imap-quota/imap-quota-plugin.c index eb8cf423e5..601fdbc2c3 100644 --- a/src/plugins/imap-quota/imap-quota-plugin.c +++ b/src/plugins/imap-quota/imap-quota-plugin.c @@ -50,7 +50,7 @@ quota_reply_write(string_t *str, struct mail_user *user, prefix_len = str_len(str); list = quota_root_get_resources(root); for (i = 0; *list != NULL; list++) { - ret = quota_get_resource(root, "", *list, &value, &limit, &error); + ret = quota_get_resource(root, NULL, *list, &value, &limit, &error); if (ret == QUOTA_GET_RESULT_INTERNAL_ERROR) { e_error(user->event, "Failed to get quota resource %s: %s", diff --git a/src/plugins/quota/doveadm-quota.c b/src/plugins/quota/doveadm-quota.c index 21449d32aa..ff544fc9bb 100644 --- a/src/plugins/quota/doveadm-quota.c +++ b/src/plugins/quota/doveadm-quota.c @@ -23,7 +23,7 @@ static int cmd_quota_get_root(struct quota_root *root, struct mail_user *user) res = quota_root_get_resources(root); for (; *res != NULL; res++) { - qret = quota_get_resource(root, "", *res, &value, &limit, &error); + qret = quota_get_resource(root, NULL, *res, &value, &limit, &error); doveadm_print(root->set->name); doveadm_print(*res); if (qret == QUOTA_GET_RESULT_LIMITED) { diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 57f69c5f57..9c082cb4ae 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -439,7 +439,7 @@ void quota_deinit(struct quota **_quota) } static void -quota_root_get_rule_limits(struct quota_root *root, const char *mailbox_name, +quota_root_get_rule_limits(struct quota_root *root, struct mailbox *box, uint64_t *bytes_limit_r, uint64_t *count_limit_r, bool *ignored_r) { @@ -454,6 +454,7 @@ quota_root_get_rule_limits(struct quota_root *root, const char *mailbox_name, /* if default rule limits are 0, user has unlimited quota. ignore any specific quota rules */ if (bytes_limit != 0 || count_limit != 0) { + const char *mailbox_name = mailbox_get_vname(box); (void)mail_namespace_find_unalias(root->quota->user->namespaces, &mailbox_name); rule = quota_root_rule_find(root->set, mailbox_name); @@ -714,7 +715,7 @@ bool quota_root_is_hidden(struct quota_root *root) } enum quota_get_result -quota_get_resource(struct quota_root *root, const char *mailbox_name, +quota_get_resource(struct quota_root *root, struct mailbox *box, const char *name, uint64_t *value_r, uint64_t *limit_r, const char **error_r) { @@ -736,14 +737,15 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name, if (ret == QUOTA_GET_RESULT_UNLIMITED) i_panic("Quota backend %s returned QUOTA_GET_RESULT_UNLIMITED " "while getting resource %s from box %s", - root->backend.name, name, mailbox_name); + root->backend.name, name, box == NULL ? "" : + mailbox_get_vname(box)); else if (ret != QUOTA_GET_RESULT_LIMITED) { *error_r = t_strdup_printf( "quota-%s: %s", root->set->backend->name, error); return ret; } - quota_root_get_rule_limits(root, mailbox_name, + quota_root_get_rule_limits(root, box, &bytes_limit, &count_limit, &ignored); if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) @@ -828,7 +830,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, const char **error_r) { struct quota_root *const *roots; - const char *mailbox_name, *error; + const char *error; unsigned int i, count; uint64_t bytes_limit, count_limit, current, limit, diff; bool use_grace, ignored; @@ -837,7 +839,6 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, if (ctx->limits_set) return 0; ctx->limits_set = TRUE; - mailbox_name = mailbox_get_vname(ctx->box); /* use quota_grace only for LDA/LMTP */ use_grace = (ctx->box->flags & MAILBOX_FLAG_POST_SESSION) != 0; ctx->no_quota_updates = TRUE; @@ -860,7 +861,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, else if (roots[i]->no_enforcing) { ignored = FALSE; } else { - quota_root_get_rule_limits(roots[i], mailbox_name, + quota_root_get_rule_limits(roots[i], ctx->box, &bytes_limit, &count_limit, &ignored); } @@ -868,7 +869,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, ctx->no_quota_updates = FALSE; if (bytes_limit > 0) { - ret = quota_get_resource(roots[i], mailbox_name, + ret = quota_get_resource(roots[i], ctx->box, QUOTA_NAME_STORAGE_BYTES, ¤t, &limit, &error); if (ret == QUOTA_GET_RESULT_LIMITED) { @@ -894,13 +895,13 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, *error_r = t_strdup_printf( "Failed to get quota resource " QUOTA_NAME_STORAGE_BYTES" for %s: %s", - mailbox_name, error); + mailbox_get_vname(ctx->box), error); return -1; } } if (count_limit > 0) { - ret = quota_get_resource(roots[i], mailbox_name, + ret = quota_get_resource(roots[i], ctx->box, QUOTA_NAME_MESSAGES, ¤t, &limit, &error); if (ret == QUOTA_GET_RESULT_LIMITED) { @@ -921,7 +922,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, *error_r = t_strdup_printf( "Failed to get quota resource " QUOTA_NAME_MESSAGES" for %s: %s", - mailbox_name, error); + mailbox_get_vname(ctx->box), error); return -1; } } @@ -1012,14 +1013,14 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx, if (count == 0) return; - if (quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES, + if (quota_get_resource(root, NULL, QUOTA_NAME_STORAGE_BYTES, &bytes_current, &bytes_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) { e_error(root->quota->event, "Failed to get quota resource "QUOTA_NAME_STORAGE_BYTES ": %s", error); return; } - if (quota_get_resource(root, "", QUOTA_NAME_MESSAGES, + if (quota_get_resource(root, NULL, QUOTA_NAME_MESSAGES, &count_current, &count_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) { e_error(root->quota->event, "Failed to get quota resource "QUOTA_NAME_MESSAGES @@ -1177,7 +1178,7 @@ static void quota_over_flag_check_root(struct quota_root *root) resources = quota_root_get_resources(root); for (i = 0; resources[i] != NULL; i++) { - ret = quota_get_resource(root, "", resources[i], &value, + ret = quota_get_resource(root, NULL, resources[i], &value, &limit, &error); if (ret == QUOTA_GET_RESULT_INTERNAL_ERROR) { /* can't reliably verify this */ @@ -1344,8 +1345,7 @@ static enum quota_alloc_result quota_default_test_alloc( roots[i]->no_enforcing) continue; - quota_root_get_rule_limits(roots[i], - mailbox_get_vname(ctx->box), + quota_root_get_rule_limits(roots[i], ctx->box, &bytes_limit, &count_limit, &ignore); diff --git a/src/plugins/quota/quota.h b/src/plugins/quota/quota.h index 5828c07619..839e54906e 100644 --- a/src/plugins/quota/quota.h +++ b/src/plugins/quota/quota.h @@ -112,7 +112,7 @@ bool quota_root_is_hidden(struct quota_root *root); /* Returns 1 if values were successfully returned, 0 if resource name doesn't exist or isn't enabled, -1 if error. */ enum quota_get_result -quota_get_resource(struct quota_root *root, const char *mailbox_name, +quota_get_resource(struct quota_root *root, struct mailbox *box, const char *name, uint64_t *value_r, uint64_t *limit_r, const char **error_r);