]> andersk Git - moira.git/blobdiff - lib/fixhost.c
make it work with negative keys
[moira.git] / lib / fixhost.c
index 0ad15b7bb6372467030c1a6de7e78b32c05c9cfa..2803aece5b43524f7013f8ccd6b1edaac0a5dfb0 100644 (file)
@@ -4,22 +4,24 @@
  *     $Header$
  *
  *     Copyright (C) 1987 by the Massachusetts Institute of Technology
- *
- *     $Log$
- *     Revision 1.1  1987-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>
+#ifdef sun
+#include <resolv.h>
+#else
 #include <arpa/resolv.h>
+#endif sun
 #include <netdb.h>
 #include <stdio.h>
 #include <strings.h>
@@ -30,10 +32,11 @@ 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.
@@ -49,6 +52,16 @@ canonicalize_hostname(host)
     char tbuf[BUFSIZ];
     register char *cp;
     
+    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 (index(host, '*') || index(host, '?'))
+      return(host);
+
     hp = gethostbyname(host);
 
     if (hp) {
This page took 0.032909 seconds and 4 git commands to generate.