Author: Andres Miller <a1kmm@mware.virtualave.net>
[ircu2.10.12-pk.git] / ircd / s_conf.c
index 06beff8ac31fde726c877181ede6e38e7efc265d..d1677b1abb44d330302af9f78036db268a602d3f 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"
@@ -49,7 +50,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"
@@ -59,7 +59,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <netdb.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 struct ConfItem* GlobalConfList  = 0;
 int              GlobalConfCount = 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
@@ -235,7 +237,7 @@ 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;
 
@@ -626,6 +628,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 +651,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 +664,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.
@@ -781,6 +780,7 @@ void conf_add_crule(const char* const* fields, int count, int type)
     cruleConfList = p;
   } 
 }
+#endif
 
 void conf_erase_crule_list(void)
 {
@@ -802,6 +802,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 +836,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 +851,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 +885,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)
 {
@@ -926,26 +934,14 @@ const struct DenyConf* conf_get_deny_list(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;
-  }
-
   feature_unmark(); /* unmark all features for resetting later */
-
+  /* Now just open an fd. The buffering isn't really needed... */
+  if ((conf_fd = open(configfile, O_RDONLY)) < 0)
+   return 0;
+  lineno = 1;
+  yyparse();
+  close(conf_fd);
+#if 0
   while (fbgets(line, sizeof(line) - 1, file)) {
     if ('#' == *line || IsSpace(*line))
       continue;
@@ -1229,11 +1225,21 @@ int read_configuration_file(void)
   if (aconf)
     free_conf(aconf);
   fbclose(file);
-  nextping = nextconnect = CurrentTime;
+/*    nextping = nextconnect = CurrentTime; */
+#endif
   feature_mark(); /* reset unmarked features */
   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);
+}
+
 /*
  * rehash
  *
@@ -1310,6 +1316,7 @@ int rehash(struct Client *cptr, int sig)
     else
       tmp = &tmp2->next;
   }
+
   for (i = 0; i <= HighestFd; i++) {
     if ((acptr = LocalClientArray[i])) {
       assert(!IsMe(acptr));
@@ -1335,6 +1342,7 @@ int rehash(struct Client *cptr, int sig)
       }
     }
   }
+
   return ret;
 }
 
@@ -1386,6 +1394,7 @@ int find_kill(struct Client *cptr)
 {
   const char*      host;
   const char*      name;
+  const char*      realname;
   struct DenyConf* deny;
   struct Gline*    agline = NULL;
 
@@ -1396,24 +1405,29 @@ int find_kill(struct Client *cptr)
 
   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, realname))
+       break;
+    } else if (deny->flags & DENY_FLAGS_IP) { /* 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)
+             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))
@@ -1424,7 +1438,7 @@ 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);