From: Jean-Marc Pigeon (Delson) Date: Sat, 21 Jun 2025 15:01:41 +0000 (-0400) Subject: Still investiguating 'L' or 'W' when Warning X-Git-Tag: tag-0.9~56 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=ed7f661de3cbab89b6dd48dd034ac415bdb2f8b7;p=jmp%2Fmailleur Still investiguating 'L' or 'W' when Warning --- diff --git a/app/chkspf.c b/app/chkspf.c index 89d4c08..29918cf 100644 --- a/app/chkspf.c +++ b/app/chkspf.c @@ -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); + } } /* diff --git a/lib/gesspf.c b/lib/gesspf.c index c54da7b..db50b62 100644 --- a/lib/gesspf.c +++ b/lib/gesspf.c @@ -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; diff --git a/lib/lvleml.c b/lib/lvleml.c index 4cc06bf..6017105 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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; diff --git a/lib/lvleml.h b/lib/lvleml.h index 32cfa3c..7a76eb3 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -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 diff --git a/lib/subafn.c b/lib/subafn.c index 2780e55..9e1fefd 100644 --- a/lib/subafn.c +++ b/lib/subafn.c @@ -4,17 +4,102 @@ /* Sub kevel procedure to manage IP number. */ /* */ /********************************************************/ -#include -#include +#include #include #include #include #include +#include +#include +#include #include "subafn.h" #define PUBLIC //to specify public variable +/* + +*/ +/********************************************************/ +/* */ +/* 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 +} /* */ @@ -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 +} +/* + +*/ +/********************************************************/ +/* */ /* 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 diff --git a/lib/subafn.h b/lib/subafn.h index d24537e..e37a49d 100644 --- a/lib/subafn.h +++ b/lib/subafn.h @@ -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); diff --git a/lib/unitls.c b/lib/unitls.c index 80e8c23..04ec588 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -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; }