Tags: patch
I have also confirmed this bug to exist in postfix 2.10.2, and have
adapted my previous patch to work with this version.
diff -ur postfix-2.10.2/src/global/mail_params.c postfix-214741/src/global/mail_params.c
--- postfix-2.10.2/src/global/mail_params.c 2012-01-17 10:33:25.000000000 -0600
+++ postfix-214741/src/global/mail_params.c 2013-10-30 10:10:12.241887399 -0500
@@ -158,6 +158,7 @@
#include <grp.h>
#include <time.h>
#include <ctype.h>
+#include <netdb.h>
#ifdef STRCASECMP_IN_STRINGS_H
#include <strings.h>
@@ -315,7 +316,6 @@
static const char *check_myhostname(void)
{
static const char *name;
- const char *dot;
const char *domain;
/*
@@ -329,10 +329,17 @@
* 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);
+ if (strchr(name, '.') == 0) {
+ /* This may or may not be the most intelligent possible method,
+ but it is what Debian 'hostname --fqdn' does. */
+ struct hostent *ent = gethostbyname(name);
+ if (ent)
+ name = strdup(ent->h_name);
+ if (strchr(name, '.') == 0) {
+ if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
+ domain = DEF_MYDOMAIN;
+ name = concatenate(name, ".", domain, (char *) 0);
+ }
}
return (name);
}
diff -ur postfix-2.10.2/src/postconf/postconf_builtin.c postfix-214741/src/postconf/postconf_builtin.c
--- postfix-2.10.2/src/postconf/postconf_builtin.c 2012-12-25 09:38:13.000000000 -0600
+++ postfix-214741/src/postconf/postconf_builtin.c 2013-10-30 10:10:17.045887195 -0500
@@ -35,6 +35,7 @@
#include <sys_defs.h>
#include <string.h>
+#include <netdb.h>
#ifdef USE_PATHS_H
#include <paths.h>
@@ -175,7 +176,6 @@
static const char *pc_check_myhostname(void)
{
static const char *name;
- const char *dot;
const char *domain;
/*
@@ -186,13 +186,20 @@
/*
* If the local machine name is not in FQDN form, try to append the
- * contents of $mydomain.
+ * 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);
+ if (strchr(name, '.') == 0) {
+ /* This may or may not be the most intelligent possible method,
+ but it is what Debian 'hostname --fqdn' does. */
+ struct hostent *ent = gethostbyname(name);
+ if (ent)
+ name = strdup(ent->h_name);
+ if (strchr(name, '.') == 0) {
+ if ((domain = mail_conf_lookup_eval(VAR_MYDOMAIN)) == 0)
+ domain = DEF_MYDOMAIN;
+ name = concatenate(name, ".", domain, (char *) 0);
+ }
}
return (name);
}