]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Still investiguating 'L' or 'W' when Warning
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 21 Jun 2025 15:01:41 +0000 (11:01 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 21 Jun 2025 15:01:41 +0000 (11:01 -0400)
app/chkspf.c
lib/gesspf.c
lib/lvleml.c
lib/lvleml.h
lib/subafn.c
lib/subafn.h
lib/unitls.c

index 89d4c0872f4a8558b80d22d499b17adfbbe05351..29918cf261bdd2a83763c4e292bd769b0f2b4624 100644 (file)
@@ -34,13 +34,17 @@ static void checkstatus(char *domain,char *peerip)
 {
 int try;
 SPFENU spf;
-AFNTYP *afnnum;
+AFNTYP **afns;
 
 try=0;
-afnnum=afn_getipnum(peerip);
-spf=spf_getstatus(&try,domain,afnnum);
-(void) fprintf(stdout,"%s\n",spf_spfASCII(spf));
-afnnum=afn_freeipnum(afnnum);
+afns=afn_getipnum(peerip);
+if (afns!=(AFNTYP **)0) {
+  for (int i=0;afns[i]!=(AFNTYP *)0;i++) {
+    spf=spf_getstatus(&try,domain,afns[i]);
+    (void) fprintf(stdout,"%s\n",spf_spfASCII(spf));
+    }
+  afns=(AFNTYP **)rou_freelist((void **)afns,(genfree_t)afn_freeipnum);
+  }
 }
 /*
 \f
index c54da7b382da16fdb478929026b3411ba36dfe43..db50b62b5020cd5c145fef73a0d96ea15e8fe067 100644 (file)
@@ -323,13 +323,13 @@ static _Bool checkip(char *domain,AFNTYP *afnnum,char *seq)
 #define OPEP    "gesspf.c:checkip"
 _Bool found;
 int cidr;
-AFNTYP *target;
+AFNTYP **target;
 int phase;
 _Bool proceed;
 
 found=false;
 cidr=128;
-target=(AFNTYP *)0;
+target=(AFNTYP **)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -352,7 +352,7 @@ while (proceed==true) {
         }
       break;
     case 2      :       //computing the target ipnumber
-      if ((target=afn_getipnum(seq))==(AFNTYP *)0) {
+      if ((target=afn_getipnum(seq))==(AFNTYP **)0) {
         (void) rou_alert(0,"%s Unable to convert <%s> from "
                            "domain <%s> (SPF bug?)",
                            OPEP,seq,domain);
@@ -360,20 +360,21 @@ while (proceed==true) {
         }
       break;
     case 3      :       //calculating the local cidr
-      switch (afn_cmpipnum(afnnum,target,cidr)) {
-        case -1 :
-          (void) rou_alert(0,"%s Unable to compare IP [%s] from SPF "
-                             "domain <%s> (errno=<%s>) (SPF?)",
-                            OPEP,seq,domain);
-          break;
-        case 1  :
-          found=true;
-          break;
-        case 0  :
-          found=false;
-          break;
+      for (int i=0;(target[i]!=(AFNTYP*)0)&&(found==false);i++) {
+        switch (afn_cmpipnum(afnnum,target[i],cidr)) {
+          case -1 :
+            (void) rou_alert(0,"%s Unable to compare IP [%s] from SPF "
+                               "domain <%s> (errno=<%s>) (SPF?)",
+                               OPEP,seq,domain);
+            break;
+          case 1  :
+            found=true;
+            break;
+          case 0  :
+            break;
+          }
         }
-      target=afn_freeipnum(target);
+      target=(AFNTYP **)rou_freelist((void **)target,(genfree_t)afn_freeipnum);
       break;
     default     :       //SAFE guard
       proceed=false;
index 4cc06bf7c18b89dec034a3a34bea54d5502bd5b1..60171052803e5b722566d06c165589d8fecdb1bc 100644 (file)
@@ -50,7 +50,8 @@ if (contact!=(CONTYP *)0) {
   contact->peername=rou_freestr(contact->peername);
   contact->peerip=rou_freestr(contact->peerip);
   contact->locserv=rou_freestr(contact->locserv);
-  contact->localafn=afn_freeipnum(contact->localafn);
+  contact->localafn=(AFNTYP **)rou_freelist((void **)contact->localafn,
+                                            (genfree_t)afn_freeipnum);
   contact->locip=rou_freestr(contact->locip);
   contact->locname=rou_freestr(contact->locname);
   (void) free(contact);
@@ -91,11 +92,8 @@ while (proceed==true) {
       break;
     case 1      :       //check about local domain, TEMPORARY code
       int status;
-      AFNTYP *afns[2];
 
-      (void) memset(afns,'\000',sizeof(afns));
-      afns[0]=contact->localafn;
-      status=dns_is_domain_local(rcpt->domain,afns);
+      status=dns_is_domain_local(rcpt->domain,contact->localafn);
       switch (status) {
         case dns_nomx   :
           done=false;
index 32cfa3cf757849eae1744b53a30e7fc41a3ae87b..7a76eb3de737a040422841b67d9701ce4fe2acab 100644 (file)
@@ -20,7 +20,7 @@ typedef struct  {
         SQLPTR *sqlptr;         //established contact database access
         char *fqdn;             //fully qualified domain from peer
         char *locip;            //socket local IP num
-        AFNTYP *localafn;       //local IP as an AFNUM
+        AFNTYP **localafn;      //local IP as an AFNUM
         char *locname;          //socket local hostname
         char *locserv;          //local service port
         char *peername;         //socket remote peer FQDN
index 2780e557682bcf10265a2f65a6d6bcf524f5019a..9e1fefd69db71ad468593a108b3749feb4185982 100644 (file)
 /*     Sub kevel procedure to manage IP number.        */
 /*                                                     */
 /********************************************************/
-#include        <arpa/inet.h>
-#include        <errno.h>
+#include        <ifaddrs.h>
 #include        <malloc.h>
 #include        <stdbool.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <arpa/inet.h>
+#include        <errno.h>
+#include        <sys/types.h>
 
 #include       "subafn.h"
 
 #define PUBLIC                  //to specify public variable
 
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     procedure to build a list of local server IP    */
+/*                                                      */
+/********************************************************/
+static char *getlocalipstr()
+
+{
+#define OPEP    "subafn.c:getlocalipstr,"
+
+char *localip;
+struct ifaddrs *ifaddr;
+int phase;
+_Bool proceed;
+
+localip=strdup("");
+ifaddr=(struct ifaddrs *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //Get list of interface
+      if (getifaddrs(&ifaddr)<0) {
+        (void) fprintf(stderr,"%s Unable to get local IP (error=<%s> system?)\n",
+                               OPEP,strerror(errno));
+        phase=999;      //No need to go further;
+        }
+      break;
+    case 1      :       //cans list of interface
+      for (struct ifaddrs *ifa=ifaddr;ifa!=(struct ifaddrs *)0;ifa=ifa->ifa_next) {
+        int family;
+        int taille;
+        int er;
+        char *newloc;
+        char host[NI_MAXHOST];
+
+        if (ifa->ifa_addr==(struct sockaddr *)0)
+          continue;
+        family=ifa->ifa_addr->sa_family;
+        switch (family) {
+          case AF_INET  :
+            taille=sizeof(struct sockaddr_in);
+            break;
+          case AF_INET6 :
+            taille=sizeof(struct sockaddr_in6);
+            continue;   //No scanning for IPV6 Number (Jun 2025)
+            break;
+          default       :
+            continue;
+            break;
+          }
+        er=getnameinfo(ifa->ifa_addr,taille,host,NI_MAXHOST,NULL,0,NI_NUMERICHOST);
+        if (er!=0) {
+          (void) fprintf(stderr,"%s getnameinfo() failed: (error=<%s> system?)\n",
+                               OPEP,gai_strerror(er));
+          continue;
+          }
+        newloc=(char *)calloc(strlen(localip)+strlen(host)+3,sizeof(char));
+        if (strlen(localip)>0) {
+          (void) strcpy(newloc,localip);
+          (void) strcat(newloc,",");
+          }
+        (void) strcat(newloc,host);
+        (void) free(localip);
+        localip=newloc;
+        }
+      break;
+    case 2      :       //free memory
+      (void) freeifaddrs(ifaddr);
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return localip;
+
+#undef  OPEP
+}
 /*
 \f
 */
@@ -57,6 +142,82 @@ 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) {
+  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> -> converted 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         */
 /*                                                      */
 /********************************************************/
@@ -84,7 +245,7 @@ return afnnum;
 PUBLIC char *afn_stripnum(AFNTYP *num)
 
 {
-#define OPEP    "subafn.c:afn_stripnum"
+#define OPEP    "subafn.c:afn_stripnumm,"
 
 char *strip;
 const char *markr;
@@ -187,17 +348,19 @@ return afnnum;
 /*     IP number in AFNTYP structure.                  */
 /*                                                      */
 /********************************************************/
-PUBLIC AFNTYP *afn_getipnum(char *cleanipstr)
+PUBLIC AFNTYP **afn_getipnum(char *cleanipstr)
 
 {
 #define OPEP    "subafn.c:afn_getipnum"
 #define        ZIPV4   "0.0.0.0"
 
-AFNTYP *afnnum;
+AFNTYP **afnlist;
+char *iplist;
 int phase;
 int proceed;
 
-afnnum=(AFNTYP *)0;
+afnlist=(AFNTYP **)calloc(1,sizeof(AFNTYP *));
+iplist=(char *)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -208,51 +371,44 @@ while (proceed==true) {
         phase=999;      //No need to go further
         }
       break;
-    case 1     :       /*lets say ip format ok */
-      afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
-      afnnum->afntype=AF_INET;
-      afnnum->afnmask=32;
-      if (strchr(cleanipstr,':')==(char *)0) 
-       phase++;        //This is an IPV4 number
-      break;
-    case 2     :       //IP is an IPV6 format
-      if (strcasestr(cleanipstr,STRIPV6)==cleanipstr) 
-       cleanipstr+=strlen(STRIPV6);
-      afnnum->afntype=AF_INET6;
-      afnnum->afnmask=128;
-      break;
-    case 3     :       //checking '0' situation
+    case 1     :       //checking '0' situation
       if (strcmp(cleanipstr,"0")==0) 
-       cleanipstr=ZIPV4;
+        cleanipstr=ZIPV4;
       break;
-    case 4     :       //lets convert it
-      switch (inet_pton(afnnum->afntype,cleanipstr,afnnum->ip)) {
-        case  1         :       //success
-          break;
-        case  0         :       //Invalid IP number
-          (void) fprintf(stderr,"Unable to convert IP <%s> (Invalid IP number)\n",
-                                cleanipstr);
-         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",
-                                cleanipstr,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",
-                                cleanipstr,strerror(errno));
-         afnnum=afn_freeipnum(afnnum);
-          phase=999;            //no need to go further
+    case 2     :       //checking '0' situation
+      iplist=strdup(cleanipstr);
+      if (strcmp(iplist,ZIPV4)==0) {
+        (void) free(iplist);
+        iplist=getlocalipstr();
         }
+      if (strlen(iplist)==0)
+        phase++;        //No need to scan  
       break;
-    case 5     :       //lets convert it
-      afnnum->strnumip=afn_getstrip(afnnum);
-      //(void) printf("JMPDBG <%s> -> converted to <%s>\n",
-                     //cleanipstr,afnnum->strnumip);
+    case 3     :       //scanning the iplist
+      char *ptr;
+      int num;
+
+      ptr=iplist;
+      num=0;
+      while (ptr!=(char *)0) {
+        char *next;
+        AFNTYP *afnloc;
+
+        if ((next=strchr(ptr,','))!=(char *)0) {
+          *next='\000';
+          next++;
+          } 
+        if ((afnloc=getoneafn(ptr))!=(AFNTYP *)0) {
+          afnlist[num]=afnloc;
+          num++;
+          afnlist=(AFNTYP **)realloc(afnlist,num*sizeof(AFNTYP *));
+          afnlist[num]=(AFNTYP *)0;
+          }
+        ptr=next;
+        }
+      break;
+    case 4      :       //free memory used
+      (void) free(iplist);
       break;
     default    :       /*SAFE guard            */
       proceed=false;
@@ -260,7 +416,7 @@ while (proceed==true) {
     }
   phase++;
   }
-return afnnum;
+return afnlist;
 
 #undef  ZIPV4
 #undef  OPEP
index d24537e006e9c1e41c07418803fb94be6621448d..e37a49dc7fbc9632eaf0aaeb16aabd7ead297f98 100644 (file)
@@ -46,7 +46,7 @@ extern char *afn_getstrip(AFNTYP *afnnum);
 extern AFNTYP *afn_getaddrinfo(struct addrinfo *rp);
 
 //procedure to convert a IP as string to an AFNTYP structure
-extern AFNTYP *afn_getipnum(char *cleanipstr);
+extern AFNTYP **afn_getipnum(char *cleanipstr);
 
 //procedure to compare 2 same class IP according a mask value
 extern int afn_cmpipnum(AFNTYP *afnnum1,AFNTYP *afnnum2,int mask);
index 80e8c231d63cb11aa7fff429d52f5e888ff56f3a..04ec5882242ee59efcb5f5a0ad8205761f00200c 100644 (file)
@@ -446,13 +446,13 @@ while (proceed==true) {
       while (seq!=(char *)0) {
         LISTYP *list;
         PROTYP proto;
-        AFNTYP *afn;
+        AFNTYP **locafns;
         char *port;
         int iteration;
         char *ptr;
 
         proto=pro_smtp;
-        afn=(AFNTYP *)0;
+        locafns=(AFNTYP **)0;
         port=DPORT;
         iteration=2;
         if ((ptr=strchr(seq,','))!=(char *)0) {
@@ -477,7 +477,7 @@ while (proceed==true) {
             case 1      :       
               if (strlen(seq)==0)
                 seq=DIP;
-              if ((afn=afn_getipnum(seq))==(AFNTYP *)0)
+              if ((locafns=afn_getipnum(seq))==(AFNTYP **)0)
                 (void) rou_alert(0,"%s, Not valid IP <%s> (config?)",OPEP,seq);
               break;
             case 2      :       
@@ -489,15 +489,18 @@ while (proceed==true) {
             }
           seq=sofar;
           }
-        if (afn!=(AFNTYP *)0) {
-          list=(LISTYP *)calloc(1,sizeof(LISTYP));
-          list->proto=proto;
-          list->port=strdup(port);;
-          list->iteration=iteration;
-          list->afn=afn;
-          (void) rou_alert(0,"%s JMPDBG adding afn=<%s>",OPEP,afn->strnumip);
-          binds=(const LISTYP **)rou_addlist((void **)binds,(void *)list);
-          afns=(AFNTYP **)rou_addlist((void **)afns,(void *)afn);
+        if (locafns!=(AFNTYP **)0) {
+          for (int i=0;locafns[i]!=(AFNTYP *)0;i++) {
+            list=(LISTYP *)calloc(1,sizeof(LISTYP));
+            list->proto=proto;
+            list->port=strdup(port);;
+            list->iteration=iteration;
+            list->afn=locafns[i];
+            (void) rou_alert(0,"%s JMDPBG adding <%s>",OPEP,list->afn->strnumip);
+            binds=(const LISTYP **)rou_addlist((void **)binds,(void *)list);
+            afns=(AFNTYP **)rou_addlist((void **)afns,(void *)locafns[i]);
+            }
+          (void) free(locafns);
           }
         seq=ptr;
         }