Bug#933231: exim4-base: /etc/cron.daily/exim4-base can't detect hostname via hostname --fqdn

2019-07-31 Thread Christian Garbs
On Sun, Jul 28, 2019 at 02:08:20PM +0200, Andreas Metzler wrote:
> On 2019-07-27 Christian Garbs  wrote:
> > Package: exim4-base
> > Version: 4.92-8+deb10u1
> > Severity: normal
> > Tags: ipv6
> 
> > After the update from Stretch to Buster, on one of my systems
> > /etc/cron.daily/exim4-base failed on every run with just
> 
> > hostname: Name or service not known
> 
> > as an error message.
> 
> > I could trace this to the usage of "hostname --fqdn" in the script.

[...]

> > Is there another way to get a proper hostname, perhaps from Exim
> > or the Exim configuration, that can be used in /etc/cron.daily/exim4-base
> > instead of calling "hostname --fqdn"?
> 
> There is
> /usr/sbin/exim4 -bP primary_hostname
> or
> /usr/sbin/exim4 -be '${primary_hostname}'
> 
> How about the attached patch?

Hello Andreas,

the patch looks good!

The fallback to hostname without any parameters is a nice touch – if
the admin can keep his systems apart, everything is ok, no need for
any flags ;-)


I have applied the patch against the original /etc/cron.daily/exim4-base
from Buster and deployed it to three systems (the one that showed the
bug plus two unaffected others):  Everything works as expected.

Please apply the patch to the next version.

Thanks for the quick reply and patch!
Christian
-- 
Christian.Garbshttps://www.cgarbs.de

A truly wise man never plays leapfrog with a unicorn.



Bug#933231: exim4-base: /etc/cron.daily/exim4-base can't detect hostname via hostname --fqdn

2019-07-28 Thread Andreas Metzler
On 2019-07-27 Christian Garbs  wrote:
> Package: exim4-base
> Version: 4.92-8+deb10u1
> Severity: normal
> Tags: ipv6

> After the update from Stretch to Buster, on one of my systems
> /etc/cron.daily/exim4-base failed on every run with just

> hostname: Name or service not known

> as an error message.

> I could trace this to the usage of "hostname --fqdn" in the script.
> On this (and so far only on this) system this call simply fails:

> $ hostname --fqdn
> hostname: Name or service not known
[...]
> I don't yet know why, but I indeed have two hostnames:

> $ hostname --all-fqdns
> het.cgarbs.de het.cgarbs.de 

> I guess one is for the IPv4 connection and the other for IPv6.
[...]

Hello Christian,

on this system, hostname --fqdn succeeds but hostname --all-fqdns fails:
--
ametzler@argenau:~$ hostname --fqdn ; echo FQDN $? ; hostname --all-fqdns ; 
echo fqdnS $?
argenau.bebt.de
FQDN 0

fqdnS 0
--

In /etc/hosts I have got 127.0.0.1 as localhost and 127.0.1.1 as my
normal FQDN, which I think is not totally broken.

> Is there another way to get a proper hostname, perhaps from Exim
> or the Exim configuration, that can be used in /etc/cron.daily/exim4-base
> instead of calling "hostname --fqdn"?

There is
/usr/sbin/exim4 -bP primary_hostname
or
/usr/sbin/exim4 -be '${primary_hostname}'

How about the attached patch?

cu Andreas
-- 
`What a good friend you are to him, Dr. Maturin. His other friends are
so grateful to you.'
`I sew his ears on from time to time, sure'
--- debian/exim4-base.cron.daily	2019-07-27 17:38:42.325457369 +0200
+++ /tmp/cron.daily	2019-07-28 14:06:59.414272250 +0200
@@ -25,6 +25,13 @@ fi
 [ -f /etc/default/exim4 ] && . /etc/default/exim4
 
 SPOOLDIR="$(exim4 -bP spool_directory | sed 's/.*=[[:space:]]\(.*\)/\1/')"
+if [ -n "$E4BCD_DAILY_REPORT_TO" ] || [ "$E4BCD_WATCH_PANICLOG" != "no" ] ; then
+	# Only needed for mail subject.
+	if ! HOSTNAME=$(/usr/sbin/exim4 -be '${primary_hostname}'); then
+		HOSTNAME="$(hostname)"
+	fi
+fi
+
 
 # The log processing code used in this cron script is not very
 # sophisticated. It relies on this cron job being executed earlier than
@@ -43,11 +50,11 @@ if [ -n "$E4BCD_DAILY_REPORT_TO" ]; then
 if [ "$(< /var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" | wc -l)" -gt "0" ]; then
   < /var/log/exim4/mainlog grep -v "$E4BCD_MAINLOG_NOISE" \
 | eximstats $E4BCD_DAILY_REPORT_OPTIONS \
-| mail -s"$(hostname --fqdn) Daily e-mail activity report" \
+| mail -s"${HOSTNAME} Daily e-mail activity report" \
 		$E4BCD_DAILY_REPORT_TO
 else
   echo "no mail activity in this interval" \
-| mail -s"$(hostname --fqdn) Daily e-mail activity report" \
+| mail -s"${HOSTNAME} Daily e-mail activity report" \
 		$E4BCD_DAILY_REPORT_TO
 fi
   else
@@ -73,7 +80,7 @@ if [ "$E4BCD_WATCH_PANICLOG" != "no" ];
 if [ -z "$E4BCD_PANICLOG_NOISE" ] || grep -vq "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog; then
   log_this "ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken"
   if ! printf "Subject: exim paniclog on %s has non-zero size\nTo: root\n\nexim paniclog /var/log/exim4/paniclog on %s has non-zero size, mail system might be broken. Up to ${E4BCD_PANICLOG_LINES} lines are quoted below.\n\n%s\n" \
-  "$(hostname --fqdn)" "$(hostname --fqdn)" \
+  "${HOSTNAME}" "${HOSTNAME}" \
   "$(if [ -z "$E4BCD_PANICLOG_NOISE" ] ; then tail -n "${E4BCD_PANICLOG_LINES}" /var/log/exim4/paniclog ; else grep -v "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog | tail -n "${E4BCD_PANICLOG_LINES}" ; fi)" \
   | exim4 root; then
 log_this "PANIC: sending out e-mail warning has failed, exim has non-zero return code"


Bug#933231: exim4-base: /etc/cron.daily/exim4-base can't detect hostname via hostname --fqdn

2019-07-27 Thread Christian Garbs
Package: exim4-base
Version: 4.92-8+deb10u1
Severity: normal
Tags: ipv6

After the update from Stretch to Buster, on one of my systems
/etc/cron.daily/exim4-base failed on every run with just

hostname: Name or service not known

as an error message.

I could trace this to the usage of "hostname --fqdn" in the script.
On this (and so far only on this) system this call simply fails:

$ hostname --fqdn
hostname: Name or service not known

The manpage of hostname(1) warns about the --fqdn option:

| If a machine has multiple network interfaces/addresses or
| is used in a mobile environment, then it may either have
| multiple FQDNs/domain names or none at  all.  Therefore
| avoid using hostname --fqdn, hostname --domain and dnsdomainname.
| hostname --ip-address is subject to the same limitations
| so it should be avoided as well.

I don't yet know why, but I indeed have two hostnames:

$ hostname --all-fqdns
het.cgarbs.de het.cgarbs.de 

I guess one is for the IPv4 connection and the other for IPv6.


Because in my case both entries are the same and the cron.daily
script only needs one, I created a shell function that returns
only the first hostname and added it to the top of the cron.daily
script (see attached changed config file below):

# fix multiple hostnames, see warning about THE FQDN in hostname(1)
hostname()
{
/bin/hostname --all-fqdns | tr " " "\n" | grep -F . | sort | uniq | head -n 
1
}


The shell function takes precedence over /bin/hostname and everything
works as expected.

Unfortunately, the hostname(1) manpage says "Do not make any assumptions
about the order of the output." regarding the --all-fqdns option.



So while using the shell function might be a partial fix, it is not a
very good one.

Is there another way to get a proper hostname, perhaps from Exim
or the Exim configuration, that can be used in /etc/cron.daily/exim4-base
instead of calling "hostname --fqdn"?


Regards
Christian

-- Package-specific info:
Exim version 4.92 #3 built 20-Jul-2019 11:35:58
Copyright (c) University of Cambridge, 1995 - 2018
(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2018
Berkeley DB: Berkeley DB 5.3.28: (September  9, 2013)
Support for: crypteq iconv() IPv6 PAM Perl Expand_dlfunc GnuTLS 
move_frozen_messages Content_Scanning DANE DKIM DNSSEC Event OCSP PRDR PROXY 
SOCKS TCP_Fast_Open
Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz 
dbmnz dnsdb dsearch ldap ldapdn ldapm mysql nis nis0 passwd pgsql sqlite
Authenticators: cram_md5 cyrus_sasl dovecot plaintext spa tls
Routers: accept dnslookup ipliteral iplookup manualroute queryprogram redirect
Transports: appendfile/maildir/mailstore/mbx autoreply lmtp pipe smtp
Malware: f-protd f-prot6d drweb fsecure sophie clamd avast sock cmdline
Fixed never_users: 0
Configure owner: 0:0
Size of off_t: 8
Configuration file search path is 
/etc/exim4/exim4.conf:/var/lib/exim4/config.autogenerated
Configuration file is /var/lib/exim4/config.autogenerated
# /etc/exim4/update-exim4.conf.conf
#
# Edit this file and /etc/mailname by hand and execute update-exim4.conf
# yourself or use 'dpkg-reconfigure exim4-config'
#
# Please note that this is _not_ a dpkg-conffile and that automatic changes
# to this file might happen. The code handling this will honor your local
# changes, so this is usually fine, but will break local schemes that mess
# around with multiple versions of the file.
#
# update-exim4.conf uses this file to determine variable values to generate
# exim configuration macros for the configuration file.
#
# Most settings found in here do have corresponding questions in the
# Debconf configuration, but not all of them.
#
# This is a Debian specific file

dc_eximconfig_configtype='internet'
dc_other_hostnames='cgarbs.de'
dc_local_interfaces='0.0.0.0.25 ; ::0.25'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='true'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

mailname:cgarbs.de
# /etc/default/exim4
EX4DEF_VERSION=''

# 'combined' -   one daemon running queue and listening on SMTP port
# 'no'   -   no daemon running the queue
# 'separate' -   two separate daemons
# 'ppp'  -   only run queue with /etc/ppp/ip-up.d/exim4.
# 'nodaemon' - no daemon is started at all.
# 'queueonly' - only a queue running daemon is started, no SMTP listener.
# setting this to 'no' will also disable queueruns from /etc/ppp/ip-up.d/exim4
QUEUERUNNER='combined'
# how often should we run the queue
QUEUEINTERVAL='30m'
# options common to quez-runner and listening daemon
COMMONOPTIONS=''
# more options for the daemon/process running the queue (applies to the one
# started in /etc/ppp/ip-up.d/exim4, too.
QUEUERUNNEROPTIONS=''
# special flags given to exim directly after the -q. See exim(8)
QFLAGS=''
# Options for the SMTP listener daemon. By default, it is listening on
# port 25 only. To listen on more ports, it is