mail/fetchmail: fix rcscript regression from _1 that broke global mode

In a situation where fetchmail is to be started globally with the
configuration in $LOCALBASE/etc, the rc.d file would try to run
fetchmail for the wrong user.

Simplify script more, avoiding recursive call in single-user mode.

Submitted by:	Corey Halpin (maintainer, direct mail to mandree@)
Reported by:	Armin Tüting
This commit is contained in:
Matthias Andree 2020-10-06 23:09:39 +00:00
parent 58f7d72c10
commit 69c372bb8c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=551607
2 changed files with 43 additions and 57 deletions

View File

@ -3,7 +3,7 @@
PORTNAME?= fetchmail
DISTVERSION= 6.4.12
PORTREVISION?= 1
PORTREVISION?= 2
CATEGORIES= mail
# The next line is inherited by the fetchmailconf slave port,
# do NOT replace fetchmail by ${PORTNAME}

View File

@ -126,8 +126,7 @@ fetchmail_dump_config()
# if this is the global or 'umbrella' run
if [ -z "$2" ] ; then
uid=$(id -u)
if [ "x${fetchmail_users}" != "x" -a "x$1" != "x" -a "$uid" = "0" ]; then
if [ "x${fetchmail_users}" != "x" -a "x$1" != "x" -a "$(id -u)" = "0" ]; then
# root mode: multiple user profiles are handled by recursive
# calls of this script
for user in ${fetchmail_users}; do
@ -138,66 +137,53 @@ if [ -z "$2" ] ; then
failed="${user} (${retcode}) ${failed:-}"
fi
done
else
if [ "x${fetchmail_users}" = "x" ]; then
# There is only one global configuration file
globalconfig=GLOBALCONFIG
fi
$fetchmail_script "$1" "$(id -u -n)" $globalconfig
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${name} (${retcode}) ${failed:-}"
# if we had any failures, exit with an error
if [ -n "${failed}" ] ; then
exit 1
fi
# otherwise, exit success
exit 0
fi
# if we had any failures, exit witn an error
if [ -n "${failed}" ] ; then
exit 1
fi
# otherwise, exit success
exit 0
else
fetchmail_user="$2"
fi
# perform action for an instance of fetchmail daemon
fetchmail_user="$2"
if [ "x${fetchmail_users}" != "x" -o "x$3" = "xGLOBALCONFIG" ]; then
if [ "x${fetchmail_users}" != "x" ]; then
# multiuser setup: determine user specific config and pid file
fetchmail_home="$(getent passwd ${fetchmail_user} | cut -f6 -d:)"
fetchmail_home="${fetchmail_home%/}"
fetchmail_config="${fetchmail_home}/${fetchmail_config_name}"
pidfile="${fetchmail_home}/.fetchmail.pid"
# PULLVARS - pull user specific variables into scope if existing
# else use global defaults
for i in chdir chroot env env_file fib flags nice \
limits login_class oomprotect program user group groups prepend \
logging_facility polling_interval
do
uvarname=fetchmail_${fetchmail_user}_${i}
eval fetchmail_${i}="\${${uvarname}-\${fetchmail_${i}}}"
done
else
pidfile=/var/run/fetchmail/fetchmail.pid
fi
required_files=${fetchmail_config}
# add early command line arguments
# if logfile set in config file, do not override with rc.conf default (note logfile overrides syslog)
_logfile="$(fetchmail_dump_config logfile)"
if [ _"${_logfile}" != _"None," ] ; then
fetchmail_logging_facility=""
fi
fetchmail_flags="${fetchmail_flags} -f ${fetchmail_config} --pidfile ${pidfile} ${fetchmail_logging_facility}"
# add late command line arguments
# if no polling interval in config file, use value from rc.conf
if [ "$(fetchmail_dump_config poll_interval)" = "0," ] ; then
fetchmail_flags="${fetchmail_flags} -d ${fetchmail_polling_interval}"
fi
if [ "x${fetchmail_users}" != "x" ]; then
# multiuser setup: determine user specific config and pid file
fetchmail_home="$(getent passwd ${fetchmail_user} | cut -f6 -d:)"
fetchmail_home="${fetchmail_home%/}"
fetchmail_config="${fetchmail_home}/${fetchmail_config_name}"
pidfile="${fetchmail_home}/.fetchmail.pid"
# PULLVARS - pull user specific variables into scope if existing
# else use global defaults
for i in chdir chroot env env_file fib flags nice \
limits login_class oomprotect program user group groups prepend \
logging_facility polling_interval
do
uvarname=fetchmail_${fetchmail_user}_${i}
eval fetchmail_${i}="\${${uvarname}-\${fetchmail_${i}}}"
done
else
echo "$0: extra argument ignored"
pidfile=/var/run/fetchmail/fetchmail.pid
fi
required_files=${fetchmail_config}
# add early command line arguments
# if logfile set in config file, do not override with rc.conf default (note logfile overrides syslog)
_logfile="$(fetchmail_dump_config logfile)"
if [ _"${_logfile}" != _"None," ] ; then
fetchmail_logging_facility=""
fi
fetchmail_flags="${fetchmail_flags} -f ${fetchmail_config} --pidfile ${pidfile} ${fetchmail_logging_facility}"
# add late command line arguments
# if no polling interval in config file, use value from rc.conf
if [ "$(fetchmail_dump_config poll_interval)" = "0," ] ; then
fetchmail_flags="${fetchmail_flags} -d ${fetchmail_polling_interval}"
fi
# actually execute the fetchmail program