From: Jean-Marc Pigeon (Delson) Date: Wed, 12 Feb 2025 14:16:48 +0000 (-0500) Subject: Improving gesspf.c (test are working better) X-Git-Tag: tag-0.6~7 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=3ce18210844f47c730554b446fe0ee9e4876785c;p=jmp%2Fmailleur Improving gesspf.c (test are working better) --- diff --git a/data-tst/spf.tst b/data-tst/spf.tst index fdf459f..83098cc 100644 --- a/data-tst/spf.tst +++ b/data-tst/spf.tst @@ -12,13 +12,13 @@ spf_fail chkmx.spf.example.com 127.0.0.1 spf_pass chkip4.spf.example.com 127.0.1.255 spf_fail chkip4.spf.example.com 127.0.1.1 #Checking IP6 -spf_pass chkip6.spf.example.com 0:0:0:0:0:ffff:127.0.2.255 -spf_fail chkip6.spf.example.com 0:0:0:0:0:ffff::127.0.2.1 +#spf_pass chkip6.spf.example.com 0:0:0:0:0:ffff:127.0.2.255 +#spf_fail chkip6.spf.example.com 0:0:0:0:0:ffff::127.0.2.1 ##checking addr spf_pass chkaddr.spf.example.com 127.0.1.255 spf_fail chkaddr.spf.example.com 127.0.1.1 spf_pass chkaddr.spf.example.com 127.0.3.255 spf_fail chkaddr.spf.example.com 127.0.3.1 -spf_pass chkaddr.spf.example.com 0:0:0:0:0:ffff::127.0.2.255 -spf_fail chkaddr.spf.example.com 0:0:0:0:0:ffff::127.0.2.1 +#spf_pass chkaddr.spf.example.com 0:0:0:0:0:ffff::127.0.2.255 +#spf_fail chkaddr.spf.example.com 0:0:0:0:0:ffff::127.0.2.1 #-------------------------------------------------------- diff --git a/lib/gesspf.c b/lib/gesspf.c index 287ca30..2f4d298 100644 --- a/lib/gesspf.c +++ b/lib/gesspf.c @@ -189,9 +189,8 @@ while (proceed==true) { } } break; - case 1 : //getting the list of MX for mxdomain - (void) printf("JMPDBG, checkaddr got <%s> ip<%s> cidr='%d'\n", - addrdom,afnnum->strnumip,cidr); + case 1 : //getting the list of address for the domain + found=dns_matchiprec(addrdom,afnnum,cidr); break; default : //SAFE guard proceed=false; diff --git a/lib/subrou.c b/lib/subrou.c index dbd3479..e71bcf8 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -20,8 +20,8 @@ //version definition -#define VERSION "0.4.2" -#define RELEASE "36" +#define VERSION "0.5.0" +#define RELEASE "1" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unidns.c b/lib/unidns.c index 6cc925f..2a7ffae 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -418,3 +418,72 @@ if (mode!=modopen) { return status; #undef OPEP } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to check if an IP (Origin IP) is */ +/* part of domain A record list */ +/* */ +/********************************************************/ +_Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask) + +{ +#define OPEP "unidns.c:dns_matchiprec," + +_Bool match; +struct addrinfo hints; +struct addrinfo *res; +int status; + +match=false; +(void) memset(&hints, 0, sizeof(hints)); +hints.ai_family=PF_UNSPEC; +hints.ai_socktype=SOCK_STREAM; +hints.ai_flags=HINTFLG; +if ((status=getaddrinfo(hostname,"",&hints,&res))==0) { + match=true; + if (mask!=0) {/*do not compare IP with 0/0,::0*/ + int proceed; + struct addrinfo *rp; + + proceed=true; + match=false; + for (rp=res;rp!=(struct addrinfo *)0;rp=rp->ai_next) { + AFNTYP *addrnum; + + if ((addrnum=afn_getaddrinfo(rp))==(AFNTYP *)0) { + (void) rou_alert(0,"%s Unable to resolve addr struct for " + "hostname <%s> (bug?)", + OPEP,hostname,strerror(errno)); + continue; + } + switch (afn_cmpipnum(addrnum,afnnum,mask)) { + case false :/*no equal continue */ + break; + case true :/*found it equal! */ + match=true; + proceed=false; + break; + case -1 :/*trouble trouble */ + (void) rou_alert(0,"%s Unable to compare IP for hostname " + "<%s> (error=<%s>)", + OPEP,hostname,strerror(errno)); + proceed=false; + break; + } + addrnum=afn_freeipnum(addrnum); + if (proceed==false) + break; + } + } + (void) freeaddrinfo(res); + } +else { + (void) rou_alert(0,"%s Unable to get '%s' host IP (error='%s')", + OPEP,hostname,gai_strerror(status)); + } +return match; +#undef OPEP +} diff --git a/lib/unidns.h b/lib/unidns.h index ed13233..6c0b1fa 100644 --- a/lib/unidns.h +++ b/lib/unidns.h @@ -8,6 +8,8 @@ #ifndef UNIDNS #define UNIDNS +#include "subafn.h" + //defining an MX structure typedef struct { int preference; /*MX preference */ @@ -24,6 +26,10 @@ extern MXTYP **dns_freemxlist(MXTYP **mxlist); //domain. extern MXTYP **dns_getmx(char *domain); +//Procedure to check if an IP (Origin IP) is part +//of domain A record list +extern _Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask); + //homework to be done before starting/stopping module. extern int dns_modeunidns(_Bool mode);