Author: Bleep <helveytw@home.com>
authorBleep <twhelvey1@home.com>
Sat, 16 Sep 2000 05:35:02 +0000 (05:35 +0000)
committerBleep <twhelvey1@home.com>
Sat, 16 Sep 2000 05:35:02 +0000 (05:35 +0000)
Log message: Add CRuleConf struct and support code, change state machine
to strip quotes from quoted strings, fixup code that depended on changes,
tested the whole mess.

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@289 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

14 files changed:
ChangeLog
include/crule.h
include/s_conf.h
include/s_stats.h
ircd/chkconf.c
ircd/crule.c
ircd/ircd.c
ircd/m_connect.c
ircd/m_server.c
ircd/m_stats.c
ircd/opercmds.c
ircd/s_conf.c
ircd/s_serv.c
ircd/s_stats.c

index 60e786177045c32d3d644c7dcabb708c05a60e75..31c59e74befa34190edddeb0a35d3a52695590e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2000-09-16  Thomas Helvey <helveytw@home.com>
+       * ircd/s_conf.c: add code for new crule data structs, strip quotes
+       * ircd/crule.c: clean up scary casting a bit, type safety stuff
+       * include/s_conf.h: add CRuleConf struct and support, remove
+       unused constants
+       * include/crule.h: type safety cleanups
+       * ircd/*.c: fixup code that depended on stuff I changed
+
 2000-09-15  Thomas Helvey <helveytw@home.com>
        * ircd/s_conf.c: start adding code for new conf data structs, changed
        listeners, admin line, motd lines, class lines. Move validate_hostent
 #
 # ChangeLog for ircu2.10.11
 #
-# $Id: ChangeLog,v 1.162 2000-09-15 07:27:08 bleep Exp $
+# $Id: ChangeLog,v 1.163 2000-09-16 05:35:01 bleep Exp $
 #
 # Insert new changes at beginning of the change list.
 #
index 38a7a89d0ffa0b95883a12dd44bf139ca688f11c..ccea385f219fcac194a9b8727476effaff7f30cb 100644 (file)
  * Proto types
  */
 
-extern void crule_free(char **elem);
-extern int crule_eval(char *rule);
-extern char *crule_parse(char *rule);
+/*
+ * opaque node pointer
+ */
+struct CRuleNode;
+
+extern void crule_free(struct CRuleNode** elem);
+extern int crule_eval(struct CRuleNode* rule);
+extern struct CRuleNode* crule_parse(const char* rule);
 
 #endif /* INCLUDED_crule_h */
index b969f4df3b37a3f6203b9b49a1eab9ba6bcf32ab..6fb618acf0c2fb82df3c6febbb9821ff751dada4 100644 (file)
@@ -40,20 +40,13 @@ struct hostent;
 #define CONF_OPERATOR           0x0020
 #define CONF_ME                 0x0040
 #define CONF_KILL               0x0080
-#define CONF_ADMIN              0x0100
-#define CONF_CLASS              0x0400
 #define CONF_LEAF               0x1000
-#define CONF_LISTEN_PORT        0x2000
 #define CONF_HUB                0x4000
 #define CONF_UWORLD             0x8000
-#define CONF_CRULEALL           0x00200000
-#define CONF_CRULEAUTO          0x00400000
-#define CONF_TLINES             0x00800000
 #define CONF_IPKILL             0x00010000
 
 #define CONF_OPS                (CONF_OPERATOR | CONF_LOCOP)
 #define CONF_CLIENT_MASK        (CONF_CLIENT | CONF_OPS | CONF_SERVER)
-#define CONF_CRULE              (CONF_CRULEALL | CONF_CRULEAUTO)
 #define CONF_KLINE              (CONF_KILL | CONF_IPKILL)
 
 #define IsIllegal(x)    ((x)->status & CONF_ILLEGAL)
@@ -100,7 +93,23 @@ struct MotdConf {
   char* path;
   struct MotdConf* next;
 };
-  
+
+enum {
+  CRULE_AUTO = 1,
+  CRULE_ALL  = 2,
+  CRULE_MASK = 3
+};
+
+struct CRuleNode;
+
+struct CRuleConf {
+  char*             hostmask;
+  char*             rule;
+  int               type;
+  struct CRuleNode* node;
+  struct CRuleConf* next;
+};
+
 struct TRecord {
   char *hostmask;
   struct MotdItem *tmotd;
@@ -132,7 +141,10 @@ extern struct TRecord*  tdata;
  */
 
 extern const struct LocalConf* conf_get_local(void);
-extern const struct MotdConf* conf_get_motd_list(void);
+extern const struct MotdConf*  conf_get_motd_list(void);
+extern const struct CRuleConf* conf_get_crule_list(void);
+
+extern const char* conf_crule_eval(const char* host, int mask);
 
 extern struct ConfItem* attach_confs_byhost(struct Client* cptr, 
                                             const char* host, int statmask);
@@ -141,7 +153,7 @@ extern struct ConfItem* find_conf_byhost(struct SLink* lp, const char* host,
 extern struct ConfItem* find_conf_byname(struct SLink* lp, const char *name,
                                          int statmask);
 extern struct ConfItem* conf_find_server(const char* name);
-const char* conf_eval_crule(struct ConfItem* conf);
+const char* conf_eval_crule(const char* name, int mask);
 
 extern void det_confs_butmask(struct Client *cptr, int mask);
 extern int detach_conf(struct Client *cptr, struct ConfItem *aconf);
index c428e2970cb6b95a81c669adba9998b503ca6063..58db90a26fcf4d077b1312eaa260e4281b310de2 100644 (file)
@@ -31,5 +31,7 @@ extern const char *statsinfo[];
 extern void report_stats(struct Client *sptr, char stat);
 extern void report_configured_links(struct Client *sptr, int mask);
 extern int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat);
+extern void report_crule_list(struct Client* to, int mask);
+extern void report_motd_list(struct Client* to);
 
 #endif /* INCLUDED_s_stats_h */
index 0799206ef96215dfd79d51c1ad92cbec0548246a..35383670e85495bd4b2cf8b76c6a4575e0e813dc 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 
+/*
+ * stuff that isn't used by s_conf.c anymore
+ */
+#define CONF_ADMIN              0x0100
+#define CONF_CLASS              0x0400
+#define CONF_LISTEN_PORT        0x2000
+#define CONF_CRULEALL           0x00200000
+#define CONF_CRULEAUTO          0x00400000
+#define CONF_TLINES             0x00800000
+
+
+#define CONF_CRULE              (CONF_CRULEALL | CONF_CRULEAUTO)
+
 
 /*
  * For the connect rule patch..  these really should be in a header,
  * but i see h.h isn't included for some reason..  so they're here.
  */
-char *crule_parse(char *rule);
-void crule_free(char **elem);
+struct CRuleNode;
+
+struct CRuleNode* crule_parse(const char* rule);
+void crule_free(struct CRuleNode** elem);
 
 static void new_class(int cn);
 static char confchar(unsigned int status);
@@ -145,7 +160,9 @@ int main(int argc, char *argv[])
 static struct ConfItem *chk_initconf(void)
 {
   FBFILE *file;
-  char line[512], *tmp, *crule;
+  char line[512];
+  char *tmp;
+  struct CRuleNode* crule;
   int ccount = 0, flags = 0;
   struct ConfItem *aconf = NULL, *ctop = NULL;
 
@@ -409,7 +426,7 @@ static struct ConfItem *chk_initconf(void)
      *  any allocated storage immediately -- we're just looking
      *  for errors..  */
     if (aconf->status & CONF_CRULE)
-      if ((crule = (char *)crule_parse(aconf->name)) != NULL)
+      if ((crule = crule_parse(aconf->name)) != NULL)
         crule_free(&crule);
 
     if (!aconf->confClass)
index a38dc48455c46c78c9f2b17b10a3a6df1a053bd6..aa27662a6908c3e78d6cc7dea7306788c8ebc766 100644 (file)
@@ -102,15 +102,14 @@ enum crule_errcode {
  */
 typedef int (*crule_funcptr) (int, void **);
 
-struct crule_treestruct {
+struct CRuleNode {
   crule_funcptr funcptr;
   int numargs;
   void *arg[CR_MAXARGS];        /* For operators arg points to a tree element;
                                    for functions arg points to a char string. */
 };
 
-typedef struct crule_treestruct crule_treeelem;
-typedef crule_treeelem *crule_treeptr;
+typedef struct CRuleNode* CRuleNodePtr;
 
 /* local rule function prototypes */
 static int crule_connected(int, void **);
@@ -121,23 +120,23 @@ static int crule__andor(int, void **);
 static int crule__not(int, void **);
 
 /* local parsing function prototypes */
-static int crule_gettoken(int *, char **);
-static void crule_getword(char *, int *, size_t, char **);
-static int crule_parseandexpr(crule_treeptr *, int *, char **);
-static int crule_parseorexpr(crule_treeptr *, int *, char **);
-static int crule_parseprimary(crule_treeptr *, int *, char **);
-static int crule_parsefunction(crule_treeptr *, int *, char **);
-static int crule_parsearglist(crule_treeptr, int *, char **);
+static int crule_gettoken(int* token, const char** str);
+static void crule_getword(char*, int*, size_t, const char**);
+static int crule_parseandexpr(CRuleNodePtr*, int *, const char**);
+static int crule_parseorexpr(CRuleNodePtr*, int *, const char**);
+static int crule_parseprimary(CRuleNodePtr*, int *, const char**);
+static int crule_parsefunction(CRuleNodePtr*, int *, const char**);
+static int crule_parsearglist(CRuleNodePtr, int *, const char**);
 
 #if defined(CR_DEBUG) || defined(CR_CHKCONF)
 /*
  * Prototypes for the test parser; if not debugging,
  * these are defined in h.h
  */
-char *crule_parse(char *);
-void crule_free(char **);
+struct CRuleNode* crule_parse(const char*);
+void crule_free(struct CRuleNode**);
 #ifdef CR_DEBUG
-void print_tree(crule_treeptr);
+void print_tree(CRuleNodePtr);
 #endif
 #endif
 
@@ -264,37 +263,36 @@ static int crule__andor(int numargs, void *crulearg[])
 {
   int result1;
 
-  result1 = ((crule_treeptr) crulearg[0])->funcptr
-      (((crule_treeptr) crulearg[0])->numargs,
-      ((crule_treeptr) crulearg[0])->arg);
+  result1 = ((CRuleNodePtr) crulearg[0])->funcptr
+      (((CRuleNodePtr) crulearg[0])->numargs,
+      ((CRuleNodePtr) crulearg[0])->arg);
   if (crulearg[2])              /* or */
     return (result1 ||
-        ((crule_treeptr) crulearg[1])->funcptr
-        (((crule_treeptr) crulearg[1])->numargs,
-        ((crule_treeptr) crulearg[1])->arg));
+        ((CRuleNodePtr) crulearg[1])->funcptr
+        (((CRuleNodePtr) crulearg[1])->numargs,
+        ((CRuleNodePtr) crulearg[1])->arg));
   else
     return (result1 &&
-        ((crule_treeptr) crulearg[1])->funcptr
-        (((crule_treeptr) crulearg[1])->numargs,
-        ((crule_treeptr) crulearg[1])->arg));
+        ((CRuleNodePtr) crulearg[1])->funcptr
+        (((CRuleNodePtr) crulearg[1])->numargs,
+        ((CRuleNodePtr) crulearg[1])->arg));
 }
 
 static int crule__not(int numargs, void *crulearg[])
 {
-  return (!((crule_treeptr) crulearg[0])->funcptr
-      (((crule_treeptr) crulearg[0])->numargs,
-      ((crule_treeptr) crulearg[0])->arg));
+  return (!((CRuleNodePtr) crulearg[0])->funcptr
+      (((CRuleNodePtr) crulearg[0])->numargs,
+      ((CRuleNodePtr) crulearg[0])->arg));
 }
 
 #if !defined(CR_DEBUG) && !defined(CR_CHKCONF)
-int crule_eval(char *rule)
+int crule_eval(struct CRuleNode* rule)
 {
-  return (((crule_treeptr) rule)->funcptr
-      (((crule_treeptr) rule)->numargs, ((crule_treeptr) rule)->arg));
+  return (rule->funcptr(rule->numargs, rule->arg));
 }
 #endif
 
-static int crule_gettoken(int *next_tokp, char **ruleptr)
+static int crule_gettoken(int* next_tokp, const char** ruleptr)
 {
   char pending = '\0';
 
@@ -351,8 +349,7 @@ static int crule_gettoken(int *next_tokp, char **ruleptr)
   return CR_NOERR;
 }
 
-static void crule_getword(char *word, int *wordlenp, size_t maxlen,
-    char **ruleptr)
+static void crule_getword(char* word, int* wordlenp, size_t maxlen, const char** ruleptr)
 {
   char *word_ptr;
 
@@ -387,22 +384,18 @@ static void crule_getword(char *word, int *wordlenp, size_t maxlen,
  *    word
  *    word , arglist
  */
-char *crule_parse(char *rule)
+struct CRuleNode* crule_parse(const char *rule)
 {
-  char *ruleptr = rule;
+  const char* ruleptr = rule;
   int next_tok;
-  crule_treeptr ruleroot = NULL;
+  struct CRuleNode* ruleroot = 0;
   int errcode = CR_NOERR;
 
-  if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR)
-  {
-    if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr))
-        == CR_NOERR)
-    {
-      if (ruleroot != NULL)
-      {
+  if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) {
+    if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) {
+      if (ruleroot != NULL) {
         if (next_tok == CR_END)
-          return ((char *)ruleroot);
+          return (ruleroot);
         else
           errcode = CR_UNEXPCTTOK;
       }
@@ -411,21 +404,20 @@ char *crule_parse(char *rule)
     }
   }
   if (ruleroot != NULL)
-    crule_free((char **)&ruleroot);
+    crule_free(&ruleroot);
 #if !defined(CR_DEBUG) && !defined(CR_CHKCONF)
   Debug((DEBUG_ERROR, "%s in rule: %s", crule_errstr[errcode], rule));
 #else
   fprintf(stderr, "%s in rule: %s\n", crule_errstr[errcode], rule);
 #endif
-  return NULL;
+  return 0;
 }
 
-static int crule_parseorexpr(crule_treeptr * orrootp, int *next_tokp,
-    char **ruleptr)
+static int crule_parseorexpr(CRuleNodePtr * orrootp, int *next_tokp, const char** ruleptr)
 {
   int errcode = CR_NOERR;
-  crule_treeptr andexpr;
-  crule_treeptr orptr;
+  CRuleNodePtr andexpr;
+  CRuleNodePtr orptr;
 
   *orrootp = NULL;
   while (errcode == CR_NOERR)
@@ -433,7 +425,7 @@ static int crule_parseorexpr(crule_treeptr * orrootp, int *next_tokp,
     errcode = crule_parseandexpr(&andexpr, next_tokp, ruleptr);
     if ((errcode == CR_NOERR) && (*next_tokp == CR_OR))
     {
-      orptr = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+      orptr = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
 #ifdef CR_DEBUG
       fprintf(stderr, "allocating or element at %ld\n", orptr);
 #endif
@@ -476,12 +468,11 @@ static int crule_parseorexpr(crule_treeptr * orrootp, int *next_tokp,
   return (errcode);
 }
 
-static int crule_parseandexpr(crule_treeptr * androotp, int *next_tokp,
-    char **ruleptr)
+static int crule_parseandexpr(CRuleNodePtr * androotp, int *next_tokp, const char** ruleptr)
 {
   int errcode = CR_NOERR;
-  crule_treeptr primary;
-  crule_treeptr andptr;
+  CRuleNodePtr primary;
+  CRuleNodePtr andptr;
 
   *androotp = NULL;
   while (errcode == CR_NOERR)
@@ -489,7 +480,7 @@ static int crule_parseandexpr(crule_treeptr * androotp, int *next_tokp,
     errcode = crule_parseprimary(&primary, next_tokp, ruleptr);
     if ((errcode == CR_NOERR) && (*next_tokp == CR_AND))
     {
-      andptr = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+      andptr = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
 #ifdef CR_DEBUG
       fprintf(stderr, "allocating and element at %ld\n", andptr);
 #endif
@@ -532,10 +523,9 @@ static int crule_parseandexpr(crule_treeptr * androotp, int *next_tokp,
   return (errcode);
 }
 
-static int crule_parseprimary(crule_treeptr * primrootp,
-    int *next_tokp, char **ruleptr)
+static int crule_parseprimary(CRuleNodePtr* primrootp, int *next_tokp, const char** ruleptr)
 {
-  crule_treeptr *insertionp;
+  CRuleNodePtr *insertionp;
   int errcode = CR_NOERR;
 
   *primrootp = NULL;
@@ -547,8 +537,7 @@ static int crule_parseprimary(crule_treeptr * primrootp,
       case CR_OPENPAREN:
         if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
           break;
-        if ((errcode = crule_parseorexpr(insertionp, next_tokp,
-            ruleptr)) != CR_NOERR)
+        if ((errcode = crule_parseorexpr(insertionp, next_tokp, ruleptr)) != CR_NOERR)
           break;
         if (*insertionp == NULL)
         {
@@ -563,14 +552,14 @@ static int crule_parseprimary(crule_treeptr * primrootp,
         errcode = crule_gettoken(next_tokp, ruleptr);
         break;
       case CR_NOT:
-        *insertionp = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+        *insertionp = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
 #ifdef CR_DEBUG
         fprintf(stderr, "allocating primary element at %ld\n", *insertionp);
 #endif
         (*insertionp)->funcptr = crule__not;
         (*insertionp)->numargs = 1;
         (*insertionp)->arg[0] = NULL;
-        insertionp = (crule_treeptr *) & ((*insertionp)->arg[0]);
+        insertionp = (CRuleNodePtr *) & ((*insertionp)->arg[0]);
         if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
           break;
         continue;
@@ -589,8 +578,7 @@ static int crule_parseprimary(crule_treeptr * primrootp,
   return (errcode);
 }
 
-static int crule_parsefunction(crule_treeptr * funcrootp,
-    int *next_tokp, char **ruleptr)
+static int crule_parsefunction(CRuleNodePtr* funcrootp, int* next_tokp, const char** ruleptr)
 {
   int errcode = CR_NOERR;
   char funcname[CR_MAXARGLEN];
@@ -612,7 +600,7 @@ static int crule_parsefunction(crule_treeptr * funcrootp,
     }
     if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
       return (errcode);
-    *funcrootp = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+    *funcrootp = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
 #ifdef CR_DEBUG
     fprintf(stderr, "allocating function element at %ld\n", *funcrootp);
 #endif
@@ -634,8 +622,7 @@ static int crule_parsefunction(crule_treeptr * funcrootp,
     return (CR_EXPCTOPEN);
 }
 
-static int crule_parsearglist(crule_treeptr argrootp, int *next_tokp,
-    char **ruleptr)
+static int crule_parsearglist(CRuleNodePtr argrootp, int *next_tokp, const char** ruleptr)
 {
   int errcode = CR_NOERR;
   char *argelemp = NULL;
@@ -693,55 +680,55 @@ static int crule_parsearglist(crule_treeptr argrootp, int *next_tokp,
  * DO NOT CALL THIS FUNTION WITH A POINTER TO A NULL POINTER
  * (ie: If *elem is NULL, you're doing it wrong - seg fault)
  */
-void crule_free(char **elem)
+void crule_free(struct CRuleNode** elem)
 {
   int arg, numargs;
 
-  if ((*((crule_treeptr *) elem))->funcptr == crule__not)
+  if ((*(elem))->funcptr == crule__not)
   {
     /* type conversions and ()'s are fun! ;)  here have an asprin.. */
-    if ((*((crule_treeptr *) elem))->arg[0] != NULL)
-      crule_free((char **)&((*((crule_treeptr *) elem))->arg[0]));
+    if ((*(elem))->arg[0] != NULL)
+      crule_free((struct CRuleNode**) &((*(elem))->arg[0]));
   }
-  else if ((*((crule_treeptr *) elem))->funcptr == crule__andor)
+  else if ((*(elem))->funcptr == crule__andor)
   {
-    crule_free((char **)&((*((crule_treeptr *) elem))->arg[0]));
-    if ((*((crule_treeptr *) elem))->arg[1] != NULL)
-      crule_free((char **)&((*((crule_treeptr *) elem))->arg[1]));
+    crule_free((struct CRuleNode**) &((*(elem))->arg[0]));
+    if ((*(elem))->arg[1] != NULL)
+      crule_free((struct CRuleNode**) &((*(elem))->arg[1]));
   }
   else
   {
-    numargs = (*((crule_treeptr *) elem))->numargs;
+    numargs = (*(elem))->numargs;
     for (arg = 0; arg < numargs; arg++)
-      MyFree((*((crule_treeptr *) elem))->arg[arg]);
+      MyFree((*(elem))->arg[arg]);
   }
 #ifdef CR_DEBUG
   fprintf(stderr, "freeing element at %ld\n", *elem);
 #endif
   MyFree(*elem);
-  *elem = NULL;
+  *elem = 0;
 }
 
 #ifdef CR_DEBUG
-static void print_tree(crule_treeptr printelem)
+static void print_tree(CRuleNodePtr printelem)
 {
   int funcnum, arg;
 
   if (printelem->funcptr == crule__not)
   {
     printf("!( ");
-    print_tree((crule_treeptr) printelem->arg[0]);
+    print_tree((CRuleNodePtr) printelem->arg[0]);
     printf(") ");
   }
   else if (printelem->funcptr == crule__andor)
   {
     printf("( ");
-    print_tree((crule_treeptr) printelem->arg[0]);
+    print_tree((CRuleNodePtr) printelem->arg[0]);
     if (printelem->arg[2])
       printf("|| ");
     else
       printf("&& ");
-    print_tree((crule_treeptr) printelem->arg[1]);
+    print_tree((CRuleNodePtr) printelem->arg[1]);
     printf(") ");
   }
   else
@@ -770,7 +757,7 @@ static void print_tree(crule_treeptr printelem)
 int main(void)
 {
   char indata[256];
-  char *rule;
+  CRuleNode* rule;
 
   printf("rule: ");
   while (fgets(indata, 256, stdin) != NULL)
@@ -779,7 +766,7 @@ int main(void)
     if ((rule = crule_parse(indata)) != NULL)
     {
       printf("equivalent rule: ");
-      print_tree((crule_treeptr) rule);
+      print_tree((CRuleNodePtr) rule);
       printf("\n");
       crule_free(&rule);
     }
index ef4e7f127100d741924c27be8c95574bacff2f2d..872ec4b202aeb3b00f8bccd04a8cfec253e6d954 100644 (file)
@@ -180,17 +180,16 @@ static void write_pidfile(void) {
  * is called earlier or later...)
  *--------------------------------------------------------------------------*/
 static time_t try_connections(void) {
-  struct ConfItem   *aconf;
-  struct Client     *cptr;
-  struct ConfItem  **pconf;
-  int                connecting;
-  int                confrq;
-  time_t             next        = 0;
-  struct ConfClass  *cltmp;
-  struct ConfItem   *cconf;
-  struct ConfItem   *con_conf    = NULL;
-  struct Jupe       *ajupe;
-  unsigned int       con_class   = 0;
+  struct ConfItem*  aconf;
+  struct Client*    cptr;
+  struct ConfItem** pconf;
+  int               connecting;
+  int               confrq;
+  time_t            next        = 0;
+  struct ConfClass* cltmp;
+  struct ConfItem*  con_conf    = 0;
+  struct Jupe*      ajupe;
+  unsigned int      con_class   = 0;
 
   connecting = FALSE;
   Debug((DEBUG_NOTICE, "Connection check at   : %s", myctime(CurrentTime)));
@@ -224,13 +223,10 @@ static time_t try_connections(void) {
 
     if (!cptr && (Links(cltmp) < MaxLinks(cltmp)) &&
         (!connecting || (ConClass(cltmp) > con_class))) {
-      /* Check connect rules to see if we're allowed to try */
-      for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-        if ((cconf->status & CONF_CRULE) && !match(cconf->host, aconf->name))
-          if (crule_eval(cconf->passwd))
-            break;
-      }
-      if (!cconf) {
+      /*
+       * Check connect rules to see if we're allowed to try
+       */
+      if (0 == conf_eval_crule(aconf->name, CRULE_MASK)) {
         con_class = ConClass(cltmp);
         con_conf = aconf;
         /* We connect only one at time... */
index 72edaaa6ac090141e500efa824d6c56cebef0974..d30151d6e3dabb110a4a295be59cbda700ff50b0 100644 (file)
@@ -120,7 +120,7 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
   unsigned short   port;
   unsigned short   tmpport;
-  const char*      crule_name;
+  const char*      rule;
   struct ConfItem* aconf;
   struct Client*   acptr;
   struct Jupe*     ajupe;
@@ -168,9 +168,8 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    * are ored together.  Oper connects are effected only by D
    * lines (CRULEALL) not d lines (CRULEAUTO).
    */
-  if ((crule_name = conf_eval_crule(aconf))) {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s",
-                 sptr, crule_name);
+  if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
     return 0;
   }
   /*
@@ -230,7 +229,7 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
   unsigned short   port;
   unsigned short   tmpport;
-  const char*      crule_name;
+  const char*      rule;
   struct ConfItem* aconf;
   struct Client*   acptr;
   struct Jupe*     ajupe;
@@ -300,9 +299,8 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
    * are ored together.  Oper connects are effected only by D
    * lines (CRULEALL) not d lines (CRULEAUTO).
    */
-  if ((crule_name = conf_eval_crule(aconf))) {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s",
-                 sptr, crule_name);
+  if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
     return 0;
   }
   /*
@@ -368,6 +366,7 @@ int m_connect(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   struct ConfItem* cconf;
   struct Client*   acptr;
   struct Jupe*     ajupe;
+  const char*      rule;
 
   if (!IsPrivileged(sptr)) {
     sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); /* XXX DEAD */
@@ -471,19 +470,14 @@ int m_connect(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
    * are ored together.  Oper connects are effected only by D
    * lines (CRULEALL) not d lines (CRULEAUTO).
    */
-  for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-    if ((CONF_CRULEALL == cconf->status) &&
-        (0 == match(cconf->host, aconf->name))) {
-      if (crule_eval(cconf->passwd)) {
-        if (MyUser(sptr))
-          sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", /* XXX DEAD */
-                     me.name, parv[0], cconf->name);
-        else
-          sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", /* XXX DEAD */
-                     NumServ(&me), NumNick(sptr), cconf->name);
-        return 0;
-      }
-    }
+  if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+    if (MyUser(sptr))
+       sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", /* XXX DEAD */
+                   me.name, parv[0], cconf->name);
+    else
+      sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", /* XXX DEAD */
+                   NumServ(&me), NumNick(sptr), cconf->name);
+    return 0;
   }
   /*
    * Check to see if the server is juped; if it is, disallow the connect
index 491b5e14b3606488513faff861e3bb8ff4ca2272..2a63dcbe032ae26f91058ef355e37e25ab2fd7cd 100644 (file)
@@ -88,7 +88,6 @@
 #include "handlers.h"
 #endif /* 0 */
 #include "client.h"
-#include "crule.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_log.h"
@@ -138,7 +137,6 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
   struct Jupe*     ajupe = 0;
   int              hop;
@@ -301,16 +299,12 @@ int mr_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd)) {
-          ServerStats->is_ref++;
-          sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.",
-                              cptr->name);
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
+
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
       sendto_opmask_butone(0, SNO_OLDSNO, "Received unauthorized connection "
@@ -813,7 +807,6 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
   struct Jupe*     ajupe = 0;
   int              hop;
@@ -978,16 +971,10 @@ int ms_server(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd))
-        {
-          ServerStats->is_ref++;
-          sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.",
-                              cptr->name);
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
@@ -1489,7 +1476,6 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
   struct Client*   bcptr;
   struct Client*   LHcptr = 0;
   struct ConfItem* aconf = 0;
-  struct ConfItem* cconf;
   struct ConfItem* lhconf = 0;
   struct Jupe*     ajupe = 0;
   int              hop;
@@ -1649,15 +1635,10 @@ int m_server(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
     cptr->hopcount = hop;
 
     /* check connection rules */
-    for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
-      if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
-        if (crule_eval(cconf->passwd))
-        {
-          ServerStats->is_ref++;
-          sendto_ops("Refused connection from %s.", cptr->name); /* XXX DEAD */
-          return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
-        }
-      }
+    if (0 != conf_eval_crule(host, CRULE_ALL)) {
+      ServerStats->is_ref++;
+      sendto_ops("Refused connection from %s.", cptr->name); /* XXX DEAD */
+      return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
     }
     if (conf_check_server(cptr)) {
       ++ServerStats->is_ref;
index 54a74064f3a0ecffddb7d81ed2775236edc7df8e..f1e08dee79a0aa353447b9eccfdf39ec41e799ca 100644 (file)
@@ -358,10 +358,10 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
       break;
     case 'D':
-      report_configured_links(sptr, CONF_CRULEALL);
+      report_crule_list(sptr, CRULE_ALL);
       break;
     case 'd':
-      report_configured_links(sptr, CONF_CRULE);
+      report_crule_list(sptr, CRULE_MASK);
       break;
     case 't':
       tstats(sptr, parv[0]);
@@ -664,10 +664,10 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
       break;
     case 'D':
-      report_configured_links(sptr, CONF_CRULEALL);
+      report_crule_list(sptr, CRULE_ALL);
       break;
     case 'd':
-      report_configured_links(sptr, CONF_CRULE);
+      report_crule_list(sptr, CRULE_MASK);
       break;
     case 't':
       tstats(sptr, parv[0]);
@@ -958,10 +958,10 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 #endif
       break;
     case 'D':
-      report_configured_links(sptr, CONF_CRULEALL);
+      report_crule_list(sptr, CRULE_ALL);
       break;
     case 'd':
-      report_configured_links(sptr, CONF_CRULE);
+      report_crule_list(sptr, CRULE_MASK);
       break;
     case 't':
       tstats(sptr, parv[0]);
@@ -1346,10 +1346,10 @@ int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
 #endif
       break;
     case 'D':
-      report_configured_links(sptr, CONF_CRULEALL);
+      report_crule_list(sptr, CRULE_ALL);
       break;
     case 'd':
-      report_configured_links(sptr, CONF_CRULE);
+      report_crule_list(sptr, CRULE_MASK);
       break;
     case 't':
       tstats(sptr, parv[0]);
index 74049be4b64021c533284ce63623e87ab092acd5..cceb1d3995eae24799649fb4b939868e447191a6 100644 (file)
@@ -25,7 +25,6 @@
 #include "opercmds.h"
 #include "class.h"
 #include "client.h"
-#include "crule.h"
 #include "ircd.h"
 #include "ircd_chattr.h"
 #include "ircd_reply.h"
index 8be6bbd7030f2b519b519021d448efd46aad8240..36680f6e103ab8c87558934eedaedccf955d2622 100644 (file)
@@ -76,6 +76,7 @@ struct tm        motd_tm;
 
 static struct LocalConf  localConf;
 static struct MotdConf*  motdConfList;
+static struct CRuleConf* cruleConfList;
 
 /*
  * output the reason for being k lined from a file  - Mmmm
@@ -272,17 +273,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;
@@ -755,7 +756,7 @@ void conf_add_motd(const char* const* fields, int count, struct MotdConf** list)
   *list = conf;
 }
 
-void erase_motd_conf_list(struct MotdConf** list)
+void conf_erase_motd_list(struct MotdConf** list)
 {
   struct MotdConf* p;
   struct MotdConf* next;
@@ -776,6 +777,54 @@ const struct MotdConf* conf_get_motd_list(void)
   return motdConfList;
 }
 
+/*
+ * 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 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);
+
+    DupString(p->hostmask, fields[1]);
+    collapse(p->hostmask);
+
+    DupString(p->rule, fields[3]);
+
+    p->type = type;
+    p->node = node;
+    p->next = cruleConfList;
+    cruleConfList = p;
+  } 
+}
+
+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;
+}
+
 /*
  * read_configuration_file
  *
@@ -873,7 +922,10 @@ int read_configuration_file(void)
           quoted = 0;
         else
           quoted = 1;
-        *dest++ = *src++;
+        /*
+         * strip quotes
+         */
+        ++src;
         break;
       case ':':
         if (quoted)
@@ -917,12 +969,14 @@ 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 'H':                /* Hub server line */
     case 'h':
@@ -1065,18 +1119,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).
@@ -1180,14 +1222,12 @@ int rehash(struct Client *cptr, int sig)
     }
     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);
+  conf_erase_motd_list(&motdConfList);
+  conf_erase_crule_list();
+
   /*
    * We don't delete the class table, rather mark all entries
    * for deletion. The table is cleaned up by check_class(). - avalon
@@ -1208,10 +1248,6 @@ int rehash(struct Client *cptr, int sig)
   if (!read_configuration_file())        /* This calls check_class(), */
     check_class();         /* unless it fails */
 
-  /*
-   * make sure that the server listener is re-added so it doesn't get
-   * closed
-   */
   close_listeners();
 
   /*
index 4084c54229087e53a50724e81798606cf2c12a40..9c8574388304fa023317ecab88d430e7a684fc7d 100644 (file)
@@ -26,7 +26,6 @@
 #include "IPcheck.h"
 #include "channel.h"
 #include "client.h"
-#include "crule.h"
 #include "gline.h"
 #include "hash.h"
 #include "ircd.h"
index 28bac493df412258510a14f3dc7ffcd339fc9ab4..a26c0b2e2c6d8ce6cb31dc6a1c49ec1e170f1988 100644 (file)
@@ -25,7 +25,6 @@
 #include "s_stats.h"
 #include "class.h"
 #include "client.h"
-#include "crule.h"
 #include "ircd.h"
 #include "ircd_chattr.h"
 #include "ircd_reply.h"
@@ -92,10 +91,7 @@ static unsigned int report_array[17][3] = {
   {CONF_OPERATOR, RPL_STATSOLINE, 'O'},
   {CONF_HUB, RPL_STATSHLINE, 'H'},
   {CONF_LOCOP, RPL_STATSOLINE, 'o'},
-  {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
-  {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
   {CONF_UWORLD, RPL_STATSULINE, 'U'},
-  {CONF_TLINES, RPL_STATSTLINE, 'T'},
   {0, 0}
 };
 
@@ -129,11 +125,6 @@ void report_configured_links(struct Client *sptr, int mask)
       /* Special-case 'k' or 'K' lines as appropriate... -Kev */
       if ((tmp->status & CONF_KLINE))
        send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
-      /*
-       * connect rules are classless
-       */
-      else if ((tmp->status & CONF_CRULE))
-       send_reply(sptr, p[1], c, host, name);
       else if ((tmp->status & CONF_UWORLD))
        send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
       else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
@@ -154,6 +145,19 @@ void report_motd_list(struct Client* to)
     send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path);
 }
 
+/*
+ * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
+ * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
+ */
+void report_crule_list(struct Client* to, int mask)
+{
+  const struct CRuleConf* p = conf_get_crule_list();
+  for ( ; p; p = p->next) {
+    if (0 != (p->type & mask))
+      send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
+  }
+}
+
 /* m_stats is so obnoxiously full of special cases that the different
  * hunt_server() possiblites were becoming very messy. It now uses a
  * switch() so as to be easier to read and update as params change. 
@@ -178,11 +182,9 @@ int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[],
     case 'P':
     {
       if (parc > 3)
-       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc,
-                              parv);
+       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
       else
-       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
-                              parv);
+       return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
     }
 
       /* oper only, varying # of params */
@@ -191,20 +193,16 @@ int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[],
     case 'M':
     {
       if (parc == 4)
-       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc,
-                              parv);
+       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc, parv);
       else if (parc > 4)
-       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2,
-                              parc, parv);
+       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2, parc, parv);
       else 
-       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
-                              parv);
+       return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
     }
 
       /* oper only, standard # of params */
     default:
-      return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
-                            parv);
+      return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
   }
 }