Author: idra Date: 2006-09-14 16:35:22 +0000 (Thu, 14 Sep 2006) New Revision: 18532
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18532 Log: back port name_to_fqdn enhancements Modified: branches/SAMBA_3_0_23/source/lib/util.c Changeset: Modified: branches/SAMBA_3_0_23/source/lib/util.c =================================================================== --- branches/SAMBA_3_0_23/source/lib/util.c 2006-09-14 16:34:04 UTC (rev 18531) +++ branches/SAMBA_3_0_23/source/lib/util.c 2006-09-14 16:35:22 UTC (rev 18532) @@ -2828,9 +2828,36 @@ 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 if the 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 && (StrCaseCmp(full, "localhost.localdomain") == 0)) { + DEBUG(1, ("WARNING: your /etc/hosts file may be broken!\n")); + DEBUGADD(1, (" Specifing the machine hostname for address 127.0.0.1 may lead\n")); + DEBUGADD(1, (" to Kerberos authentication probelms as localhost.localdomain\n")); + DEBUGADD(1, (" may end up to be used instead of the real machine FQDN.\n")); + full = hp->h_name; + } + + 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); @@ -2987,4 +3014,3 @@ return 0; #endif } -