File: //usr/share/sendmail/update_mc
#!/bin/sh -e
#-----------------------------------------------------------------------------
#
# $Sendmail: update_mc,v 8.15.2 2021-03-16 16:04:16 cowboy Exp $
#
# Update Sendmail databases for Debian
#
# Copyright (c) 2000-2010 Richard Nelson. All Rights Reserved.
#
# Notes (to all):
# * assumes makemap dbtype /etc/mail/database < /etc/mail/database
#
# Notes (to self):
# * changes made herein *must* be reflected in
# parse_mc,update_mk,update_db,debian.m4
#
#-----------------------------------------------------------------------------
set -e;
changed=0;
# Path to other sendmail helpers
if [ -x ./update_sendmail ]; then
sm_path='.';
elif [ -x $(dirname $0)/update_sendmail ]; then
sm_path=$(dirname $0);
else
sm_path=/usr/share/sendmail;
fi;
# Bring in sendmail.conf for the network definitions
if [ ! -f /etc/mail/sendmail.conf ]; then
if [ -x $sm_path/update_conf ]; then
$sm_path/update_conf;
fi;
fi;
if [ -f /etc/mail/sendmail.conf ]; then
. /etc/mail/sendmail.conf;
fi;
if [ "$HANDS_OFF" != 'No' ]; then
exit 0;
fi;
new_mc () {
chown root:smmsp /etc/mail/"$1".mc.new;
chmod 0644 /etc/mail/"$1".mc.new;
mv /etc/mail/"$1".mc.new /etc/mail/"$1".mc;
changed=1;
};
#-----------------------------------------------------------------------------
# Move sendmail.{mc,cf} from /etc/ to /etc/mail
if [ ! -f /etc/mail/sendmail.mc ]; then
if [ -f /etc/sendmail.mc ]; then
echo "Moving /etc/sendmail.* to /etc/mail/";
mv /etc/sendmail.mc /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
if [ -f /etc/sendmail.cf ]; then
mv /etc/sendmail.cf /etc/mail/sendmail.cf;
chown root:smmsp /etc/mail/sendmail.cf;
chmod 0644 /etc/mail/sendmail.cf;
changed=1;
fi;
fi;
#-----------------------------------------------------------------------------
# Create {submit,sendmail}.mc if needed
if [ ! -f /etc/mail/sendmail.mc ]; then
cp -p /usr/share/sendmail/cf/debian/sendmail.mc \
/etc/mail/sendmail.mc.new;
if [ -f /etc/mailname ] && [ ! -z /etc/mailname ]; then
masq=$(cat /etc/mailname);
sed -i "/dnl # Default Mailer setup/i\
dnl # Masquerading options\\
FEATURE(\`always_add_domain')dnl\\
MASQUERADE_AS(\`${masq}')dnl\\
FEATURE(\`allmasquerade')dnl\\
FEATURE(\`masquerade_envelope')dnl\\
dnl #" /etc/mail/sendmail.mc.new
fi;
new_mc sendmail;
fi;
if [ ! -f /etc/mail/submit.mc ]; then
if [ -f /usr/share/sendmail/cf/debian/submit.mc ]; then
cp -p /usr/share/sendmail/cf/debian/submit.mc \
/etc/mail/submit.mc.new;
new_mc submit;
fi;
fi;
#-----------------------------------------------------------------------------
# Make sure dialup support m4 files are extant
if [ ! -f /etc/mail/m4/dialup.m4 ]; then
if [ -f /etc/mail/dialup.m4 ]; then
mv /etc/mail/dialup.m4 /etc/mail/m4/dialup.m4;
else
touch /etc/mail/m4/dialup.m4;
fi;
chown root:smmsp /etc/mail/m4/dialup.m4;
chmod 0640 /etc/mail/m4/dialup.m4;
fi;
if [ ! -f /etc/mail/m4/provider.m4 ]; then
if [ -f /etc/mail/provider.m4 ]; then
mv /etc/mail/provider.m4 /etc/mail/m4/provider.m4;
else
touch /etc/mail/m4/provider.m4;
fi;
chown root:smmsp /etc/mail/m4/provider.m4;
chmod 0640 /etc/mail/m4/provider.m4;
fi;
if (grep -qEe "^[[:space:]]*include\(\`?/etc/mail/dialup.m4" \
/etc/mail/sendmail.mc); then
sed -e "s=^\([[:space:]]*\)include(\`\?/etc/mail/dialup\.m4.*$=include(\`/etc/mail/m4/dialup\.m4')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
if (grep -qEe "^[[:space:]]*include\(\`?/etc/mail/provider.m4" \
/etc/mail/sendmail.mc); then
sed -e "s=^\([[:space:]]*\)include(\`\?/etc/mail/provider\.m4.*$=include(\`/etc/mail/m4/provider\.m4')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Make sure not using text mailertable (it doesn't work)
if (grep -qEe "^[[:space:]]*FEATURE\(\`?mailertable'?, \`text /etc/mail/mailertable'\)" \
/etc/mail/sendmail.mc); then
echo "Correcting FEATURE(mailertable) in /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?mailertable'\?, \`text /etc/mail/mailertable')\(dnl\)\?=\1\2FEATURE(\`mailertable')dnl=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Make sure smrsh points to the correct location
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?smrsh'?[[:space:]]*,.*\)" \
/etc/mail/sendmail.mc); then
echo "Correcting FEATURE(smrsh) in /etc/mail/sendmail.mc";
sed -e "s=\([[:space:]]*\)\(\`\?\)FEATURE(\`\?smrsh'\?[[:space:]]*,.*)\(dnl\)\?=\1\2FEATURE(\`smrsh')dnl=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Convert FEATURE(nouucp) to FEATURE(nouucp,reject)
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?nouucp'?\)" \
/etc/mail/sendmail.mc); then
echo "Correcting FEATURE(nouucp) in /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?nouucp'\?)\(dnl\)\?=\1\2FEATURE(\`nouucp', \`reject')dnl=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Convert FEATURE(dont_masquerade_local) to FEATURE(local_no_masquerade)
if [ -e /usr/share/sendmail/cf/feature/local_no_masquerade.m4 ]; then
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?dont_masquerade_local'?\)" \
/etc/mail/sendmail.mc); then
echo "Correcting FEATURE(dont_masquerade_local) in /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?dont_masquerade_local'\?)\(dnl\)\?=\1\2FEATURE(\`local_no_masquerade')dnl=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
fi;
#-----------------------------------------------------------------------------
# Convert FEATURE(access_db,...) to FEATURE(access_db)
if (grep -qEe "^[[:space:]]*\`?FEATURE\(\`?access_db'?[[:space:]]*,.*\)" \
/etc/mail/sendmail.mc); then
sed -e "s=^\([[:space:]]*\)\(\`\?\)FEATURE(\`\?access_db'\?[[:space:]]*,[[:space:]]*\`\?hash[[:space:]]*\(-o\)\?[[:space:]]*/etc/mail/access.db'\?[[:space:]]*)\(dnl\)\?=\1\2FEATURE(\`access_db')dnl=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# change include(/usr/share/sendmail/sendmail.cf/m4/cf.m4)
if (grep -qEe "^[[:space:]]*\`?include\(\`?/usr/share/sendmail/sendmail.cf/m4/cf.m4'?\)" \
/etc/mail/sendmail.mc); then
sed -e "s=sendmail/sendmail.cf=sendmail/cf=g" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
if [ -f /etc/mail/submit.mc ]; then
sed -e "s=sendmail/sendmail.cf=sendmail/cf=g" \
/etc/mail/submit.mc > /etc/mail/submit.mc.new;
new_mc submit;
fi;
fi;
#-----------------------------------------------------------------------------
# Add include(/usr/share/sendmail/cf/m4/cf.m4)
if (grep -qEe "^[[:space:]]*\`?include\(\`?/usr/share/sendmail/cf/m4/cf.m4'?\)" \
/etc/mail/sendmail.mc); then
:;
else
echo "Adding include(.../cf.m4) to /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)VERSIONID(=\1\2include(\`/usr/share/sendmail/cf/m4/cf.m4')dnl\\
\1\2VERSIONID(=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Add define(`_USE_ETC_MAIL_')dnl
if (grep -qEe "^[[:space:]]*\`?define\(\`?_USE_ETC_MAIL_" \
/etc/mail/sendmail.mc); then
:;
else
sed -e "s=^\([[:space:]]*\)\(\`\?\)include(\`\?/usr/share/sendmail/cf/m4/cf.m4'\?)\(dnl\)\?=\1\2define(\`_USE_ETC_MAIL_')dnl\\
include(\`/usr/share/sendmail/cf/m4/cf.m4')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Check for badness
if (grep -qEe "^[[:space:]]*\`?OSTYPE\(\`?linux'?\)" \
/etc/mail/sendmail.mc); then
sed -e "s=^\([[:space:]]*\)\(\`\?\)OSTYPE(\`\?linux'\?)\(dnl\)\?=\1\2OSTYPE(\`debian')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Add DOMAIN(debian-mta)
if (grep -qEe "^[[:space:]]*\`?DOMAIN\(\`?debian-mta'?\)" \
/etc/mail/sendmail.mc); then
:;
else
echo "Adding DOMAIN(debian-mta) to /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)OSTYPE(\`\?debian'\?)\(dnl\)\?=\1\2OSTYPE(\`debian')dnl\\
\1\2DOMAIN(\`debian-mta')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Add sendmail.conf customization area
if (grep -qEe "^dnl # Items controlled by /etc/mail/sendmail.conf" \
/etc/mail/sendmail.mc); then
:;
else
echo "Adding sendmail.conf customization area to /etc/mail/sendmail.mc";
sed -e "s=^\([[:space:]]*\)\(\`\?\)DOMAIN(\`\?debian-mta'\?)\(dnl\)\?=\1\2DOMAIN(\`debian-mta')dnl\\
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE \\
dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl #DAEMON_HOSTSTATS \\
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
#-----------------------------------------------------------------------------
# Update items in sendmail.conf customization area
case "$DAEMON_HOSTSTATS" in
[Nn]*)
if (grep -qEe "^dnl undefine\(\`confHOST_STATUS_DIRECTORY'\)dnl" \
/etc/mail/sendmail.mc); then
echo "Turning off Host Status collection";
sed -e "s=^dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl=undefine(\`confHOST_STATUS_DIRECTORY')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
;;
[Yy]*)
if (grep -qEe "^undefine\(\`confHOST_STATUS_DIRECTORY'\)dnl" \
/etc/mail/sendmail.mc); then
echo "Turning on Host Status collection";
sed -e "s=^undefine(\`confHOST_STATUS_DIRECTORY')dnl=dnl undefine(\`confHOST_STATUS_DIRECTORY')dnl=" \
/etc/mail/sendmail.mc > /etc/mail/sendmail.mc.new;
new_mc sendmail;
fi;
esac;
#-----------------------------------------------------------------------------
# Cleanup submit.mc
if [ -f /etc/mail/submit.mc ]; then
sed -e "/^define(\`\?confRUN_AS_USER'\?,.*$/d" \
-e "/^define(\`\?confTRUSTED_USER'\?,.*$/d" \
/etc/mail/submit.mc > /etc/mail/submit.mc.new;
new_mc submit;
fi;
exit $changed;