From 0cd4ec5d99b6401efc04e86f15c3f28d7b967d69 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 31 Jan 2020 21:15:40 +0100 Subject: 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. --- fetchmailconf.py | 9 +++++++-- 1 file 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() -- cgit v1.2.3