diff options
Diffstat (limited to 'debian/debconf/update-exim4.conf')
-rw-r--r-- | debian/debconf/update-exim4.conf | 406 |
1 files changed, 406 insertions, 0 deletions
diff --git a/debian/debconf/update-exim4.conf b/debian/debconf/update-exim4.conf new file mode 100644 index 0000000..befa59d --- /dev/null +++ b/debian/debconf/update-exim4.conf @@ -0,0 +1,406 @@ +#!/bin/sh +# update-exim4.conf(8) - Generate /var/lib/exim4/config.autogenerated + + +# exit immediately if /etc/exim4/exim4.conf exists +[ -e /etc/exim4/exim4.conf ] && exit 0 + +UPEX4C_confd="/etc/exim4/conf.d" +UPEX4C_sections="main acl router transport retry rewrite auth" +EXIM="/usr/sbin/exim4" + +[ -d /var/lib/exim4/ ] && \ +[ -d ${UPEX4C_confd} ] || \ +{ printf "$0: Error, no ${UPEX4C_confd} or missing\n/var/lib/exim4/, exiting.\n" 1>&2 ; exit 1 ; } + +. /etc/exim4/update-exim4.conf.conf || \ +{ printf "$0: Error, no /etc/exim4/update-exim4.conf.conf, exiting.\n" 1>&2 ; exit 1 ; } + +[ "x${CFILEMODE}" = "x" ] && CFILEMODE=644 + +UPEX4C_verbose=no +UPEX4C_comments=no +UPEX4C_autoconfigfile=/var/lib/exim4/config.autogenerated +UPEX4C_outputfile="${UPEX4C_autoconfigfile}" +UPEX4C_version="" + +usage() { +cat <<EOF +$0 - Generate exim4 configuration files + Options: + -v|--verbose - Enable verbose mode, tell about ignored files + -h|--help - Show this message + --keepcomments - Do not remove comment lines + --removecomments - Remove comment lines + -o|--output file - write output to file instead of ${UPEX4C_outputfile} +EOF +} + +## Parse commandline +TEMP=$(getopt -n update-exim4.conf \ + -l keepcomments,removecomments,output:,help,verbose -- \ + +o:vh "$@") + +if test "$?" != 0; then + echo "Terminating..." >&2 + exit 1 +fi + +eval set -- ${TEMP} +while test "$1" != "--"; do + case $1 in + -h|--help) + usage + exit 0 + ;; + -v|--verbose) + UPEX4C_verbose=yes + ;; + --keepcomments) + UPEX4C_comments=yes + ;; + --removecomments) + UPEX4C_comments=no + ;; + -o|--output) + shift + UPEX4C_outputfile="$1" + ;; + esac + shift +done +shift + +# No non-option arguments allowed. +if [ "$#" -ne 0 ]; then + echo "No non option arguments allowed" >&2 + usage >&2 + exit 1 +fi + +mailname=`cat /etc/mailname | head` + +# add localhost and mailname, get rid of spaces and trailing colons +local_domains="`echo ${mailname}:localhost:${dc_other_hostnames} | \ + sed -e 'sÄ[: ]*$ÄÄ' -e 'sÄ *ÄÄ'`" + +TEMPLATEFILE=/etc/exim4/exim4.conf.template + +UPEX4C_internal_tmp=`tempfile -m600 -p ex4` + +trap "rm -f ${UPEX4C_internal_tmp}" 0 2 15 + +# test if $1 is user modified, print message +unmodifandmessage() { + [ "$#" -eq 1 ] || return 1 + if unmodified "$1" ; then + return 0 + else + [ "${UPEX4C_verbose}" = "yes" ] && \ + echo "ignoring user modified file $1" + return 1 + fi +} + +# 0123456789abcdef0123456789abcdef +generatemasquerade() { + UPEX4C_internal_currfile="${UPEX4C_confd}/rewrite/35_exim4-config_masquerade" + unmodifandmessage "${UPEX4C_internal_currfile}" || return +cat << EOF > "${UPEX4C_internal_tmp}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# This is an md5sum. +####################################### +# WARNING WARNING WARNING WARNING +# This file is dynamically generated by update-exim4.conf(8) using the data +# in /etc/exim4/update-exim4.conf.conf. + +# If you make _any_ changes to it update-exim4.conf(8) won't update it any +# more! - Especially it will be used _even_ if you change to a different +# conftype. + +# If you just want to ADD your additional rewriting rules put them in a +# different file, for example CONFDIR/conf.d/rewrite/50_local_mywrite +################## +EOF + if [ "$1" = "yes" ] ; then + for domain in `echo "${local_domains}" | sed -e 's/:/ /g'` ; do + # mailfuerpostmaster=fuser + #fuser=sysmail + #echo '^(?i)(root|postmaster|mailer-daemon)@'"$domain" '${local_part}@in.limbo Ffr' + echo '*@'"$domain" '${local_part}@'"${dc_readhost} Ffr" + done >> "${UPEX4C_internal_tmp}" + #echo '*@in.limbo' "$fuser"'@'"${dc_readhost} Ffr" >> "${UPEX4C_internal_tmp}" + fi + UPEX4C_internal_md5=`cat "${UPEX4C_internal_tmp}" | md5sum | cut -d\ -f1` + { echo "# ${UPEX4C_internal_md5}" ; cat "${UPEX4C_internal_tmp}" ; } > \ + "${UPEX4C_internal_currfile}" +} + +# generate code for evaluation of email_addresses +generateemailaddresses() { + UPEX4C_internal_currfile="${UPEX4C_confd}/rewrite/30_exim4-config_email-addresses" + unmodifandmessage "${UPEX4C_internal_currfile}" || return +cat << EOF > "${UPEX4C_internal_tmp}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# This is an md5sum. +####################################### +# WARNING WARNING WARNING WARNING +# This file is dynamically generated by update-exim4.conf(8) using the data +# in /etc/exim4/update-exim4.conf.conf. + +# If you make _any_ changes to it update-exim4.conf(8) won't update it any +# more! - Especially it will be used _even_ if you change to a different +# conftype. + +# If you just want to ADD your additional rewriting rules put them in a +# different file, for example CONFDIR/conf.d/rewrite/50_local_mywrite +################## + +# This rewriting rule is particularly useful for dialup users who +# don't have their own domain, but could be useful for anyone. +# It looks up the real address of all local users in a file + +# it needs to be generated dynamically for i in local_domains +# +EOF + for domain in `echo ${local_domains} | sed -e 's/:/ /g'` ; do + echo '*@'"$domain" '${lookup{${local_part}}lsearch{CONFDIR/email-addresses}{$value}fail} Ffrs' + done >> "${UPEX4C_internal_tmp}" + UPEX4C_internal_md5=`cat "${UPEX4C_internal_tmp}" | md5sum | cut -d\ -f1` + { echo "# ${UPEX4C_internal_md5}" ; cat "${UPEX4C_internal_tmp}" ; } > \ + "${UPEX4C_internal_currfile}" +} + + +# generate "never_users=root" option if root is aliased somewhere. +gen_neverusers(){ + UPEX4C_internal_currfile="${UPEX4C_confd}/main/03_exim4-config_neverusers" + unmodifandmessage "${UPEX4C_internal_currfile}" || return + cat << EOF > "${UPEX4C_internal_tmp}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# This is an md5sum. +####################################### +# WARNING WARNING WARNING WARNING +# This file is dynamically generated by update-exim4.conf(8) depending on +# the data in /etc/aliases. - If it finds an alias for root it'll +# set 'never_users=root' otherwise not. + +# If you make _any_ changes to this file update-exim4.conf(8) won't +# update it any more! +################## +# No deliveries will ever be run under the uids of these users (a colon- +# separated list). An attempt to do so causes a panic error to be logged, and +# the delivery to be deferred. This is a paranoic safety catch. Note that the +# default setting means you cannot deliver mail addressed to root as if it +# were a normal user. This isn't usually a problem, as most sites have an alias +# for root that redirects such mail to a human administrator. +# +EOF + if [ -r /etc/aliases ] &&\ + grep -q '^root:[[:space:]]*[^[:space:]]' /etc/aliases; then + echo 'never_users = root' >> "${UPEX4C_internal_tmp}" + else + echo '#never_users = root' >> "${UPEX4C_internal_tmp}" + fi + UPEX4C_internal_md5=`cat "${UPEX4C_internal_tmp}" | md5sum | cut -d\ -f1` + { echo "# ${UPEX4C_internal_md5}" ; cat "${UPEX4C_internal_tmp}" ; } > \ + "${UPEX4C_internal_currfile}" +} + +# use this as template for new gen_something functions. +UPEX4C_skeleton() { + UPEX4C_internal_currfile="${UPEX4C_confd}/foo/bar" + unmodifandmessage "${UPEX4C_internal_currfile}" || return + cat << EOF > "${UPEX4C_internal_tmp}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +# This is an md5sum. +####################################### +# WARNING WARNING WARNING WARNING +# This file is dynamically generated by update-exim4.conf(8) using the data +# in /etc/exim4/update-exim4.conf.conf. +EOF +# insert more code that appends to ${UPEX4C_internal_tmp} + UPEX4C_internal_md5=`cat "${UPEX4C_internal_tmp}" | md5sum | cut -d\ -f1` + { echo "# ${UPEX4C_internal_md5}" ; cat "${UPEX4C_internal_tmp}" ; } > \ + "${UPEX4C_internal_currfile}" +} + +# run-parts emulation, stolen from Branden's /etc/X11/Xsession +# Addition: Use file.rul instead if file if it exists. +run_parts () { + # reset LC_COLLATE + unset LANG LC_COLLATE LC_ALL + + if [ -z "$1" ]; then + errormessage "$0: internal run_parts called without an argument" + fi + if [ ! -d "$1" ]; then + errormessage "$0: internal run_parts called, but $1 does not exist or is not a directory." + fi + for F in $(ls $1); do + if expr "$F" : '[[:alnum:]_-]\+$' > /dev/null 2>&1; then + if [ -f "$1/$F" ] ; then + if [ -f "$1/${F}.rul" ] ; then + echo "$1/${F}.rul" + else + echo "$1/$F" + fi + fi + fi + done; +} +# also from Branden +errormessage () { + # pretty-print messages of arbitrary length (no trailing newline) + echo "$*" | fold -s -w ${COLUMNS:-80} >&2; +} + +# check whether the file given as argument was modified by the user +# by comparing the md5sum in the first line with the real one. +unmodified() { + [ "$#" -eq 1 ] || return 1 + [ -f "$1" ] || return 1 + # first line, without the leading '# '. + checksum_current=`sed -n -e '1s/^# //' -e '1p;1q' "$1"` + + # md5sum over the rest of the file. + # some versions of md5sum produce + # '68b329da9893e34099c7d8ad5cb9c940 -' others don't add the dash. + # '68b329da9893e34099c7d8ad5cb9c940' + checksum_new=`sed -n '2,$p' "$1" | md5sum | cut -d\ -f1` + + if [ "${checksum_current}" = "${checksum_new}" ] ; then + return 0 + else + return 1 + fi +} + +# update the md5sum given in the first line, return an error if the file does +# not have an md5sum header in the first line. +updatechecksumheader() { + [ "$#" -eq 1 ] || return 1 + [ -f "$1" ] || return 1 + # check for correct format "# 76a51391da4a0687697224a124b71a17" + sed -n -e '1p;1q' "$1" | grep -q -E '^# [[:xdigit:]]{32}$' || \ + { echo "incorrect format" ; return 1 ;} + + NEWFILE=`tempfile -m600 -p ex4` + sed -n '2,$p' "$1" | md5sum | cut -d\ -f1 | sed '1s/^/# /' > $NEWFILE + sed -n '2,$p' "$1" >> $NEWFILE + mv -f $NEWFILE "$1" +} + +gentmpconf() { + touch ${UPEX4C_outputfile}.tmp + #chown --reference=${TEMPLATEFILE} \ + # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} + #chmod --reference=${TEMPLATEFILE} \ + # ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} + chown root:mail ${UPEX4C_outputfile}.tmp + [ -e ${UPEX4C_outputfile} ] && chown root:mail ${UPEX4C_outputfile} + chmod 640 ${UPEX4C_outputfile}.tmp + [ -e ${UPEX4C_outputfile} ] && chmod 640 ${UPEX4C_outputfile} +} + +removecomments(){ + if [ "x${UPEX4C_comments}" = "xno" ] ; then + egrep -v '^[[:space:]]*#' | sed -e '/^$/N;/\n$/D' ; + else + cat + fi +} + +case "$dc_eximconfig_configtype" in + satellite) + # hide mailname with rewriting rules + generatemasquerade yes + ;; + local) + generatemasquerade no + ;; + smarthost|internet) + generatemasquerade no + ;; + none|*) + generatemasquerade no + gentmpconf + for i in ${UPEX4C_sections} ; do + cat `run_parts ${UPEX4C_confd}/$i` + done | \ + removecomments \ + sed -e "s/DEBCONF[^D][^E][^B].*DEBCONF//g" \ + > ${UPEX4C_outputfile}.tmp + mv -f ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} + chmod ${CFILEMODE} ${UPEX4C_outputfile} + [ "${UPEX4C_verbose}" = "yes" ] && \ + echo "Not substituting variables since conftype is none (or other)" + exit 0 + ;; +esac + +if [ "x${dc_local_interfaces}" = "x" ] ; then + listenonpublic='# if local_interfaces is unset, we listen on all interfaces' +else + listenonpublic="local_interfaces = ${dc_local_interfaces}" +fi + +if [ "x${dc_minimaldns}" = "xtrue" ] ; then + UPEX4C_minimaldns='DC_minimaldns = 1' +else + UPEX4C_minimaldns='' +fi + +gen_neverusers +generateemailaddresses +gentmpconf + +cat << EOF > ${UPEX4C_outputfile}.tmp +######### +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# this file is generated dynamically from the files in +# CONFDIR/conf.d/ and /etc/exim4/update-exim4.conf.conf +# Any changes you make here will be lost. +# See /usr/share/doc/exim4-base/README.Debian and update-exim4.conf(8) +# for instructions of customization. +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +# WARNING WARNING WARNING +######### +EOF + +for i in ${UPEX4C_sections} ; do + echo "# begin processing $i #####" + cat `run_parts ${UPEX4C_confd}/$i` + echo "# end of $i #####" +done | \ +removecomments | \ +sed -e "sÄDEBCONFlocal_domainsDEBCONFÄ@:${local_domains}Äg" \ + -e "sÄDEBCONFrelay_domainsDEBCONFÄ${dc_relay_domains}Äg" \ + -e "sÄDEBCONFrelay_netsDEBCONFÄ${dc_relay_nets}Äg" \ + -e "sÄDEBCONFvisiblenameDEBCONFÄ${mailname}Äg" \ + -e "sÄDEBCONFreadhostDEBCONFÄ${dc_readhost}Äg" \ + -e "sÄDEBCONFsmarthostDEBCONFÄ${dc_smarthost}Äg" \ + -e "sÄDEBCONFconfigtypeDEBCONFÄ${dc_eximconfig_configtype}Äg" \ + -e "sÄDEBCONFlistenonpublicDEBCONFÄ${listenonpublic}Äg" \ + -e "sÄDEBCONFpackageversionDEBCONFÄ${UPEX4C_version}Äg" \ + -e "sÄDEBCONFminimaldnsDEBCONFÄ${UPEX4C_minimaldns}Äg" \ + >> ${UPEX4C_outputfile}.tmp + +# test validity if called without -o +if [ "x${UPEX4C_outputfile}" = "x${UPEX4C_autoconfigfile}" ] ; then + if ! ${EXIM} -C "${UPEX4C_outputfile}.tmp" -bV > /dev/null ; then + errormessage "Invalid new configfile ${UPEX4C_outputfile}.tmp" + errormessage "not installing ${UPEX4C_outputfile}.tmp to ${UPEX4C_outputfile}" + exit 1 + fi +fi + +mv -f ${UPEX4C_outputfile}.tmp ${UPEX4C_outputfile} +chmod ${CFILEMODE} ${UPEX4C_outputfile} |