r16997: Simo's patch (based on repotr from Seth Elssworth of Quest) to try to be...
authorGerald Carter <jerry@samba.org>
Wed, 12 Jul 2006 21:02:22 +0000 (21:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:19:17 +0000 (11:19 -0500)
(This used to be commit 6413df8348829659807c0c30e6eaef511815e0ed)

source3/lib/util.c

index 96263bf39475ad6e9422e78463bbfce48597ca63..c75008e9a72b86cb607b343fa0e22ecd6978de34 100644 (file)
@@ -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);