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
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
lib-imap \
lib-imap-storage \
lib-oauth2 \
- lib-doveadm
+ lib-doveadm \
+ lib-var-expand-crypt
SUBDIRS = \
$(LIBDOVECOT_SUBDIRS) \
--- /dev/null
+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
#include "test-common.h"
#include "str.h"
#include "var-expand.h"
-#include "randgen.h"
#include "dcrypt.h"
struct module;
#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"
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)
/* 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();
}
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
expansion-statement.c \
expansion-filter.c \
expansion-filter-if.c \
+ expansion-filter-crypt.c \
expansion-program.c \
var-expand.c \
var-expand-parser.y \
--- /dev/null
+/* 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);
+}
{ .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 }
};
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
entry_b->func = entry_a->func;
}
+void var_expand_crypt_load(void);
+
#endif
$(DICT_LDAP) \
$(APPARMOR) \
fs-compress \
- var-expand-crypt \
charset-alias
+++ /dev/null
-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)