]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/data.c
GLINES: fix null pointer deref in trustgline / trustungline
[irc/quakenet/newserv.git] / trusts / data.c
index f287aa97dd4763c2de2fae9e296cb441211b011c..3e8427fb82799a75fe0f937c996e7a8afe485633 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <stdio.h>
 
 #include "../lib/sstring.h"
@@ -214,7 +215,6 @@ static trusthost *th_getnextchildbyhost(trusthost *orig, trusthost *th) {
   if(!th) {
     trustgroup *tg;
 
-    tg = tglist;
     for(tg=tglist;tg;tg=tg->next) {
       th = tg->hosts;
       if(th)
@@ -233,12 +233,19 @@ static trusthost *th_getnextchildbyhost(trusthost *orig, trusthost *th) {
     if(th->next) {
       th = th->next;
     } else {
-      if(!th->group->next)
+      trustgroup *tg = th->group;
+
+      do {
+        tg = tg->next;
+      } while (tg && !tg->hosts);
+
+      if(!tg)
         return NULL;
-      th = th->group->next->hosts;
+
+      th = tg->hosts;
     }
 
-    if(!th || th->parent == orig)
+    if(th->parent == orig)
       return th;
   }
 }
@@ -283,13 +290,15 @@ trustgroup *tg_strtotg(char *name) {
   }
 
   for(tg=tglist;tg;tg=tg->next)
-    if(!strcmp(name, tg->name->content))
+    if(!strcasecmp(name, tg->name->content))
       return tg;
 
   return NULL;
 }
 
 void th_adjusthosts(trusthost *th, trusthost *superset, trusthost *subset) {
+  struct irc_in_addr ipaddress_canonical;
+
   /*
    * First and foremost, CIDR doesn't allow hosts to cross boundaries, i.e. everything with a smaller prefix
    * is entirely contained with the prefix that is one smaller.
@@ -355,7 +364,8 @@ void th_adjusthosts(trusthost *th, trusthost *superset, trusthost *subset) {
     nick *np, *nnp;
     for(np=superset->users;np;np=nnp) {
       nnp = nextbytrust(np);
-      if(ipmask_check(&np->p_nodeaddr, &th->ip, th->bits)) {
+      ip_canonicalize_tunnel(&ipaddress_canonical, &np->ipaddress);
+      if(ipmask_check(&ipaddress_canonical, &th->ip, th->bits)) {
         trusts_lostnick(np, 1);
         trusts_newnick(np, 1);
       }
@@ -366,10 +376,13 @@ void th_adjusthosts(trusthost *th, trusthost *superset, trusthost *subset) {
     nick *np;
     int i;
 
-    for(i=0;i<NICKHASHSIZE;i++)
-      for(np=nicktable[i];np;np=np->next)
-        if(!gettrusthost(np) && ipmask_check(&np->p_nodeaddr, &th->ip, th->bits))
+    for(i=0;i<NICKHASHSIZE;i++) {
+      for(np=nicktable[i];np;np=np->next) {
+        ip_canonicalize_tunnel(&ipaddress_canonical, &np->ipaddress);
+        if(!gettrusthost(np) && ipmask_check(&ipaddress_canonical, &th->ip, th->bits))
           trusts_newnick(np, 1);
+      }
+    }
   }
 }
 
@@ -440,7 +453,7 @@ int tg_modify(trustgroup *oldtg, trustgroup *newtg) {
 
   /* id remains the same, count/hosts/marker/next/exts are ignored */
   vnewtg.trustedfor = newtg->trustedfor;
-  vnewtg.mode = newtg->mode;
+  vnewtg.flags = newtg->flags;
   vnewtg.maxperident = newtg->maxperident;
   vnewtg.maxusage = newtg->maxusage;
   vnewtg.expires = newtg->expires;