diff options
author | Matthias Andree <matthias.andree@gmx.de> | 2020-01-31 21:15:40 +0100 |
---|---|---|
committer | Matthias Andree <matthias.andree@gmx.de> | 2020-01-31 21:22:54 +0100 |
commit | 0cd4ec5d99b6401efc04e86f15c3f28d7b967d69 (patch) | |
tree | 636deb80563115c072eab12ad17303113cd1ecd3 | |
parent | 168ba422791ddbdca0c4b447b2669a322ba1f7f9 (diff) | |
download | fetchmail-0cd4ec5d99b6401efc04e86f15c3f28d7b967d69.tar.gz fetchmail-0cd4ec5d99b6401efc04e86f15c3f28d7b967d69.tar.bz2 fetchmail-0cd4ec5d99b6401efc04e86f15c3f28d7b967d69.zip |
fetchmailconf.py: hostname qualification fixup
If socket.gethostname() returns a qualified name, don't look further,
to match fetchmail's behaviour - in case of an FQDN /etc/hostname
with broken /etc/hosts, this helps us survive.
Else, call socket.getfqdn() and not gethostbyaddr() in an attempt to qualify
the hostname.
Failing that, print an error message that tells the user to fix
/etc/hosts, which has this canonical format:
10.9.8.7 host.example.org host
on the assumption that that line and DNS might both be broken.
Gitlab, fixes #12 reported by Sergey Alirzaev - the prior attempt fixed
the wrong place (which also needed fixing).
Bump version to 1.63.
-rwxr-xr-x | fetchmailconf.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/fetchmailconf.py b/fetchmailconf.py index e6b6ae05..07596b17 100755 --- a/fetchmailconf.py +++ b/fetchmailconf.py @@ -29,7 +29,7 @@ import subprocess from tkinter import * from tkinter.dialog import * -VERSION = "1.62" +VERSION = "1.63" MIN_PY = (2, 7, 13) if sys.version_info < MIN_PY: @@ -2204,7 +2204,12 @@ COPYING in the source or documentation directory for details.""") sys.exit(0) # Get client host's FQDN - hostname = socket.gethostbyaddr(socket.gethostname())[0] + hostname = socket.gethostname() + if not '.' in hostname: + hostname = socket.getfqdn(hostname) + # still unqualified? + if not '.' in hostname: + sys.exit('Cannot qualify my own hostname, "{}".\nFix /etc/hosts, see man 5 hosts, or add the host to DNS.'.format(hostname)) # Compute defaults ConfigurationDefaults = Configuration() |