From 78defb31d029f71ea0abae368114aed2b9c54c66 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 10 Jun 2025 20:27:45 -0400 Subject: [PATCH] Adding DNS local extraction --- app/sender.c | 3 ++ app/sorter.c | 4 ++- lib/lvleml.c | 14 ++++++++ lib/lvleml.h | 3 ++ lib/unidns.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unidns.h | 17 ++++++++-- 6 files changed, 128 insertions(+), 3 deletions(-) diff --git a/app/sender.c b/app/sender.c index e91caad..ab4f33e 100644 --- a/app/sender.c +++ b/app/sender.c @@ -47,6 +47,9 @@ if (tra!=(TRATYP **)0) { case 'R' : //Remote delivery (void) eml_remote_email(tra); break; + case 'W' : //Remote delivery + (void) eml_rebounce_email(tra); + break; default : (void) rou_alert(0,"%s unexpected code '%c'",OPEP,(*tra)->code); status=false; diff --git a/app/sorter.c b/app/sorter.c index 0c0ee74..901577b 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -122,6 +122,7 @@ while (proceed==true) { (void) sig_modeunisig(true); (void) sig_trapsignal(true,sig_alrm); (void) rou_setappname(SORTER); + (void) dns_set_local_smtp(); (void) rou_loadconfig(config,true); (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON); if (foreground==false) { @@ -152,7 +153,8 @@ while (proceed==true) { break; default : //end of task params=par_freeparams(params); - (void) rou_loadconfig(config,false); + (void) dns_drop_local_smtp(); + (void) rou_loadconfig(config,false); (void) sig_trapsignal(false,sig_alrm); (void) sig_modeunisig(false); (void) rou_modesubrou(false); diff --git a/lib/lvleml.c b/lib/lvleml.c index a479bc4..4735963 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1555,3 +1555,17 @@ while (proceed==true) { #undef OPEP } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to rebounce an email which was NOT */ +/* deliverable. */ +/* */ +/********************************************************/ +PUBLIC void eml_rebounce_email(TRATYP **tra) + +{ +} + diff --git a/lib/lvleml.h b/lib/lvleml.h index 966807b..da5882b 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -51,4 +51,7 @@ extern void eml_local_email(TRATYP **tra); //sending email to remote recipents extern void eml_remote_email(TRATYP **tra); +//Rebouncing Email to the first originator +extern void eml_rebounce_email(TRATYP **tra); + #endif diff --git a/lib/unidns.c b/lib/unidns.c index f98c596..adac29b 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -26,6 +26,10 @@ typedef union { u_char buf[B64K]; //according US Cert VU#738331 }RSPTYP; +//list of SMTP local IPV4 +in_addr_t *local_ipv4=(in_addr_t *)0; +int num_ipv4=0; //number of IP within local_ipv4 + /* */ @@ -464,3 +468,89 @@ else { return match; #undef OPEP } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to collect IP binded to listen SMTP */ +/* port. */ +/* */ +/********************************************************/ +PUBLIC void dns_set_local_smtp() + +{ +#define OPEP "unidns.c:dns_set_local_smtp," +#define MXIP 20 +#define TCP "/proc/net/tcp" + +int numip; +FILE *fichier; +int phase; +_Bool proceed; + +numip=0; +fichier=(FILE *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Opening the netstat directory + if ((fichier=fopen(TCP,"r"))==(FILE *)0) { + (void) rou_alert(0,"%s Unable to open <%s> (error=<%s>)", + OPEP,strerror(errno)); + (void) rou_alert(0,"%s (not an linux system? exiting!)",OPEP); + (void) exit(-1);//BIG BIG trouble + } + break; + case 1 : //scanning netstat file + int numline; + char line[200]; + + numline=0; + local_ipv4=calloc(MXIP,sizeof(in_addr_t)); + while (fgets(line,sizeof(line),fichier)!=(char *)0) { + int seq; + int addr; + int port; + + numline++; + if (numline==1) + continue; //discarding first line + if (sscanf(line,"%d: %8x:%4x",&seq,&addr,&port)==3) { + (void) fprintf(stdout,"JMPDBG seq=%d addr=%x port=%d\n",seq,addr,port); + numip++; + } + } + break; + case 2 : //closing file + (void) fclose(fichier); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } + +#undef TCP +#undef MXIP +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to free memory used by SMTP local IP */ +/* */ +/********************************************************/ +PUBLIC void dns_drop_local_smtp() + +{ +if (local_ipv4!=(in_addr_t *)0) { + (void) free(local_ipv4); + num_ipv4=0; + local_ipv4=(in_addr_t *)0; + } +} diff --git a/lib/unidns.h b/lib/unidns.h index 7b8ee83..0ddf7a8 100644 --- a/lib/unidns.h +++ b/lib/unidns.h @@ -12,8 +12,9 @@ //defining an MX structure typedef struct { - int preference; /*MX preference */ - char *mxname; /*MX hostname */ + int preference; //MX preference + char *mxname; //MX hostname + char **mxip; //MX IPNUM list }MXTYP; //Procedure to get ONE SPF entry within domain dns @@ -30,4 +31,16 @@ extern MXTYP **dns_getmx(const char *domain); //of domain A record list extern _Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask); +//procedure to create the list of local IP used to listen +//the smtp protocol +extern void dns_set_local_smtp(); + +//procedure to free the list of local IP used to listen +//the smtp protocol +extern void dns_drop_local_smtp(); + +//procedure to detect if a domain is served by a local +//smtp server +extern _Bool dns_is_domain_local(const char *domain); + #endif -- 2.47.3