From: Timo Sirainen Date: Thu, 22 Aug 2024 08:00:16 +0000 (+0300) Subject: quota: Replace quota_warning_command and quota_over_status_script with execute {... X-Git-Tag: 2.4.0~387 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b480c5aa7e2e3bf377c14cf49c6870a607209c4d;p=thirdparty%2Fdovecot%2Fcore.git quota: Replace quota_warning_command and quota_over_status_script with execute { .. } --- diff --git a/src/plugins/quota/quota-settings.c b/src/plugins/quota/quota-settings.c index 59f9328b85..699c176fd8 100644 --- a/src/plugins/quota/quota-settings.c +++ b/src/plugins/quota/quota-settings.c @@ -38,12 +38,12 @@ static const struct setting_define quota_setting_defines[] = { DEF(STR, quota_warning_name), DEF(ENUM, quota_warning_resource), DEF(ENUM, quota_warning_threshold), - DEF(STR, quota_warning_command), + { .type = SET_FILTER_NAME, .key = "quota_over_status", + .required_setting = "execute", }, DEF(BOOL, quota_over_status_lazy_check), DEF(STR, quota_over_status_current), DEF(STR, quota_over_status_mask), - DEF(STR, quota_over_status_script), DEF(UINT, quota_mailbox_count), DEF(UINT, quota_mailbox_message_count), @@ -73,12 +73,10 @@ static const struct quota_settings quota_default_settings = { QUOTA_WARNING_RESOURCE_MESSAGE, .quota_warning_threshold = QUOTA_WARNING_THRESHOLD_OVER":" QUOTA_WARNING_THRESHOLD_UNDER, - .quota_warning_command = "", .quota_over_status_lazy_check = FALSE, .quota_over_status_current = "", .quota_over_status_mask = "", - .quota_over_status_script = "", .quota_mailbox_count = SET_UINT_UNLIMITED, .quota_mail_size = SET_SIZE_UNLIMITED, diff --git a/src/plugins/quota/quota-settings.h b/src/plugins/quota/quota-settings.h index 3af4e9454d..dd740d4180 100644 --- a/src/plugins/quota/quota-settings.h +++ b/src/plugins/quota/quota-settings.h @@ -52,13 +52,11 @@ struct quota_settings { /* Specifies whether the warning is executed when going over the limit or back under the limit. */ const char *quota_warning_threshold; - const char *quota_warning_command; /* For quota_over_status: */ bool quota_over_status_lazy_check; const char *quota_over_status_current; const char *quota_over_status_mask; - const char *quota_over_status_script; /* Globals: */ diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index f470e02853..5cb1218928 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -879,57 +879,26 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, return 0; } -static void quota_warning_execute(struct quota_root *root, const char *cmd, - const char *last_arg, const char *reason) +static void +quota_warning_execute(struct event *event, const char *last_arg, + const char *reason) { - const char *socket_path, *const *args, *error, *scheme, *ptr; - + const char *const append_args[] = { last_arg, NULL }; struct program_client_parameters params = { .client_connect_timeout_msecs = 1000, .no_reply = TRUE, + .append_args = append_args, }; struct program_client *pc; + const char *error; - e_debug(root->backend.event, "Executing warning: %s (because %s)", cmd, reason); - - args = t_strsplit_spaces(cmd, " "); - if (last_arg != NULL) { - unsigned int count = str_array_length(args); - const char **new_args = t_new(const char *, count + 2); - - memcpy(new_args, args, sizeof(const char *) * count); - new_args[count] = last_arg; - args = new_args; - } - socket_path = args[0]; - - if ((ptr = strchr(socket_path, ':')) != NULL) { - scheme = t_strcut(socket_path, ':'); - socket_path = ptr+1; - } else { - scheme = "unix"; - } - - if (*socket_path != '/' && - strcmp(scheme, "unix") == 0) - socket_path = - t_strconcat(root->quota->user->set->base_dir, - "/", socket_path, NULL); - - socket_path = t_strdup_printf("%s:%s", scheme, socket_path); - - args++; + e_debug(event, "Executing because: %s", reason); - if (program_client_create(root->backend.event, socket_path, args, - ¶ms, &pc, &error) < 0) { - e_error(root->backend.event, - "program_client_create(%s) failed: %s", socket_path, - error); + if (program_client_create_auto(event, ¶ms, &pc, &error) <= 0) { + e_error(event, "%s", error); return; } - (void)program_client_run(pc); - program_client_destroy(&pc); } @@ -980,8 +949,15 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx, if (quota_warning_match(set, bytes_before, bytes_current, count_before, count_current, &reason)) { - quota_warning_execute(root, set->quota_warning_command, - NULL, reason); + struct event *event = event_create(root->backend.event); + event_set_ptr(event, SETTINGS_EVENT_FILTER_NAME, + p_strdup_printf(event_get_pool(event), + "quota_warning/%s", + warn_name)); + event_set_append_log_prefix(event, t_strdup_printf( + "quota_warning %s: ", warn_name)); + quota_warning_execute(event, NULL, reason); + event_unref(&event); settings_free(set); break; } @@ -1050,11 +1026,6 @@ static bool quota_over_status_init_root(struct quota_root *root, bool *status_r) { *status_r = FALSE; - if (root->set->quota_over_status_script[0] == '\0') { - e_debug(root->backend.event, "quota_over_status check: " - "quota_over_script unset - skipping"); - return FALSE; - } /* e.g.: quota_over_status_mask=TRUE or quota_over_status_mask=* */ if (root->set->quota_over_status_mask[0] == '\0') { @@ -1123,9 +1094,14 @@ static void quota_over_status_check_root(struct quota_root *root) root->set->quota_over_status_current, cur_overquota ? 1 : 0); if (cur_overquota != quota_over_status) { - quota_warning_execute(root, root->set->quota_over_status_script, + struct event *event = event_create(root->backend.event); + event_set_ptr(event, SETTINGS_EVENT_FILTER_NAME, + "quota_over_status"); + event_set_append_log_prefix(event, "quota_over_status: "); + quota_warning_execute(event, root->set->quota_over_status_current, "quota_over_status mismatch"); + event_unref(&event); } }