Postfix myhostname defaults to uname() not gethostname().

Bug #180551 reported by Ralph Corderoy
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
postfix (Ubuntu)
Confirmed
Low
Unassigned

Bug Description

Binary package hint: postfix

Given 7.10's postfix-2.4.5-3ubuntu1's postconf(5) says

myhostname (default: see postconf -d output)
    The internet hostname of this mail system.
    The default is to use the fully-qualified domain name from gethostname().
    $myhostname is used as a default value for many other configuration parameters.

why is it using uname(2) and tacking on "localdomain".

$ hostname
blake
$ hostname -f
blake.inputplus.co.uk
$ uname -n
blake
$ sudo ltrace -So /tmp/3 postconf -d myhostname
myhostname = blake.localdomain
$ sed -n '/^get_hostname/,$p' /tmp/3
get_hostname(0xbf972e38, 0xb7f46660, 109, 0xf0000000, 0xb7b10020 <unfinished ...>
SYS_uname(0xbf972b36) = 0
<... get_hostname resumed> ) = 0x8061098
strchr("blake", '.') = NULL
mail_conf_lookup_eval(0x804f15a, 46, 109, 0xf0000000, 0xb7b10020) = 0
concatenate(0x8061098, 0x804e501, 0x804e4f5, 0, 0xb7b10020) = 0x80610b0
vstream_printf(0x804e503, 0x8050bfa, 0x80610b0, 0, 0x80559e0) = 0x8055cdc
vstream_fflush(0x8055cdc, 0xbf9737b1, 0x8055ac4, 0xb7f4f820, 3 <unfinished ...>
SYS_write(1, "myhostname = blake.localdomain\n", 31) = 31
<... vstream_fflush resumed> ) = 0
exit(0 <unfinished ...>
SYS_exit_group(0 <unfinished ...>
+++ exited (status 0) +++
$

Note, it's get_hostname() calls uname(2). Following postconf(5), I should be able to live with the default myhostname but can't. Either the documentation or the code would seem incorrect.

Revision history for this message
LaMont Jones (lamont) wrote :

[somewhat edited for brevity...]
const char *get_hostname(void)
{
    /*
     * The gethostname() call is not (or not yet) in ANSI or POSIX, but it is
     * part of the socket interface library. We avoid the more politically-
     * correct uname() routine because that has no portable way of dealing
     * with long (FQDN) hostnames.
     */
    if (my_host_name == 0) {
        if (gethostname(namebuf, sizeof(namebuf)) < 0)
            msg_fatal("gethostname: %m");

postfix doesn't call uname. Sounds like glibc is doing something "helpful".

lamont

Revision history for this message
Ralph Corderoy (ralph-inputplus) wrote :

Hi Lamont, I think I've mislead you with the uname() comment. Yes, I agree postfix calls glibc's gethostname() and it's that which calls uname(), but the fault appears to lie with postfix's check_myhostname(). It's got two definitions but they appear the same apart from comments. It includes

    /*
     * If the local machine name is not in FQDN form, try to append the
     * contents of $mydomain. Use a default domain as a final workaround.
     */
    name = get_hostname();
    if ((dot = strchr(name, '.')) == 0) {
        if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
            domain = DEF_MYDOMAIN;
        name = concatenate(name, ".", domain, (char *) 0);
    }

and my ltrace output above does include the strchr(), mail_conf_lookup_eval(), and concatenate(). So I think it's this that's appending "localdomain".

The documentation, fully quoted above, says "The default is to use the fully-qualified domain name from gethostname()." However, gethostname() is returning just "blake" but postfix doesn't use that and instead goes and tacks on ".localdomain". Either the code or the documentation seems wrong.

Revision history for this message
Nikolaus Rath (nikratio) wrote :

I can confirm this on hardy. It is not using the FQDN as default value but does something else.

Changed in postfix:
status: New → Confirmed
Mathias Gug (mathiaz)
Changed in postfix (Ubuntu):
importance: Undecided → Low
Revision history for this message
Geek87 (geek87) wrote :

I can confirm this bug is still present in Jaunty and Karmic.

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Bug still present in Trusty (14.04 LTS).

Revision history for this message
Robie Basak (racb) wrote :

So...

gethostname(2) is supposed to return an unqualified name (on Debian and Ubuntu at least).

The Postfix docs say that "The default is to use the fully-qualified domain name from gethostname()." but gethostname() on Debian and Ubuntu will never return a fully-qualified name.

hostname -f returns the result of getaddrinfo(2) on gethostname(2), as defined in hostname(1).

Postfix, when $mydomain is not set and when the result of gethostname(2) is unqualified, appends ".localdomain", when you instead expect it to use what "hostname -f" returns and thus to use the result of getaddrinfo(2) on gethostname(2).

Sounds like a question for upstream to resolve to me. Can someone check this issue is still current upstream and check for and/or file a bug upstream as appropriate, please?

tags: added: needs-upstream-report
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.