]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Defining afn-getoneipnum
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 16 Jul 2025 13:04:33 +0000 (09:04 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 16 Jul 2025 13:04:33 +0000 (09:04 -0400)
lib/gesspf.c
lib/subafn.c
lib/subafn.h

index db50b62b5020cd5c145fef73a0d96ea15e8fe067..8a0f5c12d6a160d2e95c401375986a80067f29d1 100644 (file)
@@ -352,7 +352,7 @@ while (proceed==true) {
         }
       break;
     case 2      :       //computing the target ipnumber
-      if ((target=afn_getipnum(seq))==(AFNTYP **)0) {
+      if ((target=afn_getipnums(seq))==(AFNTYP **)0) {
         (void) rou_alert(0,"%s Unable to convert <%s> from "
                            "domain <%s> (SPF bug?)",
                            OPEP,seq,domain);
index 9da2d0ef193343af020b43399a397d2d01b08a5e..50d16e92310f7069a0e795d1719d3527e8af7c39 100644 (file)
@@ -140,85 +140,6 @@ return areequal;
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to transforme ONE clean IP to an AFN  */
-/*      structure.                                      */
-/*                                                      */
-/********************************************************/
-static AFNTYP *getoneafn(char *onecleanipstr)
-
-{
-#define OPEP    "subafn.c:getoneanf,"
-#define        ZIPV4   "0.0.0.0"
-
-AFNTYP *afnnum;
-int phase;
-int proceed;
-
-afnnum=(AFNTYP *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
-#ifdef  JMPDBG
-  (void) fprintf(stderr,"%s DEBUGING phase='%d', onecleanipstr=<%s>\n",
-                           OPEP,phase,onecleanipstr);
-#endif
-  switch (phase) {
-    case 0     :       /*lets say ip format ok */
-      afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
-      afnnum->afntype=AF_INET;
-      afnnum->afnmask=32;
-      if (strchr(onecleanipstr,'|')==(char *)0) 
-       phase++;        //This is an IPV4 number
-      break;
-    case 1     :       //IP is an IPV6 format
-      if (strcasestr(onecleanipstr,STRIPV6)==onecleanipstr) 
-       onecleanipstr+=strlen(STRIPV6);
-      afnnum->afntype=AF_INET6;
-      afnnum->afnmask=128;
-      break;
-    case 2     :       //lets convert it
-      switch (inet_pton(afnnum->afntype,onecleanipstr,afnnum->ip)) {
-        case  1         :       //success
-          break;
-        case  0         :       //Invalid IP number
-          (void) fprintf(stderr,"Unable to convert IP <%s> (Invalid IP number)\n",
-                                onecleanipstr);
-         afnnum=afn_freeipnum(afnnum);
-          phase=999;            //no need to go further
-          break;
-        case -1         :       //Invalid IP number
-          (void) fprintf(stderr,"Unable to convert IP <%s> (error=<%s>)\n",
-                                onecleanipstr,strerror(errno));
-         afnnum=afn_freeipnum(afnnum);
-          phase=999;            //no need to go further
-          break;
-        default         :       //Unexpected Result
-          (void) fprintf(stderr,"Unexpected status to convert IP <%s>  "
-                                "(error=<%s> BUG!?)\n",
-                                onecleanipstr,strerror(errno));
-         afnnum=afn_freeipnum(afnnum);
-          phase=999;            //no need to go further
-        }
-      break;
-    case 3     :       //lets convert it
-      afnnum->strnumip=afn_getstrip(afnnum);
-      //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
-      break;
-    default    :       /*SAFE guard            */
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-return afnnum;
-
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
 /*     Routine to fee memory used by an AFNTYP         */
 /*                                                      */
 /********************************************************/
@@ -345,14 +266,91 @@ return afnnum;
 */
 /********************************************************/
 /*                                                      */
-/*     Routine to convert clean string to be           */
-/*     IP number in AFNTYP structure.                  */
+/*     Procedure to transforme ONE clean IP to an AFN  */
+/*      structure.                                      */
 /*                                                      */
 /********************************************************/
-PUBLIC AFNTYP **afn_getipnum(char *cleanipstr)
+PUBLIC AFNTYP *afn_getoneipnum(char *oneipstr)
 
 {
-#define OPEP    "subafn.c:afn_getipnum"
+#define OPEP    "subafn.c:afn_getoneipnum,"
+#define        ZIPV4   "0.0.0.0"
+
+AFNTYP *afnnum;
+int phase;
+int proceed;
+
+afnnum=(AFNTYP *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  (void) fprintf(stderr,"%s JMPDBG DEBUGING phase='%d', oneipstr=<%s>\n",
+                        OPEP,phase,oneipstr);
+  switch (phase) {
+    case 0     :       /*lets say ip format ok */
+      afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
+      afnnum->afntype=AF_INET;
+      afnnum->afnmask=32;
+      if (strchr(oneipstr,'|')==(char *)0) 
+       phase++;        //This is an IPV4 number
+      break;
+    case 1     :       //IP is an IPV6 format
+      if (strcasestr(oneipstr,STRIPV6)==oneipstr) 
+       oneipstr+=strlen(STRIPV6);
+      afnnum->afntype=AF_INET6;
+      afnnum->afnmask=128;
+      break;
+    case 2     :       //lets convert it
+      switch (inet_pton(afnnum->afntype,oneipstr,afnnum->ip)) {
+        case  1         :       //success
+          break;
+        case  0         :       //Invalid IP number
+          (void) fprintf(stderr,"Unable to convert IP <%s> (Invalid IP number)\n",
+                                oneipstr);
+         afnnum=afn_freeipnum(afnnum);
+          phase=999;            //no need to go further
+          break;
+        case -1         :       //Invalid IP number
+          (void) fprintf(stderr,"Unable to convert IP <%s> (error=<%s>)\n",
+                                oneipstr,strerror(errno));
+         afnnum=afn_freeipnum(afnnum);
+          phase=999;            //no need to go further
+          break;
+        default         :       //Unexpected Result
+          (void) fprintf(stderr,"Unexpected status to convert IP <%s>  "
+                                "(error=<%s> BUG!?)\n",
+                                oneipstr,strerror(errno));
+         afnnum=afn_freeipnum(afnnum);
+          phase=999;            //no need to go further
+        }
+      break;
+    case 3     :       //lets convert it
+      afnnum->strnumip=afn_getstrip(afnnum);
+      //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip);
+      break;
+    default    :       /*SAFE guard            */
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return afnnum;
+
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     Routine to convert clean string list to an      */
+/*     IP number in AFNTYP list.                       */
+/*                                                      */
+/********************************************************/
+PUBLIC AFNTYP **afn_getipnums(char *seqipstr)
+
+{
+#define OPEP    "subafn.c:afn_getipnums"
 #define        ZIPV4   "0.0.0.0"
 
 AFNTYP **afnlist;
@@ -367,17 +365,17 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //Do we have an IP string
-      if (cleanipstr==(char *)0) {
+      if (seqipstr==(char *)0) {
         (void) fprintf(stderr,"%s No ip provided (bug?)\n",OPEP);
         phase=999;      //No need to go further
         }
       break;
     case 1     :       //checking '0' situation
-      if (strcmp(cleanipstr,"0")==0) 
-        cleanipstr=ZIPV4;
+      if (strcmp(seqipstr,"0")==0) 
+        seqipstr=ZIPV4;
       break;
     case 2     :       //checking '0' situation
-      iplist=strdup(cleanipstr);
+      iplist=strdup(seqipstr);
       if (strcmp(iplist,ZIPV4)==0) {
         (void) free(iplist);
         iplist=getlocalipstr();
@@ -399,7 +397,7 @@ while (proceed==true) {
           *next='\000';
           next++;
           } 
-        if ((afnloc=getoneafn(ptr))!=(AFNTYP *)0) {
+        if ((afnloc=afn_getoneipnum(ptr))!=(AFNTYP *)0) {
           afnlist=(AFNTYP **)realloc(afnlist,(num+2)*sizeof(AFNTYP *));
           afnlist[num]=afnloc;
           num++;
@@ -463,7 +461,7 @@ if (afnnum!=(AFNTYP *)0) {
                                            afnnum->ip[14],afnnum->ip[15]);
       break;
     default            :
-      (void) fprintf(stderr,"%s, unable to fin IP type (bug?)",OPEP);
+      (void) fprintf(stderr,"%s, unable to find IP type (bug?)",OPEP);
     } 
   }
 if (strlen(buffer)>0)
@@ -583,3 +581,54 @@ while (proceed==true) {
   }
 return areequal;
 }
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to check if a remote IP is part of    */
+/*      acceptable to be relayed list.                  */
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool afn_ip_rlylist(char *iptocheck,AFNTYP **list)
+
+{
+#define OPEP    "subafn.c:afn_ip_inlist,"
+
+_Bool isok;
+AFNTYP *afn;
+int phase;
+_Bool proceed;
+
+isok=false;
+afn=(AFNTYP *)0;
+phase=0;
+proceed=false;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //converting IP
+      if ((afn=afn_getoneipnum(iptocheck))==(AFNTYP *)0) {
+        (void) fprintf(stderr,"%s, Unable to convert IP=<%s> (bug?)",
+                              OPEP,iptocheck);
+        phase=999;
+        }
+      break;
+    case 1      :       //do we have a list
+      if (list==(AFNTYP **)0) 
+        phase=999;      //No need to go further
+      break;
+    case 2      :       //do we have a list
+      while (*list!=(AFNTYP *)0) {
+        list++;
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return isok;
+
+#undef  OPEP
+}
index bc5a615e5d57500787d1843d1fc70c2fd1579273..f19a494f5151b0229b2edf93d26f87e0eeb90fe4 100644 (file)
@@ -45,8 +45,11 @@ extern char *afn_getstrip(AFNTYP *afnnum);
 //IP number in AFNTYP structure.
 extern AFNTYP *afn_getaddrinfo(struct addrinfo *rp);
 
-//procedure to convert a IP as string to an AFNTYP structure
-extern AFNTYP **afn_getipnum(char *cleanipstr);
+//procedure to convert on IP seen as a string to an AFNTYP structure
+extern AFNTYP *afn_getoneipnum(char *oneipstr);
+
+//procedure to convert multiple IP seen as a string to an AFNTYP list
+extern AFNTYP **afn_getipnums(char *listipstr);
 
 //procedure to 'compute' a reverss-addres from the IP
 extern char *afn_reversipnum(AFNTYP *afnnum);
@@ -54,4 +57,7 @@ extern char *afn_reversipnum(AFNTYP *afnnum);
 //procedure to compare 2 same class IP according a mask value
 extern int afn_cmpipnum(AFNTYP *afnnum1,AFNTYP *afnnum2,int mask);
 
+//procedure to check if a remote ip is part of the relayable list
+extern _Bool afn_ip_inrlylist(char *iptocheck,AFNTYP **list);
+
 #endif