#!/bin/sh
# postfinger - captures Postfix configuration for reporting errors
#
# Inspired by comments on the postfix-users mailing list.
# Copyright (C) 2003 Simon J. Mudd (sjmudd@pobox.com)
# With help from:
# Matthias Andree <ma@dt.e-technik.uni-dortmund.de>
# Victor Duchovni <Victor.Duchovni@morganstanley.com>
# Sasa Babic <sasab@hygia.pharmacy.bg.ac.yu>
# Iņaki Arenaza <iarenaza@escomposlinux.org>
# Jorge Gordoy <gordoy@g2ctech.com>
# $Revision: 1.31 $
#
# License:
# 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 may have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
# An on-line copy of the GNU General Public License can be found
# http://www.fsf.org/copyleft/gpl.html.
version_number=1.30 # don't use rcs version here
version="version: ${version_number}"
BACKUP_IFS=$IFS
usage="postfinger ${version}: a Postfix configuration extraction utility
Usage: postfinger [options]
Options can be any of:
--all Show all configuration information
--system Show basic system environment (os/kernel/...) [default]
--package Show packaging information [default]
--locking Show mailbox locking methods
--tables Show supported lookup tables
--main Show main.cf non-default configuration values [default]
--defaultsinmain Show main.cf defined values which are identical to defaults
--master Show master.cf configuration [default]
--permissions Show some of the spool_directory permissions
--libraries Show the Postfix libraries dependencies
--nosystem Do not show basic system environment (os/kernel/...)
--nomain Do not show main.cf non-default configuration values
--nomaster Do not show master.cf configuration
--nowarn Do not warn about private information being leaked to
outsiders
--version print the version of postfinger being used and exit
Mail bug reports and suggestions to <postfinger@WL0.org>".
system=1; package=1; locking=; tables=; main=1; master=1; permissions=; libraries=;warn=1;defaultsinmain=
for arg
do
case $arg in
--version) echo "postfinger ${version}"; exit 0;;
--all) system=1; package=1; locking=1; tables=1; main=1; master=1; permissions=1; libraries=1; warn=1;;
--system) system=1;;
--package) package=1;;
--locking) locking=1;;
--tables) tables=1;;
--main) main=1;;
--defaultsinmain) defaultsinmain=1;;
--master) master=1;;
--permissions) permissions=1;;
--libraries) libraries=1;;
--nosystem) system=;;
--nomain) main=;;
--nomaster) master=;;
--nowarn) warn=;;
--help) echo "${usage}"; exit 0;;
*) echo "Error: ${usage}" 1>&2; exit 1;;
esac
shift
done
echo "postfinger - postfix configuration on `LANG=C date`"
echo ${version}
echo ''
[ "${warn}" = 1 ] && {
cat <<END
Warning: postfinger output may show private configuration information,
such as ip addresses and/or domain names which you do not want to show
to the public. If this is the case it is your responsibility to modify
the output to hide this private information. [Remove this warning with
the --nowarn option.]
END
}
# Look for postconf, using environment variable if given
[ -n "${POSTCONF}" ] && [ ! -x "${POSTCONF}" ] && POSTCONF=
[ -z "${POSTCONF}" ] && [ -x /usr/sbin/postconf ] && POSTCONF=/usr/sbin/postconf
[ -z "${POSTCONF}" ] && [ -x /usr/local/sbin/postconf ] && POSTCONF=/usr/local/sbin/postconf
[ -z "${POSTCONF}" ] && {
echo "$0: can not find postconf"
echo "set POSTCONF to postconf's location and try again"
exit 1
}
# Look for smtpd, using environment variable if given
[ -z "${SMTPD}" ] && {
SMTPD=`${POSTCONF} -h daemon_directory`/smtpd
[ -d "${SMTPD}" -o ! -x "${SMTPD}" ] && SMTPD=
}
[ -z "${SMTPD}" ] && {
echo "$0: can not find smtpd"
echo "set SMTPD to smtpd's location and try again"
exit 1
}
[ "${system}" = 1 ] && {
echo '--System Parameters--'
${POSTCONF} -d mail_version
echo "hostname = `hostname`"
echo "uname = `uname -a`"
echo ""
}
# check for different packaging systems and try to identify if this postfix
# (smtpd) comes from a package.
# I would appreciate help in adapting this part to include other packaging
# systems.
[ "${package}" = 1 ] && {
echo "--Packaging information--"
DPKG=
[ -x /usr/bin/dpkg ] && DPKG=/usr/bin/dpkg
[ -z "${DPKG}" ] && [ -x /usr/local/bin/dpkg ] && DPKG=/usr/local/bin/dpkg
[ -n "${DPKG}" ] && {
${DPKG} -S ${SMTPD} >/dev/null 2>/dev/null && {
package=`${DPKG} -S ${SMTPD} | awk -F: '{print $1}' | head -n 1`
package_ver=`COLUMNS=132 ${DPKG} -l ${package} | grep ii | grep -v "documentation" | awk '{print $3}'`
echo "looks like this postfix comes from deb package: ${package}-${package_ver}"
}
}
RPM=
[ -x /bin/rpm ] && RPM=/bin/rpm
[ -z "${RPM}" ] && [ -x /usr/local/bin/rpm ] && RPM=/usr/local/bin/rpm
[ -n "${RPM}" ] && {
${RPM} -qf ${SMTPD} >/dev/null 2>/dev/null && \
echo "looks like this postfix comes from RPM package: `${RPM} -qf ${SMTPD}`"
}
BSDPKG=
[ -x /usr/sbin/pkg_info ] && BSDPKG=/usr/sbin/pkg_info
[ -n "${BSDPKG}" ] && {
${BSDPKG} -q -W ${SMTPD} >/dev/null 2>/dev/null && \
echo "looks like this postfix comes from BSD package: `${BSDPKG} -q -W ${SMTPD}`"
}
PKGCHK=
PKGINFO=
[ -x /usr/sbin/pkgchk ] && PKGCHK=/usr/sbin/pkgchk
[ -x /usr/bin/pkginfo ] && PKGINFO=/usr/bin/pkginfo
[ -n "$PKGCHK" -a -n "$PKGINFO" ] && {
pkgs=`pkgchk -l -p ${SMTPD} | tr '\011' ' ' |
sed -ne '/^Referenced by the following packages:/,/^C/ {
/^ /p
}'`
[ -n "$pkgs" ] && {
echo "looks like this postfix comes from the SVR4 package:"
${PKGINFO} -x ${pkgs}
}
}
echo ""
}
IFS="
"
[ "${locking}" = 1 ] && {
echo "--Mailbox locking methods--"
locking_methods=`${POSTCONF} -l`
echo $locking_methods
echo ""
}
[ "${tables}" = 1 ] && {
echo "--Supported Lookup tables--"
lookup_tables=`${POSTCONF} -m`
echo $lookup_tables
echo ""
}
[ "${main}" = 1 -o "${defaultsinmain}" = 1 ] && {
if [ "x`find . -prune \( -perm 020 -o -perm 002 \) -print`" != "x" ]
then
echo 2>&2 "Do not run this in a public- or group-writable directory"
exit 1
fi
rm -f postfinger.$$.d postfinger.$$.n
${POSTCONF} -d | tr -s [:blank:] | sort > postfinger.$$.d
${POSTCONF} -n | tr -s [:blank:] | sort > postfinger.$$.n
[ "$main" = 1 ] && {
echo "--main.cf non-default parameters--"
comm -13 postfinger.$$.d postfinger.$$.n
echo ""
}
[ "${defaultsinmain}" = 1 ] && {
echo "--main.cf parameters defined as per defaults--"
comm -12 postfinger.$$.d postfinger.$$.n
echo ""
}
rm -f postfinger.$$.d postfinger.$$.n
}
[ "${master}" = 1 ] && {
echo "--master.cf--"
# Remove blank and commented lines to reduce the output
# Note: the second grep contains a space followed by a tab character
cat `${POSTCONF} -h config_directory`/master.cf | \
grep -v '^#' | \
grep -v '^[ ]*$'
echo ""
}
[ "${permissions}" = 1 ] && {
echo "--Specific file and directory permissions--"
ls -ld `${POSTCONF} -h queue_directory`/maildrop
ls -ld `${POSTCONF} -h queue_directory`/public
ls -l `${POSTCONF} -h queue_directory`/public 2>/dev/null || {
echo 'WARNING: No access to $queue_directory/public'
echo ' Try running postfinger as user root or postfix'
}
ls -ld `${POSTCONF} -h queue_directory`/private
ls -l `${POSTCONF} -h queue_directory`/private 2>/dev/null || {
echo 'WARNING: No access to $queue_directory/private'
echo ' Try running postfinger as user root or postfix'
}
ls -l `${POSTCONF} -h command_directory`/postdrop
ls -l `${POSTCONF} -h command_directory`/postqueue
echo ""
}
[ "${libraries}" = 1 ] && {
echo "--Library dependencies--"
echo "${SMTPD}:"
ldd ${SMTPD} || echo "WARNING: Can not find ldd. Check you have it installed and in your path"
}
echo "-- end of postfinger output --"
syntax highlighted by Code2HTML, v. 0.9.1