fix some NIS problems
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 26 May 1995 02:38:47 +0000 (18:38 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Fri, 26 May 1995 02:38:47 +0000 (18:38 -0800)
SCCS-vsn: usr.sbin/sendmail/src/conf.c 8.176

usr/src/usr.sbin/sendmail/src/conf.c

index 76d3c94..e00c406 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)conf.c     8.175 (Berkeley) %G%";
+static char sccsid[] = "@(#)conf.c     8.176 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -3001,7 +3001,35 @@ sm_gethostbyname(name)
        return __switch_gethostbyname(name);
 # endif
 #else
        return __switch_gethostbyname(name);
 # endif
 #else
-       return gethostbyname(name);
+       struct hostent *h;
+       int nmaps;
+       int i;
+       char *maptype[MAXMAPSTACK];
+       short mapreturn[MAXMAPACTIONS];
+       char hbuf[MAXNAME];
+
+       h = gethostbyname(name);
+# if defined(NIS)
+       if (h != NULL)
+               return h;
+       nmaps = switch_map_find("hosts", maptype, mapreturn);
+       while (--nmaps >= 0)
+               if (strcmp(maptype[nmaps], "nis") == 0)
+                       break;
+       if (nmaps >= 0)
+       {
+               /* try short name */
+               if (strlen(name) > sizeof hbuf - 1)
+                       return NULL;
+               strcpy(hbuf, name);
+               shorten_hostname(hbuf);
+
+               /* if it hasn't been shortened, there's no point */
+               if (strcmp(hbuf, name) != 0)
+                       return gethostbyname(hbuf);
+       }
+# endif
+       return h;
 #endif
 }
 
 #endif
 }