From: Aki Tuomi Date: Mon, 18 Nov 2024 12:15:53 +0000 (+0200) Subject: lib-var-expand: Move var-expand-crypt-plugin to lib-var-expand-crypto X-Git-Tag: 2.4.1~520 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73ae2a9e45144f05a179d17d9b201226d93b81a0;p=thirdparty%2Fdovecot%2Fcore.git lib-var-expand: Move var-expand-crypt-plugin to lib-var-expand-crypto --- diff --git a/configure.ac b/configure.ac index 413b46bc98..b573ff3a79 100644 --- a/configure.ac +++ b/configure.ac @@ -846,6 +846,7 @@ src/lib-storage/index/dbox-single/Makefile src/lib-storage/index/raw/Makefile src/lib-storage/index/shared/Makefile src/lib-var-expand/Makefile +src/lib-var-expand-crypt/Makefile src/anvil/Makefile src/auth/Makefile src/config/Makefile @@ -893,7 +894,6 @@ src/plugins/virtual/Makefile src/plugins/welcome/Makefile src/plugins/mail-compress/Makefile src/plugins/mail-crypt/Makefile -src/plugins/var-expand-crypt/Makefile src/plugins/apparmor/Makefile src/plugins/charset-alias/Makefile stamp.h diff --git a/src/Makefile.am b/src/Makefile.am index 79897f51d0..2ae86b8e54 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,7 +34,8 @@ LIBDOVECOT_SUBDIRS = \ lib-imap \ lib-imap-storage \ lib-oauth2 \ - lib-doveadm + lib-doveadm \ + lib-var-expand-crypt SUBDIRS = \ $(LIBDOVECOT_SUBDIRS) \ diff --git a/src/lib-var-expand-crypt/Makefile.am b/src/lib-var-expand-crypt/Makefile.am new file mode 100644 index 0000000000..8f829bcc02 --- /dev/null +++ b/src/lib-var-expand-crypt/Makefile.am @@ -0,0 +1,44 @@ +module_LTLIBRARIES = var_expand_crypt.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ + -I$(top_srcdir)/src/lib-var-expand \ + -I$(top_srcdir)/src/lib-dcrypt + +var_expand_crypt_la_SOURCES = \ + var-expand-crypt.c + +var_expand_crypt_la_LDFLAGS = $(MODULE_LIBS) -avoid-version -module + +pkginc_libdir=$(pkgincludedir) +pkginc_lib_HEADERS = $(headers) + +test_programs = \ + test-var-expand-crypt + +noinst_PROGRAMS = $(test_programs) + +test_libs = \ + $(LIBUNWIND_LIBS) \ + $(module_LTLIBRARIES) \ + ../lib-dcrypt/libdcrypt.la \ + ../lib-var-expand/libvar_expand.la \ + ../lib-settings/libsettings.la \ + ../lib-test/libtest.la \ + $(DLLIB) + +test_var_expand_crypt_SOURCES = test-var-expand-crypt.c +test_var_expand_crypt_LDADD = $(test_libs) +test_var_expand_crypt_DEPENDENCIES = $(module_LTLIBRARIES) +if HAVE_WHOLE_ARCHIVE +test_var_expand_crypt_LDFLAGS = -export-dynamic -Wl,$(LD_WHOLE_ARCHIVE),../lib/.libs/liblib.a,../lib-json/.libs/libjson.a,../lib-ssl-iostream/.libs/libssl_iostream.a,$(LD_NO_WHOLE_ARCHIVE) +endif + +test_var_expand_crypt_CFLAGS = $(AM_CPPFLAGS) \ + -DDCRYPT_BUILD_DIR=\"$(top_builddir)/src/lib-dcrypt\" + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done diff --git a/src/plugins/var-expand-crypt/test-var-expand-crypt.c b/src/lib-var-expand-crypt/test-var-expand-crypt.c similarity index 99% rename from src/plugins/var-expand-crypt/test-var-expand-crypt.c rename to src/lib-var-expand-crypt/test-var-expand-crypt.c index d9ed4954ce..5aebb4696a 100644 --- a/src/plugins/var-expand-crypt/test-var-expand-crypt.c +++ b/src/lib-var-expand-crypt/test-var-expand-crypt.c @@ -4,7 +4,6 @@ #include "test-common.h" #include "str.h" #include "var-expand.h" -#include "randgen.h" #include "dcrypt.h" struct module; diff --git a/src/plugins/var-expand-crypt/var-expand-crypt-plugin.c b/src/lib-var-expand-crypt/var-expand-crypt.c similarity index 94% rename from src/plugins/var-expand-crypt/var-expand-crypt-plugin.c rename to src/lib-var-expand-crypt/var-expand-crypt.c index 88f4888359..5a72d7c40f 100644 --- a/src/plugins/var-expand-crypt/var-expand-crypt-plugin.c +++ b/src/lib-var-expand-crypt/var-expand-crypt.c @@ -4,6 +4,7 @@ #include "hex-binary.h" #include "str.h" #include "var-expand-private.h" +#include "expansion.h" #include "dcrypt.h" #define VAR_EXPAND_CRYPT_DEFAULT_ALGO "AES-256-CBC" @@ -25,10 +26,8 @@ struct var_expand_crypt_context { static bool var_expand_crypt_initialize(const char **error_r); -void var_expand_crypt_init(struct module *module); -void var_expand_crypt_deinit(void); -void auth_var_expand_crypt_init(struct module *module); -void auth_var_expand_crypt_deinit(void); +extern void var_expand_crypt_init(struct module *module); +extern void var_expand_crypt_deinit(void); static int parse_parameters(struct var_expand_crypt_context *ctx, const char *const *parts, const char **error_r) @@ -320,22 +319,11 @@ void var_expand_crypt_init(struct module *module ATTR_UNUSED) /* do not initialize dcrypt here - saves alot of memory to not load openssl every time. Only load it if needed */ - var_expand_register_filter("encrypt", var_expand_encrypt); - var_expand_register_filter("decrypt", var_expand_decrypt); -} -void var_expand_crypt_deinit(void) -{ - var_expand_unregister_filter("encrypt"); - var_expand_unregister_filter("decrypt"); + expansion_filter_crypt_set_functions(var_expand_encrypt, + var_expand_decrypt); } -void auth_var_expand_crypt_init(struct module *module) -{ - var_expand_crypt_init(module); -} - -void auth_var_expand_crypt_deinit(void) +void var_expand_crypt_deinit(void) { - var_expand_crypt_deinit(); } diff --git a/src/lib-var-expand/Makefile.am b/src/lib-var-expand/Makefile.am index cb78496a72..08da4c9aac 100644 --- a/src/lib-var-expand/Makefile.am +++ b/src/lib-var-expand/Makefile.am @@ -19,8 +19,8 @@ YACC=/bin/false AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ -I$(top_srcdir)/src/lib-test \ - -I$(top_srcdir)/src/lib-dcrypt \ - -Wno-error=unused-function + -Wno-error=unused-function \ + -DVAR_EXPAND_MODULE_DIR=\"$(pkglibdir)\" var-expand-parser.h: var-expand-parser.c @@ -29,6 +29,7 @@ libvar_expand_la_SOURCES = \ expansion-statement.c \ expansion-filter.c \ expansion-filter-if.c \ + expansion-filter-crypt.c \ expansion-program.c \ var-expand.c \ var-expand-parser.y \ diff --git a/src/lib-var-expand/expansion-filter-crypt.c b/src/lib-var-expand/expansion-filter-crypt.c new file mode 100644 index 0000000000..0cab9dd5d7 --- /dev/null +++ b/src/lib-var-expand/expansion-filter-crypt.c @@ -0,0 +1,52 @@ +/* Copyright (c) 2024 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "module-dir.h" +#include "var-expand-private.h" +#include "expansion.h" + +static struct module *var_expand_crypt_module; + +static var_expand_filter_func_t *fn_encrypt = NULL; +static var_expand_filter_func_t *fn_decrypt = NULL; + +void var_expand_crypt_load(void) +{ + struct module_dir_load_settings set = { + .require_init_funcs = TRUE + }; + const char *const mods[] = { + "var_expand_crypt", + NULL + }; + + var_expand_crypt_module = + module_dir_load(VAR_EXPAND_MODULE_DIR, mods, &set); + module_dir_init(var_expand_crypt_module); +} + +void expansion_filter_crypt_set_functions(var_expand_filter_func_t *encrypt, + var_expand_filter_func_t *decrypt) +{ + i_assert(fn_encrypt == NULL && fn_decrypt == NULL); + fn_encrypt = encrypt; + fn_decrypt = decrypt; +} + +int +expansion_filter_encrypt(const struct var_expand_statement *stmt, + struct var_expand_state *state, const char **error_r) +{ + if (fn_encrypt == NULL) + var_expand_crypt_load(); + return fn_encrypt(stmt, state, error_r); +} + +int +expansion_filter_decrypt(const struct var_expand_statement *stmt, + struct var_expand_state *state, const char **error_r) +{ + if (fn_decrypt == NULL) + var_expand_crypt_load(); + return fn_decrypt(stmt, state, error_r); +} diff --git a/src/lib-var-expand/expansion-filter.c b/src/lib-var-expand/expansion-filter.c index 7ae07224ae..dc62779eba 100644 --- a/src/lib-var-expand/expansion-filter.c +++ b/src/lib-var-expand/expansion-filter.c @@ -1164,6 +1164,8 @@ static const struct var_expand_filter var_expand_builtin_filters[] = { { .name = "lfill", .filter = fn_lfill }, { .name = "rfill", .filter = fn_rfill }, { .name = "text", .filter = fn_text }, + { .name = "encrypt", .filter = expansion_filter_encrypt }, + { .name = "decrypt", .filter = expansion_filter_decrypt }, { .name = NULL } }; diff --git a/src/lib-var-expand/expansion.h b/src/lib-var-expand/expansion.h index 04d6ea3c60..403d483398 100644 --- a/src/lib-var-expand/expansion.h +++ b/src/lib-var-expand/expansion.h @@ -33,5 +33,14 @@ int var_expand_find_filter(const char *name, var_expand_filter_func_t **fn_r); int expansion_filter_if(const struct var_expand_statement *stmt, struct var_expand_state *state, const char **error_r); +int +expansion_filter_encrypt(const struct var_expand_statement *stmt, + struct var_expand_state *state, const char **error_r); +int +expansion_filter_decrypt(const struct var_expand_statement *stmt, + struct var_expand_state *state, const char **error_r); + +void expansion_filter_crypt_set_functions(var_expand_filter_func_t *encrypt, + var_expand_filter_func_t *decrypt); #endif diff --git a/src/lib-var-expand/var-expand.h b/src/lib-var-expand/var-expand.h index 30eb60936b..f8c71a24ef 100644 --- a/src/lib-var-expand/var-expand.h +++ b/src/lib-var-expand/var-expand.h @@ -167,4 +167,6 @@ static inline void var_expand_table_copy(struct var_expand_table *table, entry_b->func = entry_a->func; } +void var_expand_crypt_load(void); + #endif diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 5c7fd0ea1e..12acec64fd 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -39,5 +39,4 @@ SUBDIRS = \ $(DICT_LDAP) \ $(APPARMOR) \ fs-compress \ - var-expand-crypt \ charset-alias diff --git a/src/plugins/var-expand-crypt/Makefile.am b/src/plugins/var-expand-crypt/Makefile.am deleted file mode 100644 index 8b198f243e..0000000000 --- a/src/plugins/var-expand-crypt/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/lib-var-expand \ - -I$(top_srcdir)/src/lib \ - -I$(top_srcdir)/src/lib-test \ - -I$(top_srcdir)/src/lib-dcrypt - -NOPLUGIN_LDFLAGS = -lib20_var_expand_crypt_la_LDFLAGS = -module -avoid-version -lib20_auth_var_expand_crypt_la_LDFLAGS = -module -avoid-version - -auth_moduledir = $(moduledir)/auth - -module_LTLIBRARIES = \ - lib20_var_expand_crypt.la - -auth_module_LTLIBRARIES = \ - lib20_auth_var_expand_crypt.la - -lib20_auth_var_expand_crypt_la_SOURCES = \ - var-expand-crypt-plugin.c - -lib20_var_expand_crypt_la_SOURCES = \ - var-expand-crypt-plugin.c - -test_programs = test-var-expand-crypt - -test_var_expand_crypt_CFLAGS = \ - $(AM_CPPFLAGS) \ - -DDCRYPT_BUILD_DIR=\"$(top_builddir)/src/lib-dcrypt\" -test_var_expand_crypt_SOURCES = \ - test-var-expand-crypt.c -test_var_expand_crypt_LDADD = \ - $(LIBDOVECOT) \ - lib20_auth_var_expand_crypt.la -test_var_expand_crypt_DEPENDENCIES = \ - $(LIBDOVECOT_DEPS) \ - lib20_auth_var_expand_crypt.la - -check-local: - for bin in $(test_programs); do \ - if ! env $(test_options) $(RUN_TEST) ./$$bin; then exit 1; fi; \ - done - -noinst_PROGRAMS = $(test_programs)