Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / s_conf.c
index 8be6bbd7030f2b519b519021d448efd46aad8240..4be9c2a00c9a4df30fd4c646ef7ae2294335b066 100644 (file)
@@ -25,6 +25,7 @@
 #include "class.h"
 #include "client.h"
 #include "crule.h"
+#include "ircd_features.h"
 #include "fileio.h"
 #include "gline.h"
 #include "hash.h"
@@ -38,6 +39,7 @@
 #include "list.h"
 #include "listener.h"
 #include "match.h"
+#include "motd.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "opercmds.h"
 
 struct ConfItem* GlobalConfList  = 0;
 int              GlobalConfCount = 0;
-struct MotdItem* motd = NULL;
-struct MotdItem* rmotd = NULL;
-struct TRecord*  tdata = NULL;
-struct tm        motd_tm;
 
-static struct LocalConf  localConf;
-static struct MotdConf*  motdConfList;
+static struct LocalConf   localConf;
+static struct CRuleConf*  cruleConfList;
+static struct ServerConf* serverConfList;
+static struct DenyConf*   denyConfList;
 
 /*
  * output the reason for being k lined from a file  - Mmmm
- * sptr is server
- * parv is the sender prefix
+ * sptr is client being dumped
  * filename is the file that is to be output to the K lined client
  */
-static void killcomment(struct Client *sptr, char *parv, char *filename)
+static void killcomment(struct Client* sptr, const char* filename)
 {
-  FBFILE*     file = NULL;
+  FBFILE*     file = 0;
   char        line[80];
-  char*       tmp = NULL;
   struct stat sb;
   struct tm*  tm;
 
   if (NULL == (file = fbopen(filename, "r"))) {
     send_reply(sptr, ERR_NOMOTD);
     send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
-              ":Connection from your host is refused on this server.");
+               ":Connection from your host is refused on this server.");
     return;
   }
   fbstat(&sb, file);
   tm = localtime((time_t*) &sb.st_mtime);        /* NetBSD needs cast */
   while (fbgets(line, sizeof(line) - 1, file)) {
-    if ((tmp = strchr(line, '\n')))
-      *tmp = '\0';
-    if ((tmp = strchr(line, '\r')))
-      *tmp = '\0';
+    char* end = line + strlen(line);
+    while (end > line) {
+      --end;
+      if ('\n' == *end || '\r' == *end)
+        *end = '\0';
+      else
+        break;
+    }
     send_reply(sptr, RPL_MOTD, line);
   }
   send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
-            ":Connection from your host is refused on this server.");
+             ":Connection from your host is refused on this server.");
   fbclose(file);
 }
 
@@ -120,17 +122,9 @@ struct ConfItem* make_conf(void)
 #ifdef        DEBUGMODE
   ++GlobalConfCount;
 #endif
+  memset(aconf, 0, sizeof(struct ConfItem));
   aconf->status       = CONF_ILLEGAL;
-  aconf->clients      = 0;
   aconf->ipnum.s_addr = INADDR_NONE;
-  aconf->host         = 0;
-  aconf->passwd       = 0;
-  aconf->name         = 0;
-  aconf->port         = 0;
-  aconf->hold         = 0;
-  aconf->dns_pending  = 0;
-  aconf->confClass    = 0;
-  aconf->next         = 0;
   return aconf;
 }
 
@@ -145,7 +139,7 @@ void delist_conf(struct ConfItem *aconf)
       ;
     bconf->next = aconf->next;
   }
-  aconf->next = NULL;
+  aconf->next = 0;
 }
 
 void free_conf(struct ConfItem *aconf)
@@ -167,6 +161,37 @@ void free_conf(struct ConfItem *aconf)
 #endif
 }
 
+/*
+ * detach_conf - Disassociate configuration from the client.
+ */
+static void detach_conf(struct Client* cptr, struct ConfItem* aconf)
+{
+  struct SLink** lp;
+  struct SLink*  tmp;
+
+  assert(0 != aconf);
+  assert(0 != cptr);
+  assert(0 < aconf->clients);
+
+  lp = &(cli_confs(cptr));
+
+  while (*lp) {
+    if ((*lp)->value.aconf == aconf) {
+      if (aconf->conn_class && (aconf->status & CONF_CLIENT_MASK) && ConfLinks(aconf) > 0)
+        --ConfLinks(aconf);
+
+      assert(0 < aconf->clients);
+      if (0 == --aconf->clients && IsIllegal(aconf))
+        free_conf(aconf);
+      tmp = *lp;
+      *lp = tmp->next;
+      free_link(tmp);
+      return;
+    }
+    lp = &((*lp)->next);
+  }
+}
+
 /*
  * conf_dns_callback - called when resolver query finishes
  * if the query resulted in a successful search, hp will contain
@@ -272,17 +297,17 @@ struct ConfItem* conf_find_server(const char* name)
  * Evaluate connection rules...  If no rules found, allow the
  * connect.   Otherwise stop with the first true rule (ie: rules
  * are ored together.  Oper connects are effected only by D
- * lines (CRULEALL) not d lines (CRULEAUTO).
+ * lines (CRULE_ALL) not d lines (CRULE_AUTO).
  */
-const char* conf_eval_crule(struct ConfItem* conf)
+const char* conf_eval_crule(const char* name, int mask)
 {
-  struct ConfItem* rule;
-  assert(0 != conf);
+  struct CRuleConf* p = cruleConfList;
+  assert(0 != name);
 
-  for (rule = GlobalConfList; rule; rule = rule->next) {
-    if ((CONF_CRULEALL == rule->status) && (0 == match(rule->host, conf->name))) {
-      if (crule_eval(rule->passwd))
-        return rule->name;
+  for ( ; p; p = p->next) {
+    if (0 != (p->type & mask) && 0 == match(p->hostmask, name)) {
+      if (crule_eval(p->node))
+        return p->rule;
     }
   }
   return 0;
@@ -292,14 +317,16 @@ const char* conf_eval_crule(struct ConfItem* conf)
  * Remove all conf entries from the client except those which match
  * the status field mask.
  */
-void det_confs_butmask(struct Client *cptr, int mask)
+void det_confs_butmask(struct Clientcptr, int mask)
 {
-  struct SLink *tmp, *tmp2;
+  struct SLink* link;
+  struct SLink* next;
+  assert(0 != cptr);
 
-  for (tmp = cptr->confs; tmp; tmp = tmp2) {
-    tmp2 = tmp->next;
-    if ((tmp->value.aconf->status & mask) == 0)
-      detach_conf(cptr, tmp->value.aconf);
+  for (link = cli_confs(cptr); link; link = next) {
+    next = link->next;
+    if ((link->value.aconf->status & mask) == 0)
+      detach_conf(cptr, link->value.aconf);
   }
 }
 
@@ -323,7 +350,7 @@ check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
              !aconf->passwd[2])
       number = (*aconf->passwd-'0')*10+(aconf->passwd[1]-'0');
   }
-  if (ip_registry_count(cptr->ip.s_addr) > number)
+  if (IPcheck_nr(cptr) > number)
     return ACR_TOO_MANY_FROM_IP;
   return attach_conf(cptr, aconf);
 }
@@ -342,13 +369,13 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
 
   assert(0 != cptr);
 
-  if (cptr->dns_reply)
-    hp = cptr->dns_reply->hp;
+  if (cli_dns_reply(cptr))
+    hp = cli_dns_reply(cptr)->hp;
 
   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;
@@ -357,10 +384,10 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
         ircd_strncpy(fullname, hname, HOSTLEN);
         fullname[HOSTLEN] = '\0';
 
-        Debug((DEBUG_DNS, "a_il: %s->%s", cptr->sockhost, fullname));
+        Debug((DEBUG_DNS, "a_il: %s->%s", cli_sockhost(cptr), fullname));
 
         if (strchr(aconf->name, '@')) {
-          strcpy(uhost, cptr->username);
+          strcpy(uhost, cli_username(cptr));
           strcat(uhost, "@");
         }
         else
@@ -369,71 +396,39 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
         uhost[sizeof(uhost) - 1] = 0;
         if (0 == match(aconf->name, uhost)) {
           if (strchr(uhost, '@'))
-            cptr->flags |= FLAGS_DOID;
+            cli_flags(cptr) |= FLAGS_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;
+      cli_flags(cptr) |= FLAGS_DOID;
 
     return check_limit_and_attach(cptr, aconf);
   }
   return ACR_NO_AUTHORIZATION;
 }
 
-/*
- * detach_conf - Disassociate configuration from the client.
- */
-int detach_conf(struct Client *cptr, struct ConfItem *aconf)
-{
-  struct SLink** lp;
-  struct SLink*  tmp;
-
-  assert(0 != aconf);
-  assert(0 != cptr);
-  assert(0 < aconf->clients);
-
-  lp = &(cptr->confs);
-
-  while (*lp) {
-    if ((*lp)->value.aconf == aconf) {
-      if (aconf->confClass && (aconf->status & CONF_CLIENT_MASK) && 
-          ConfLinks(aconf) > 0)
-        --ConfLinks(aconf);
-      if (0 == --aconf->clients && IsIllegal(aconf))
-        free_conf(aconf);
-      tmp = *lp;
-      *lp = tmp->next;
-      free_link(tmp);
-      return 0;
-    }
-    else
-      lp = &((*lp)->next);
-  }
-  return -1;
-}
-
 static int is_attached(struct ConfItem *aconf, struct Client *cptr)
 {
   struct SLink *lp;
 
-  for (lp = cptr->confs; lp; lp = lp->next)
+  for (lp = cptr->confs; lp; lp = lp->next) {
     if (lp->value.aconf == aconf)
-      break;
-
-  return (lp) ? 1 : 0;
+      return 1;
+  }
+  return 0;
 }
 
 /*
@@ -470,16 +465,6 @@ const struct LocalConf* conf_get_local(void)
   return &localConf;
 }
 
-struct ConfItem* find_me(void)
-{
-  struct ConfItem* aconf;
-  for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
-    if (aconf->status & CONF_ME)
-      break;
-  }
-  return aconf;
-}
-
 /*
  * attach_confs_byname
  *
@@ -561,7 +546,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->clients < MaxLinks(tmp->confClass))
+      if (tmp->clients < MaxLinks(tmp->conn_class))
         return tmp;
       else
         continue;
@@ -715,15 +700,49 @@ void conf_add_listener(const char* const* fields, int count)
   add_listener(atoi(fields[4]), fields[2], fields[1], is_server, is_hidden);
 }
 
+void conf_add_local(const char* const* fields, int count)
+{
+  if (count < 6 || EmptyString(fields[1]) || EmptyString(fields[5])) {
+    log_write(LS_CONFIG, L_CRIT, 0, "Your M: line must have 6 fields!");
+    return;
+  }
+  /*
+   * these two can only be set the first time
+   */
+  if (0 == localConf.name) {
+    if (string_is_hostname(fields[1]))
+      DupString(localConf.name, fields[1]);
+  }
+  if (0 == localConf.numeric) {
+    localConf.numeric = atoi(fields[5]);
+    if (0 == localConf.numeric)
+      log_write(LS_CONFIG, L_WARNING, 0,
+               "Your M: line must have a Numeric value greater than 0");
+  }
+  /*
+   * these two can be changed while the server is running
+   */
+  if (string_is_address(fields[2])) {
+    if (INADDR_NONE == (localConf.vhost_address.s_addr = inet_addr(fields[2])))
+      localConf.vhost_address.s_addr = INADDR_ANY;
+  }
+  MyFree(localConf.description);
+  DupString(localConf.description, fields[3]);
+  /*
+   * XXX - shouldn't be setting these directly here
+   */
+  ircd_strncpy(cli_info(&me), fields[3], REALLEN);
+  set_virtual_host(localConf.vhost_address);
+}
+
 void conf_add_admin(const char* const* fields, int count)
 {
   /*
    * if you have one, it MUST have 3 lines
    */
   if (count < 4) {
-    Debug((DEBUG_FATAL, "Your A: line must have 4 fields!\n"));
-    ircd_log(L_CRIT, "Your A: line must have 4 fields!\n");
-    exit(-1);
+    log_write(LS_CONFIG, L_CRIT, 0, "Your A: line must have 4 fields!");
+    return;
   }
   MyFree(localConf.location1);
   DupString(localConf.location1, fields[1]);
@@ -735,45 +754,163 @@ void conf_add_admin(const char* const* fields, int count)
   DupString(localConf.contact, fields[3]);
 }
 
-void conf_add_motd(const char* const* fields, int count, struct MotdConf** list)
+/*
+ * conf_add_crule - Create expression tree from connect rule and add it
+ * to the crule list
+ */
+void conf_add_crule(const char* const* fields, int count, int type)
 {
-  struct MotdConf* conf;
-  if (count < 3 || EmptyString(fields[1]) || EmptyString(fields[2]))
+  struct CRuleNode* node;
+  assert(0 != fields);
+  
+  if (count < 4 || EmptyString(fields[1]) || EmptyString(fields[3]))
     return;
+  
+  if ((node = crule_parse(fields[3]))) {
+    struct CRuleConf* p = (struct CRuleConf*) MyMalloc(sizeof(struct CRuleConf));
+    assert(0 != p);
 
-  conf = (struct MotdConf*) MyMalloc(sizeof(struct MotdConf));
-  assert(0 != conf);
+    DupString(p->hostmask, fields[1]);
+    collapse(p->hostmask);
 
-  DupString(conf->hostmask, fields[1]);
-  collapse(conf->hostmask);
+    DupString(p->rule, fields[3]);
 
-  DupString(conf->path, fields[2]);
+    p->type = type;
+    p->node = node;
+    p->next = cruleConfList;
+    cruleConfList = p;
+  } 
+}
 
-  assert(0 != list);
+void conf_erase_crule_list(void)
+{
+  struct CRuleConf* next;
+  struct CRuleConf* p = cruleConfList;
+
+  for ( ; p; p = next) {
+    next = p->next;
+    crule_free(&p->node);
+    MyFree(p->hostmask);
+    MyFree(p->rule);
+    MyFree(p);
+  }
+  cruleConfList = 0;
+}
+
+const struct CRuleConf* conf_get_crule_list(void)
+{
+  return cruleConfList;
+}
+
+void conf_add_server(const char* const* fields, int count)
+{
+  struct ServerConf* server;
+  struct in_addr    addr;
+  assert(0 != fields);
+  /*
+   * missing host, password, or alias?
+   */
+  if (count < 6 || EmptyString(fields[1]) || EmptyString(fields[2]) || EmptyString(fields[3]))
+    return;
+  /*
+   * check the host
+   */
+  if (string_is_hostname(fields[1]))
+    addr.s_addr = INADDR_NONE;
+  else if (INADDR_NONE == (addr.s_addr = inet_addr(fields[1])))
+    return;
 
-  conf->next = *list;
-  *list = conf;
+  server = (struct ServerConf*) MyMalloc(sizeof(struct ServerConf));
+  assert(0 != server);
+  DupString(server->hostname, fields[1]);
+  DupString(server->passwd,   fields[2]);
+  DupString(server->alias,    fields[3]);
+  server->address.s_addr = addr.s_addr;
+  server->port           = atoi(fields[4]);
+  server->dns_pending    = 0;
+  server->connected      = 0;
+  server->hold           = 0;
+  server->conn_class      = find_class(atoi(fields[5]));
+
+  server->next = serverConfList;
+  serverConfList = server;
+
+  // if (INADDR_NONE == server->address.s_addr)
+    // lookup_confhost(server);
 }
 
-void erase_motd_conf_list(struct MotdConf** list)
+void conf_add_deny(const char* const* fields, int count, int ip_kill)
 {
-  struct MotdConf* p;
-  struct MotdConf* next;
+  struct DenyConf* conf;
+
+  if (count < 4 || EmptyString(fields[1]) || EmptyString(fields[3]))
+    return;
+  
+  conf = (struct DenyConf*) MyMalloc(sizeof(struct DenyConf));
+  assert(0 != conf);
+  memset(conf, 0, sizeof(struct DenyConf));
+
+  DupString(conf->hostmask, fields[1]);
+  collapse(conf->hostmask);
 
-  assert(0 != list);
+  if (!EmptyString(fields[2])) {
+    const char* p = fields[2];
+    if ('!' == *p) {
+      conf->is_file = 1;
+      ++p;
+    }
+    DupString(conf->message, p);
+  }
+  DupString(conf->usermask, fields[3]);
+  collapse(conf->usermask);
 
-  for (p = *list; p; p = next) {
+  if (ip_kill) {
+    /* 
+     * Here we use the same kludge as in listener.c to parse
+     * a.b.c.d, or a.b.c.*, or a.b.c.d/e.
+     */
+    int  c_class;
+    char ipname[16];
+    int  ad[4] = { 0 };
+    int  bits2 = 0;
+    c_class = sscanf(conf->hostmask, "%d.%d.%d.%d/%d",
+                     &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
+    if (c_class != 5) {
+      conf->bits = c_class * 8;
+    }
+    else {
+      conf->bits = bits2;
+    }
+    sprintf_irc(ipname, "%d.%d.%d.%d", ad[0], ad[1], ad[2], ad[3]);
+    
+    /*
+     * This ensures endian correctness
+     */
+    conf->s_addr = inet_addr(ipname);
+    Debug((DEBUG_DEBUG, "IPkill: %s = %08x/%i (%08x)", ipname,
+           conf->s_addr, conf->bits, NETMASK(conf->bits)));
+  }
+  conf->next = denyConfList;
+  denyConfList = conf;
+}
+
+void conf_erase_deny_list(void)
+{
+  struct DenyConf* next;
+  struct DenyConf* p = denyConfList;
+  for ( ; p; p = next) {
     next = p->next;
     MyFree(p->hostmask);
-    MyFree(p->path);
+    MyFree(p->usermask);
+    MyFree(p->message);
     MyFree(p);
   }
-  *list = 0;
+  denyConfList = 0;
 }
-
-const struct MotdConf* conf_get_motd_list(void)
+const struct DenyConf* conf_get_deny_list(void)
 {
-  return motdConfList;
+  return denyConfList;
 }
 
 /*
@@ -816,7 +953,7 @@ int read_configuration_file(void)
     
     if (':' != line[1]) {
       Debug((DEBUG_ERROR, "Bad config line: %s", line));
-      sendto_op_mask(SNO_OLDSNO,"Bad Config line");
+      sendto_opmask_butone(0, SNO_OLDSNO,"Bad Config line");
       continue;
     }
 
@@ -873,7 +1010,10 @@ int read_configuration_file(void)
           quoted = 0;
         else
           quoted = 1;
-        *dest++ = *src++;
+        /*
+         * strip quotes
+         */
+        ++src;
         break;
       case ':':
         if (quoted)
@@ -917,12 +1057,19 @@ int read_configuration_file(void)
       aconf->status = CONF_SERVER;
       break;
       /* Connect rule */
-    case 'D':
-      aconf->status = CONF_CRULEALL;
+    case 'D':  /* CONF_CRULEALL */
+      conf_add_crule(field_vector, field_count, CRULE_ALL);
+      aconf->status = CONF_ILLEGAL;
       break;
       /* Connect rule - autos only */
-    case 'd':
-      aconf->status = CONF_CRULEAUTO;
+    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':
@@ -933,10 +1080,12 @@ int read_configuration_file(void)
       aconf->status = CONF_CLIENT;
       break;
     case 'K':                /* Kill user line on irc.conf           */
-      aconf->status = CONF_KILL;
+      conf_add_deny(field_vector, field_count, 0);
+      aconf->status = CONF_ILLEGAL;
       break;
     case 'k':                /* Kill user line based on IP in ircd.conf */
-      aconf->status = CONF_IPKILL;
+      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  */
@@ -947,8 +1096,9 @@ int read_configuration_file(void)
       /* Me. Host field is name used for this host */
       /* and port number is the number of the port */
     case 'M':
-    case 'm':
-      aconf->status = CONF_ME;
+    case 'm':        /* CONF_ME */
+      conf_add_local(field_vector, field_count);
+      aconf->status = CONF_ILLEGAL;
       break;
     case 'O':
       aconf->status = CONF_OPERATOR;
@@ -964,7 +1114,7 @@ int read_configuration_file(void)
       break;
     case 'T':                /* print out different motd's */
     case 't':                /* based on hostmask - CONF_TLINES */
-      conf_add_motd(field_vector, field_count, &motdConfList);
+      motd_add(field_vector[1], field_vector[2]);
       aconf->status = CONF_ILLEGAL;
       break;
     case 'U':      /* Underworld server, allowed to hack modes */
@@ -978,7 +1128,8 @@ int read_configuration_file(void)
       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]);
+      sendto_opmask_butone(0, SNO_OLDSNO, "Unknown prefix in config file: %c",
+                          *field_vector[0]);
       aconf->status = CONF_ILLEGAL;
       break;
     }
@@ -997,27 +1148,16 @@ int read_configuration_file(void)
     if (field_count > 4 && !EmptyString(field_vector[4]))
         aconf->port = atoi(field_vector[4]); 
 
-    if (field_count > 5 && !EmptyString(field_vector[5])) {
-      int n = atoi(field_vector[5]);
-      if (CONF_ME == (aconf->status & CONF_ME))
-        SetYXXServerName(&me, n);        /* Our Numeric Nick */
-      else
-        aconf->confClass = find_class(n);
-    }
-    else if (CONF_ME == (aconf->status & CONF_ME)) {
-      Debug((DEBUG_FATAL, "Your M: line must have the Numeric, "
-             "assigned to you by routing-com!\n"));
-      ircd_log(L_WARNING, "Your M: line must have the Numeric, "
-              "assigned to you by routing-com!\n");
-      exit(-1);
-    }
+    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->confClass == 0)
-        aconf->confClass = find_class(0);
+      if (aconf->conn_class == 0)
+        aconf->conn_class = find_class(0);
     }
     if (aconf->status & CONF_CLIENT) {
       struct ConfItem *bconf;
@@ -1034,8 +1174,8 @@ int read_configuration_file(void)
           aconf->passwd = 0;
 
           ConfLinks(bconf) -= bconf->clients;
-          bconf->confClass = aconf->confClass;
-          if (bconf->confClass)
+          bconf->conn_class = aconf->conn_class;
+          if (bconf->conn_class)
             ConfLinks(bconf) += bconf->clients;
         }
         free_conf(aconf);
@@ -1055,7 +1195,7 @@ int read_configuration_file(void)
         len += strlen(aconf->host);
         newhost = (char*) MyMalloc(len);
         assert(0 != newhost);
-       ircd_snprintf(0, newhost, len, "*@%s", aconf->host);
+        ircd_snprintf(0, newhost, len, "*@%s", aconf->host);
         MyFree(aconf->host);
         aconf->host = newhost;
       }
@@ -1065,54 +1205,6 @@ int read_configuration_file(void)
         continue;
       lookup_confhost(aconf);
     }
-
-    /* Create expression tree from connect rule...
-     * If there's a parsing error, nuke the conf structure */
-    if (aconf->status & (CONF_CRULEALL | CONF_CRULEAUTO)) {
-      MyFree(aconf->passwd);
-      if ((aconf->passwd = (char *)crule_parse(aconf->name)) == NULL) {
-        free_conf(aconf);
-        aconf = NULL;
-        continue;
-      }
-    }
-
-    /*
-     * Own port and name cannot be changed after the startup.
-     * (or could be allowed, but only if all links are closed first).
-     * Configuration info does not override the name and port
-     * if previously defined. Note, that "info"-field can be
-     * changed by "/rehash".
-     */
-    if (aconf->status == CONF_ME) {
-      ircd_strncpy(me.info, aconf->name, REALLEN);
-    }
-    
-    if (aconf->status == CONF_IPKILL) {
-      /* 
-       * Here we use the same kludge as in listener.c to parse
-       * a.b.c.d, or a.b.c.*, or a.b.c.d/e.
-       */
-      int class;
-      char ipname[16];
-      int ad[4] = { 0 };
-      int bits2=0;
-      class=sscanf(aconf->host,"%d.%d.%d.%d/%d",
-                   &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
-      if (class!=5) {
-        aconf->bits=class*8;
-      }
-      else {
-        aconf->bits=bits2;
-      }
-      sprintf_irc(ipname,"%d.%d.%d.%d",ad[0], ad[1], ad[2], ad[3]);
-      
-      /* This ensures endian correctness */
-      aconf->ipnum.s_addr = inet_addr(ipname);
-      Debug((DEBUG_DEBUG,"IPkill: %s = %08x/%i (%08x)",ipname,
-       aconf->ipnum.s_addr,aconf->bits,NETMASK(aconf->bits)));
-    }
-
     /*
      * Juped nicks are listed in the 'password' field of U:lines,
      * the list is comma separated and might be empty and/or contain
@@ -1127,7 +1219,7 @@ int read_configuration_file(void)
     Debug((DEBUG_NOTICE,
         "Read Init: (%d) (%s) (%s) (%s) (%u) (%p)",
         aconf->status, aconf->host, aconf->passwd,
-        aconf->name, aconf->port, aconf->confClass));
+        aconf->name, aconf->port, aconf->conn_class));
     aconf->next = GlobalConfList;
     GlobalConfList = aconf;
     aconf = NULL;
@@ -1135,7 +1227,6 @@ int read_configuration_file(void)
   if (aconf)
     free_conf(aconf);
   fbclose(file);
-  check_class();
   nextping = nextconnect = CurrentTime;
   return 1;
 }
@@ -1151,16 +1242,14 @@ int rehash(struct Client *cptr, int sig)
 {
   struct ConfItem** tmp = &GlobalConfList;
   struct ConfItem*  tmp2;
-  struct ConfClass* cltmp;
   struct Client*    acptr;
-  struct MotdItem*  temp;
   int               i;
   int               ret = 0;
   int               found_g = 0;
 
   if (1 == sig)
     sendto_opmask_butone(0, SNO_OLDSNO,
-                        "Got signal SIGHUP, reloading ircd conf. file");
+                         "Got signal SIGHUP, reloading ircd conf. file");
 
   while ((tmp2 = *tmp)) {
     if (tmp2->clients) {
@@ -1170,30 +1259,22 @@ int rehash(struct Client *cptr, int sig)
        * that it will be deleted when the last client
        * exits...
        */
-      if (!(tmp2->status & CONF_CLIENT)) {
+      if (CONF_CLIENT == (tmp2->status & CONF_CLIENT))
+        tmp = &tmp2->next;
+      else {
         *tmp = tmp2->next;
         tmp2->next = 0;
       }
-      else
-        tmp = &tmp2->next;
       tmp2->status |= CONF_ILLEGAL;
     }
     else {
       *tmp = tmp2->next;
-      /* free expression trees of connect rules */
-      if ((tmp2->status & (CONF_CRULEALL | CONF_CRULEAUTO)) &&
-          (tmp2->passwd != NULL))
-        crule_free(&(tmp2->passwd));
       free_conf(tmp2);
     }
   }
-  erase_motd_conf_list(&motdConfList);
-  /*
-   * We don't delete the class table, rather mark all entries
-   * for deletion. The table is cleaned up by check_class(). - avalon
-   */
-  for (cltmp = NextClass(FirstClass()); cltmp; cltmp = NextClass(cltmp))
-    MarkDelete(cltmp);
+  conf_erase_crule_list();
+  conf_erase_deny_list();
+  motd_clear();
 
   /*
    * delete the juped nicks list
@@ -1203,30 +1284,28 @@ int rehash(struct Client *cptr, int sig)
   if (sig != 2)
     flush_resolver_cache();
 
+  class_mark_delete();
   mark_listeners_closing();
 
-  if (!read_configuration_file())        /* This calls check_class(), */
-    check_class();         /* unless it fails */
+  read_configuration_file();
+
+  log_reopen(); /* reopen log files */
 
-  /*
-   * make sure that the server listener is re-added so it doesn't get
-   * closed
-   */
   close_listeners();
+  class_delete_marked();         /* unless it fails */
 
   /*
    * Flush out deleted I and P lines although still in use.
    */
   for (tmp = &GlobalConfList; (tmp2 = *tmp);) {
-    if (!(tmp2->status & CONF_ILLEGAL))
-      tmp = &tmp2->next;
-    else
-    {
+    if (CONF_ILLEGAL == (tmp2->status & CONF_ILLEGAL)) {
       *tmp = tmp2->next;
       tmp2->next = NULL;
       if (!tmp2->clients)
         free_conf(tmp2);
     }
+    else
+      tmp = &tmp2->next;
   }
   for (i = 0; i <= HighestFd; i++) {
     if ((acptr = LocalClientArray[i])) {
@@ -1243,38 +1322,21 @@ int rehash(struct Client *cptr, int sig)
        */
       if ((found_g = find_kill(acptr))) {
         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));
+                             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));
         if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" :
             "K-lined") == CPTR_KILLED)
           ret = CPTR_KILLED;
       }
     }
   }
-  /* 
-   * free old motd structs
-   */
-  while (motd) {
-    temp = motd->next;
-    MyFree(motd);
-    motd = temp;
-  }
-  while (rmotd) {
-    temp = rmotd->next;
-    MyFree(rmotd);
-    rmotd = temp;
-  }
-  /* reload motd files */
-  read_tlines();
-  rmotd = read_motd(RPATH);
-  motd = read_motd(MPATH);
   return ret;
 }
 
 /*
- * conf_init
+ * init_conf
  *
  * Read configuration file.
  *
@@ -1282,7 +1344,7 @@ int rehash(struct Client *cptr, int sig)
  *         1, if file read
  */
 
-int conf_init(void)
+int init_conf(void)
 {
   if (read_configuration_file()) {
     /*
@@ -1291,6 +1353,9 @@ int conf_init(void)
      * XXX - should any of these abort the server?
      * TODO: add warning messages
      */
+    if (0 == localConf.name || 0 == localConf.numeric)
+      return 0;
+
     if (0 == localConf.location1)
       DupString(localConf.location1, "");
     if (0 == localConf.location2)
@@ -1303,48 +1368,6 @@ int conf_init(void)
   return 0;
 }
 
-
-/* read_tlines 
- * Read info from T:lines into TRecords which include the file 
- * timestamp, the hostmask, and the contents of the motd file 
- * -Ghostwolf 7sep97
- */
-void read_tlines()
-{
-  struct MotdConf* conf;
-  struct TRecord *temp;
-  struct TRecord *last = NULL;        /* Init. to avoid compiler warning */
-  struct MotdItem *amotd;
-
-  /* Free the old trecords and the associated motd contents first */
-  while (tdata) {
-    last = tdata->next;
-    while (tdata->tmotd) {
-      amotd = tdata->tmotd->next;
-      MyFree(tdata->tmotd);
-      tdata->tmotd = amotd;
-    }
-    MyFree(tdata);
-    tdata = last;
-  }
-
-  for (conf = motdConfList; conf; conf = conf->next) {
-    temp = (struct TRecord*) MyMalloc(sizeof(struct TRecord));
-    assert(0 != temp);
-
-    temp->hostmask = conf->hostmask;
-    temp->tmotd = read_motd(conf->path);
-    temp->tmotd_tm = motd_tm;
-    temp->next = 0;
-
-    if (!tdata)
-      tdata = temp;
-    else
-      last->next = temp;
-    last = temp;
-  }
-}
-
 /*
  * find_kill
  * input:
@@ -1360,16 +1383,16 @@ int find_kill(struct Client *cptr)
 {
   const char*      host;
   const char*      name;
-  struct ConfItem* tmp;
+  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;
 
   assert(strlen(host) <= HOSTLEN);
   assert((name ? strlen(name) : 0) <= HOSTLEN);
@@ -1377,66 +1400,44 @@ int find_kill(struct Client *cptr)
   /* 2000-07-14: Rewrote this loop for massive speed increases.
    *             -- Isomer
    */
-  for (tmp = GlobalConfList; tmp; tmp = tmp->next) {
-  
-    if ((tmp->status & CONF_KLINE) == 0)
-       continue;
-       
-    /*
-     * What is this for?  You can K: by port?!
-     *   -- Isomer
-     */
-    if (tmp->port && tmp->port != cptr->listener->port)
-       continue;
-
-    if (!tmp->name || match(tmp->name, name) != 0)
-       continue;
-       
-    if (!tmp->host)
-       break;
+  for (deny = denyConfList; deny; deny = deny->next) {
+    if (0 != match(deny->usermask, name))
+      continue;
+            
+    if (EmptyString(deny->hostmask))
+      break;
     
-    if (tmp->status != CONF_IPKILL) {
-       if (match(tmp->host, host) == 0)
-         break;
-    }
-    else { /* k: by IP */
-       Debug((DEBUG_DEBUG, "ip: %08x network: %08x/%i mask: %08x",
-               cptr->ip.s_addr, tmp->ipnum.s_addr, tmp->bits, 
-               NETMASK(tmp->bits)));
-       if ((cptr->ip.s_addr & NETMASK(tmp->bits)) == tmp->ipnum.s_addr)
-               break;
+    if (deny->ip_kill) { /* k: by IP */
+      Debug((DEBUG_DEBUG, "ip: %08x network: %08x/%i mask: %08x",
+             cli_ip(cptr).s_addr, deny->s_addr, deny->bits, NETMASK(deny->bits)));
+      if ((cli_ip(cptr).s_addr & NETMASK(deny->bits)) == deny->s_addr)
+        break;
     }
+    else if (0 == match(deny->hostmask, host))
+      break;
   }
-  if (tmp) {
-    if (EmptyString(tmp->passwd))
+  if (deny) {
+    if (EmptyString(deny->message))
       send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
-                ":Connection from your host is refused on this server.");
+                 ":Connection from your host is refused on this server.");
     else {
-      if (*tmp->passwd == '"') {
-       send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%*s.",
-                  strlen(tmp->passwd + 1) - 1, tmp->passwd + 1);
-      }
-      else if (*tmp->passwd == '!')
-        killcomment(cptr, cptr->name, &tmp->passwd[1]);
+      if (deny->is_file)
+        killcomment(cptr, deny->message);
       else
-#ifdef COMMENT_IS_FILE
-        killcomment(cptr, cptr->name, tmp->passwd);
-#else
-       send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.",
-                  tmp->passwd);
-#endif
+        send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", deny->message);
     }
   }
-
-  /* find active glines */
-  /* added a check against the user's IP address to find_gline() -Kev */
-  else if ((agline = gline_lookup(cptr, 0)) && GlineIsActive(agline))
-    send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.",
-              GlineReason(agline));
+  else if ((agline = gline_lookup(cptr, 0)) && GlineIsActive(agline)) {
+    /*
+     * 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 = NULL;                /* if a gline was found, it was inactive */
+    agline = 0;          /* if a gline was found, it was inactive */
 
-  if (tmp)
+  if (deny)
     return -1;
   if (agline)
     return -2;
@@ -1444,46 +1445,6 @@ int find_kill(struct Client *cptr)
   return 0;
 }
 
-struct MotdItem* read_motd(const char* motdfile)
-{
-  FBFILE*          file = NULL;
-  struct MotdItem* temp;
-  struct MotdItem* newmotd;
-  struct MotdItem* last;
-  struct stat      sb;
-  char             line[80];
-  char*            tmp;
-
-  if (NULL == (file = fbopen(motdfile, "r"))) {
-    Debug((DEBUG_ERROR, "Couldn't open \"%s\": %s", motdfile, strerror(errno)));
-    return NULL;
-  }
-  if (-1 == fbstat(&sb, file)) {
-    fbclose(file);
-    return NULL;
-  }
-  newmotd = last = NULL;
-  motd_tm = *localtime((time_t *) & sb.st_mtime);        /* NetBSD needs cast */
-  while (fbgets(line, sizeof(line) - 1, file)) {
-    if ((tmp = (char *)strchr(line, '\n')))
-      *tmp = '\0';
-    if ((tmp = (char *)strchr(line, '\r')))
-      *tmp = '\0';
-    temp = (struct MotdItem*) MyMalloc(sizeof(struct MotdItem));
-    assert(0 != temp);
-    strcpy(temp->line, line);
-    temp->next = NULL;
-    if (!newmotd)
-      newmotd = temp;
-    else
-      last->next = temp;
-    last = temp;
-  }
-  fbclose(file);
-  return newmotd;
-}
-
-
 /*
  * Ordinary client access check. Look for conf lines which have the same
  * status as the flags passed.
@@ -1496,7 +1457,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;
@@ -1522,23 +1483,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;
     }
@@ -1547,9 +1508,9 @@ int conf_check_server(struct Client *cptr)
   ClearAccess(cptr);
 
   if (!c_conf) {
-    if (cptr->dns_reply) {
+    if (cli_dns_reply(cptr)) {
       int             i;
-      struct hostent* hp = cptr->dns_reply->hp;
+      struct hostent* hp = cli_dns_reply(cptr)->hp;
       const char*     name = hp->h_name;
       /*
        * If we are missing a C or N line from above, search for
@@ -1557,7 +1518,7 @@ int conf_check_server(struct Client *cptr)
        */
       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);
+          ircd_strncpy(cli_sockhost(cptr), name, HOSTLEN);
           break;
         }
       }
@@ -1574,7 +1535,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);
     }
   }
   /*
@@ -1583,7 +1544,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()
    */
@@ -1593,20 +1554,20 @@ 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;
 }