2004-05-09 Michael Poole <mdpoole@troilus.org>
[ircu2.10.12-pk.git] / ircd / s_conf.c
index 21fa6aca7c8e904a09928dc23f973bbc3d2d0e1d..7733c9f8e26cfc01e277db2ade0bcf73311db099 100644 (file)
 #include <errno.h>
 #include <fcntl.h>
 #include <netdb.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <stdio.h>
 
 #ifndef INADDR_NONE
 #define INADDR_NONE 0xffffffff
 #endif
 
-struct ConfItemGlobalConfList  = 0;
+struct ConfItem  *GlobalConfList  = 0;
 int              GlobalConfCount = 0;
+struct s_map     *GlobalServiceMapList = 0;
+struct qline     *GlobalQuarantineList = 0;
 
 void yyparse(void);
 int conf_fd, lineno;
@@ -201,12 +203,15 @@ 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 hostent* 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) {
+    memcpy(&aconf->ipnum, hp->h_addr, sizeof(struct in_addr));
+    MyFree(hp);
+  }
 }
 
 /*
@@ -214,9 +219,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;
@@ -225,10 +229,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;
 }
 
 
@@ -238,10 +241,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.
  */
-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));
@@ -262,8 +264,8 @@ 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);
 }
 
 /*
@@ -373,7 +375,7 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
   assert(0 != cptr);
 
   if (cli_dns_reply(cptr))
-    hp = cli_dns_reply(cptr)->hp;
+    hp = cli_dns_reply(cptr);
 
   for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
     if (aconf->status != CONF_CLIENT)
@@ -399,7 +401,7 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
         uhost[sizeof(uhost) - 1] = 0;
         if (0 == match(aconf->name, uhost)) {
           if (strchr(uhost, '@'))
-            cli_flags(cptr) |= FLAGS_DOID;
+            SetFlag(cptr, FLAG_DOID);
           return check_limit_and_attach(cptr, aconf);
         }
       }
@@ -416,7 +418,7 @@ enum AuthorizationCheckResult attach_iline(struct Client*  cptr)
     if (match(aconf->host, uhost))
       continue;
     if (strchr(uhost, '@'))
-      cli_flags(cptr) |= FLAGS_DOID;
+      SetFlag(cptr, FLAG_DOID);
 
     return check_limit_and_attach(cptr, aconf);
   }
@@ -922,6 +924,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
  *
@@ -933,11 +972,14 @@ 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)
 {
+  conf_error = 0;
   feature_unmark(); /* unmark all features for resetting later */
   /* Now just open an fd. The buffering isn't really needed... */
   init_lexer();
@@ -945,6 +987,7 @@ int read_configuration_file(void)
   fclose(yyin);
   yyin = NULL;
   feature_mark(); /* reset unmarked features */
+  conf_already_read = 1;
   return 1;
 }
 
@@ -955,6 +998,9 @@ yyerror(const char *msg)
                       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;
 }
 
 /*
@@ -1008,7 +1054,7 @@ int rehash(struct Client *cptr, int sig)
   clearNickJupes();
 
   if (sig != 2)
-    flush_resolver_cache();
+    restart_resolver();
 
   class_mark_delete();
   mark_listeners_closing();
@@ -1083,6 +1129,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, "");
@@ -1090,7 +1138,7 @@ int init_conf(void)
       DupString(localConf.location2, "");
     if (0 == localConf.contact)
       DupString(localConf.contact, "");
-    
+
     return 1;
   }
   return 0;
@@ -1244,7 +1292,7 @@ int conf_check_server(struct Client *cptr)
   if (!c_conf) {
     if (cli_dns_reply(cptr)) {
       int             i;
-      struct hostent* hp = cli_dns_reply(cptr)->hp;
+      struct hostent* hp = cli_dns_reply(cptr);
       const char*     name = hp->h_name;
       /*
        * If we are missing a C or N line from above, search for
@@ -1301,7 +1349,8 @@ int conf_check_server(struct Client *cptr)
   if (INADDR_NONE == c_conf->ipnum.s_addr)
     c_conf->ipnum.s_addr = cli_ip(cptr).s_addr;
 
-  Debug((DEBUG_DNS, "sv_cl: access ok: %s[%s]", cli_name(cptr), cli_sockhost(cptr)));
+  Debug((DEBUG_DNS, "sv_cl: access ok: %s[%s]",
+         cli_name(cptr), cli_sockhost(cptr)));
   return 0;
 }