From 5de93164b87ba7289ab42b1d398cb828989b8861 Mon Sep 17 00:00:00 2001 From: Jean-Marc Pigeon Date: Sun, 16 Nov 2025 16:21:11 -0500 Subject: [PATCH] Working on the SPF value detection --- lib/geseml.c | 9 ++++----- lib/gesspf.c | 34 ++++++++++++++++++++++++++++++++++ lib/gesspf.h | 6 +++++- lib/lvleml.c | 5 ++++- lib/lvleml.h | 4 +++- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/geseml.c b/lib/geseml.c index 648b156..8b091dd 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -620,7 +620,7 @@ locdom=(char *)0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase); + (void) rou_dbglive(9,OPEP,"phase='%d'",phase); switch (phase) { case 0 : //Extracting recipient email if ((tra!=(TRATYP *)0)&&(tra->rcptto!=(char *)0)&&(strlen(tra->rcptto)>0)) @@ -747,8 +747,7 @@ switch (fork()) { argv[6]=rootdir; argv[7]=buffer; } - (void) rou_alert(0,"%s JMPDBG starting sender=<%s> todo= <%s>", - OPEP,execpath,buffer); + (void) rou_dbglive(2,OPEP,"Starting sender=<%s> todo= <%s>",execpath,buffer); if (execv(execpath,argv)<0) { (void) rou_alert(0,"%s Unable to exec process=<%s> (error=<%s> Bug?)", OPEP,execpath,strerror(errno)); @@ -818,7 +817,7 @@ qout=(FILE *)0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_dbglive(9,OPEP,"phase='%d'",phase); switch (phase) { case 0 : //create the new attachement file if ((qout=eml_createqfile(sessata,(char *)0))==(FILE *)0) { @@ -938,7 +937,7 @@ const char *look[]={HFROM,HTITLE,(char *)0}; extracted=false; if ((line!=(char *)0)&&(strlen(line)>0)) { - (void) rou_alert(0,"%s JMPDBG scan header <%s>",OPEP,line); + (void) rou_dbglive(0,OPEP,"scaning header <%s>",line); for (int i=0;(extracted==false)&&(look[i]!=(char *)0);i++) { int max; diff --git a/lib/gesspf.c b/lib/gesspf.c index 2794b09..6a20a42 100644 --- a/lib/gesspf.c +++ b/lib/gesspf.c @@ -635,3 +635,37 @@ return spf; #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to get the SPF domain/peerip status */ +/* return the SPF status. */ +/* */ +/********************************************************/ +PUBLIC SPFENU spf_getspf(char *domain,char *peerip) + +{ +#define OPEP "gesspf.c:spf_getspf" + +SPFENU spf; +AFNTYP **afns; + +spf=spf_unknown; +afns=afn_getipnums(peerip); +if (afns!=(AFNTYP **)0) { + int try; + + try=0; + for (int i=0;afns[i]!=(AFNTYP *)0;i++) { + spf=spf_getstatus(&try,domain,afns[i]); + (void) rou_dbglive(9,OPEP,"SPF[%d] for [%s]=<%s>", + i,afns[i]->strnumip,spf_spfASCII(spf)); + } + afns=(AFNTYP **)rou_freelist((void **)afns,(genfree_t)afn_freeipnum); + } +return spf; + +#undef OPEP +} diff --git a/lib/gesspf.h b/lib/gesspf.h index dfd63ff..5d5f89a 100644 --- a/lib/gesspf.h +++ b/lib/gesspf.h @@ -9,6 +9,7 @@ #define GESSPF #include "subafn.h" +#include "gesspf.h" typedef enum { spf_pass, //OK if condition apply @@ -24,7 +25,10 @@ typedef enum { //procedure to return spf status as an ASCII string extern const char *spf_spfASCII(SPFENU spf); -//get the SPF status for a specific domain and a remote peer IP +//get the SPF status for a specific domain and an IP extern SPFENU spf_getstatus(int *try,char *domain,AFNTYP *afnnum); +//get the SPF status for a specific domain according remote peer ipnumer +extern SPFENU spf_getspf(char *domain,char *peerip); + #endif diff --git a/lib/lvleml.c b/lib/lvleml.c index 1aaa8e2..b5e22e1 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1715,6 +1715,7 @@ status=CMDOK; proceed=true; phase=0; while (proceed==true) { + (void) rou_dbglive(9,OPEP,"Phase='%d'",phase); switch (phase) { case 0 : //do we have an originator if ((mailfrom==(char *)0)||(strlen(mailfrom)<3)) { @@ -1770,7 +1771,9 @@ while (proceed==true) { break; } break; - case 5 : //everything ok + case 5 : //Checking if the SPF is good from the originator + break; + case 6 : //everything ok contact->mailfrom=strdup(mailfrom); (void) eml_transmit(contact,true,"%d 2.1.3 %s sender ok", CMDOK,contact->mailfrom); diff --git a/lib/lvleml.h b/lib/lvleml.h index 9e0f5f1..45b83ff 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -13,13 +13,14 @@ #include "devsoc.h" #include "devsql.h" #include "gestcp.h" +#include "gesspf.h" #include "geseml.h" typedef struct { SOCPTR *socptr; //established contact socket context SQLPTR *sqlptr; //established contact database access int delay; //communication max delay - _Bool isgoodfqdn; //Remoted presented a valid fqdn + _Bool isgoodfqdn; //Remote presented a valid fqdn char *fqdn; //fully qualified domain from peer int credit; //Credits to be added or removed from contact RELTYP privilege; //onnection privilege @@ -36,6 +37,7 @@ typedef struct { char *termend; //contact ending condition SESTYP *session; //SMTP current session information char *mailfrom; //current mail from originator + SPFENU isgoodspf; //remote mail spf status RCPTYP **recipients; //List of email recipient LOGPTR *logptr; //reference to session log char *transout; //data to be flush out to remote -- 2.47.3