]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: Move var-expand-crypt-plugin to lib-var-expand-crypto
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 18 Nov 2024 12:15:53 +0000 (14:15 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:15 +0000 (12:34 +0200)
12 files changed:
configure.ac
src/Makefile.am
src/lib-var-expand-crypt/Makefile.am [new file with mode: 0644]
src/lib-var-expand-crypt/test-var-expand-crypt.c [moved from src/plugins/var-expand-crypt/test-var-expand-crypt.c with 99% similarity]
src/lib-var-expand-crypt/var-expand-crypt.c [moved from src/plugins/var-expand-crypt/var-expand-crypt-plugin.c with 94% similarity]
src/lib-var-expand/Makefile.am
src/lib-var-expand/expansion-filter-crypt.c [new file with mode: 0644]
src/lib-var-expand/expansion-filter.c
src/lib-var-expand/expansion.h
src/lib-var-expand/var-expand.h
src/plugins/Makefile.am
src/plugins/var-expand-crypt/Makefile.am [deleted file]

index 413b46bc98a0dc72389ca7cdf17ed42e796e90a7..b573ff3a7952180b7959337f5e19fff59236c456 100644 (file)
@@ -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
index 79897f51d0139e370f2e9c0f480321d31f66cb46..2ae86b8e540da7ba29a56b404c2a85bcb9334260 100644 (file)
@@ -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 (file)
index 0000000..8f829bc
--- /dev/null
@@ -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
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 d9ed4954cef67fb59543187014f0f46bbb152ce3..5aebb4696ad9c4d043a1a06a748edcdbb3c534cd 100644 (file)
@@ -4,7 +4,6 @@
 #include "test-common.h"
 #include "str.h"
 #include "var-expand.h"
-#include "randgen.h"
 #include "dcrypt.h"
 
 struct module;
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 88f4888359072dc653bfcefe02bba621b01e31bf..5a72d7c40f7e804ca404a28c1022c2e78b18767a 100644 (file)
@@ -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();
 }
index cb78496a729c95ff05735e3cbd64ed02fc5c1c15..08da4c9aac2aae13078575067e0318cd25c2d8a3 100644 (file)
@@ -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 (file)
index 0000000..0cab9dd
--- /dev/null
@@ -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);
+}
index 7ae07224ae7ea18f6effb112b818e1697f4195fe..dc62779eba69b94866b40712c4469ce3ff849f4b 100644 (file)
@@ -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 }
 };
 
index 04d6ea3c60ce0f63fb6a30ef4f612b1dc154b7d1..403d483398a0cefd456b7c0a47c4420c411d5314 100644 (file)
@@ -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
index 30eb60936b14a12f5bf7257d56784eb94e933e68..f8c71a24ef15a7969ea53186bd2e807291f9ba41 100644 (file)
@@ -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
index 5c7fd0ea1e7f9dae9b941f76c794c3dc4c3238bb..12acec64fdc28cbb06882d57a0ec7ffcd5ed8fa1 100644 (file)
@@ -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 (file)
index 8b198f2..0000000
+++ /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)