]> andersk Git - moira.git/blobdiff - lib/fixhost.c
mucked with host table authorization checks...
[moira.git] / lib / fixhost.c
index 059b453891b09a053d09848da443909003921c5a..54bc7205408ddb6629730c313a8426597cf8fc87 100644 (file)
@@ -4,39 +4,36 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
- *
- *     $Log$
- *     Revision 1.2  1988-08-02 21:12:18  mar
- *     don't change hostname if it contains wildcards
- *
- * Revision 1.1  87/09/03  03:12:45  wesommer
- * Initial revision
- * 
+ *     For copying and distribution information, please see the file
+ *     <mit-copyright.h>.
  */
 
 #ifndef lint
 static char *rcsid_fixhost_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/resolv.h>
 #include <netdb.h>
 #include <stdio.h>
-#include <strings.h>
+#ifdef POSIX
+#include <sys/utsname.h>
+#endif
+#include <string.h>
 #include <ctype.h>
+#include <moira.h>
 
 extern char *malloc();
 extern char *realloc();
-extern char *strsave();
 
 /*
- * Canonicalize hostname; if it is in the namespace, call the
- * nameserver to expand it; otherwise uppercase it and append the
- * default domain (using an, er, undocumented global of the
- * nameserver).
+ * Canonicalize hostname:
+ *  if it is in double-quotes, then strip the quotes and return the name.
+ *  if it is in the namespace, call the nameserver to expand it
+ *  otherwise uppercase it and append the default domain (using an, er,
+ *    undocumented global of the nameserver).
  *
  * Assumes that host was allocated using malloc(); it may be freed or
  * realloc'ed, so the old pointer should not be considered valid.
@@ -50,9 +47,19 @@ canonicalize_hostname(host)
     int n_len;
     int has_dot = 0;
     char tbuf[BUFSIZ];
+#ifdef POSIX
+    struct utsname name;
+#endif
     register char *cp;
     
-    if (index(host, '*') || index(host, '?'))
+    if (strlen(host) > 2 && host[0] == '"' && host[strlen(host)-1] == '"') {
+       strcpy(tbuf, host+1);
+       free(host);
+       tbuf[strlen(tbuf)-1] = 0;
+       return(strsave(tbuf));
+    }
+
+    if (strchr(host, '*') || strchr(host, '?') || strchr(host, '['))
       return(host);
 
     hp = gethostbyname(host);
@@ -71,7 +78,23 @@ canonicalize_hostname(host)
            has_dot |= (c == '.');
        }
        if (!has_dot) {
-           (void) sprintf(tbuf, "%s.%s", host, _res.defdname);
+           static char *domain = NULL;
+
+           if (domain == NULL) {
+#ifdef POSIX
+               (void) uname(&name);
+               strncpy(tbuf, name.nodename, sizeof(tbuf));
+#else
+               gethostname(tbuf, sizeof(tbuf));
+#endif
+               hp = gethostbyname(tbuf);
+               cp = strchr(hp->h_name, '.');
+               if (cp)
+                 domain = strsave(++cp);
+               else
+                 domain = "";
+           }
+           (void) sprintf(tbuf, "%s.%s", host, domain);
            free(host);
            host = strsave(tbuf);
        }
This page took 0.038326 seconds and 4 git commands to generate.