]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/formats.c
GLINES: fix null pointer deref in trustgline / trustungline
[irc/quakenet/newserv.git] / trusts / formats.c
index 3f0ac5f4fb236b6c173f90733749f6516a52e3a3..35bee39d80179f44f5e12452dc0bb813d8fb44e3 100644 (file)
@@ -4,16 +4,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include "../lib/strlfunc.h"
+#include "../irc/irc.h"
 #include "trusts.h"
 
-char *trusts_cidr2str(struct irc_in_addr *ip, unsigned char bits) {
-  static char buf[100];
-
-  snprintf(buf, sizeof(buf), "%s/%u", IPtostr(*ip), (irc_in_addr_is_ipv4(ip))?bits-96:bits);
-
-  return buf;
-}
-
 char *trusts_timetostr(time_t t) {
   static char buf[100];
 
@@ -26,9 +19,9 @@ char *dumpth(trusthost *th, int oformat) {
   static char buf[512];
 
   if(oformat) {
-    snprintf(buf, sizeof(buf), "#%u,%s,%u,%u,%jd", th->group->id, trusts_cidr2str(&th->ip, th->bits), th->count, th->maxusage, (intmax_t)th->lastseen);
+    snprintf(buf, sizeof(buf), "#%u,%s,%u,%u,%jd", th->group->id, CIDRtostr(th->ip, th->bits), th->count, th->maxusage, (intmax_t)th->lastseen);
   } else {
-    snprintf(buf, sizeof(buf), "%u,%s,%u,%u,%jd,%jd,%u,%u", th->group->id, trusts_cidr2str(&th->ip, th->bits), th->id, th->maxusage, (intmax_t)th->lastseen, (intmax_t)th->created, th->maxpernode, th->nodebits);
+    snprintf(buf, sizeof(buf), "%u,%s,%u,%u,%jd,%jd,%u,%u", th->group->id, CIDRtostr(th->ip, th->bits), th->id, th->maxusage, (intmax_t)th->lastseen, (intmax_t)th->created, th->maxpernode, th->nodebits);
   }
 
   return buf;
@@ -38,9 +31,9 @@ char *dumptg(trustgroup *tg, int oformat) {
   static char buf[512];
 
   if(oformat) {
-    snprintf(buf, sizeof(buf), "#%u,%s,%u,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg->id, tg->name->content, tg->count, tg->trustedfor, tg->mode, tg->maxperident, tg->maxusage, (intmax_t)tg->expires, (intmax_t)tg->lastseen, (intmax_t)tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content);
+    snprintf(buf, sizeof(buf), "#%u,%s,%u,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg->id, tg->name->content, tg->count, tg->trustedfor, tg->flags & TRUST_ENFORCE_IDENT, tg->maxperident, tg->maxusage, (intmax_t)tg->expires, (intmax_t)tg->lastseen, (intmax_t)tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content);
   } else {
-    snprintf(buf, sizeof(buf), "%u,%s,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg->id, tg->name->content, tg->trustedfor, tg->mode, tg->maxperident, tg->maxusage, (intmax_t)tg->expires, (intmax_t)tg->lastseen, (intmax_t)tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content);
+    snprintf(buf, sizeof(buf), "%u,%s,%u,%d,%u,%u,%jd,%jd,%jd,%s,%s,%s", tg->id, tg->name->content, tg->trustedfor, tg->flags, tg->maxperident, tg->maxusage, (intmax_t)tg->expires, (intmax_t)tg->lastseen, (intmax_t)tg->lastmaxusereset, tg->createdby->content, tg->contact->content, tg->comment->content);
   }
 
   return buf;
@@ -55,7 +48,7 @@ int parsetg(char *buf, trustgroup *tg, int oformat) {
 /* #id,ticket35153,14,20,1,1,17,1879854575,1222639249,0,nterfacer,Qwhois&2120764,Non-Commercial Bouncer (Created by: doomie)
       ,name       ,current
                      ,trustedfor
-                        ,mode
+                        ,flags
                           ,maxperident
                             ,maxusage
                                ,expires  ,lastseen   ,lastmaxusereset
@@ -96,11 +89,14 @@ int parsetg(char *buf, trustgroup *tg, int oformat) {
 
   if(oformat) {
     r = sscanf(line, "%*u,%u,%u,%u,%u,%lu,%lu,%lu,%n",
-               /*current, */ &tg->trustedfor, &tg->mode, &tg->maxperident,
+               /*current, */ &tg->trustedfor, &tg->flags, &tg->maxperident,
                &tg->maxusage, &expires, &lastseen, &lastmaxusereset, &pos);
+
+    if(tg->maxperident > 0)
+      tg->flags |= TRUST_RELIABLE_USERNAME;
   } else {
     r = sscanf(line, "%u,%u,%u,%u,%lu,%lu,%lu,%n",
-               &tg->trustedfor, &tg->mode, &tg->maxperident,
+               &tg->trustedfor, &tg->flags, &tg->maxperident,
                &tg->maxusage, &expires, &lastseen, &lastmaxusereset, &pos);
   }
   if(r != 7)
@@ -141,7 +137,7 @@ int parseth(char *line, trusthost *th, unsigned int *tgid, int oformat) {
   int maxpernode, nodebits;
   char *ip, xbuf[1024], *id;
 
-/* #id,213.230.192.128/26,20,23,1222732944
+/* #id,192.168.2.128/26,20,23,1222732944
        ip                ,cur,max,lastseen */
 
   strlcpy(xbuf, line, sizeof(xbuf));
@@ -171,7 +167,9 @@ int parseth(char *line, trusthost *th, unsigned int *tgid, int oformat) {
   if(oformat) {
     if(sscanf(line, "%*u,%u,%lu", /*current, */&th->maxusage, &lastseen) != 2)
       return 0;
-    created = time(NULL);
+    created = getnettime();
+    maxpernode = 0;
+    nodebits = 128;
   } else {
     if(sscanf(line, "%u,%u,%lu,%lu,%d,%d", &th->id, &th->maxusage, &lastseen, &created, &maxpernode, &nodebits) != 6)
       return 0;