Four years later (to the day, coincidentally), this bug still exists,
though in a slightly different form.  I've done some research and can
provide a bit more information.

If $myhostname isn't defined manually in the config file, Postfix uses
gethostname() to query the system's hostname.  $myhostname needs to be
an FQDN, though, so if the name returned by gethostname() doesn't
contain at least one dot, it appends the value of $mydomain if that's
defined in the config file, or else the static string "localdomain".

Notably, Postfix does *not* call gethostbyname() on the name returned by
gethostname(), the way the "hostname --fqdn" command does.

This'll work as expected if gethostname() returns an FQDN, but on a
typically-configured Debian system, it doesn't.  It returns a "short"
hostname, and this leads to Postfix using e.g. "foo.localdomain" as
$myhostname, even though "hostname --fqdn" returns "foo.bar.com".

Steps to reproduce:
      * Install a fresh copy of Debian (current release is etch).
      * When asked for the machine's hostname during installation, enter
        "foo".
      * When asked for the machine's domain name, enter "bar.com".
      * Install Postfix, and choose the default "Internet Site"
        configuration.  The "mail name" setting doesn't matter.
      * Remove the "myhostname = foo.bar.com" line
        from /etc/postfix/main.cf.  This line is put there by debconf,
        and it works around the problem, but it's redundant and
        shouldn't be necessary.  The machine already knows its FQDN, and
        the sensible default would be to use it.
      * Run "hostname --fqdn" and "hostname --domain".  They will return
        "foo.bar.com" and "bar.com" respectively, as expected.
      * Run "postconf myhostname" and "postconf mydomain".  They will
        return "foo.localdomain" and "localdomain" respectively.  This
        is wrong.

Postfix's behavior here suggests that the machine's hostname, as
returned by gethostname() (i.e. the "hostname" command, without the
"--fqdn" option) is supposed to be an FQDN.  But that isn't the case on
Debian, (nor on other common Linux distros AFAIK), and I don't see why
I'd want my system configured that way anyway.  There don't seem to be
any clear guidelines or best practices on this matter.

Since Postfix wants an FQDN for $myhostname, I think it should get the
default value in the same way the "hostname --fqdn" command does:  get
the (probably short) hostname using gethostname(), and then call
gethostbyname() on it to look up the FQDN.  It's still possible to get
something that isn't an FQDN on a misconfigured system, but at least the
behavior would be consistent with that of the well-known hostname tool,
and would work as expected with Debian's out-of-the-box configuration.

(As an aside, it's possible to get an FQDN hostname in Debian by typing
an FQDN into the hostname box during installation.  It contradicts the
instructions in that box, which say that "the hostname is a single
word", but the installer is smart enough to skip asking for the domain
name when an FQDN is entered as the hostname.  But this causes problems
of its own:  the Postfix Debconf stuff thinks the machine's FQDN is
"foo.bar.com.bar.com".)
-- 
Mike Paul <[EMAIL PROTECTED]>

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to