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,
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) {
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;
#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)
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);
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;
(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) {
*bytes_limit_r = bytes_limit <= 0 ? 0 : bytes_limit;
*count_limit_r = count_limit <= 0 ? 0 : count_limit;
- return ret;
}
static bool
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;
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;
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;
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 */