]> SAFE projects GIT repository - jmp/mailleur/commitdiff
IP to be relayed file is properly scanned
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 16 Jul 2025 15:03:12 +0000 (11:03 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 16 Jul 2025 15:03:12 +0000 (11:03 -0400)
lib/subafn.c
lib/subafn.h
lib/unieml.c

index 50d16e92310f7069a0e795d1719d3527e8af7c39..eeb856a1bc2da1fc5cb74c6a88e53164f06476fd 100644 (file)
@@ -15,6 +15,7 @@
 
 #include       "subafn.h"
 
+#define        AFT     sizeof(struct in6_addr)
 /*
 \f
 */
@@ -159,6 +160,38 @@ return afnnum;
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to set IPNUM mask.                    */
+/*                                                      */
+/********************************************************/
+PUBLIC AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr)
+
+{
+if (afnnum!=(AFNTYP *)0) {
+  unsigned int num;
+  int mxcidr;
+
+  mxcidr=32;
+  if (afnnum->afntype==AF_INET6)
+    mxcidr=128;
+  if (cidr>mxcidr)
+    cidr=mxcidr;
+  afnnum->afnmask=cidr;
+  num=cidr/8;
+  cidr%=8;
+  if (cidr!=0) {
+    afnnum->ip[num]&=(~0U<<(8-cidr));
+    num++;
+    }
+  if (num<AFT)
+    (void) memset(afnnum->ip+num,'\000',AFT-num);
+  }
+return afnnum;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to return a string with               */
 /*     ipnum address and MASK in clear format          */
 /*     Address need to freed.                          */
@@ -291,7 +324,7 @@ while (proceed==true) {
       afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
       afnnum->afntype=AF_INET;
       afnnum->afnmask=32;
-      if (strchr(oneipstr,'|')==(char *)0) 
+      if (strchr(oneipstr,':')==(char *)0) 
        phase++;        //This is an IPV4 number
       break;
     case 1     :       //IP is an IPV6 format
@@ -326,7 +359,7 @@ while (proceed==true) {
       break;
     case 3     :       //lets convert it
       afnnum->strnumip=afn_getstrip(afnnum);
-      //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
+      //(void) printf("JMPDBG <%s> -> to <%s>\n",oneipstr,afnnum->strnumip);
       break;
     default    :       /*SAFE guard            */
       proceed=false;
index f19a494f5151b0229b2edf93d26f87e0eeb90fe4..3b0662364dd1ba9c5bba7c1119ae7201437b3e81 100644 (file)
@@ -33,6 +33,9 @@ typedef       struct  {
 //procedure to free memory used by an AFNTYP structure
 extern AFNTYP *afn_freeipnum(AFNTYP *afnnum);
 
+//procedure to set IPNUM mask
+extern AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr);
+
 //procedure to convert a AFNTYP structure to an standardised
 //IP number
 extern char *afn_stripnum(AFNTYP *afnnum);
index 930b2f08665335e644e5ebe39087e6937015cedc..518d9216ec3ab109cfeef4883d504311722f99cc 100644 (file)
@@ -467,22 +467,30 @@ while (proceed==true) {
       break;
     case 2      :  {    //scanning relayable contents
       int num;
+      char format[40];
+      char ip[80];
       char line[300];
     
       num=0; 
+      snprintf(format,sizeof(format),"%%%ld[^/]/%%d",sizeof(ip));
       while (fgets(line,sizeof(line)-1,relays)!=(char *)0) {
         AFNTYP *afn;
+        int mask;
 
         num++;
         (void) rou_clean_conf_line(line);
         if (strlen(line)==0)
           continue;
-        if ((afn=afn_getoneipnum(line))==(AFNTYP *)0) {
+        (void) memset(ip,'\000',sizeof(ip));
+        if (sscanf(line,format,ip,&mask)<1)
+          continue;
+        if ((afn=afn_getoneipnum(ip))==(AFNTYP *)0) {
           (void) rou_alert(0,"%s line='%03d' <%s> not a valid IP "
                              "(error=<%s>, config?)",
                              OPEP,num,line,strerror(errno));
           continue;
           }
+        (void) afn_maskip(afn,mask);
         list=(AFNTYP **)rou_addlist((void **)list,(void *)afn);
         }
       }