From 9846cf3daf83c309f51a3f93b9b34aa0ab5d6205 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 12 Jul 2006 21:02:22 +0000 Subject: r16997: Simo's patch (based on repotr from Seth Elssworth of Quest) to try to be more robust in the precense of more broken /etc/hosts files when determining our fwdn (This used to be commit 6413df8348829659807c0c30e6eaef511815e0ed) --- source3/lib/util.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 96263bf394..c75008e9a7 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2830,9 +2830,28 @@ BOOL unix_wild_match(const char *pattern, const char *string) void name_to_fqdn(fstring fqdn, const char *name) { struct hostent *hp = sys_gethostbyname(name); + if ( hp && hp->h_name && *hp->h_name ) { - DEBUG(10,("name_to_fqdn: lookup for %s -> %s.\n", name, hp->h_name)); - fstrcpy(fqdn,hp->h_name); + char *full = NULL; + + /* find out i fthe fqdn is returned as an alias + * to cope with /etc/hosts files where the first + * name is not the fqdn but the short name */ + if (hp->h_aliases && (! strchr_m(hp->h_name, '.'))) { + int i; + for (i = 0; hp->h_aliases[i]; i++) { + if (strchr_m(hp->h_aliases[i], '.')) { + full = hp->h_aliases[i]; + break; + } + } + } + if (!full) { + full = hp->h_name; + } + + DEBUG(10,("name_to_fqdn: lookup for %s -> %s.\n", name, full)); + fstrcpy(fqdn, full); } else { DEBUG(10,("name_to_fqdn: lookup for %s failed.\n", name)); fstrcpy(fqdn, name); -- cgit