From: Aki Tuomi Date: Mon, 13 Nov 2023 08:07:08 +0000 (+0200) Subject: plugins: imap-acl - Add imap_acl_settings X-Git-Tag: 2.4.1~1152 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55b1f25ba51ae19e308af001a56d75d376ef7ace;p=thirdparty%2Fdovecot%2Fcore.git plugins: imap-acl - Add imap_acl_settings Renames acl_anyone to imap_acl_allow_anyone. --- diff --git a/src/plugins/imap-acl/Makefile.am b/src/plugins/imap-acl/Makefile.am index c6839747b5..80d966beda 100644 --- a/src/plugins/imap-acl/Makefile.am +++ b/src/plugins/imap-acl/Makefile.am @@ -1,5 +1,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-mail \ -I$(top_srcdir)/src/lib-imap \ -I$(top_srcdir)/src/lib-index \ diff --git a/src/plugins/imap-acl/imap-acl-plugin.c b/src/plugins/imap-acl/imap-acl-plugin.c index 43dac0b08e..f873ece501 100644 --- a/src/plugins/imap-acl/imap-acl-plugin.c +++ b/src/plugins/imap-acl/imap-acl-plugin.c @@ -2,6 +2,7 @@ #include "imap-common.h" #include "str.h" +#include "settings.h" #include "imap-quote.h" #include "imap-resp-code.h" #include "imap-commands.h" @@ -34,6 +35,38 @@ #define IMAP_ACL_CONTEXT_REQUIRE(obj) \ MODULE_CONTEXT_REQUIRE(obj, imap_acl_storage_module) +/* */ +struct imap_acl_settings { + pool_t pool; + bool allow_anyone; +}; + +#undef DEF +#define DEF(type, name) \ + SETTING_DEFINE_STRUCT_##type("imap_acl_" #name, name, \ + struct imap_acl_settings) + +static const struct setting_define imap_acl_setting_defines[] = { + DEF(BOOL, allow_anyone), + + SETTING_DEFINE_LIST_END +}; + +static struct imap_acl_settings imap_acl_default_settings = { + .allow_anyone = FALSE, +}; +/* */ + +const struct setting_parser_info imap_acl_setting_parser_info = { + .name = "imap_acl", + + .defines = imap_acl_setting_defines, + .defaults = &imap_acl_default_settings, + + .struct_size = sizeof(struct imap_acl_settings), + .pool_offset1 = 1 + offsetof(struct imap_acl_settings, pool), +}; + struct imap_acl_letter_map { char letter; const char *name; @@ -807,20 +840,23 @@ imap_acl_letters_parse(const char *letters, const char *const **rights_r, return 0; } -static bool acl_anyone_allow(struct mail_user *user) -{ - const char *env; - - env = mail_user_plugin_getenv(user, "acl_anyone"); - return env != NULL && strcmp(env, "allow") == 0; -} - static int imap_acl_identifier_parse(struct client_command_context *cmd, const char *id, struct acl_rights *rights, bool check_anyone, const char **client_error_r) { + const struct imap_acl_settings *set; struct mail_user *user = cmd->client->user; + const char *error; + bool allow_anyone; + if (settings_get(user->event, &imap_acl_setting_parser_info, 0, &set, + &error) < 0) { + e_error(user->event, "%s", error); + *client_error_r = MAIL_ERRSTR_CRITICAL_MSG; + return -1; + } + allow_anyone = set->allow_anyone; + settings_free(set); if (str_begins_with(id, IMAP_ACL_GLOBAL_PREFIX)) { *client_error_r = t_strdup_printf("Global ACLs can't be modified: %s", @@ -829,14 +865,15 @@ imap_acl_identifier_parse(struct client_command_context *cmd, } if (strcmp(id, IMAP_ACL_ANYONE) == 0) { - if (check_anyone && !acl_anyone_allow(user)) { + if (check_anyone && !allow_anyone) { *client_error_r = "'anyone' identifier is disallowed"; return -1; } rights->id_type = ACL_ID_ANYONE; } else if (strcmp(id, IMAP_ACL_AUTHENTICATED) == 0) { - if (check_anyone && !acl_anyone_allow(user)) { - *client_error_r = "'authenticated' identifier is disallowed"; + if (check_anyone && !allow_anyone) { + *client_error_r = + "'authenticated' identifier is disallowed"; return -1; } rights->id_type = ACL_ID_AUTHENTICATED;