summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/managesieve/managesieve-quota.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:36:47 +0000
commit0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch)
tree3f3789daa2f6db22da6e55e92bee0062a7d613fe /pigeonhole/src/managesieve/managesieve-quota.c
parentInitial commit. (diff)
downloaddovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz
dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/managesieve/managesieve-quota.c')
-rw-r--r--pigeonhole/src/managesieve/managesieve-quota.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/pigeonhole/src/managesieve/managesieve-quota.c b/pigeonhole/src/managesieve/managesieve-quota.c
new file mode 100644
index 0000000..07b58ca
--- /dev/null
+++ b/pigeonhole/src/managesieve/managesieve-quota.c
@@ -0,0 +1,98 @@
+/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "lib.h"
+#include "strfuncs.h"
+
+#include "sieve.h"
+#include "sieve-storage.h"
+
+#include "managesieve-client.h"
+#include "managesieve-quota.h"
+
+uint64_t managesieve_quota_max_script_size(struct client *client)
+{
+ return sieve_storage_quota_max_script_size(client->storage);
+}
+
+bool managesieve_quota_check_validsize(struct client_command_context *cmd,
+ size_t size)
+{
+ struct client *client = cmd->client;
+ uint64_t limit;
+
+ if (!sieve_storage_quota_validsize(client->storage, size, &limit)) {
+ const char *error_msg;
+
+ error_msg = t_strdup_printf(
+ "Script is too large (max %llu bytes).",
+ (unsigned long long int)limit);
+
+ struct event_passthrough *e =
+ client_command_create_finish_event(cmd);
+ e_debug(e->event(),
+ "Script size check failed (size %zu bytes): %s",
+ size, error_msg);
+
+ client_send_noresp(client, "QUOTA/MAXSIZE", error_msg);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+bool managesieve_quota_check_all(struct client_command_context *cmd,
+ const char *scriptname, size_t size)
+{
+ struct client *client = cmd->client;
+ enum sieve_storage_quota quota;
+ uint64_t limit;
+ const char *resp_code = NULL, *error_msg = NULL;
+ int ret;
+
+ ret = sieve_storage_quota_havespace(client->storage, scriptname,
+ size, &quota, &limit);
+ if (ret > 0)
+ return TRUE;
+ if (ret < 0) {
+ client_command_storage_error(
+ cmd, "Failed to check quota for script `%s' "
+ "(size %zu bytes)", scriptname, size);
+ return FALSE;
+ }
+
+ switch (quota) {
+ case SIEVE_STORAGE_QUOTA_MAXSIZE:
+ resp_code = "QUOTA/MAXSIZE";
+ error_msg = t_strdup_printf("Script is too large "
+ "(max %llu bytes).",
+ (unsigned long long int)limit);
+ break;
+ case SIEVE_STORAGE_QUOTA_MAXSCRIPTS:
+ resp_code = "QUOTA/MAXSCRIPTS";
+ error_msg = t_strdup_printf("Script count quota exceeded "
+ "(max %llu scripts).",
+ (unsigned long long int)limit);
+ break;
+ case SIEVE_STORAGE_QUOTA_MAXSTORAGE:
+ resp_code = "QUOTA/MAXSTORAGE";
+ error_msg = t_strdup_printf("Script storage quota exceeded "
+ "(max %llu bytes).",
+ (unsigned long long int)limit);
+ break;
+ default:
+ resp_code = "QUOTA";
+ error_msg = "Quota exceeded.";
+ }
+
+ struct event_passthrough *e =
+ client_command_create_finish_event(cmd)->
+ add_str("error", error_msg);
+ e_debug(e->event(),
+ "Quota check failed for script `%s' (size %zu bytes): %s",
+ scriptname, size, error_msg);
+
+ client_send_noresp(client, resp_code, error_msg);
+
+ return FALSE;
+}
+