Hostnames not being handled correctly if domain|search not found in resolv.conf

Since 1.910, if resolv.conf does not contain search or domain lines, Webmin fails in two areas that I have noticed.

  • In the Dashboard the System Hostname is shown as "foo.", where if the search or domain lines exist, or in a version prior to 1.910, you see the FQDN such as "foo.example.com".
  • Email sent following an automated backup does not have the correct From address.

This is what an email log looks like with a search or domain line configured, or pre-1.910.

/var/log/mail.log.1.gz:Jan  9 00:09:55 foo postfix/cleanup[29843]: 28093203B0: warning: header Subject: Completed backup of Virtualmin on foo.domain.tld to /var/backups/remote/vsites/foo/2020-01-09 on SSH server bkp.domain.tld from local; from=<webmin@foo.domain.tld> to=<admin@domain.tld>

This is what an email log looks like without a search or domain line configured. The receiving email server rejects these emails. Note the "from=" address.

/var/log/mail.log.1.gz:Jan 10 00:03:49 foo postfix/cleanup[20471]: 395A2201AD: warning: header Subject: Completed backup of Virtualmin on foo. to /var/backups/remote/vsites/foo/2020-01-10 on SSH server bkp.domain.tld from local; from=<webmin@foo> to=<admin@domain.tld>

I tracked down the "offending" code to being within the get_system_hostname() function in web-lib-funcs.pl.

           # Append domain name from DNS config if needed
           if ($fromfile && $fromfile !~ /\./) {
                   my $lref = &read_file_lines("/etc/resolv.conf", 1);
                   foreach my $l (@$lref) {
                           if ($l =~ /^(search|domain)\s+(\S+)/) {
                                   $dname = $2;
                                   last;
                                   }
                           }
                   $fromfile .= ".".$dname;
                   }

Either commenting out the above code or adding search or domain lines to resolv.conf corrects the issue.

The "bug" part is that search or domain lines are not guaranteed to be added to /etc/resolv.conf. My own experience is many VPS templates only contain nameserver entries. I have been a Linux sysadmin for roughly 25 years and I personally rarely use search or domain lines, but I'm probably more particular about name resolution where needed. I feel that the current method for getting the system FQDN is fragile. Perhaps a further check if no name is obtained from the method above might be to use "hostname -d"?

I originally started a thread on the forum while trying to figure this out. Another user claimed to be having the same issue while using CentOS. https://forum.virtualmin.com/t/is-1-940-handling-hostnames-differently/1...

Thanks guys.

Status: 
Fixed (pending)

Comments