Skip to content

Commit

Permalink
quota: Remove support for setting quota limits via dict
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Jul 8, 2024
1 parent c21c21c commit 52c9f93
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 82 deletions.
2 changes: 0 additions & 2 deletions src/plugins/quota/quota-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ struct quota_root_settings {
struct quota_rule default_rule;
ARRAY(struct quota_rule) rules;
ARRAY(struct quota_warning_rule) warning_rules;
const char *limit_set;

/* If user is under quota before saving a mail, allow the last mail to
bring the user over quota by this many bytes. */
Expand All @@ -125,7 +124,6 @@ struct quota_root {
struct quota_root_settings *set;
struct quota *quota;
struct quota_backend backend;
struct dict *limit_set_dict;

/* this quota root applies only to this namespace. it may also be
a public namespace without an owner. */
Expand Down
77 changes: 0 additions & 77 deletions src/plugins/quota/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "write-full.h"
#include "eacces-error.h"
#include "wildcard-match.h"
#include "dict.h"
#include "mailbox-list-private.h"
#include "quota-private.h"
#include "quota-fs.h"
Expand All @@ -21,7 +20,6 @@

#define DEFAULT_QUOTA_EXCEEDED_MSG \
"Quota exceeded (mailbox for user is full)"
#define QUOTA_LIMIT_SET_PATH DICT_PATH_PRIVATE"quota/limit/"

/* How many seconds after the userdb lookup do we still want to execute the
quota_over_script. This applies to quota_over_flag_lazy_check=yes and also
Expand Down Expand Up @@ -168,26 +166,6 @@ quota_root_add_warning_rules(struct mail_user *user, const char *root_name,
return 0;
}

static int
quota_root_parse_set(struct mail_user *user, const char *root_name,
struct quota_root_settings *root_set,
const char **error_r)
{
const char *name, *value;

name = t_strconcat(root_name, "_set", NULL);
value = mail_user_plugin_getenv(user, name);
if (value == NULL)
return 0;

if (!str_begins(value, "dict:", &value)) {
*error_r = t_strdup_printf("%s supports only dict backend", name);
return -1;
}
root_set->limit_set = p_strdup(root_set->set->pool, value);
return 0;
}

static int
quota_root_settings_init(struct quota_settings *quota_set, const char *root_def,
struct quota_root_settings **set_r,
Expand Down Expand Up @@ -258,8 +236,6 @@ quota_root_add(struct quota_settings *quota_set, struct mail_user *user,
return -1;
if (quota_root_add_warning_rules(user, root_name, root_set, error_r) < 0)
return -1;
if (quota_root_parse_set(user, root_name, root_set, error_r) < 0)
return -1;

set_name = t_strconcat(root_name, "_grace", NULL);
value = mail_user_plugin_getenv(user, set_name);
Expand Down Expand Up @@ -393,8 +369,6 @@ static void quota_root_deinit(struct quota_root *root)
{
pool_t pool = root->pool;

if (root->limit_set_dict != NULL)
dict_deinit(&root->limit_set_dict);
event_unref(&root->backend.event);
root->backend.v.deinit(root);
pool_unref(&pool);
Expand Down Expand Up @@ -854,57 +828,6 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
return *limit_r == 0 ? QUOTA_GET_RESULT_UNLIMITED : QUOTA_GET_RESULT_LIMITED;
}

int quota_set_resource(struct quota_root *root, const char *name,
uint64_t value, const char **client_error_r)
{
struct dict_transaction_context *trans;
const char *key, *error;
const struct dict_op_settings *set;

if (root->set->limit_set == NULL) {
*client_error_r = MAIL_ERRSTR_NO_PERMISSION;
return -1;
}
if (strcasecmp(name, QUOTA_NAME_STORAGE_KILOBYTES) == 0)
key = "storage";
else if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
key = "bytes";
else if (strcasecmp(name, QUOTA_NAME_MESSAGES) == 0)
key = "messages";
else {
*client_error_r = t_strdup_printf(
"Unsupported resource name: %s", name);
return -1;
}

if (root->limit_set_dict == NULL) {
struct dict_legacy_settings set;

i_zero(&set);
set.base_dir = root->quota->user->set->base_dir;
set.event_parent = root->quota->user->event;
if (dict_init_legacy(root->set->limit_set, &set,
&root->limit_set_dict, &error) < 0) {
e_error(root->quota->event,
"dict_init() failed: %s", error);
*client_error_r = "Internal quota limit update error";
return -1;
}
}

set = mail_user_get_dict_op_settings(root->ns->user);
trans = dict_transaction_begin(root->limit_set_dict, set);
key = t_strdup_printf(QUOTA_LIMIT_SET_PATH"%s", key);
dict_set(trans, key, dec2str(value));
if (dict_transaction_commit(&trans, &error) < 0) {
e_error(root->quota->event,
"dict_transaction_commit() failed: %s", error);
*client_error_r = "Internal quota limit update error";
return -1;
}
return 0;
}

struct quota_transaction_context *quota_transaction_begin(struct mailbox *box)
{
struct quota_transaction_context *ctx;
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/quota/quota.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ enum quota_get_result
quota_get_resource(struct quota_root *root, const char *mailbox_name,
const char *name, uint64_t *value_r, uint64_t *limit_r,
const char **error_r);
/* Returns 0 if OK, -1 if error (eg. permission denied, invalid name). */
int quota_set_resource(struct quota_root *root, const char *name,
uint64_t value, const char **client_error_r);

/* Start a new quota transaction. */
struct quota_transaction_context *quota_transaction_begin(struct mailbox *box);
Expand Down

0 comments on commit 52c9f93

Please sign in to comment.