]> andersk Git - moira.git/commitdiff
Don't all-capsify unrecognized hostnames in non-MIT.EDU domains.
authordanw <danw>
Tue, 14 Dec 1999 20:43:58 +0000 (20:43 +0000)
committerdanw <danw>
Tue, 14 Dec 1999 20:43:58 +0000 (20:43 +0000)
Fixes [1264] in moira.

lib/fixhost.c

index d9797a001dd49b173faa62c16f69baefa462aef0..6bdb70f91dd4999620b2aa575e53f748c52e17ea 100644 (file)
 
 RCSID("$Header$");
 
+static char *local_domain(void)
+{
+  static char *domain = NULL;
+  char *cp;
+  struct hostent *hp;
+
+  if (domain == NULL)
+    {
+      char hostbuf[256];
+
+      if (mr_host(hostbuf, sizeof(hostbuf)) == MR_SUCCESS)
+       {
+         cp = strchr(hostbuf, '.');
+         if (cp)
+           domain = strdup(++cp);
+       }
+      else
+       {
+         struct utsname name;
+         uname(&name);
+         hp = gethostbyname(name.nodename);
+         if (hp)
+           {
+             cp = strchr(hp->h_name, '.');
+             if (cp)
+               domain = strdup(++cp);
+           }
+       }
+      if (!domain)
+       domain = "";
+    }
+
+  return domain;
+}
+
 /*
  * Canonicalize hostname:
  *  if it is in double-quotes, then strip the quotes and return the name.
@@ -39,7 +74,6 @@ char *canonicalize_hostname(char *host)
 {
   struct hostent *hp;
   int len;
-  int has_dot = 0;
   char *tbuf, *cp;
 
   len = strlen(host);
@@ -69,48 +103,22 @@ char *canonicalize_hostname(char *host)
   else
     {
       /* can't get name from nameserver; fix up the format a bit */
-      for (cp = host; *cp; cp++)
-       {
-         if (islower(*cp))
-           *cp = toupper(*cp);
-         has_dot |= (*cp == '.');
-       }
-      if (!has_dot)
+      cp = strchr(host, '.');
+      if (!cp)
        {
-         static char *domain = NULL;
-
-         if (domain == NULL)
-           {
-             char hostbuf[256];
-
-             if (mr_host(hostbuf, sizeof(hostbuf)) == MR_SUCCESS)
-               {
-                 cp = strchr(hostbuf, '.');
-                 if (cp)
-                   domain = strdup(++cp);
-               }
-             else
-               {
-                 struct utsname name;
-                 uname(&name);
-                 hp = gethostbyname(name.nodename);
-                 if (hp)
-                   {
-                     cp = strchr(hp->h_name, '.');
-                     if (cp)
-                       domain = strdup(++cp);
-                   }
-               }
-             if (!domain)
-               domain = "";
-           }
-         tbuf = malloc(strlen(host) + strlen(domain) + 2);
+         tbuf = malloc(strlen(host) + strlen(local_domain()) + 2);
          if (!tbuf)
            return NULL;
-         sprintf(tbuf, "%s.%s", host, domain);
+         sprintf(tbuf, "%s.%s", host, local_domain());
          free(host);
          host = tbuf;
        }
+      else if (strcasecmp(cp + 1, local_domain()) != 0)
+       return host;
+
+      /* This is a host in our local domain, so capitalize it. */
+      for (cp = host; *cp; cp++)
+       *cp = toupper(*cp);
       return host;
     }
 }
This page took 0.087201 seconds and 5 git commands to generate.