Import new (much simpler) resolver code from Hybrid.
[ircu2.10.12-pk.git] / ircd / s_conf.c
index 0a017bf1e14486aa61f39c6cc384bc93dd18b1d2..8d6d6b299b2839565aacacd2648feef59e2e052d 100644 (file)
@@ -19,8 +19,9 @@
  *
  * $Id$
  */
-#include "s_conf.h"
+#include "config.h"
 
+#include "s_conf.h"
 #include "IPcheck.h"
 #include "class.h"
 #include "client.h"
@@ -31,6 +32,7 @@
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_auth.h"
 #include "ircd_chattr.h"
 #include "ircd_log.h"
 #include "ircd_reply.h"
@@ -49,7 +51,6 @@
 #include "s_debug.h"
 #include "s_misc.h"
 #include "send.h"
-#include "sprintf_irc.h"
 #include "struct.h"
 #include "support.h"
 #include "sys.h"
 #define INADDR_NONE 0xffffffff
 #endif
 
-struct ConfItemGlobalConfList  = 0;
+struct ConfItem  *GlobalConfList  = 0;
 int              GlobalConfCount = 0;
+struct s_map     *GlobalServiceMapList = 0;
+struct qline     *GlobalQuarantineList = 0;
 
-static struct LocalConf   localConf;
-static struct CRuleConf*  cruleConfList;
-static struct ServerConf* serverConfList;
-static struct DenyConf*   denyConfList;
+void yyparse(void);
+int conf_fd, lineno;
+
+struct LocalConf   localConf;
+struct CRuleConf*  cruleConfList;
+/* struct ServerConf* serverConfList; */
+struct DenyConf*   denyConfList;
 
 /*
  * output the reason for being k lined from a file  - Mmmm
@@ -173,7 +179,7 @@ static void detach_conf(struct Client* cptr, struct ConfItem* aconf)
   assert(0 != cptr);
   assert(0 < aconf->clients);
 
-  lp = &(cptr->confs);
+  lp = &(cli_confs(cptr));
 
   while (*lp) {
     if ((*lp)->value.aconf == aconf) {
@@ -198,12 +204,16 @@ static void detach_conf(struct Client* cptr, struct ConfItem* aconf)
  * a non-null pointer, otherwise hp will be null.
  * if successful save hp in the conf item it was called with
  */
-static void conf_dns_callback(void* vptr, struct DNSReply* reply)
+static void conf_dns_callback(void* vptr, struct DNSReply* hp)
 {
   struct ConfItem* aconf = (struct ConfItem*) vptr;
+  assert(aconf);
   aconf->dns_pending = 0;
-  if (reply)
-    memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
+  if (hp) {
+    struct sockaddr_in *sin = (struct sockaddr_in*)&hp->addr;
+    memcpy(&aconf->ipnum, &sin->sin_addr, sizeof(struct in_addr));
+    MyFree(hp);
+  }
 }
 
 /*
@@ -211,9 +221,8 @@ static void conf_dns_callback(void* vptr, struct DNSReply* reply)
  * if the conf entry is currently doing a ns lookup do nothing, otherwise
  * if the lookup returns a null pointer, set the conf dns_pending flag
  */
-static struct DNSReply* conf_dns_lookup(struct ConfItem* aconf)
+static void conf_dns_lookup(struct ConfItem* aconf)
 {
-  struct DNSReply* dns_reply = 0;
   if (!aconf->dns_pending) {
     char            buf[HOSTLEN + 1];
     struct DNSQuery query;
@@ -222,10 +231,9 @@ static struct DNSReply* conf_dns_lookup(struct ConfItem* aconf)
     host_from_uh(buf, aconf->host, HOSTLEN);
     buf[HOSTLEN] = '\0';
 
-    if (0 == (dns_reply = gethost_byname(buf, &query)))
-      aconf->dns_pending = 1;
+    gethost_byname(buf, &query);
+    aconf->dns_pending = 1;
   }
-  return dns_reply;
 }
 
 
@@ -235,10 +243,9 @@ static struct DNSReply* conf_dns_lookup(struct ConfItem* aconf)
  * Do (start) DNS lookups of all hostnames in the conf line and convert
  * an IP addresses in a.b.c.d number for to IP#s.
  */
-static void lookup_confhost(struct ConfItem *aconf)
+void
+lookup_confhost(struct ConfItem *aconf)
 {
-  struct DNSReply* reply;
-
   if (EmptyString(aconf->host) || EmptyString(aconf->name)) {
     Debug((DEBUG_ERROR, "Host/server name error: (%s) (%s)",
            aconf->host, aconf->name));
@@ -259,8 +266,8 @@ static void lookup_confhost(struct ConfItem *aconf)
             aconf->host, aconf->name));
     }
   }
-  else if ((reply = conf_dns_lookup(aconf)))
-    memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
+  else 
+    conf_dns_lookup(aconf);
 }
 
 /*
@@ -323,7 +330,7 @@ void det_confs_butmask(struct Client* cptr, int mask)
   struct SLink* next;
   assert(0 != cptr);
 
-  for (link = cptr->confs; link; link = next) {
+  for (link = cli_confs(cptr); link; link = next) {
     next = link->next;
     if ((link->value.aconf->status & mask) == 0)
       detach_conf(cptr, link->value.aconf);
@@ -361,59 +368,55 @@ check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
 enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
 {
   struct ConfItem* aconf;
-  const char*      hname;
-  int              i;
   static char      uhost[HOSTLEN + USERLEN + 3];
   static char      fullname[HOSTLEN + 1];
-  struct hostent*  hp = 0;
+  struct DNSReply* hp = 0;
 
   assert(0 != cptr);
 
-  if (cptr->dns_reply)
-    hp = cptr->dns_reply->hp;
+  if (cli_dns_reply(cptr))
+    hp = cli_dns_reply(cptr);
 
   for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
     if (aconf->status != CONF_CLIENT)
       continue;
-    if (aconf->port && aconf->port != cptr->listener->port)
+    if (aconf->port && aconf->port != cli_listener(cptr)->port)
       continue;
     if (!aconf->host || !aconf->name)
       continue;
     if (hp) {
-      for (i = 0, hname = hp->h_name; hname; hname = hp->h_aliases[i++]) {
-        ircd_strncpy(fullname, hname, HOSTLEN);
-        fullname[HOSTLEN] = '\0';
-
-        Debug((DEBUG_DNS, "a_il: %s->%s", cptr->sockhost, fullname));
-
-        if (strchr(aconf->name, '@')) {
-          strcpy(uhost, cptr->username);
-          strcat(uhost, "@");
-        }
-        else
-          *uhost = '\0';
-        strncat(uhost, fullname, sizeof(uhost) - 1 - strlen(uhost));
-        uhost[sizeof(uhost) - 1] = 0;
-        if (0 == match(aconf->name, uhost)) {
-          if (strchr(uhost, '@'))
-            cptr->flags |= FLAGS_DOID;
-          return check_limit_and_attach(cptr, aconf);
-        }
+      ircd_strncpy(fullname, hp->h_name, HOSTLEN);
+      fullname[HOSTLEN] = '\0';
+
+      Debug((DEBUG_DNS, "a_il: %s->%s", cli_sockhost(cptr), fullname));
+
+      if (strchr(aconf->name, '@')) {
+        strcpy(uhost, cli_username(cptr));
+        strcat(uhost, "@");
+      }
+      else
+        *uhost = '\0';
+      strncat(uhost, fullname, sizeof(uhost) - 1 - strlen(uhost));
+      uhost[sizeof(uhost) - 1] = 0;
+      if (0 == match(aconf->name, uhost)) {
+        if (strchr(uhost, '@'))
+          SetFlag(cptr, FLAG_DOID);
+        return check_limit_and_attach(cptr, aconf);
       }
     }
     if (strchr(aconf->host, '@')) {
-      ircd_strncpy(uhost, cptr->username, sizeof(uhost) - 2);
+      ircd_strncpy(uhost, cli_username(cptr), sizeof(uhost) - 2);
       uhost[sizeof(uhost) - 2] = 0;
       strcat(uhost, "@");
     }
     else
       *uhost = '\0';
-    strncat(uhost, cptr->sock_ip, sizeof(uhost) - 1 - strlen(uhost));
+    strncat(uhost, cli_sock_ip(cptr), sizeof(uhost) - 1 - strlen(uhost));
     uhost[sizeof(uhost) - 1] = 0;
     if (match(aconf->host, uhost))
       continue;
     if (strchr(uhost, '@'))
-      cptr->flags |= FLAGS_DOID;
+      SetFlag(cptr, FLAG_DOID);
 
     return check_limit_and_attach(cptr, aconf);
   }
@@ -424,7 +427,7 @@ static int is_attached(struct ConfItem *aconf, struct Client *cptr)
 {
   struct SLink *lp;
 
-  for (lp = cptr->confs; lp; lp = lp->next) {
+  for (lp = cli_confs(cptr); lp; lp = lp->next) {
     if (lp->value.aconf == aconf)
       return 1;
   }
@@ -447,13 +450,13 @@ enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *
     return ACR_ALREADY_AUTHORIZED;
   if (IsIllegal(aconf))
     return ACR_NO_AUTHORIZATION;
-  if ((aconf->status & (CONF_LOCOP | CONF_OPERATOR | CONF_CLIENT)) &&
+  if ((aconf->status & (CONF_OPERATOR | CONF_CLIENT)) &&
       ConfLinks(aconf) >= ConfMaxLinks(aconf) && ConfMaxLinks(aconf) > 0)
     return ACR_TOO_MANY_IN_CLASS;  /* Use this for printing error message */
   lp = make_link();
-  lp->next = cptr->confs;
+  lp->next = cli_confs(cptr);
   lp->value.aconf = aconf;
-  cptr->confs = lp;
+  cli_confs(cptr) = lp;
   ++aconf->clients;
   if (aconf->status & CONF_CLIENT_MASK)
     ConfLinks(aconf)++;
@@ -545,7 +548,7 @@ struct ConfItem* find_conf_exact(const char* name, const char* user,
      */
     if (match(tmp->host, userhost))
       continue;
-    if (tmp->status & (CONF_OPERATOR | CONF_LOCOP)) {
+    if (tmp->status & CONF_OPERATOR) {
       if (tmp->clients < MaxLinks(tmp->conn_class))
         return tmp;
       else
@@ -626,6 +629,7 @@ struct ConfItem* find_conf_byip(struct SLink* lp, const char* ip,
  *
  * - looks for a match on all given fields.
  */
+#if 0
 static struct ConfItem *find_conf_entry(struct ConfItem *aconf,
                                         unsigned int mask)
 {
@@ -648,9 +652,6 @@ static struct ConfItem *find_conf_entry(struct ConfItem *aconf,
         (EmptyString(aconf->passwd) && !EmptyString(bconf->passwd)))
       continue;
     if (!EmptyString(bconf->passwd) && (!IsDigit(*bconf->passwd) || bconf->passwd[1])
-#ifdef USEONE
-        && 0 != ircd_strcmp(bconf->passwd, "ONE")
-#endif
         && 0 != ircd_strcmp(bconf->passwd, aconf->passwd))
       continue;
 
@@ -664,7 +665,6 @@ static struct ConfItem *find_conf_entry(struct ConfItem *aconf,
   return bconf;
 }
 
-
 /*
  * If conf line is a class definition, create a class entry
  * for it and make the conf_line illegal and delete it.
@@ -731,7 +731,7 @@ void conf_add_local(const char* const* fields, int count)
   /*
    * XXX - shouldn't be setting these directly here
    */
-  ircd_strncpy(me.info, fields[3], REALLEN);
+  ircd_strncpy(cli_info(&me), fields[3], REALLEN);
   set_virtual_host(localConf.vhost_address);
 }
 
@@ -781,6 +781,7 @@ void conf_add_crule(const char* const* fields, int count, int type)
     cruleConfList = p;
   } 
 }
+#endif
 
 void conf_erase_crule_list(void)
 {
@@ -802,6 +803,7 @@ const struct CRuleConf* conf_get_crule_list(void)
   return cruleConfList;
 }
 
+#if 0
 void conf_add_server(const char* const* fields, int count)
 {
   struct ServerConf* server;
@@ -835,8 +837,8 @@ void conf_add_server(const char* const* fields, int count)
   server->next = serverConfList;
   serverConfList = server;
 
-  // if (INADDR_NONE == server->address.s_addr)
-    // lookup_confhost(server);
+  /* if (INADDR_NONE == server->address.s_addr) */
+    /* lookup_confhost(server); */
 }
 
 void conf_add_deny(const char* const* fields, int count, int ip_kill)
@@ -850,13 +852,16 @@ void conf_add_deny(const char* const* fields, int count, int ip_kill)
   assert(0 != conf);
   memset(conf, 0, sizeof(struct DenyConf));
 
+  if (fields[1][0] == '$' && fields[1][1] == 'R')
+    conf->flags |= DENY_FLAGS_REALNAME;
+
   DupString(conf->hostmask, fields[1]);
   collapse(conf->hostmask);
 
   if (!EmptyString(fields[2])) {
     const char* p = fields[2];
     if ('!' == *p) {
-      conf->is_file = 1;
+      conf->flags |= DENY_FLAGS_FILE;
       ++p;
     }
     DupString(conf->message, p);
@@ -881,18 +886,22 @@ void conf_add_deny(const char* const* fields, int count, int ip_kill)
     else {
       conf->bits = bits2;
     }
-    sprintf_irc(ipname, "%d.%d.%d.%d", ad[0], ad[1], ad[2], ad[3]);
+    ircd_snprintf(0, ipname, sizeof(ipname), "%d.%d.%d.%d", ad[0], ad[1],
+                 ad[2], ad[3]);
     
     /*
      * This ensures endian correctness
      */
-    conf->s_addr = inet_addr(ipname);
+    conf->address = inet_addr(ipname);
     Debug((DEBUG_DEBUG, "IPkill: %s = %08x/%i (%08x)", ipname,
-           conf->s_addr, conf->bits, NETMASK(conf->bits)));
+           conf->address, conf->bits, NETMASK(conf->bits)));
+    conf->flags |= DENY_FLAGS_IP;
   }
   conf->next = denyConfList;
   denyConfList = conf;
 }
+#endif
+
 
 void conf_erase_deny_list(void)
 {
@@ -913,6 +922,43 @@ const struct DenyConf* conf_get_deny_list(void)
   return denyConfList;
 }
 
+#if 0
+void conf_add_quarantine(const char *chname, const char *reason)
+{
+  struct qline *qline;
+
+  qline = (struct qline *) MyMalloc(sizeof(struct qline));
+  DupString(qline->chname, chname);
+  DupString(qline->reason, reason);
+  qline->next = GlobalQuarantineList;
+  GlobalQuarantineList = qline;
+}
+#endif
+
+const char*
+find_quarantine(const char *chname)
+{
+  struct qline *qline;
+  
+  for (qline = GlobalQuarantineList; qline; qline = qline->next)
+    if (!ircd_strcmp(qline->chname, chname))
+      return qline->reason;
+  return NULL;
+}
+
+void clear_quarantines(void)
+{
+  struct qline *qline;
+  while ((qline = GlobalQuarantineList))
+  {
+    GlobalQuarantineList = qline->next;
+    MyFree(qline->reason);
+    MyFree(qline->chname);
+    MyFree(qline);
+  }
+}
+
+
 /*
  * read_configuration_file
  *
@@ -924,312 +970,37 @@ const struct DenyConf* conf_get_deny_list(void)
 
 #define MAXCONFLINKS 150
 
+static int conf_error;
+static int conf_already_read;
+extern FILE *yyin;
+void init_lexer(void);
+
 int read_configuration_file(void)
 {
-  enum { MAX_FIELDS = 15 };
-
-  char* src;
-  char* dest;
-  int quoted;
-  FBFILE *file;
-  char line[512];
-  int ccount = 0;
-  struct ConfItem *aconf = 0;
-  
-  int   field_count = 0;
-  const char* field_vector[MAX_FIELDS + 1];
-
-  Debug((DEBUG_DEBUG, "read_configuration_file: ircd.conf = %s", configfile));
-  if (0 == (file = fbopen(configfile, "r"))) {
-    return 0;
-  }
-
-  while (fbgets(line, sizeof(line) - 1, file)) {
-    if ('#' == *line || IsSpace(*line))
-      continue;
-
-    if ((src = strchr(line, '\n')))
-      *src = '\0';
-    
-    if (':' != line[1]) {
-      Debug((DEBUG_ERROR, "Bad config line: %s", line));
-      sendto_op_mask(SNO_OLDSNO,"Bad Config line");
-      continue;
-    }
-
-    /*
-     * do escapes, quoting, comments, and field breakup in place
-     * in one pass with a poor mans state machine
-     */
-    field_vector[0] = line;
-    field_count = 1;
-    quoted = 0;
-
-    for (src = line, dest = line; *src; ) {
-      switch (*src) {
-      case '\\':
-        ++src;
-        switch (*src) {
-        case 'b':
-          *dest++ = '\b';
-          ++src;
-          break;
-        case 'f':
-          *dest++ = '\f';
-          ++src;
-          break;
-        case 'n':
-          *dest++ = '\n';
-          ++src;
-          break;
-        case 'r':
-          *dest++ = '\r';      
-          ++src;
-          break;
-        case 't':
-          *dest++ = '\t';
-          ++src;
-          break;
-        case 'v':
-          *dest++ = '\v';
-          ++src;
-          break;
-        case '\\':
-          *dest++ = '\\';
-          ++src;
-          break;
-        case '\0':
-          break;
-        default:
-          *dest++ = *src++;
-          break;
-        }
-        break;
-      case '"':
-        if (quoted)
-          quoted = 0;
-        else
-          quoted = 1;
-        /*
-         * strip quotes
-         */
-        ++src;
-        break;
-      case ':':
-        if (quoted)
-          *dest++ = *src++;
-        else {
-          *dest++ = '\0';
-          field_vector[field_count++] = dest;
-          if (field_count > MAX_FIELDS)
-            *src = '\0';
-          else  
-            ++src;
-        }
-        break;
-      case '#':
-        *src = '\0';
-        break;
-      default:
-        *dest++ = *src++;
-        break;
-      }
-    }
-    *dest = '\0';
-
-    if (field_count < 2 || EmptyString(field_vector[0]))
-      continue;
-
-    if (aconf)
-      free_conf(aconf);
-
-    aconf = make_conf();
-
-    switch (*field_vector[0]) {
-    case 'A':                /* Name, e-mail address of administrator */
-    case 'a':                /* of this server. CONF_ADMIN */
-      conf_add_admin(field_vector, field_count);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'C':                /* Server where I should try to connect */
-    case 'c':                /* in case of lp failures             */
-      ++ccount;
-      aconf->status = CONF_SERVER;
-      break;
-      /* Connect rule */
-    case 'D':  /* CONF_CRULEALL */
-      conf_add_crule(field_vector, field_count, CRULE_ALL);
-      aconf->status = CONF_ILLEGAL;
-      break;
-      /* Connect rule - autos only */
-    case 'd':  /* CONF_CRULEAUTO */
-      conf_add_crule(field_vector, field_count, CRULE_AUTO);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'F':                /* Feature line */
-    case 'f':
-      feature_set(0, &field_vector[1], field_count - 1);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'H':                /* Hub server line */
-    case 'h':
-      aconf->status = CONF_HUB;
-      break;
-    case 'I':                /* Just plain normal irc client trying  */
-    case 'i':                /* to connect me */
-      aconf->status = CONF_CLIENT;
-      break;
-    case 'K':                /* Kill user line on irc.conf           */
-      conf_add_deny(field_vector, field_count, 0);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'k':                /* Kill user line based on IP in ircd.conf */
-      conf_add_deny(field_vector, field_count, 1);
-      aconf->status = CONF_ILLEGAL;
-      break;
-      /* Operator. Line should contain at least */
-      /* password and host where connection is  */
-    case 'L':                /* guaranteed leaf server */
-    case 'l':
-      aconf->status = CONF_LEAF;
-      break;
-      /* Me. Host field is name used for this host */
-      /* and port number is the number of the port */
-    case 'M':
-    case 'm':        /* CONF_ME */
-      conf_add_local(field_vector, field_count);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'O':
-      aconf->status = CONF_OPERATOR;
-      break;
-      /* Local Operator, (limited privs --SRB) */
-    case 'o':
-      aconf->status = CONF_LOCOP;
-      break;
-    case 'P':                /* listen port line */
-    case 'p':        /* CONF_LISTEN_PORT */
-      conf_add_listener(field_vector, field_count);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'T':                /* print out different motd's */
-    case 't':                /* based on hostmask - CONF_TLINES */
-      motd_add(field_vector[1], field_vector[2]);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    case 'U':      /* Underworld server, allowed to hack modes */
-    case 'u':      /* *Every* server on the net must define the same !!! */
-      aconf->status = CONF_UWORLD;
-      break;
-    case 'Y':
-    case 'y':      /* CONF_CLASS */
-      conf_add_class(field_vector, field_count);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    default:
-      Debug((DEBUG_ERROR, "Error in config file: %s", line));
-      sendto_op_mask(SNO_OLDSNO,"Unknown prefix in config file: %c", *field_vector[0]);
-      aconf->status = CONF_ILLEGAL;
-      break;
-    }
-    if (IsIllegal(aconf))
-      continue;
-
-    if (!EmptyString(field_vector[1]))
-      DupString(aconf->host, field_vector[1]);
-
-    if (!EmptyString(field_vector[2]))
-      DupString(aconf->passwd, field_vector[2]);
-
-    if (field_count > 3 && !EmptyString(field_vector[3]))
-        DupString(aconf->name, field_vector[3]);
-
-    if (field_count > 4 && !EmptyString(field_vector[4]))
-        aconf->port = atoi(field_vector[4]); 
-
-    if (field_count > 5 && !EmptyString(field_vector[5]))
-      aconf->conn_class = find_class(atoi(field_vector[5]));
-
-    /*
-     * Associate each conf line with a class by using a pointer
-     * to the correct class record. -avalon
-     */
-    if (aconf->status & CONF_CLIENT_MASK) {
-      if (aconf->conn_class == 0)
-        aconf->conn_class = find_class(0);
-    }
-    if (aconf->status & CONF_CLIENT) {
-      struct ConfItem *bconf;
-
-      if ((bconf = find_conf_entry(aconf, aconf->status))) {
-        delist_conf(bconf);
-        bconf->status &= ~CONF_ILLEGAL;
-        if (aconf->status == CONF_CLIENT) {
-          /*
-           * copy the password field in case it changed
-           */
-          MyFree(bconf->passwd);
-          bconf->passwd = aconf->passwd;
-          aconf->passwd = 0;
-
-          ConfLinks(bconf) -= bconf->clients;
-          bconf->conn_class = aconf->conn_class;
-          if (bconf->conn_class)
-            ConfLinks(bconf) += bconf->clients;
-        }
-        free_conf(aconf);
-        aconf = bconf;
-      }
-    }
-    if (aconf->status & CONF_SERVER) {
-      if (ccount > MAXCONFLINKS || !aconf->host || strchr(aconf->host, '*') ||
-          strchr(aconf->host, '?') || !aconf->name)
-        continue;
-    }
-    if (aconf->status & (CONF_LOCOP | CONF_OPERATOR)) {
-      if (!strchr(aconf->host, '@')) {
-        char* newhost;
-        int len = 3;                /* *@\0 = 3 */
-
-        len += strlen(aconf->host);
-        newhost = (char*) MyMalloc(len);
-        assert(0 != newhost);
-        ircd_snprintf(0, newhost, len, "*@%s", aconf->host);
-        MyFree(aconf->host);
-        aconf->host = newhost;
-      }
-    }
-    if (aconf->status & CONF_SERVER) {
-      if (EmptyString(aconf->passwd))
-        continue;
-      lookup_confhost(aconf);
-    }
-    /*
-     * Juped nicks are listed in the 'password' field of U:lines,
-     * the list is comma separated and might be empty and/or contain
-     * empty elements... the only limit is that it MUST be shorter
-     * than 512 chars, or they will be cutted out :)
-     */
-    if ((aconf->status == CONF_UWORLD) && (aconf->passwd) && (*aconf->passwd))
-      addNickJupes(aconf->passwd);
-
-    collapse(aconf->host);
-    collapse(aconf->name);
-    Debug((DEBUG_NOTICE,
-        "Read Init: (%d) (%s) (%s) (%s) (%u) (%p)",
-        aconf->status, aconf->host, aconf->passwd,
-        aconf->name, aconf->port, aconf->conn_class));
-    aconf->next = GlobalConfList;
-    GlobalConfList = aconf;
-    aconf = NULL;
-  }
-  if (aconf)
-    free_conf(aconf);
-  fbclose(file);
-  nextping = nextconnect = CurrentTime;
+  conf_error = 0;
+  feature_unmark(); /* unmark all features for resetting later */
+  /* Now just open an fd. The buffering isn't really needed... */
+  init_lexer();
+  yyparse();
+  fclose(yyin);
+  yyin = NULL;
+  feature_mark(); /* reset unmarked features */
+  conf_already_read = 1;
   return 1;
 }
 
+void
+yyerror(const char *msg)
+{
+ sendto_opmask_butone(0, SNO_ALL, "Config file parse error line %d: %s",
+                      lineno, msg);
+ log_write(LS_CONFIG, L_ERROR, 0, "Config file parse error line %d: %s",
+           lineno, msg);
+ if (!conf_already_read)
+   fprintf(stderr, "Config file parse error line %d: %s\n", lineno, msg);
+ conf_error = 1;
+}
+
 /*
  * rehash
  *
@@ -1280,16 +1051,20 @@ int rehash(struct Client *cptr, int sig)
    */
   clearNickJupes();
 
+  clear_quarantines();
+
   if (sig != 2)
-    flush_resolver_cache();
+    restart_resolver();
 
   class_mark_delete();
   mark_listeners_closing();
+  iauth_mark_closing();
 
   read_configuration_file();
 
   log_reopen(); /* reopen log files */
 
+  iauth_close_unused();
   close_listeners();
   class_delete_marked();         /* unless it fails */
 
@@ -1306,13 +1081,14 @@ int rehash(struct Client *cptr, int sig)
     else
       tmp = &tmp2->next;
   }
+
   for (i = 0; i <= HighestFd; i++) {
     if ((acptr = LocalClientArray[i])) {
       assert(!IsMe(acptr));
       if (IsServer(acptr)) {
         det_confs_butmask(acptr,
             ~(CONF_HUB | CONF_LEAF | CONF_UWORLD | CONF_ILLEGAL));
-        attach_confs_byname(acptr, acptr->name,
+        attach_confs_byname(acptr, cli_name(acptr),
                             CONF_HUB | CONF_LEAF | CONF_UWORLD);
       }
       /* Because admin's are getting so uppity about people managing to
@@ -1323,14 +1099,15 @@ int rehash(struct Client *cptr, int sig)
         sendto_opmask_butone(0, found_g == -2 ? SNO_GLINE : SNO_OPERKILL,
                              found_g == -2 ? "G-line active for %s%s" :
                              "K-line active for %s%s",
-                             IsUnknown(acptr) ? "Unregistered Client ":"",                     
-                             get_client_name(acptr, HIDE_IP));
+                             IsUnknown(acptr) ? "Unregistered Client ":"",
+                             get_client_name(acptr, SHOW_IP));
         if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" :
             "K-lined") == CPTR_KILLED)
           ret = CPTR_KILLED;
       }
     }
   }
+
   return ret;
 }
 
@@ -1354,6 +1131,8 @@ int init_conf(void)
      */
     if (0 == localConf.name || 0 == localConf.numeric)
       return 0;
+    if (conf_error)
+      return 0;
 
     if (0 == localConf.location1)
       DupString(localConf.location1, "");
@@ -1361,7 +1140,7 @@ int init_conf(void)
       DupString(localConf.location2, "");
     if (0 == localConf.contact)
       DupString(localConf.contact, "");
-    
+
     return 1;
   }
   return 0;
@@ -1382,34 +1161,40 @@ int find_kill(struct Client *cptr)
 {
   const char*      host;
   const char*      name;
+  const char*      realname;
   struct DenyConf* deny;
   struct Gline*    agline = NULL;
 
   assert(0 != cptr);
 
-  if (!cptr->user)
+  if (!cli_user(cptr))
     return 0;
 
-  host = cptr->sockhost;
-  name = cptr->user->username;
+  host = cli_sockhost(cptr);
+  name = cli_user(cptr)->username;
+  realname = cli_info(cptr);
 
   assert(strlen(host) <= HOSTLEN);
   assert((name ? strlen(name) : 0) <= HOSTLEN);
-  
+  assert((realname ? strlen(realname) : 0) <= REALLEN);
+
   /* 2000-07-14: Rewrote this loop for massive speed increases.
    *             -- Isomer
    */
   for (deny = denyConfList; deny; deny = deny->next) {
     if (0 != match(deny->usermask, name))
       continue;
-            
+
     if (EmptyString(deny->hostmask))
       break;
-    
-    if (deny->ip_kill) { /* k: by IP */
+
+    if (deny->flags & DENY_FLAGS_REALNAME) { /* K: by real name */
+      if (0 == match(deny->hostmask + 2, realname))
+       break;
+    } else if (deny->flags & DENY_FLAGS_IP) { /* k: by IP */
       Debug((DEBUG_DEBUG, "ip: %08x network: %08x/%i mask: %08x",
-             cptr->ip.s_addr, deny->s_addr, deny->bits, NETMASK(deny->bits)));
-      if ((cptr->ip.s_addr & NETMASK(deny->bits)) == deny->s_addr)
+             cli_ip(cptr).s_addr, deny->address, deny->bits, NETMASK(deny->bits)));
+      if ((cli_ip(cptr).s_addr & NETMASK(deny->bits)) == deny->address)
         break;
     }
     else if (0 == match(deny->hostmask, host))
@@ -1420,21 +1205,19 @@ int find_kill(struct Client *cptr)
       send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
                  ":Connection from your host is refused on this server.");
     else {
-      if (deny->is_file)
+      if (deny->flags & DENY_FLAGS_FILE)
         killcomment(cptr, deny->message);
       else
         send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", deny->message);
     }
   }
-  else if ((agline = gline_lookup(cptr, 0)) && GlineIsActive(agline)) {
+  else if ((agline = gline_lookup(cptr, 0))) {
     /*
      * find active glines
      * added a check against the user's IP address to find_gline() -Kev
      */
     send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", GlineReason(agline));
   }
-  else
-    agline = 0;          /* if a gline was found, it was inactive */
 
   if (deny)
     return -1;
@@ -1456,7 +1239,7 @@ enum AuthorizationCheckResult conf_check_client(struct Client *cptr)
 
   if ((acr = attach_iline(cptr))) {
     Debug((DEBUG_DNS, "ch_cl: access denied: %s[%s]", 
-          cptr->name, cptr->sockhost));
+          cli_name(cptr), cli_sockhost(cptr)));
     return acr;
   }
   return ACR_OK;
@@ -1482,23 +1265,23 @@ int conf_check_server(struct Client *cptr)
   struct SLink*    lp;
 
   Debug((DEBUG_DNS, "sv_cl: check access for %s[%s]", 
-        cptr->name, cptr->sockhost));
+        cli_name(cptr), cli_sockhost(cptr)));
 
-  if (IsUnknown(cptr) && !attach_confs_byname(cptr, cptr->name, CONF_SERVER)) {
-    Debug((DEBUG_DNS, "No C/N lines for %s", cptr->sockhost));
+  if (IsUnknown(cptr) && !attach_confs_byname(cptr, cli_name(cptr), CONF_SERVER)) {
+    Debug((DEBUG_DNS, "No C/N lines for %s", cli_sockhost(cptr)));
     return -1;
   }
-  lp = cptr->confs;
+  lp = cli_confs(cptr);
   /*
    * We initiated this connection so the client should have a C and N
    * line already attached after passing through the connect_server()
    * function earlier.
    */
   if (IsConnecting(cptr) || IsHandshake(cptr)) {
-    c_conf = find_conf_byname(lp, cptr->name, CONF_SERVER);
+    c_conf = find_conf_byname(lp, cli_name(cptr), CONF_SERVER);
     if (!c_conf) {
       sendto_opmask_butone(0, SNO_OLDSNO, "Connect Error: lost C:line for %s",
-                           cptr->name);
+                           cli_name(cptr));
       det_confs_butmask(cptr, 0);
       return -1;
     }
@@ -1507,26 +1290,17 @@ int conf_check_server(struct Client *cptr)
   ClearAccess(cptr);
 
   if (!c_conf) {
-    if (cptr->dns_reply) {
-      int             i;
-      struct hostent* hp = cptr->dns_reply->hp;
+    if (cli_dns_reply(cptr)) {
+      struct DNSReply* hp = cli_dns_reply(cptr);
       const char*     name = hp->h_name;
       /*
        * If we are missing a C or N line from above, search for
        * it under all known hostnames we have for this ip#.
        */
-      for (i = 0; name; name = hp->h_aliases[i++]) {
-        if ((c_conf = find_conf_byhost(lp, name, CONF_SERVER))) {
-          ircd_strncpy(cptr->sockhost, name, HOSTLEN);
-          break;
-        }
-      }
-      if (!c_conf) {
-        for (i = 0; hp->h_addr_list[i]; i++) {
-          if ((c_conf = find_conf_byip(lp, hp->h_addr_list[i], CONF_SERVER)))
-            break;
-        }
-      }
+      if ((c_conf = find_conf_byhost(lp, hp->h_name, CONF_SERVER)))
+        ircd_strncpy(cli_sockhost(cptr), name, HOSTLEN);
+      else
+          c_conf = find_conf_byip(lp, (char*)&((struct sockaddr_in*)&hp->addr)->sin_addr, CONF_SERVER);
     }
     else {
       /*
@@ -1534,7 +1308,7 @@ int conf_check_server(struct Client *cptr)
        * of the host the server runs on. This also checks the case where
        * there is a server connecting from 'localhost'.
        */
-      c_conf = find_conf_byhost(lp, cptr->sockhost, CONF_SERVER);
+      c_conf = find_conf_byhost(lp, cli_sockhost(cptr), CONF_SERVER);
     }
   }
   /*
@@ -1543,7 +1317,7 @@ int conf_check_server(struct Client *cptr)
    * happen when using DNS in the way the irc server does. -avalon
    */
   if (!c_conf)
-    c_conf = find_conf_byip(lp, (const char*) &cptr->ip, CONF_SERVER);
+    c_conf = find_conf_byip(lp, (const char*) &(cli_ip(cptr)), CONF_SERVER);
   /*
    * detach all conf lines that got attached by attach_confs()
    */
@@ -1553,20 +1327,21 @@ int conf_check_server(struct Client *cptr)
    */
   if (!c_conf) {
     Debug((DEBUG_DNS, "sv_cl: access denied: %s[%s@%s]",
-          cptr->name, cptr->username, cptr->sockhost));
+          cli_name(cptr), cli_username(cptr), cli_sockhost(cptr)));
     return -1;
   }
-  ircd_strncpy(cptr->name, c_conf->name, HOSTLEN);
+  ircd_strncpy(cli_name(cptr), c_conf->name, HOSTLEN);
   /*
    * attach the C and N lines to the client structure for later use.
    */
   attach_conf(cptr, c_conf);
-  attach_confs_byname(cptr, cptr->name, CONF_HUB | CONF_LEAF | CONF_UWORLD);
+  attach_confs_byname(cptr, cli_name(cptr), CONF_HUB | CONF_LEAF | CONF_UWORLD);
 
   if (INADDR_NONE == c_conf->ipnum.s_addr)
-    c_conf->ipnum.s_addr = cptr->ip.s_addr;
+    c_conf->ipnum.s_addr = cli_ip(cptr).s_addr;
 
-  Debug((DEBUG_DNS, "sv_cl: access ok: %s[%s]", cptr->name, cptr->sockhost));
+  Debug((DEBUG_DNS, "sv_cl: access ok: %s[%s]",
+         cli_name(cptr), cli_sockhost(cptr)));
   return 0;
 }