diff options
Diffstat (limited to 'pigeonhole/src/lib-sieve/plugins/include')
13 files changed, 3591 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/plugins/include/Makefile.am b/pigeonhole/src/lib-sieve/plugins/include/Makefile.am new file mode 100644 index 0000000..5ce1599 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/Makefile.am @@ -0,0 +1,24 @@ +noinst_LTLIBRARIES = libsieve_ext_include.la + +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../variables \ + $(LIBDOVECOT_INCLUDE) + +cmds = \ + cmd-include.c \ + cmd-return.c \ + cmd-global.c + +libsieve_ext_include_la_SOURCES = \ + $(cmds) \ + ext-include-common.c \ + ext-include-binary.c \ + ext-include-variables.c \ + ext-include.c + +noinst_HEADERS = \ + ext-include-common.h \ + ext-include-limits.h \ + ext-include-binary.h \ + ext-include-variables.h diff --git a/pigeonhole/src/lib-sieve/plugins/include/Makefile.in b/pigeonhole/src/lib-sieve/plugins/include/Makefile.in new file mode 100644 index 0000000..bf24f9c --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/Makefile.in @@ -0,0 +1,718 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/lib-sieve/plugins/include +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/dummy-config.h \ + $(top_builddir)/pigeonhole-config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libsieve_ext_include_la_LIBADD = +am__objects_1 = cmd-include.lo cmd-return.lo cmd-global.lo +am_libsieve_ext_include_la_OBJECTS = $(am__objects_1) \ + ext-include-common.lo ext-include-binary.lo \ + ext-include-variables.lo ext-include.lo +libsieve_ext_include_la_OBJECTS = \ + $(am_libsieve_ext_include_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cmd-global.Plo \ + ./$(DEPDIR)/cmd-include.Plo ./$(DEPDIR)/cmd-return.Plo \ + ./$(DEPDIR)/ext-include-binary.Plo \ + ./$(DEPDIR)/ext-include-common.Plo \ + ./$(DEPDIR)/ext-include-variables.Plo \ + ./$(DEPDIR)/ext-include.Plo +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libsieve_ext_include_la_SOURCES) +DIST_SOURCES = $(libsieve_ext_include_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_CONFIGURE_FLAGS = @DISTCHECK_CONFIGURE_FLAGS@ +DLLTOOL = @DLLTOOL@ +DOVECOT_BINARY_CFLAGS = @DOVECOT_BINARY_CFLAGS@ +DOVECOT_BINARY_LDFLAGS = @DOVECOT_BINARY_LDFLAGS@ +DOVECOT_CFLAGS = @DOVECOT_CFLAGS@ +DOVECOT_COMPRESS_LIBS = @DOVECOT_COMPRESS_LIBS@ +DOVECOT_INSTALLED = @DOVECOT_INSTALLED@ +DOVECOT_LIBS = @DOVECOT_LIBS@ +DOVECOT_LUA_CFLAGS = @DOVECOT_LUA_CFLAGS@ +DOVECOT_LUA_LIBS = @DOVECOT_LUA_LIBS@ +DOVECOT_SQL_LIBS = @DOVECOT_SQL_LIBS@ +DOVECOT_SSL_LIBS = @DOVECOT_SSL_LIBS@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_ACL_INCLUDE = @LIBDOVECOT_ACL_INCLUDE@ +LIBDOVECOT_AUTH_INCLUDE = @LIBDOVECOT_AUTH_INCLUDE@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_COMPRESS_DEPS = @LIBDOVECOT_COMPRESS_DEPS@ +LIBDOVECOT_CONFIG_INCLUDE = @LIBDOVECOT_CONFIG_INCLUDE@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DOVEADM_INCLUDE = @LIBDOVECOT_DOVEADM_INCLUDE@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_DSYNC_DEPS = @LIBDOVECOT_DSYNC_DEPS@ +LIBDOVECOT_DSYNC_INCLUDE = @LIBDOVECOT_DSYNC_INCLUDE@ +LIBDOVECOT_FTS_INCLUDE = @LIBDOVECOT_FTS_INCLUDE@ +LIBDOVECOT_IMAPC_INCLUDE = @LIBDOVECOT_IMAPC_INCLUDE@ +LIBDOVECOT_IMAP_INCLUDE = @LIBDOVECOT_IMAP_INCLUDE@ +LIBDOVECOT_IMAP_LOGIN_INCLUDE = @LIBDOVECOT_IMAP_LOGIN_INCLUDE@ +LIBDOVECOT_INCLUDE = @LIBDOVECOT_INCLUDE@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDA_DEPS = @LIBDOVECOT_LDA_DEPS@ +LIBDOVECOT_LDA_INCLUDE = @LIBDOVECOT_LDA_INCLUDE@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LIBFTS_INCLUDE = @LIBDOVECOT_LIBFTS_INCLUDE@ +LIBDOVECOT_LMTP_INCLUDE = @LIBDOVECOT_LMTP_INCLUDE@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LOGIN_DEPS = @LIBDOVECOT_LOGIN_DEPS@ +LIBDOVECOT_LOGIN_INCLUDE = @LIBDOVECOT_LOGIN_INCLUDE@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_LUA_INCLUDE = @LIBDOVECOT_LUA_INCLUDE@ +LIBDOVECOT_NOTIFY_INCLUDE = @LIBDOVECOT_NOTIFY_INCLUDE@ +LIBDOVECOT_POP3_INCLUDE = @LIBDOVECOT_POP3_INCLUDE@ +LIBDOVECOT_PUSH_NOTIFICATION_INCLUDE = @LIBDOVECOT_PUSH_NOTIFICATION_INCLUDE@ +LIBDOVECOT_SERVICE_INCLUDE = @LIBDOVECOT_SERVICE_INCLUDE@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_SQL_DEPS = @LIBDOVECOT_SQL_DEPS@ +LIBDOVECOT_SQL_INCLUDE = @LIBDOVECOT_SQL_INCLUDE@ +LIBDOVECOT_SSL = @LIBDOVECOT_SSL@ +LIBDOVECOT_SSL_DEPS = @LIBDOVECOT_SSL_DEPS@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBDOVECOT_STORAGE_INCLUDE = @LIBDOVECOT_STORAGE_INCLUDE@ +LIBDOVECOT_SUBMISSION_INCLUDE = @LIBDOVECOT_SUBMISSION_INCLUDE@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dovecot_docdir = @dovecot_docdir@ +dovecot_installed_moduledir = @dovecot_installed_moduledir@ +dovecot_moduledir = @dovecot_moduledir@ +dovecot_pkgincludedir = @dovecot_pkgincludedir@ +dovecot_pkglibdir = @dovecot_pkglibdir@ +dovecot_pkglibexecdir = @dovecot_pkglibexecdir@ +dovecot_statedir = @dovecot_statedir@ +dovecotdir = @dovecotdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sieve_docdir = @sieve_docdir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = libsieve_ext_include.la +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../variables \ + $(LIBDOVECOT_INCLUDE) + +cmds = \ + cmd-include.c \ + cmd-return.c \ + cmd-global.c + +libsieve_ext_include_la_SOURCES = \ + $(cmds) \ + ext-include-common.c \ + ext-include-binary.c \ + ext-include-variables.c \ + ext-include.c + +noinst_HEADERS = \ + ext-include-common.h \ + ext-include-limits.h \ + ext-include-binary.h \ + ext-include-variables.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib-sieve/plugins/include/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib-sieve/plugins/include/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libsieve_ext_include.la: $(libsieve_ext_include_la_OBJECTS) $(libsieve_ext_include_la_DEPENDENCIES) $(EXTRA_libsieve_ext_include_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libsieve_ext_include_la_OBJECTS) $(libsieve_ext_include_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-global.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-include.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-return.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-include-binary.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-include-common.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-include-variables.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-include.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/cmd-global.Plo + -rm -f ./$(DEPDIR)/cmd-include.Plo + -rm -f ./$(DEPDIR)/cmd-return.Plo + -rm -f ./$(DEPDIR)/ext-include-binary.Plo + -rm -f ./$(DEPDIR)/ext-include-common.Plo + -rm -f ./$(DEPDIR)/ext-include-variables.Plo + -rm -f ./$(DEPDIR)/ext-include.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/cmd-global.Plo + -rm -f ./$(DEPDIR)/cmd-include.Plo + -rm -f ./$(DEPDIR)/cmd-return.Plo + -rm -f ./$(DEPDIR)/ext-include-binary.Plo + -rm -f ./$(DEPDIR)/ext-include-common.Plo + -rm -f ./$(DEPDIR)/ext-include-variables.Plo + -rm -f ./$(DEPDIR)/ext-include.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-noinstLTLIBRARIES \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/pigeonhole/src/lib-sieve/plugins/include/cmd-global.c b/pigeonhole/src/lib-sieve/plugins/include/cmd-global.c new file mode 100644 index 0000000..0ef37eb --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/cmd-global.c @@ -0,0 +1,329 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" + +#include "sieve-common.h" +#include "sieve-code.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-binary.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "sieve-ext-variables.h" + +#include "ext-include-common.h" +#include "ext-include-binary.h" +#include "ext-include-variables.h" + +/* + * Commands + */ + +static bool cmd_global_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_global_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); + +const struct sieve_command_def cmd_global = { + .identifier = "global", + .type = SCT_COMMAND, + .positional_args = 1, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .validate = cmd_global_validate, + .generate = cmd_global_generate, +}; + +/* DEPRICATED: + */ + +/* Import command + * + * Syntax + * import + */ +const struct sieve_command_def cmd_import = { + .identifier = "import", + .type = SCT_COMMAND, + .positional_args = 1, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .validate = cmd_global_validate, + .generate = cmd_global_generate, +}; + +/* Export command + * + * Syntax + * export + */ +const struct sieve_command_def cmd_export = { + .identifier = "export", + .type = SCT_COMMAND, + .positional_args = 1, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .validate = cmd_global_validate, + .generate = cmd_global_generate, +}; + +/* + * Operations + */ + +static bool opc_global_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int opc_global_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +/* Global operation */ + +const struct sieve_operation_def global_operation = { + .mnemonic = "GLOBAL", + .ext_def = &include_extension, + .code = EXT_INCLUDE_OPERATION_GLOBAL, + .dump = opc_global_dump, + .execute = opc_global_execute +}; + +/* + * Validation + */ + +static inline struct sieve_argument *_create_variable_argument +(struct sieve_command *cmd, struct sieve_variable *var) +{ + struct sieve_argument *argument = sieve_argument_create + (cmd->ast_node->ast, NULL, cmd->ext, 0); + + argument->data = (void *) var; + + return argument; +} + +static bool cmd_global_validate +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct sieve_ast_argument *arg = cmd->first_positional; + struct sieve_command *prev = sieve_command_prev(cmd); + + /* DEPRECATED: Check valid command placement */ + if ( !sieve_command_is(cmd, cmd_global) ) { + if ( !sieve_command_is_toplevel(cmd) || + ( !sieve_command_is_first(cmd) && prev != NULL && + !sieve_command_is(prev, cmd_require) && + !sieve_command_is(prev, cmd_import) && + !sieve_command_is(prev, cmd_export) ) ) { + sieve_command_validate_error(valdtr, cmd, + "the DEPRECATED %s command can only be placed at top level " + "at the beginning of the file after any require or " + "import/export commands", + sieve_command_identifier(cmd)); + return FALSE; + } + } + + /* Check for use of variables extension */ + if ( !ext_include_validator_have_variables(this_ext, valdtr) ) { + sieve_command_validate_error(valdtr, cmd, + "%s command requires that variables extension is active", + sieve_command_identifier(cmd)); + return FALSE; + } + + /* Register global variable */ + if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { + /* Single string */ + const char *identifier = sieve_ast_argument_strc(arg); + struct sieve_variable *var; + + if ( (var=ext_include_variable_import_global + (valdtr, cmd, identifier)) == NULL ) + return FALSE; + + arg->argument = _create_variable_argument(cmd, var); + + } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { + /* String list */ + struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); + + while ( stritem != NULL ) { + const char *identifier = sieve_ast_argument_strc(stritem); + struct sieve_variable *var; + + if ( (var=ext_include_variable_import_global + (valdtr, cmd, identifier)) == NULL ) + return FALSE; + + stritem->argument = _create_variable_argument(cmd, var); + + stritem = sieve_ast_strlist_next(stritem); + } + } else { + /* Something else */ + sieve_argument_validate_error(valdtr, arg, + "the %s command accepts a single string or string list argument, " + "but %s was found", sieve_command_identifier(cmd), + sieve_ast_argument_name(arg)); + return FALSE; + } + + /* Join global commands with predecessors if possible */ + if ( sieve_commands_equal(prev, cmd) ) { + /* Join this command's string list with the previous one */ + prev->first_positional = sieve_ast_stringlist_join + (prev->first_positional, cmd->first_positional); + + if ( prev->first_positional == NULL ) { + /* Not going to happen unless MAXINT stringlist items are specified */ + sieve_command_validate_error(valdtr, cmd, + "compiler reached AST limit (script too complex)"); + return FALSE; + } + + /* Detach this command node */ + sieve_ast_node_detach(cmd->ast_node); + } + + return TRUE; +} + +/* + * Code generation + */ + +static bool cmd_global_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + struct sieve_ast_argument *arg = cmd->first_positional; + + sieve_operation_emit(cgenv->sblock, cmd->ext, &global_operation); + + if ( sieve_ast_argument_type(arg) == SAAT_STRING ) { + /* Single string */ + struct sieve_variable *var = (struct sieve_variable *) arg->argument->data; + + (void)sieve_binary_emit_unsigned(cgenv->sblock, 1); + (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); + + } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { + /* String list */ + struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg); + + (void)sieve_binary_emit_unsigned + (cgenv->sblock, sieve_ast_strlist_count(arg)); + + while ( stritem != NULL ) { + struct sieve_variable *var = + (struct sieve_variable *) stritem->argument->data; + + (void)sieve_binary_emit_unsigned(cgenv->sblock, var->index); + + stritem = sieve_ast_strlist_next(stritem); + } + } else { + i_unreached(); + } + + return TRUE; +} + +/* + * Code dump + */ + +static bool opc_global_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + const struct sieve_extension *this_ext = denv->oprtn->ext; + unsigned int count, i, var_count; + struct sieve_variable_scope_binary *global_vars; + struct sieve_variable_scope *global_scope; + struct sieve_variable * const *vars; + + if ( !sieve_binary_read_unsigned(denv->sblock, address, &count) ) + return FALSE; + + sieve_code_dumpf(denv, "GLOBAL (count: %u):", count); + + global_vars = ext_include_binary_get_global_scope(this_ext, denv->sbin); + global_scope = sieve_variable_scope_binary_get(global_vars); + vars = sieve_variable_scope_get_variables(global_scope, &var_count); + + sieve_code_descend(denv); + + for ( i = 0; i < count; i++ ) { + unsigned int index; + + sieve_code_mark(denv); + if ( !sieve_binary_read_unsigned(denv->sblock, address, &index) || + index >= var_count ) + return FALSE; + + sieve_code_dumpf(denv, "%d: VAR[%d]: '%s'", i, index, vars[index]->identifier); + } + + return TRUE; +} + +/* + * Execution + */ + +static int opc_global_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + const struct sieve_extension *this_ext = renv->oprtn->ext; + struct sieve_variable_scope_binary *global_vars; + struct sieve_variable_scope *global_scope; + struct sieve_variable_storage *storage; + struct sieve_variable * const *vars; + unsigned int var_count, count, i; + + if ( !sieve_binary_read_unsigned(renv->sblock, address, &count) ) { + sieve_runtime_trace_error(renv, + "global: count operand invalid"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + global_vars = ext_include_binary_get_global_scope(this_ext, renv->sbin); + global_scope = sieve_variable_scope_binary_get(global_vars); + vars = sieve_variable_scope_get_variables(global_scope, &var_count); + storage = ext_include_interpreter_get_global_variables + (this_ext, renv->interp); + + for ( i = 0; i < count; i++ ) { + unsigned int index; + + if ( !sieve_binary_read_unsigned(renv->sblock, address, &index) ) { + sieve_runtime_trace_error(renv, + "global: variable index operand invalid"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if ( index >= var_count ) { + sieve_runtime_trace_error(renv, + "global: variable index %u is invalid in global storage (> %u)", + index, var_count); + return SIEVE_EXEC_BIN_CORRUPT; + } + + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "global: exporting variable '%s' [gvid: %u, vid: %u]", + vars[index]->identifier, i, index); + + /* Make sure variable is initialized (export) */ + (void)sieve_variable_get_modifiable(storage, index, NULL); + } + + return SIEVE_EXEC_OK; +} + + diff --git a/pigeonhole/src/lib-sieve/plugins/include/cmd-include.c b/pigeonhole/src/lib-sieve/plugins/include/cmd-include.c new file mode 100644 index 0000000..92aefb4 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/cmd-include.c @@ -0,0 +1,406 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "str-sanitize.h" + +#include "sieve-common.h" +#include "sieve-script.h" +#include "sieve-storage.h" +#include "sieve-ast.h" +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-binary.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "ext-include-common.h" +#include "ext-include-binary.h" + +/* + * Include command + * + * Syntax: + * include [LOCATION] [":once"] [":optional"] <value: string> + * + * [LOCATION]: + * ":personal" / ":global" + */ + +static bool cmd_include_registered + (struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool cmd_include_pre_validate + (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd); +static bool cmd_include_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_include_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); + +const struct sieve_command_def cmd_include = { + .identifier = "include", + .type = SCT_COMMAND, + .positional_args = 1, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .registered = cmd_include_registered, + .pre_validate = cmd_include_pre_validate, + .validate = cmd_include_validate, + .generate = cmd_include_generate +}; + +/* + * Include operation + */ + +static bool opc_include_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int opc_include_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def include_operation = { + .mnemonic = "include", + .ext_def = &include_extension, + .code = EXT_INCLUDE_OPERATION_INCLUDE, + .dump = opc_include_dump, + .execute = opc_include_execute +}; + +/* + * Context structures + */ + +struct cmd_include_context_data { + enum ext_include_script_location location; + + struct sieve_script *script; + enum ext_include_flags flags; + + bool location_assigned:1; +}; + +/* + * Tagged arguments + */ + +static bool cmd_include_validate_location_tag + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +static const struct sieve_argument_def include_personal_tag = { + .identifier = "personal", + .validate = cmd_include_validate_location_tag +}; + +static const struct sieve_argument_def include_global_tag = { + .identifier = "global", + .validate = cmd_include_validate_location_tag +}; + +static bool cmd_include_validate_boolean_tag + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +static const struct sieve_argument_def include_once_tag = { + .identifier = "once", + .validate = cmd_include_validate_boolean_tag +}; + +static const struct sieve_argument_def include_optional_tag = { + .identifier = "optional", + .validate = cmd_include_validate_boolean_tag +}; + +/* + * Tag validation + */ + +static bool cmd_include_validate_location_tag +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct cmd_include_context_data *ctx_data = + (struct cmd_include_context_data *) cmd->data; + + if ( ctx_data->location_assigned) { + sieve_argument_validate_error(valdtr, *arg, + "include: cannot use location tags ':personal' and ':global' " + "multiple times"); + return FALSE; + } + + if ( sieve_argument_is(*arg, include_personal_tag) ) + ctx_data->location = EXT_INCLUDE_LOCATION_PERSONAL; + else if ( sieve_argument_is(*arg, include_global_tag) ) + ctx_data->location = EXT_INCLUDE_LOCATION_GLOBAL; + else + return FALSE; + + ctx_data->location_assigned = TRUE; + + /* Delete this tag (for now) */ + *arg = sieve_ast_arguments_detach(*arg, 1); + + return TRUE; +} + +static bool cmd_include_validate_boolean_tag +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct cmd_include_context_data *ctx_data = + (struct cmd_include_context_data *) cmd->data; + + if ( sieve_argument_is(*arg, include_once_tag) ) + ctx_data->flags |= EXT_INCLUDE_FLAG_ONCE; + else + ctx_data->flags |= EXT_INCLUDE_FLAG_OPTIONAL; + + /* Delete this tag (for now) */ + *arg = sieve_ast_arguments_detach(*arg, 1); + + return TRUE; +} + +/* + * Command registration + */ + +static bool cmd_include_registered +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_personal_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_global_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_once_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, &include_optional_tag, 0); + + return TRUE; +} + +/* + * Command validation + */ + +static bool cmd_include_pre_validate +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +{ + struct cmd_include_context_data *ctx_data; + + /* Assign context */ + ctx_data = p_new(sieve_command_pool(cmd), struct cmd_include_context_data, 1); + ctx_data->location = EXT_INCLUDE_LOCATION_PERSONAL; + cmd->data = ctx_data; + + return TRUE; +} + +static bool cmd_include_validate +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct sieve_ast_argument *arg = cmd->first_positional; + struct cmd_include_context_data *ctx_data = + (struct cmd_include_context_data *) cmd->data; + struct sieve_storage *storage; + struct sieve_script *script; + const char *script_name; + enum sieve_error error = SIEVE_ERROR_NONE; + int ret; + + /* Check argument */ + if ( !sieve_validate_positional_argument + (valdtr, cmd, arg, "value", 1, SAAT_STRING) ) { + return FALSE; + } + + if ( !sieve_validator_argument_activate(valdtr, cmd, arg, FALSE) ) + return FALSE; + + /* + * Variables are not allowed. + */ + if ( !sieve_argument_is_string_literal(arg) ) { + sieve_argument_validate_error(valdtr, arg, + "the include command requires a constant string for its value argument"); + return FALSE; + } + + /* Find the script */ + + script_name = sieve_ast_argument_strc(arg); + + if ( !sieve_script_name_is_valid(script_name) ) { + sieve_argument_validate_error(valdtr, arg, + "include: invalid script name '%s'", + str_sanitize(script_name, 80)); + return FALSE; + } + + storage = ext_include_get_script_storage + (this_ext, ctx_data->location, script_name, &error); + if ( storage == NULL ) { + // FIXME: handle ':optional' in this case + if (error == SIEVE_ERROR_NOT_FOUND) { + sieve_argument_validate_error(valdtr, arg, + "include: %s location for included script `%s' is unavailable " + "(contact system administrator for more information)", + ext_include_script_location_name(ctx_data->location), + str_sanitize(script_name, 80)); + } else { + sieve_argument_validate_error(valdtr, arg, + "include: failed to access %s location for included script `%s' " + "(contact system administrator for more information)", + ext_include_script_location_name(ctx_data->location), + str_sanitize(script_name, 80)); + } + return FALSE; + } + + /* Create script object */ + script = sieve_storage_get_script + (storage, script_name, &error); + if ( script == NULL ) + return FALSE; + + ret = sieve_script_open(script, &error); + if ( ret < 0 ) { + if ( error != SIEVE_ERROR_NOT_FOUND ) { + sieve_argument_validate_error(valdtr, arg, + "failed to access included %s script '%s': %s", + ext_include_script_location_name(ctx_data->location), + str_sanitize(script_name, 80), + sieve_script_get_last_error_lcase(script)); + sieve_script_unref(&script); + return FALSE; + + /* Not found */ + } else { + enum sieve_compile_flags cpflags = + sieve_validator_compile_flags(valdtr); + + if ( (ctx_data->flags & EXT_INCLUDE_FLAG_OPTIONAL) != 0 ) { + /* :optional */ + + } else if ( (cpflags & SIEVE_COMPILE_FLAG_UPLOADED) != 0 ) { + /* Script is being uploaded */ + sieve_argument_validate_warning(valdtr, arg, + "included %s script '%s' does not exist (ignored during upload)", + ext_include_script_location_name(ctx_data->location), + str_sanitize(script_name, 80)); + ctx_data->flags |= EXT_INCLUDE_FLAG_MISSING_AT_UPLOAD; + + } else { + /* Should have existed */ + sieve_argument_validate_error(valdtr, arg, + "included %s script '%s' does not exist", + ext_include_script_location_name(ctx_data->location), + str_sanitize(script_name, 80)); + sieve_script_unref(&script); + return FALSE; + } + } + } + + ext_include_ast_link_included_script(cmd->ext, cmd->ast_node->ast, script); + ctx_data->script = script; + + (void)sieve_ast_arguments_detach(arg, 1); + return TRUE; +} + +/* + * Code Generation + */ + +static bool cmd_include_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + struct cmd_include_context_data *ctx_data = + (struct cmd_include_context_data *) cmd->data; + const struct ext_include_script_info *included; + int ret; + + /* Compile (if necessary) and include the script into the binary. + * This yields the id of the binary block containing the compiled byte code. + */ + if ( (ret=ext_include_generate_include + (cgenv, cmd, ctx_data->location, ctx_data->flags, ctx_data->script, + &included)) < 0 ) + return FALSE; + + if ( ret > 0 ) { + (void)sieve_operation_emit(cgenv->sblock, cmd->ext, &include_operation); + (void)sieve_binary_emit_unsigned(cgenv->sblock, included->id); + (void)sieve_binary_emit_byte(cgenv->sblock, ctx_data->flags); + } + + return TRUE; +} + +/* + * Code dump + */ + +static bool opc_include_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + const struct ext_include_script_info *included; + struct ext_include_binary_context *binctx; + unsigned int include_id, flags; + + sieve_code_dumpf(denv, "INCLUDE:"); + + sieve_code_mark(denv); + if ( !sieve_binary_read_unsigned(denv->sblock, address, &include_id) ) + return FALSE; + + if ( !sieve_binary_read_byte(denv->sblock, address, &flags) ) + return FALSE; + + binctx = ext_include_binary_get_context(denv->oprtn->ext, denv->sbin); + included = ext_include_binary_script_get_included(binctx, include_id); + if ( included == NULL ) + return FALSE; + + sieve_code_descend(denv); + sieve_code_dumpf(denv, "script: `%s' from %s %s%s[ID: %d, BLOCK: %d]", + sieve_script_name(included->script), sieve_script_location(included->script), + ((flags & EXT_INCLUDE_FLAG_ONCE) != 0 ? "(once) " : ""), + ((flags & EXT_INCLUDE_FLAG_OPTIONAL) != 0 ? "(optional) " : ""), + include_id, sieve_binary_block_get_id(included->block)); + + return TRUE; +} + +/* + * Execution + */ + +static int opc_include_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + unsigned int include_id, flags; + + if ( !sieve_binary_read_unsigned(renv->sblock, address, &include_id) ) { + sieve_runtime_trace_error(renv, "invalid include-id operand"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if ( !sieve_binary_read_unsigned(renv->sblock, address, &flags) ) { + sieve_runtime_trace_error(renv, "invalid flags operand"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + return ext_include_execute_include + (renv, include_id, (enum ext_include_flags)flags); +} + + + + + diff --git a/pigeonhole/src/lib-sieve/plugins/include/cmd-return.c b/pigeonhole/src/lib-sieve/plugins/include/cmd-return.c new file mode 100644 index 0000000..65a156d --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/cmd-return.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" + +#include "sieve-code.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" + +#include "ext-include-common.h" + +/* + * Return command + * + * Syntax + * return + */ + +static bool cmd_return_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); + +const struct sieve_command_def cmd_return = { + .identifier = "return", + .type = SCT_COMMAND, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .generate = cmd_return_generate +}; + +/* + * Return operation + */ + +static int opc_return_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def return_operation = { + .mnemonic = "RETURN", + .ext_def = &include_extension, + .code = EXT_INCLUDE_OPERATION_RETURN, + .execute = opc_return_execute +}; + +/* + * Code generation + */ + +static bool cmd_return_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + sieve_operation_emit(cgenv->sblock, cmd->ext, &return_operation); + + return TRUE; +} + +/* + * Execution + */ + +static int opc_return_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED) +{ + ext_include_execute_return(renv); + return SIEVE_EXEC_OK; +} + + diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.c b/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.c new file mode 100644 index 0000000..3711c30 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.c @@ -0,0 +1,492 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "str.h" + +#include "sieve-common.h" +#include "sieve-error.h" +#include "sieve-script.h" +#include "sieve-storage.h" +#include "sieve-binary.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "sieve-ext-variables.h" + +#include "ext-include-common.h" +#include "ext-include-limits.h" +#include "ext-include-variables.h" +#include "ext-include-binary.h" + +/* + * Forward declarations + */ + +static bool ext_include_binary_pre_save + (const struct sieve_extension *ext, struct sieve_binary *sbin, + void *context, enum sieve_error *error_r); +static bool ext_include_binary_open + (const struct sieve_extension *ext, struct sieve_binary *sbin, + void *context); +static bool ext_include_binary_up_to_date + (const struct sieve_extension *ext, struct sieve_binary *sbin, + void *context, enum sieve_compile_flags cpflags); +static void ext_include_binary_free + (const struct sieve_extension *ext, struct sieve_binary *sbin, + void *context); + +/* + * Binary include extension + */ + +const struct sieve_binary_extension include_binary_ext = { + .extension = &include_extension, + .binary_pre_save = ext_include_binary_pre_save, + .binary_open = ext_include_binary_open, + .binary_free = ext_include_binary_free, + .binary_up_to_date = ext_include_binary_up_to_date +}; + +/* + * Binary context management + */ + +struct ext_include_binary_context { + struct sieve_binary *binary; + struct sieve_binary_block *dependency_block; + + HASH_TABLE(struct sieve_script *, + struct ext_include_script_info *) included_scripts; + ARRAY(struct ext_include_script_info *) include_index; + + struct sieve_variable_scope_binary *global_vars; + + bool outdated:1; +}; + +static struct ext_include_binary_context *ext_include_binary_create_context +(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +{ + pool_t pool = sieve_binary_pool(sbin); + + struct ext_include_binary_context *ctx = + p_new(pool, struct ext_include_binary_context, 1); + + ctx->binary = sbin; + hash_table_create(&ctx->included_scripts, pool, 0, + sieve_script_hash, sieve_script_cmp); + p_array_init(&ctx->include_index, pool, 128); + + sieve_binary_extension_set(sbin, this_ext, &include_binary_ext, ctx); + + return ctx; +} + +struct ext_include_binary_context *ext_include_binary_get_context +(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +{ + struct ext_include_binary_context *ctx = (struct ext_include_binary_context *) + sieve_binary_extension_get_context(sbin, this_ext); + + if ( ctx == NULL ) + ctx = ext_include_binary_create_context(this_ext, sbin); + + return ctx; +} + +struct ext_include_binary_context *ext_include_binary_init +(const struct sieve_extension *this_ext, struct sieve_binary *sbin, + struct sieve_ast *ast) +{ + struct ext_include_ast_context *ast_ctx = + ext_include_get_ast_context(this_ext, ast); + struct ext_include_binary_context *ctx; + + /* Get/create our context from the binary we are working on */ + ctx = ext_include_binary_get_context(this_ext, sbin); + + /* Create dependency block */ + if ( ctx->dependency_block == 0 ) + ctx->dependency_block = + sieve_binary_extension_create_block(sbin, this_ext); + + if ( ctx->global_vars == NULL ) { + ctx->global_vars = + sieve_variable_scope_binary_create(ast_ctx->global_vars); + sieve_variable_scope_binary_ref(ctx->global_vars); + } + + return ctx; +} + +/* + * Script inclusion + */ + +struct ext_include_script_info *ext_include_binary_script_include +(struct ext_include_binary_context *binctx, + enum ext_include_script_location location, enum ext_include_flags flags, + struct sieve_script *script, struct sieve_binary_block *inc_block) +{ + pool_t pool = sieve_binary_pool(binctx->binary); + struct ext_include_script_info *incscript; + + incscript = p_new(pool, struct ext_include_script_info, 1); + incscript->id = array_count(&binctx->include_index)+1; + incscript->location = location; + incscript->flags = flags; + incscript->script = script; + incscript->block = inc_block; + + /* Unreferenced on binary_free */ + sieve_script_ref(script); + + hash_table_insert(binctx->included_scripts, script, incscript); + array_append(&binctx->include_index, &incscript, 1); + + return incscript; +} + +struct ext_include_script_info *ext_include_binary_script_get_include_info +(struct ext_include_binary_context *binctx, struct sieve_script *script) +{ + struct ext_include_script_info *incscript = + hash_table_lookup(binctx->included_scripts, script); + + return incscript; +} + +const struct ext_include_script_info *ext_include_binary_script_get_included +(struct ext_include_binary_context *binctx, unsigned int include_id) +{ + if ( include_id > 0 && + (include_id - 1) < array_count(&binctx->include_index) ) { + struct ext_include_script_info *const *sinfo = + array_idx(&binctx->include_index, include_id - 1); + + return *sinfo; + } + + return NULL; +} + +const struct ext_include_script_info *ext_include_binary_script_get +(struct ext_include_binary_context *binctx, struct sieve_script *script) +{ + return hash_table_lookup(binctx->included_scripts, script); +} + +unsigned int ext_include_binary_script_get_count +(struct ext_include_binary_context *binctx) +{ + return array_count(&binctx->include_index); +} + +/* + * Variables + */ + +struct sieve_variable_scope_binary *ext_include_binary_get_global_scope +(const struct sieve_extension *this_ext, struct sieve_binary *sbin) +{ + struct ext_include_binary_context *binctx = + ext_include_binary_get_context(this_ext, sbin); + + return binctx->global_vars; +} + +/* + * Binary extension + */ + +static bool ext_include_binary_pre_save +(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_binary *sbin ATTR_UNUSED, void *context, + enum sieve_error *error_r) +{ + struct ext_include_binary_context *binctx = + (struct ext_include_binary_context *) context; + struct ext_include_script_info *const *scripts; + struct sieve_binary_block *sblock = binctx->dependency_block; + unsigned int script_count, i; + bool result = TRUE; + + sieve_binary_block_clear(sblock); + + scripts = array_get(&binctx->include_index, &script_count); + + sieve_binary_emit_unsigned(sblock, script_count); + + for ( i = 0; i < script_count; i++ ) { + struct ext_include_script_info *incscript = scripts[i]; + + if ( incscript->block != NULL ) { + sieve_binary_emit_unsigned + (sblock, sieve_binary_block_get_id(incscript->block)); + } else { + sieve_binary_emit_unsigned(sblock, 0); + } + sieve_binary_emit_byte(sblock, incscript->location); + sieve_binary_emit_cstring(sblock, sieve_script_name(incscript->script)); + sieve_binary_emit_byte(sblock, incscript->flags); + sieve_script_binary_write_metadata(incscript->script, sblock); + } + + result = ext_include_variables_save(sblock, binctx->global_vars, error_r); + + return result; +} + +static bool ext_include_binary_open +(const struct sieve_extension *ext, struct sieve_binary *sbin, void *context) +{ + struct sieve_instance *svinst = ext->svinst; + struct ext_include_context *ext_ctx = + (struct ext_include_context *)ext->context; + struct ext_include_binary_context *binctx = + (struct ext_include_binary_context *) context; + struct sieve_binary_block *sblock; + unsigned int depcount, i, block_id; + sieve_size_t offset; + + sblock = sieve_binary_extension_get_block(sbin, ext); + block_id = sieve_binary_block_get_id(sblock); + + offset = 0; + + if ( !sieve_binary_read_unsigned(sblock, &offset, &depcount) ) { + e_error(svinst->event, + "include: failed to read include count " + "for dependency block %d of binary %s", block_id, + sieve_binary_path(sbin)); + return FALSE; + } + + /* Check include limit */ + if ( depcount > ext_ctx->max_includes ) { + e_error(svinst->event, + "include: binary %s includes too many scripts (%u > %u)", + sieve_binary_path(sbin), depcount, ext_ctx->max_includes); + return FALSE; + } + + /* Read dependencies */ + for ( i = 0; i < depcount; i++ ) { + unsigned int inc_block_id; + struct sieve_binary_block *inc_block = NULL; + unsigned int location, flags; + string_t *script_name; + struct sieve_storage *storage; + struct sieve_script *script; + enum sieve_error error; + int ret; + + if ( + !sieve_binary_read_unsigned(sblock, &offset, &inc_block_id) || + !sieve_binary_read_byte(sblock, &offset, &location) || + !sieve_binary_read_string(sblock, &offset, &script_name) || + !sieve_binary_read_byte(sblock, &offset, &flags) ) { + /* Binary is corrupt, recompile */ + e_error(svinst->event, + "include: failed to read included script " + "from dependency block %d of binary %s", + block_id, sieve_binary_path(sbin)); + return FALSE; + } + + if ( inc_block_id != 0 && + (inc_block=sieve_binary_block_get(sbin, inc_block_id)) == NULL ) { + e_error(svinst->event, + "include: failed to find block %d for included script " + "from dependency block %d of binary %s", + inc_block_id, block_id, + sieve_binary_path(sbin)); + return FALSE; + } + + if ( location >= EXT_INCLUDE_LOCATION_INVALID ) { + /* Binary is corrupt, recompile */ + e_error(svinst->event, + "include: dependency block %d of binary %s " + "uses invalid script location (id %d)", + block_id, sieve_binary_path(sbin), location); + return FALSE; + } + + /* Can we find the script dependency ? */ + storage = ext_include_get_script_storage + (ext, location, str_c(script_name), &error); + if ( storage == NULL ) { + /* No, recompile */ + // FIXME: handle ':optional' in this case + return FALSE; + } + + /* Can we open the script dependency ? */ + script = sieve_storage_get_script + (storage, str_c(script_name), &error); + if ( script == NULL ) { + /* No, recompile */ + return FALSE; + } + if ( sieve_script_open(script, &error) < 0 ) { + if ( error != SIEVE_ERROR_NOT_FOUND ) { + /* No, recompile */ + return FALSE; + } + + if ( (flags & EXT_INCLUDE_FLAG_OPTIONAL) == 0 ) { + /* Not supposed to be missing, recompile */ + if ( svinst->debug ) { + e_debug(svinst->event, "include: " + "script '%s' included in binary %s is missing, " + "so recompile", + str_c(script_name), + sieve_binary_path(sbin)); + } + return FALSE; + } + + } else if (inc_block == NULL) { + /* Script exists, but it is missing from the binary, recompile no matter + * what. + */ + if ( svinst->debug ) { + e_debug(svinst->event, "include: " + "script '%s' is missing in binary %s, but is now available, " + "so recompile", str_c(script_name), sieve_binary_path(sbin)); + } + sieve_script_unref(&script); + return FALSE; + } + + /* Can we read script metadata ? */ + if ( (ret=sieve_script_binary_read_metadata + (script, sblock, &offset)) < 0 ) { + /* Binary is corrupt, recompile */ + e_error(svinst->event, "include: " + "dependency block %d of binary %s " + "contains invalid script metadata for script %s", + block_id, sieve_binary_path(sbin), + sieve_script_location(script)); + sieve_script_unref(&script); + return FALSE; + } + + if ( ret == 0 ) + binctx->outdated = TRUE; + + (void)ext_include_binary_script_include + (binctx, location, flags, script, inc_block); + + sieve_script_unref(&script); + } + + if ( !ext_include_variables_load + (ext, sblock, &offset, &binctx->global_vars) ) + return FALSE; + + return TRUE; +} + +static bool ext_include_binary_up_to_date +(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_binary *sbin ATTR_UNUSED, void *context, + enum sieve_compile_flags cpflags ATTR_UNUSED) +{ + struct ext_include_binary_context *binctx = + (struct ext_include_binary_context *) context; + + return !binctx->outdated; +} + +static void ext_include_binary_free +(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_binary *sbin ATTR_UNUSED, void *context) +{ + struct ext_include_binary_context *binctx = + (struct ext_include_binary_context *) context; + struct hash_iterate_context *hctx; + struct sieve_script *script; + struct ext_include_script_info *incscript; + + /* Release references to all included script objects */ + hctx = hash_table_iterate_init(binctx->included_scripts); + while ( hash_table_iterate + (hctx, binctx->included_scripts, &script, &incscript) ) + sieve_script_unref(&incscript->script); + hash_table_iterate_deinit(&hctx); + + hash_table_destroy(&binctx->included_scripts); + + if ( binctx->global_vars != NULL ) + sieve_variable_scope_binary_unref(&binctx->global_vars); +} + +/* + * Dumping the binary + */ + +bool ext_include_binary_dump +(const struct sieve_extension *ext, struct sieve_dumptime_env *denv) +{ + struct sieve_binary *sbin = denv->sbin; + struct ext_include_binary_context *binctx = + ext_include_binary_get_context(ext, sbin); + struct hash_iterate_context *hctx; + struct sieve_script *script; + struct ext_include_script_info *incscript; + + if ( !ext_include_variables_dump(denv, binctx->global_vars) ) + return FALSE; + + hctx = hash_table_iterate_init(binctx->included_scripts); + while ( hash_table_iterate + (hctx, binctx->included_scripts, &script, &incscript) ) { + + if ( incscript->block == NULL ) { + sieve_binary_dump_sectionf(denv, "Included %s script '%s' (MISSING)", + ext_include_script_location_name(incscript->location), + sieve_script_name(incscript->script)); + + } else { + unsigned int block_id = sieve_binary_block_get_id(incscript->block); + + sieve_binary_dump_sectionf(denv, "Included %s script '%s' (block: %d)", + ext_include_script_location_name(incscript->location), + sieve_script_name(incscript->script), block_id); + + denv->sblock = incscript->block; + denv->cdumper = sieve_code_dumper_create(denv); + + if ( denv->cdumper == NULL ) + return FALSE; + + sieve_code_dumper_run(denv->cdumper); + sieve_code_dumper_free(&(denv->cdumper)); + } + } + hash_table_iterate_deinit(&hctx); + + return TRUE; +} + +bool ext_include_code_dump +(const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, + sieve_size_t *address ATTR_UNUSED) +{ + struct sieve_binary *sbin = denv->sbin; + struct ext_include_binary_context *binctx = + ext_include_binary_get_context(ext, sbin); + struct ext_include_context *ectx = ext_include_get_context(ext); + + sieve_ext_variables_dump_set_scope + (ectx->var_ext, denv, ext, + sieve_variable_scope_binary_get(binctx->global_vars)); + + return TRUE; +} + + diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.h b/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.h new file mode 100644 index 0000000..066df2f --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-binary.h @@ -0,0 +1,64 @@ +#ifndef EXT_INCLUDE_BINARY_H +#define EXT_INCLUDE_BINARY_H + +#include "sieve-common.h" + +/* + * Binary context management + */ + +struct ext_include_binary_context; + +struct ext_include_binary_context *ext_include_binary_init + (const struct sieve_extension *this_ext, struct sieve_binary *sbin, + struct sieve_ast *ast); +struct ext_include_binary_context *ext_include_binary_get_context + (const struct sieve_extension *this_ext, struct sieve_binary *sbin); + +/* + * Variables + */ + +struct sieve_variable_scope_binary *ext_include_binary_get_global_scope + (const struct sieve_extension *this_ext, struct sieve_binary *sbin); + +/* + * Including scripts + */ + +struct ext_include_script_info { + unsigned int id; + + struct sieve_script *script; + enum ext_include_flags flags; + enum ext_include_script_location location; + + struct sieve_binary_block *block; +}; + +struct ext_include_script_info *ext_include_binary_script_include + (struct ext_include_binary_context *binctx, + enum ext_include_script_location location, enum ext_include_flags flags, + struct sieve_script *script, struct sieve_binary_block *inc_block); +struct ext_include_script_info *ext_include_binary_script_get_include_info + (struct ext_include_binary_context *binctx, struct sieve_script *script); + +const struct ext_include_script_info *ext_include_binary_script_get_included + (struct ext_include_binary_context *binctx, unsigned int include_id); +const struct ext_include_script_info *ext_include_binary_script_get + (struct ext_include_binary_context *binctx, struct sieve_script *script); +unsigned int ext_include_binary_script_get_count + (struct ext_include_binary_context *binctx); + +/* + * Dumping the binary + */ + +bool ext_include_binary_dump + (const struct sieve_extension *ext, struct sieve_dumptime_env *denv); +bool ext_include_code_dump + (const struct sieve_extension *ext, const struct sieve_dumptime_env *denv, + sieve_size_t *address ATTR_UNUSED); + +#endif + diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.c b/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.c new file mode 100644 index 0000000..7af3f00 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.c @@ -0,0 +1,892 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "array.h" +#include "str-sanitize.h" +#include "home-expand.h" + +#include "sieve-common.h" +#include "sieve-settings.h" +#include "sieve-error.h" +#include "sieve-script.h" +#include "sieve-storage.h" +#include "sieve-ast.h" +#include "sieve-binary.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" + +#include "ext-include-common.h" +#include "ext-include-limits.h" +#include "ext-include-binary.h" +#include "ext-include-variables.h" + + +/* + * Forward declarations + */ + +/* Generator context */ + +struct ext_include_generator_context { + unsigned int nesting_depth; + struct sieve_script *script; + struct ext_include_generator_context *parent; +}; + +static inline struct ext_include_generator_context * +ext_include_get_generator_context(const struct sieve_extension *ext_this, + struct sieve_generator *gentr); + +/* Interpreter context */ + +struct ext_include_interpreter_global { + ARRAY(struct sieve_script *) included_scripts; + + struct sieve_variable_scope_binary *var_scope; + struct sieve_variable_storage *var_storage; +}; + +struct ext_include_interpreter_context { + struct ext_include_interpreter_context *parent; + struct ext_include_interpreter_global *global; + + struct sieve_interpreter *interp; + pool_t pool; + + unsigned int nesting_depth; + + struct sieve_script *script; + const struct ext_include_script_info *script_info; + + const struct ext_include_script_info *include; + bool returned; +}; + +/* + * Extension configuration + */ + +/* Extension hooks */ + +bool ext_include_load(const struct sieve_extension *ext, void **context) +{ + struct sieve_instance *svinst = ext->svinst; + struct ext_include_context *ctx; + const char *location; + unsigned long long int uint_setting; + + if (*context != NULL) + ext_include_unload(ext); + + ctx = i_new(struct ext_include_context, 1); + + /* Get location for :global scripts */ + location = sieve_setting_get(svinst, "sieve_global"); + if (location == NULL) + location = sieve_setting_get(svinst, "sieve_global_dir"); + + if (location == NULL) { + e_debug(svinst->event, "include: " + "sieve_global is not set; " + "it is currently not possible to include `:global' scripts."); + } + + ctx->global_location = i_strdup(location); + + /* Get limits */ + ctx->max_nesting_depth = EXT_INCLUDE_DEFAULT_MAX_NESTING_DEPTH; + ctx->max_includes = EXT_INCLUDE_DEFAULT_MAX_INCLUDES; + + if (sieve_setting_get_uint_value( + svinst, "sieve_include_max_nesting_depth", &uint_setting)) + ctx->max_nesting_depth = (unsigned int)uint_setting; + if (sieve_setting_get_uint_value( + svinst, "sieve_include_max_includes", &uint_setting)) + ctx->max_includes = (unsigned int)uint_setting; + + /* Extension dependencies */ + ctx->var_ext = sieve_ext_variables_get_extension(ext->svinst); + + *context = (void *)ctx; + return TRUE; +} + +void ext_include_unload(const struct sieve_extension *ext) +{ + struct ext_include_context *ctx = + (struct ext_include_context *)ext->context; + + if (ctx->global_storage != NULL) + sieve_storage_unref(&ctx->global_storage); + if (ctx->personal_storage != NULL) + sieve_storage_unref(&ctx->personal_storage); + + i_free(ctx->global_location); + i_free(ctx); +} + +/* + * Script access + */ + +struct sieve_storage * +ext_include_get_script_storage(const struct sieve_extension *ext, + enum ext_include_script_location location, + const char *script_name, + enum sieve_error *error_r) +{ + struct sieve_instance *svinst = ext->svinst; + struct ext_include_context *ctx = + (struct ext_include_context *)ext->context; + + switch (location) { + case EXT_INCLUDE_LOCATION_PERSONAL: + if (ctx->personal_storage == NULL) { + ctx->personal_storage = + sieve_storage_create_main(svinst, NULL, 0, + error_r); + } + return ctx->personal_storage; + case EXT_INCLUDE_LOCATION_GLOBAL: + if (ctx->global_location == NULL) { + e_info(svinst->event, "include: " + "sieve_global is unconfigured; " + "include of `:global' script `%s' is therefore not possible", + str_sanitize(script_name, 80)); + if (error_r != NULL) + *error_r = SIEVE_ERROR_NOT_FOUND; + return NULL; + } + if (ctx->global_storage == NULL) { + ctx->global_storage = sieve_storage_create( + svinst, ctx->global_location, 0, error_r); + } + return ctx->global_storage; + default: + break; + } + + i_unreached(); + return NULL; +} + +/* + * AST context management + */ + +static void +ext_include_ast_free(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_ast *ast ATTR_UNUSED, void *context) +{ + struct ext_include_ast_context *actx = + (struct ext_include_ast_context *)context; + struct sieve_script **scripts; + unsigned int count, i; + + /* Unreference included scripts */ + scripts = array_get_modifiable(&actx->included_scripts, &count); + for (i = 0; i < count; i++) { + sieve_script_unref(&scripts[i]); + } + + /* Unreference variable scopes */ + if (actx->global_vars != NULL) + sieve_variable_scope_unref(&actx->global_vars); +} + +static const struct sieve_ast_extension include_ast_extension = { + &include_extension, + ext_include_ast_free +}; + +struct ext_include_ast_context * +ext_include_create_ast_context(const struct sieve_extension *this_ext, + struct sieve_ast *ast, struct sieve_ast *parent) +{ + struct ext_include_ast_context *actx; + + pool_t pool = sieve_ast_pool(ast); + actx = p_new(pool, struct ext_include_ast_context, 1); + p_array_init(&actx->included_scripts, pool, 32); + + if (parent != NULL) { + struct ext_include_ast_context *parent_ctx = + (struct ext_include_ast_context *) + sieve_ast_extension_get_context(parent, this_ext); + + actx->global_vars = parent_ctx->global_vars; + i_assert(actx->global_vars != NULL); + + sieve_variable_scope_ref(actx->global_vars); + } else { + struct ext_include_context *ectx = + ext_include_get_context(this_ext); + + actx->global_vars = sieve_variable_scope_create( + this_ext->svinst, ectx->var_ext, this_ext); + } + + sieve_ast_extension_register(ast, this_ext, &include_ast_extension, + (void *)actx); + return actx; +} + +struct ext_include_ast_context * +ext_include_get_ast_context(const struct sieve_extension *this_ext, + struct sieve_ast *ast) +{ + struct ext_include_ast_context *actx = + (struct ext_include_ast_context *) + sieve_ast_extension_get_context(ast, this_ext); + + if (actx != NULL) + return actx; + return ext_include_create_ast_context(this_ext, ast, NULL); +} + +void ext_include_ast_link_included_script( + const struct sieve_extension *this_ext, struct sieve_ast *ast, + struct sieve_script *script) +{ + struct ext_include_ast_context *actx = + ext_include_get_ast_context(this_ext, ast); + + array_append(&actx->included_scripts, &script, 1); +} + +bool ext_include_validator_have_variables( + const struct sieve_extension *this_ext, struct sieve_validator *valdtr) +{ + struct ext_include_context *ectx = ext_include_get_context(this_ext); + + return sieve_ext_variables_is_active(ectx->var_ext, valdtr); +} + +/* + * Generator context management + */ + +static struct ext_include_generator_context * +ext_include_create_generator_context( + struct sieve_generator *gentr, + struct ext_include_generator_context *parent, + struct sieve_script *script) +{ + struct ext_include_generator_context *ctx; + + pool_t pool = sieve_generator_pool(gentr); + ctx = p_new(pool, struct ext_include_generator_context, 1); + ctx->parent = parent; + ctx->script = script; + if (parent == NULL) + ctx->nesting_depth = 0; + else + ctx->nesting_depth = parent->nesting_depth + 1; + + return ctx; +} + +static inline struct ext_include_generator_context * +ext_include_get_generator_context(const struct sieve_extension *this_ext, + struct sieve_generator *gentr) +{ + return (struct ext_include_generator_context *) + sieve_generator_extension_get_context(gentr, this_ext); +} + +static inline void +ext_include_initialize_generator_context( + const struct sieve_extension *this_ext, struct sieve_generator *gentr, + struct ext_include_generator_context *parent, + struct sieve_script *script) +{ + sieve_generator_extension_set_context( + gentr, this_ext, + ext_include_create_generator_context(gentr, parent, script)); +} + +void ext_include_register_generator_context( + const struct sieve_extension *this_ext, + const struct sieve_codegen_env *cgenv) +{ + struct ext_include_generator_context *ctx = + ext_include_get_generator_context(this_ext, cgenv->gentr); + + /* Initialize generator context if necessary */ + if (ctx == NULL) { + ctx = ext_include_create_generator_context( + cgenv->gentr, NULL, cgenv->script); + + sieve_generator_extension_set_context( + cgenv->gentr, this_ext, (void *)ctx); + } + + /* Initialize ast context if necessary */ + (void)ext_include_get_ast_context(this_ext, cgenv->ast); + (void)ext_include_binary_init(this_ext, cgenv->sbin, cgenv->ast); +} + +/* + * Runtime initialization + */ + +static int +ext_include_runtime_init(const struct sieve_extension *this_ext, + const struct sieve_runtime_env *renv, + void *context, bool deferred ATTR_UNUSED) +{ + struct ext_include_interpreter_context *ctx = + (struct ext_include_interpreter_context *)context; + struct ext_include_context *ectx = ext_include_get_context(this_ext); + + if (ctx->parent == NULL) { + ctx->global = p_new(ctx->pool, + struct ext_include_interpreter_global, 1); + p_array_init(&ctx->global->included_scripts, ctx->pool, 10); + + ctx->global->var_scope = + ext_include_binary_get_global_scope( + this_ext, renv->sbin); + ctx->global->var_storage = + sieve_variable_storage_create(ectx->var_ext, ctx->pool, + ctx->global->var_scope); + } else { + ctx->global = ctx->parent->global; + } + + sieve_ext_variables_runtime_set_storage(ectx->var_ext, renv, this_ext, + ctx->global->var_storage); + return SIEVE_EXEC_OK; +} + +static struct sieve_interpreter_extension include_interpreter_extension = { + .ext_def = &include_extension, + .run = ext_include_runtime_init +}; + +/* + * Interpreter context management + */ + +static struct ext_include_interpreter_context * +ext_include_interpreter_context_create( + struct sieve_interpreter *interp, + struct ext_include_interpreter_context *parent, + struct sieve_script *script, + const struct ext_include_script_info *sinfo) +{ + struct ext_include_interpreter_context *ctx; + + pool_t pool = sieve_interpreter_pool(interp); + ctx = p_new(pool, struct ext_include_interpreter_context, 1); + ctx->pool = pool; + ctx->parent = parent; + ctx->interp = interp; + ctx->script = script; + ctx->script_info = sinfo; + + if (parent == NULL) + ctx->nesting_depth = 0; + else + ctx->nesting_depth = parent->nesting_depth + 1; + return ctx; +} + +static inline struct ext_include_interpreter_context * +ext_include_get_interpreter_context(const struct sieve_extension *this_ext, + struct sieve_interpreter *interp) +{ + return (struct ext_include_interpreter_context *) + sieve_interpreter_extension_get_context(interp, this_ext); +} + +static inline struct ext_include_interpreter_context * +ext_include_interpreter_context_init_child( + const struct sieve_extension *this_ext, + struct sieve_interpreter *interp, + struct ext_include_interpreter_context *parent, + struct sieve_script *script, + const struct ext_include_script_info *sinfo) +{ + struct ext_include_interpreter_context *ctx = + ext_include_interpreter_context_create(interp, parent, + script, sinfo); + + sieve_interpreter_extension_register(interp, this_ext, + &include_interpreter_extension, + ctx); + return ctx; +} + +void ext_include_interpreter_context_init( + const struct sieve_extension *this_ext, + struct sieve_interpreter *interp) +{ + struct ext_include_interpreter_context *ctx = + ext_include_get_interpreter_context(this_ext, interp); + + /* Is this is the top-level interpreter ? */ + if (ctx == NULL) { + struct sieve_script *script; + + /* Initialize top context */ + script = sieve_interpreter_script(interp); + ctx = ext_include_interpreter_context_create(interp, NULL, + script, NULL); + + sieve_interpreter_extension_register( + interp, this_ext, &include_interpreter_extension, + (void *)ctx); + } +} + +struct sieve_variable_storage * +ext_include_interpreter_get_global_variables( + const struct sieve_extension *this_ext, + struct sieve_interpreter *interp) +{ + struct ext_include_interpreter_context *ctx = + ext_include_get_interpreter_context(this_ext, interp); + + return ctx->global->var_storage; +} + +/* + * Including a script during code generation + */ + +int ext_include_generate_include( + const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + enum ext_include_script_location location, enum ext_include_flags flags, + struct sieve_script *script, + const struct ext_include_script_info **included_r) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct ext_include_context *ext_ctx = + (struct ext_include_context *)this_ext->context; + int result = 1; + struct sieve_ast *ast; + struct sieve_binary *sbin = cgenv->sbin; + struct sieve_generator *gentr = cgenv->gentr; + struct ext_include_binary_context *binctx; + struct sieve_generator *subgentr; + struct ext_include_generator_context *ctx = + ext_include_get_generator_context(this_ext, gentr); + struct ext_include_generator_context *pctx; + struct sieve_error_handler *ehandler = + sieve_generator_error_handler(gentr); + struct ext_include_script_info *included; + + *included_r = NULL; + + /* Just to be sure: do not include more scripts when errors have occured + already. + */ + if (sieve_get_errors(ehandler) > 0) + return -1; + + /* Limit nesting level */ + if (ctx->nesting_depth >= ext_ctx->max_nesting_depth) { + sieve_command_generate_error( + gentr, cmd, + "cannot nest includes deeper than %d levels", + ext_ctx->max_nesting_depth); + return -1; + } + + /* Check for circular include */ + if ((flags & EXT_INCLUDE_FLAG_ONCE) == 0) { + pctx = ctx; + while (pctx != NULL) { + if (sieve_script_equals(pctx->script, script)) { + /* Just drop circular include when uploading + inactive script; not an error + */ + if ((cgenv->flags & SIEVE_COMPILE_FLAG_UPLOADED) != 0 && + (cgenv->flags & SIEVE_COMPILE_FLAG_ACTIVATED) == 0) { + sieve_command_generate_warning( + gentr, cmd, + "circular include (ignored during upload)"); + return 0; + } + + sieve_command_generate_error(gentr, cmd, + "circular include"); + return -1; + } + + pctx = pctx->parent; + } + } + + /* Get binary context */ + binctx = ext_include_binary_init(this_ext, sbin, cgenv->ast); + + /* Is the script already compiled into the current binary? */ + included = ext_include_binary_script_get_include_info(binctx, script); + if (included != NULL) { + /* Yes, only update flags */ + if ((flags & EXT_INCLUDE_FLAG_OPTIONAL) == 0) + included->flags &= ENUM_NEGATE(EXT_INCLUDE_FLAG_OPTIONAL); + if ((flags & EXT_INCLUDE_FLAG_ONCE) == 0) + included->flags &= ENUM_NEGATE(EXT_INCLUDE_FLAG_ONCE); + } else { + const char *script_name = sieve_script_name(script); + enum sieve_compile_flags cpflags = cgenv->flags; + + /* No, include new script */ + + /* Check whether include limit is exceeded */ + if (ext_include_binary_script_get_count(binctx) >= + ext_ctx->max_includes) { + sieve_command_generate_error( + gentr, cmd, "failed to include script '%s': " + "no more than %u includes allowed", + str_sanitize(script_name, 80), + ext_ctx->max_includes); + return -1; + } + + /* Allocate a new block in the binary and mark the script as + included. */ + if (!sieve_script_is_open(script)) { + /* Just making an empty entry to mark a missing script + */ + i_assert((flags & EXT_INCLUDE_FLAG_MISSING_AT_UPLOAD) != 0 || + (flags & EXT_INCLUDE_FLAG_OPTIONAL) != 0); + included = ext_include_binary_script_include( + binctx, location, flags, script, NULL); + result = 0; + + } else { + struct sieve_binary_block *inc_block = + sieve_binary_block_create(sbin); + + /* Real include */ + included = ext_include_binary_script_include( + binctx, location, flags, script, inc_block); + + /* Parse */ + if ((ast = sieve_parse(script, ehandler, + NULL)) == NULL) { + sieve_command_generate_error( + gentr, cmd, + "failed to parse included script '%s'", + str_sanitize(script_name, 80)); + return -1; + } + + /* Included scripts inherit global variable scope */ + (void)ext_include_create_ast_context( + this_ext, ast, cmd->ast_node->ast); + + if (location == EXT_INCLUDE_LOCATION_GLOBAL) { + cpflags &= + ENUM_NEGATE(SIEVE_EXECUTE_FLAG_NOGLOBAL); + } else { + cpflags |= SIEVE_EXECUTE_FLAG_NOGLOBAL; + } + + /* Validate */ + if (!sieve_validate(ast, ehandler, cpflags, NULL)) { + sieve_command_generate_error( + gentr, cmd, + "failed to validate included script '%s'", + str_sanitize(script_name, 80)); + sieve_ast_unref(&ast); + return -1; + } + + /* Generate + + FIXME: It might not be a good idea to recurse code + generation for included scripts. + */ + subgentr = sieve_generator_create(ast, ehandler, cpflags); + ext_include_initialize_generator_context( + cmd->ext, subgentr, ctx, script); + + if (sieve_generator_run(subgentr, &inc_block) == NULL) { + sieve_command_generate_error( + gentr, cmd, + "failed to generate code for included script '%s'", + str_sanitize(script_name, 80)); + result = -1; + } + + sieve_generator_free(&subgentr); + + /* Cleanup */ + sieve_ast_unref(&ast); + } + } + + if (result > 0) + *included_r = included; + return result; +} + +/* + * Executing an included script during interpretation + */ + +static bool +ext_include_runtime_check_circular( + struct ext_include_interpreter_context *ctx, + const struct ext_include_script_info *include) +{ + struct ext_include_interpreter_context *pctx; + + pctx = ctx; + while (pctx != NULL) { + + if (sieve_script_equals(include->script, pctx->script)) + return TRUE; + + pctx = pctx->parent; + } + + return FALSE; +} + +static bool +ext_include_runtime_include_mark(struct ext_include_interpreter_context *ctx, + const struct ext_include_script_info *include, + bool once) +{ + struct sieve_script *const *includes; + unsigned int count, i; + + includes = array_get(&ctx->global->included_scripts, &count); + for (i = 0; i < count; i++) { + if (sieve_script_equals(include->script, includes[i])) + return (!once); + } + + array_append(&ctx->global->included_scripts, &include->script, 1); + return TRUE; +} + +int ext_include_execute_include(const struct sieve_runtime_env *renv, + unsigned int include_id, + enum ext_include_flags flags) +{ + const struct sieve_execute_env *eenv = renv->exec_env; + const struct sieve_extension *this_ext = renv->oprtn->ext; + int result = SIEVE_EXEC_OK; + struct ext_include_interpreter_context *ctx; + const struct ext_include_script_info *included; + struct ext_include_binary_context *binctx = + ext_include_binary_get_context(this_ext, renv->sbin); + bool once = ((flags & EXT_INCLUDE_FLAG_ONCE) != 0); + unsigned int block_id; + + /* Check for invalid include id (== corrupt binary) */ + included = ext_include_binary_script_get_included(binctx, include_id); + if (included == NULL) { + sieve_runtime_trace_error( + renv, "include: include id %d is invalid", include_id); + return SIEVE_EXEC_BIN_CORRUPT; + } + + ctx = ext_include_get_interpreter_context(this_ext, renv->interp); + block_id = sieve_binary_block_get_id(included->block); + + /* If :once modifier is specified, check for duplicate include */ + if (ext_include_runtime_include_mark(ctx, included, once)) { + sieve_runtime_trace( + renv, SIEVE_TRLVL_NONE, + "include: start script '%s' [inc id: %d, block: %d]", + sieve_script_name(included->script), + include_id, block_id); + } else { + /* skip */ + sieve_runtime_trace( + renv, SIEVE_TRLVL_NONE, + "include: skipped include for script '%s' " + "[inc id: %d, block: %d]; already run once", + sieve_script_name(included->script), + include_id, block_id); + return result; + } + + /* Check circular include during interpretation as well. + * Let's not trust binaries. + */ + if (ext_include_runtime_check_circular(ctx, included)) { + sieve_runtime_trace_error(renv, + "include: circular include of script '%s' " + "[inc id: %d, block: %d]", + sieve_script_name(included->script), + include_id, block_id); + + /* Situation has no valid way to emerge at runtime */ + return SIEVE_EXEC_BIN_CORRUPT; + } + + if (ctx->parent == NULL) { + struct ext_include_interpreter_context *curctx = NULL; + struct sieve_error_handler *ehandler = renv->ehandler; + struct sieve_interpreter *subinterp; + bool interrupted = FALSE; + + /* We are the top-level interpreter instance */ + if (result == SIEVE_EXEC_OK) { + struct sieve_execute_env eenv_new = *eenv; + + if (included->location != EXT_INCLUDE_LOCATION_GLOBAL) + eenv_new.flags |= SIEVE_EXECUTE_FLAG_NOGLOBAL; + else { + eenv_new.flags &= + ENUM_NEGATE(SIEVE_EXECUTE_FLAG_NOGLOBAL); + } + + /* Create interpreter for top-level included script + (first sub-interpreter) + */ + subinterp = sieve_interpreter_create_for_block( + included->block, included->script, renv->interp, + &eenv_new, ehandler); + if (subinterp != NULL) { + curctx = ext_include_interpreter_context_init_child( + this_ext, subinterp, ctx, included->script, + included); + + /* Activate and start the top-level included script */ + result = sieve_interpreter_start( + subinterp, renv->result, &interrupted); + } else { + result = SIEVE_EXEC_BIN_CORRUPT; + } + } + + /* Included scripts can have includes of their own. This is not + implemented recursively. Rather, the sub-interpreter + interrupts and defers the include to the top-level + interpreter, which is here. */ + if (result == SIEVE_EXEC_OK && interrupted && + !curctx->returned) { + while (result == SIEVE_EXEC_OK) { + if (((interrupted && curctx->returned) || + (!interrupted)) && + curctx->parent != NULL) { + const struct ext_include_script_info *ended_script = + curctx->script_info; + + /* Sub-interpreter ended or executed + return */ + + /* Ascend interpreter stack */ + curctx = curctx->parent; + sieve_interpreter_free(&subinterp); + + sieve_runtime_trace(renv, SIEVE_TRLVL_NONE, + "include: script '%s' ended " + "[inc id: %d, block: %d]", + sieve_script_name(ended_script->script), + ended_script->id, + sieve_binary_block_get_id(ended_script->block)); + + /* This is the top-most sub-interpreter, + bail out */ + if (curctx->parent == NULL) + break; + + subinterp = curctx->interp; + + /* Continue parent */ + curctx->include = NULL; + curctx->returned = FALSE; + + result = sieve_interpreter_continue( + subinterp, &interrupted); + } else { + if (curctx->include != NULL) { + /* Sub-include requested */ + + if (result == SIEVE_EXEC_OK) { + struct sieve_execute_env eenv_new = *eenv; + + if (curctx->include->location != EXT_INCLUDE_LOCATION_GLOBAL) + eenv_new.flags |= SIEVE_EXECUTE_FLAG_NOGLOBAL; + else { + eenv_new.flags &= + ENUM_NEGATE(SIEVE_EXECUTE_FLAG_NOGLOBAL); + } + + /* Create sub-interpreter */ + subinterp = sieve_interpreter_create_for_block( + curctx->include->block, curctx->include->script, + curctx->interp, &eenv_new, ehandler); + if (subinterp != NULL) { + curctx = ext_include_interpreter_context_init_child( + this_ext, subinterp, curctx, + curctx->include->script, curctx->include); + + /* Start the sub-include's interpreter */ + curctx->include = NULL; + curctx->returned = FALSE; + result = sieve_interpreter_start( + subinterp, renv->result, &interrupted); + } else { + result = SIEVE_EXEC_BIN_CORRUPT; + } + } + } else { + /* Sub-interpreter was interrupted outside + this extension, probably stop command was + executed. Generate an interrupt ourselves, + ending all script execution. */ + sieve_interpreter_interrupt(renv->interp); + break; + } + } + } + } + + /* Free any sub-interpreters that might still be active */ + while (curctx != NULL && curctx->parent != NULL) { + struct ext_include_interpreter_context *nextctx = + curctx->parent; + struct sieve_interpreter *killed_interp = curctx->interp; + const struct ext_include_script_info *ended_script = + curctx->script_info; + + /* This kills curctx too */ + sieve_interpreter_free(&killed_interp); + + sieve_runtime_trace( + renv, SIEVE_TRLVL_NONE, + "include: script '%s' ended [id: %d, block: %d]", + sieve_script_name(ended_script->script), + ended_script->id, + sieve_binary_block_get_id(ended_script->block)); + + /* Luckily we recorded the parent earlier */ + curctx = nextctx; + } + + } else { + /* We are an included script already, defer inclusion to main + interpreter */ + ctx->include = included; + sieve_interpreter_interrupt(renv->interp); + } + + return result; +} + +void ext_include_execute_return(const struct sieve_runtime_env *renv) +{ + const struct sieve_extension *this_ext = renv->oprtn->ext; + struct ext_include_interpreter_context *ctx = + ext_include_get_interpreter_context(this_ext, renv->interp); + + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "return: exiting included script"); + ctx->returned = TRUE; + sieve_interpreter_interrupt(renv->interp); +} diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.h b/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.h new file mode 100644 index 0000000..44bfe9a --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-common.h @@ -0,0 +1,170 @@ +#ifndef EXT_INCLUDE_COMMON_H +#define EXT_INCLUDE_COMMON_H + +#include "lib.h" +#include "hash.h" + +#include "sieve-common.h" +#include "sieve-extensions.h" + +/* + * Forward declarations + */ + +struct ext_include_script_info; +struct ext_include_binary_context; + +/* + * Types + */ + +enum ext_include_flags { // stored in one byte + EXT_INCLUDE_FLAG_ONCE = 0x01, + EXT_INCLUDE_FLAG_OPTIONAL = 0x02, + EXT_INCLUDE_FLAG_MISSING_AT_UPLOAD = 0x04 +}; + +enum ext_include_script_location { + EXT_INCLUDE_LOCATION_PERSONAL, + EXT_INCLUDE_LOCATION_GLOBAL, + EXT_INCLUDE_LOCATION_INVALID +}; + +static inline const char * +ext_include_script_location_name(enum ext_include_script_location location) +{ + switch (location) { + case EXT_INCLUDE_LOCATION_PERSONAL: + return "personal"; + case EXT_INCLUDE_LOCATION_GLOBAL: + return "global"; + default: + break; + } + + return "[INVALID LOCATION]"; +} + + +/* + * Extension + */ + +extern const struct sieve_extension_def include_extension; +extern const struct sieve_binary_extension include_binary_ext; + +bool ext_include_load(const struct sieve_extension *ext, void **context); +void ext_include_unload(const struct sieve_extension *ext); + +/* + * Commands + */ + +extern const struct sieve_command_def cmd_include; +extern const struct sieve_command_def cmd_return; +extern const struct sieve_command_def cmd_global; + +/* DEPRICATED */ +extern const struct sieve_command_def cmd_import; +extern const struct sieve_command_def cmd_export; + +/* + * Operations + */ + +enum ext_include_opcode { + EXT_INCLUDE_OPERATION_INCLUDE, + EXT_INCLUDE_OPERATION_RETURN, + EXT_INCLUDE_OPERATION_GLOBAL +}; + +extern const struct sieve_operation_def include_operation; +extern const struct sieve_operation_def return_operation; +extern const struct sieve_operation_def global_operation; + +/* + * Script access + */ + +struct sieve_storage * +ext_include_get_script_storage(const struct sieve_extension *ext, + enum ext_include_script_location location, + const char *script_name, + enum sieve_error *error_r); +/* + * Context + */ + +/* Extension context */ + +struct ext_include_context { + /* Extension dependencies */ + const struct sieve_extension *var_ext; + + /* Configuration */ + char *global_location; + + struct sieve_storage *global_storage; + struct sieve_storage *personal_storage; + + unsigned int max_nesting_depth; + unsigned int max_includes; +}; + +static inline struct ext_include_context * +ext_include_get_context(const struct sieve_extension *ext) +{ + return (struct ext_include_context *) ext->context; +} + +/* AST Context */ + +struct ext_include_ast_context { + struct sieve_variable_scope *global_vars; + + ARRAY(struct sieve_script *) included_scripts; +}; + +struct ext_include_ast_context * +ext_include_create_ast_context(const struct sieve_extension *this_ext, + struct sieve_ast *ast, struct sieve_ast *parent); +struct ext_include_ast_context * +ext_include_get_ast_context(const struct sieve_extension *this_ext, + struct sieve_ast *ast); + +void ext_include_ast_link_included_script( + const struct sieve_extension *this_ext, struct sieve_ast *ast, + struct sieve_script *script); + +bool ext_include_validator_have_variables( + const struct sieve_extension *this_ext, struct sieve_validator *valdtr); + +/* Generator context */ + +void ext_include_register_generator_context( + const struct sieve_extension *this_ext, + const struct sieve_codegen_env *cgenv); + +int ext_include_generate_include( + const struct sieve_codegen_env *cgenv, struct sieve_command *cmd, + enum ext_include_script_location location, enum ext_include_flags flags, + struct sieve_script *script, + const struct ext_include_script_info **included_r); + +/* Interpreter context */ + +void ext_include_interpreter_context_init( + const struct sieve_extension *this_ext, + struct sieve_interpreter *interp); + +int ext_include_execute_include(const struct sieve_runtime_env *renv, + unsigned int block_id, + enum ext_include_flags flags); +void ext_include_execute_return(const struct sieve_runtime_env *renv); + +struct sieve_variable_storage * +ext_include_interpreter_get_global_variables( + const struct sieve_extension *this_ext, + struct sieve_interpreter *interp); + +#endif diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-limits.h b/pigeonhole/src/lib-sieve/plugins/include/ext-include-limits.h new file mode 100644 index 0000000..37246c0 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-limits.h @@ -0,0 +1,9 @@ +#ifndef EXT_INCLUDE_LIMITS_H +#define EXT_INCLUDE_LIMITS_H + +#include "sieve-common.h" + +#define EXT_INCLUDE_DEFAULT_MAX_NESTING_DEPTH 10 +#define EXT_INCLUDE_DEFAULT_MAX_INCLUDES 255 + +#endif diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.c b/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.c new file mode 100644 index 0000000..28cd803 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.c @@ -0,0 +1,254 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "str-sanitize.h" + +#include "sieve-common.h" +#include "sieve-error.h" +#include "sieve-script.h" +#include "sieve-ast.h" +#include "sieve-binary.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "sieve-ext-variables.h" + +#include "ext-include-common.h" +#include "ext-include-binary.h" +#include "ext-include-variables.h" + +/* + * Variable import-export + */ + +struct sieve_variable *ext_include_variable_import_global +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *variable) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct sieve_ast *ast = cmd->ast_node->ast; + struct ext_include_ast_context *ctx = + ext_include_get_ast_context(this_ext, ast); + struct ext_include_context *ectx = ext_include_get_context(this_ext); + struct sieve_variable_scope *local_scope; + struct sieve_variable_scope *global_scope = ctx->global_vars; + struct sieve_variable *global_var = NULL, *local_var; + + /* Sanity safeguard */ + i_assert ( ctx->global_vars != NULL ); + + if ( !sieve_variable_identifier_is_valid(variable) ) { + sieve_command_validate_error(valdtr, cmd, + "invalid variable identifier '%s'", str_sanitize(variable,80)); + return NULL; + } + + /* Get/Declare the variable in the global scope */ + global_var = sieve_variable_scope_declare(global_scope, variable); + + /* Check whether scope is over its size limit */ + if ( global_var == NULL ) { + sieve_command_validate_error(valdtr, cmd, + "declaration of new global variable '%s' exceeds the limit " + "(max variables: %u)", variable, + sieve_variables_get_max_scope_size(ectx->var_ext)); + return NULL; + } + + /* Import the global variable into the local script scope */ + local_scope = sieve_ext_variables_get_local_scope(ectx->var_ext, valdtr); + + local_var = sieve_variable_scope_get_variable(local_scope, variable); + if ( local_var != NULL && local_var->ext != this_ext ) { + /* FIXME: indicate location of conflicting set statement */ + sieve_command_validate_error(valdtr, cmd, + "declaration of new global variable '%s' conflicts with earlier local " + "use", variable); + return NULL; + } + + return sieve_variable_scope_import(local_scope, global_var); +} + +/* + * Binary symbol table + */ + +bool ext_include_variables_save +(struct sieve_binary_block *sblock, + struct sieve_variable_scope_binary *global_vars, + enum sieve_error *error_r ATTR_UNUSED) +{ + struct sieve_variable_scope *global_scope = + sieve_variable_scope_binary_get(global_vars); + unsigned int count = sieve_variable_scope_size(global_scope); + sieve_size_t jump; + + sieve_binary_emit_unsigned(sblock, count); + + jump = sieve_binary_emit_offset(sblock, 0); + + if ( count > 0 ) { + unsigned int size, i; + struct sieve_variable *const *vars = + sieve_variable_scope_get_variables(global_scope, &size); + + for ( i = 0; i < size; i++ ) { + sieve_binary_emit_cstring(sblock, vars[i]->identifier); + } + } + + sieve_binary_resolve_offset(sblock, jump); + + return TRUE; +} + +bool ext_include_variables_load +(const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, + sieve_size_t *offset, struct sieve_variable_scope_binary **global_vars_r) +{ + struct ext_include_context *ectx = + ext_include_get_context(this_ext); + + /* Sanity assert */ + i_assert( *global_vars_r == NULL ); + + *global_vars_r = sieve_variable_scope_binary_read + (this_ext->svinst, ectx->var_ext, this_ext, sblock, offset); + + return ( *global_vars_r != NULL ); +} + +bool ext_include_variables_dump +(struct sieve_dumptime_env *denv, + struct sieve_variable_scope_binary *global_vars) +{ + struct sieve_variable_scope *global_scope = + sieve_variable_scope_binary_get(global_vars); + unsigned int size; + struct sieve_variable *const *vars; + + i_assert(global_scope != NULL); + + vars = sieve_variable_scope_get_variables(global_scope, &size); + + if ( size > 0 ) { + unsigned int i; + + sieve_binary_dump_sectionf(denv, "Global variables"); + + for ( i = 0; i < size; i++ ) { + sieve_binary_dumpf(denv, "%3d: '%s' \n", i, vars[i]->identifier); + } + } + + return TRUE; +} + +/* + * Global variables namespace + */ + +bool vnspc_global_variables_validate + (struct sieve_validator *valdtr, const struct sieve_variables_namespace *nspc, + struct sieve_ast_argument *arg, struct sieve_command *cmd, + ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, + bool assignment); +bool vnspc_global_variables_generate + (const struct sieve_codegen_env *cgenv, + const struct sieve_variables_namespace *nspc, + struct sieve_ast_argument *arg, struct sieve_command *cmd, void *var_data); + +static const struct sieve_variables_namespace_def +global_variables_namespace = { + SIEVE_OBJECT("global", NULL, 0), + .validate = vnspc_global_variables_validate, + .generate = vnspc_global_variables_generate +}; + +bool vnspc_global_variables_validate +(struct sieve_validator *valdtr, + const struct sieve_variables_namespace *nspc, struct sieve_ast_argument *arg, + struct sieve_command *cmd ATTR_UNUSED, + ARRAY_TYPE(sieve_variable_name) *var_name, void **var_data, + bool assignment ATTR_UNUSED) +{ + const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc); + struct sieve_ast *ast = arg->ast; + struct ext_include_context *ectx = + ext_include_get_context(this_ext); + struct ext_include_ast_context *ctx = + ext_include_get_ast_context(this_ext, ast); + struct sieve_variable *var = NULL; + const struct sieve_variable_name *name_element; + const char *variable; + + /* Sanity safeguard */ + i_assert ( ctx->global_vars != NULL ); + + /* Check variable name */ + + if ( array_count(var_name) != 2 ) { + sieve_argument_validate_error(valdtr, arg, + "invalid variable name within global namespace: " + "encountered sub-namespace"); + return FALSE; + } + + name_element = array_idx(var_name, 1); + if ( name_element->num_variable >= 0 ) { + sieve_argument_validate_error(valdtr, arg, + "invalid variable name within global namespace: " + "encountered numeric variable name"); + return FALSE; + } + + variable = str_c(name_element->identifier); + + /* Get/Declare the variable in the global scope */ + + var = sieve_variable_scope_declare(ctx->global_vars, variable); + + if ( var == NULL ) { + sieve_argument_validate_error(valdtr, arg, + "(implicit) declaration of new global variable '%s' exceeds the limit " + "(max variables: %u)", variable, + sieve_variables_get_max_scope_size(ectx->var_ext)); + return FALSE; + } + + *var_data = (void *) var; + + return TRUE; +} + +bool vnspc_global_variables_generate +(const struct sieve_codegen_env *cgenv, + const struct sieve_variables_namespace *nspc, + struct sieve_ast_argument *arg ATTR_UNUSED, + struct sieve_command *cmd ATTR_UNUSED, void *var_data) +{ + const struct sieve_extension *this_ext = SIEVE_OBJECT_EXTENSION(nspc); + struct ext_include_context *ectx = ext_include_get_context(this_ext); + struct sieve_variable *var = (struct sieve_variable *) var_data; + + sieve_variables_opr_variable_emit(cgenv->sblock, ectx->var_ext, var); + + return TRUE; +} + +void ext_include_variables_global_namespace_init +(const struct sieve_extension *this_ext, struct sieve_validator *valdtr) +{ + struct ext_include_context *ectx = ext_include_get_context(this_ext); + + sieve_variables_namespace_register + (ectx->var_ext, valdtr, this_ext, &global_variables_namespace); +} + + + diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.h b/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.h new file mode 100644 index 0000000..d5927b2 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include-variables.h @@ -0,0 +1,41 @@ +#ifndef EXT_INCLUDE_VARIABLES_H +#define EXT_INCLUDE_VARIABLES_H + +#include "sieve-common.h" + +#include "sieve-ext-variables.h" + +#include "ext-include-common.h" + +/* + * Variable import-export + */ + +struct sieve_variable *ext_include_variable_import_global + (struct sieve_validator *valdtr, struct sieve_command *cmd, + const char *variable); + +/* + * Binary symbol table + */ + +bool ext_include_variables_save + (struct sieve_binary_block *sblock, + struct sieve_variable_scope_binary *global_vars, + enum sieve_error *error_r); +bool ext_include_variables_load + (const struct sieve_extension *this_ext, struct sieve_binary_block *sblock, + sieve_size_t *offset, struct sieve_variable_scope_binary **global_vars_r); +bool ext_include_variables_dump + (struct sieve_dumptime_env *denv, + struct sieve_variable_scope_binary *global_vars); + +/* + * Validation + */ + +void ext_include_variables_global_namespace_init + (const struct sieve_extension *this_ext, struct sieve_validator *valdtr); + +#endif + diff --git a/pigeonhole/src/lib-sieve/plugins/include/ext-include.c b/pigeonhole/src/lib-sieve/plugins/include/ext-include.c new file mode 100644 index 0000000..0a38687 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/include/ext-include.c @@ -0,0 +1,121 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension include + * ----------------- + * + * Authors: Stephan Bosch + * Specification: RFC 6609 + * Implementation: full + * Status: testing + * + */ + +/* FIXME: Current include implementation does not allow for parts of the script + * to be located in external binaries; all included scripts are recompiled and + * the resulting byte code is imported into the main binary in separate blocks. + */ + +#include "lib.h" + +#include "sieve-common.h" + +#include "sieve-extensions.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-binary.h" +#include "sieve-dump.h" + +#include "sieve-ext-variables.h" + +#include "ext-include-common.h" +#include "ext-include-binary.h" +#include "ext-include-variables.h" + +/* + * Operations + */ + +static const struct sieve_operation_def *ext_include_operations[] = { + &include_operation, + &return_operation, + &global_operation +}; + +/* + * Extension + */ + +/* Forward declaration */ + +static bool ext_include_validator_load + (const struct sieve_extension *ext, struct sieve_validator *validator); +static bool ext_include_generator_load + (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv); +static bool ext_include_interpreter_load + (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + sieve_size_t *address); +static bool ext_include_binary_load + (const struct sieve_extension *ext, struct sieve_binary *binary); + +/* Extension objects */ + +const struct sieve_extension_def include_extension = { + .name = "include", + .version = 1, + + .load = ext_include_load, + .unload = ext_include_unload, + .validator_load = ext_include_validator_load, + .generator_load = ext_include_generator_load, + .interpreter_load = ext_include_interpreter_load, + .binary_load = ext_include_binary_load, + .binary_dump = ext_include_binary_dump, + .code_dump = ext_include_code_dump, + + SIEVE_EXT_DEFINE_OPERATIONS(ext_include_operations) +}; + +static bool ext_include_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register new commands */ + sieve_validator_register_command(valdtr, ext, &cmd_include); + sieve_validator_register_command(valdtr, ext, &cmd_return); + sieve_validator_register_command(valdtr, ext, &cmd_global); + + /* DEPRICATED */ + sieve_validator_register_command(valdtr, ext, &cmd_import); + sieve_validator_register_command(valdtr, ext, &cmd_export); + + /* Initialize global variables namespace */ + ext_include_variables_global_namespace_init(ext, valdtr); + + return TRUE; +} + +static bool ext_include_generator_load +(const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv) +{ + ext_include_register_generator_context(ext, cgenv); + + return TRUE; +} + +static bool ext_include_interpreter_load +(const struct sieve_extension *ext, const struct sieve_runtime_env *renv, + sieve_size_t *address ATTR_UNUSED) +{ + ext_include_interpreter_context_init(ext, renv->interp); + + return TRUE; +} + +static bool ext_include_binary_load +(const struct sieve_extension *ext, struct sieve_binary *sbin) +{ + (void)ext_include_binary_get_context(ext, sbin); + + return TRUE; +} |