141 lines
3.9 KiB
Bash
Executable file
141 lines
3.9 KiB
Bash
Executable file
#!/bin/bash
|
|
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# runtest.sh of /CoreOS/postfix/Sanity/headercheck
|
|
# Description: headercheck
|
|
# Author: Robin Hack <rhack@redhat.com>
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# Copyright (c) 2019 Red Hat, Inc.
|
|
#
|
|
# This program is free software: you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation, either version 2 of
|
|
# the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see http://www.gnu.org/licenses/.
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# Include Beaker environment
|
|
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
|
|
|
PACKAGE="postfix"
|
|
|
|
rlJournalStart
|
|
rlPhaseStartSetup
|
|
rlAssertRpm $PACKAGE
|
|
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
|
|
rlRun "pushd $TmpDir"
|
|
|
|
rlServiceStart "rsyslog"
|
|
|
|
if rlIsRHEL 5; then
|
|
rlServiceStop "sendmail"
|
|
fi
|
|
|
|
rlServiceStop "postfix"
|
|
rlFileBackup "/etc/postfix/main.cf"
|
|
rlFileBackup "/etc/postfix/vmailbox"
|
|
rlFileBackup "/etc/postfix/virtual"
|
|
rlFileBackup "/var/log/maillog"
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartSetup
|
|
|
|
# don't care
|
|
rm -rf /var/mail/vhosts
|
|
rlRun "mkdir -p /var/mail/vhosts/example.com"
|
|
rlRun "chown -R 5000:5000 /var/mail/vhosts/"
|
|
|
|
cat << "EOF" > "/etc/postfix/main.cf"
|
|
myhostname = randomstuff.at
|
|
|
|
alias_maps = hash:/etc/aliases
|
|
alias_database = hash:/etc/aliases
|
|
|
|
myorigin = /etc/mailname
|
|
mydestination = localhost.randomstuff.at, localhost
|
|
|
|
relayhost =
|
|
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
|
|
mailbox_size_limit = 0
|
|
recipient_delimiter = +
|
|
inet_interfaces = all
|
|
|
|
smtpd_relay_restrictions = reject_unauth_destination
|
|
|
|
virtual_mailbox_domains = example.com
|
|
virtual_mailbox_base = /var/mail/vhosts
|
|
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
|
|
virtual_minimum_uid = 100
|
|
virtual_uid_maps = static:5000
|
|
virtual_gid_maps = static:5000
|
|
virtual_alias_maps = hash:/etc/postfix/virtual
|
|
|
|
header_checks = regexp:/etc/postfix/header_checks
|
|
EOF
|
|
|
|
cat << "EOF" > "/etc/postfix/vmailbox"
|
|
info@example.com example.com/info
|
|
sales@example.com example.com/sales/
|
|
EOF
|
|
|
|
cat << "EOF" > "/etc/postfix/virtual"
|
|
postmaster@example.com postmaster
|
|
EOF
|
|
|
|
cat << "EOF" > "/etc/postfix/header_checks"
|
|
/^From.*alien\.xt/ REJECT Sorry, no aliens welcome!
|
|
EOF
|
|
|
|
rlRun "postmap /etc/postfix/virtual"
|
|
rlRun "postmap /etc/postfix/vmailbox"
|
|
|
|
rlServiceStart "postfix"
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartTest
|
|
cat << "EOF" | nc localhost 25 &> TESTOUT
|
|
EHLO aliens.outerworld
|
|
MAIL FROM: friendly@alien.xt
|
|
RCPT TO: info@example.com
|
|
DATA
|
|
From: friendly@alien.xt
|
|
Hello we are friendly Aliens and we are comming in peace!
|
|
.
|
|
EOF
|
|
|
|
rlAssertGrep "Sorry, no aliens welcome!" TESTOUT
|
|
rlAssertNotGrep "Ok: queued as" TESTOUT
|
|
rlPhaseEnd
|
|
|
|
rlPhaseStartCleanup
|
|
rlRun "popd"
|
|
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
|
|
|
|
rlRun "rm -rf /var/mail/vhosts"
|
|
|
|
rlServiceStop "postfix"
|
|
rlRun "rm -rf /etc/postfix/vmailbox.db"
|
|
rlRun "rm -rf /etc/postfix/virtual.db"
|
|
rlRun "rm -rf /etc/postfix/header_checks"
|
|
|
|
rlFileRestore
|
|
if rlIsRHEL 5; then
|
|
rlServiceRestore "sendmail"
|
|
rlServiceStop "postfix"
|
|
else
|
|
rlServiceRestore "postfix"
|
|
fi
|
|
rlPhaseEnd
|
|
rlJournalPrintText
|
|
rlJournalEnd
|