From: Jean-Marc Pigeon (Delson) Date: Tue, 15 Jul 2025 22:47:43 +0000 (-0400) Subject: Starting to implement the relayable list X-Git-Tag: tag-0.14~88 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=a931197c35bed8d62d1ce59d49452554cd0328f4;p=jmp%2Fmailleur Starting to implement the relayable list --- diff --git a/conf/mailleur.conf b/conf/mailleur.conf index 73a179a..f7471a4 100644 --- a/conf/mailleur.conf +++ b/conf/mailleur.conf @@ -53,4 +53,6 @@ DOV_MAILDIR="/var/spool/mailleur/mails" #------------------------------------------------ #The list of public blacklist serveur BLACKLISTER=/etc/mailleur/blacklister.conf +#the list of IP from which we accept to releay email +RELAYABLE=/etc/mailleur/relayable.conf #------------------------------------------------ diff --git a/conf/mailleur.conf.dvl b/conf/mailleur.conf.dvl index f834b3e..ee6d312 100644 --- a/conf/mailleur.conf.dvl +++ b/conf/mailleur.conf.dvl @@ -57,4 +57,6 @@ SMTPPORTS="|127.127.10.25|1025|5,smtps|127.127.10.26|1465|3,smtp|127.127.10.26|1 #------------------------------------------------ #The list of public blacklist serveur BLACKLISTER=/etc/mailleur/blacklister.conf +#the list of IP from which we accept to releay email +RELAYABLE=/etc/mailleur/relayable.conf #------------------------------------------------ diff --git a/conf/relayed.conf b/conf/relayed.conf index 863788a..5c217dc 100644 --- a/conf/relayed.conf +++ b/conf/relayed.conf @@ -1,2 +1,6 @@ -#list of IP number which are relayable -127.0.0.1/32 +#-------------------------------------------------------- +##Private address block which email can be relayed from +127.0.0.0/8 #local loop number +192.168.254.0/24 #local network +#-------------------------------------------------------- +#Setup you own list diff --git a/lib/lvleml.c b/lib/lvleml.c index eeea431..f71b107 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -85,7 +85,6 @@ static CONTYP *freecontact(CONTYP *contact) if (contact!=(CONTYP *)0) { (void) freesessid(contact); - (void) sql_droplinks(contact->sqlptr); contact->sqlptr=sql_closesql(contact->sqlptr); contact->logptr=log_closelog(contact->logptr); contact->recipients=(RCPTYP **)rou_freelist((void **)contact->recipients, @@ -2319,13 +2318,12 @@ while (proceed==true) { if (contact->sqlptr==(SQLPTR *)0) { (void) rou_alert(0,"%s Unable to contact database",OPEP); (void) sleep(2);//delay to avoid avalanche - (void) free(contact); + (void) eml_dropcontact(contact); contact=(CONTYP *)0; phase=999; //no contact possible. } break; case 2 : //waiting from contact - (void) sql_droplinks(contact->sqlptr); if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) { (void) rou_alert(3,"%s Unable to open contact",OPEP); contact=freecontact(contact); diff --git a/lib/lvleml.h b/lib/lvleml.h index 7aec7b0..8e685e7 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -28,6 +28,7 @@ typedef struct { char *locserv; //local service port char *peername; //socket remote peer FQDN char *peerip; //socket remote peer IP + char **relayok; //List of IP which are relayable int numreset; //number of SMTP reset received char *mainsesid; //session main ID SESTYP *session; //SMTP current session information diff --git a/lib/unieml.c b/lib/unieml.c index f79f849..935a0c8 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -5,6 +5,7 @@ /* exchange. */ /* */ /********************************************************/ +#include #include #include #include @@ -426,6 +427,80 @@ return qfile; */ /********************************************************/ /* */ +/* Procedure to load a list of IP from which email */ +/* to a NONE local domain can be accepted and */ +/* relayed. */ +/* */ +/********************************************************/ +PUBLIC char **eml_load_relayed(char *relayedfile) + +{ +#define OPEP "unieml.c:eml_load_relayed," + +char **list; +char *filename; +FILE *relays; +int phase; +_Bool proceed; + +list=(char **)0; +filename=(char *)0; +relays=(FILE *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Check if we have a ffilename + if ((relayedfile==(char *)0)||(strlen(relayedfile)==0)) { + (void) rou_alert(0,"%s No file name config?)",OPEP); + phase=999; //*no need to go further + } + break; + case 1 : //let open the relayable file + filename=rou_apppath(relayedfile); + if ((relays=fopen(filename,"r"))==(FILE *)0) { + (void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>, config?)", + OPEP,filename,strerror(errno)); + phase=999; //No need to go further + } + break; + case 2 : { //scanning relayable contents + char line[300]; + + while (fgets(line,sizeof(line)-1,relays)!=(char *)0) { + struct sockaddr_in sa; + + (void) rou_clean_conf_line(line); + if (strlen(line)==0) + continue; + if (inet_pton(AF_INET,line,&(sa.sin_addr))<=0) { + (void) rou_alert(0,"%s <%s> not a valie IP (error=<%s>, config?)", + OPEP,line,strerror(errno)); + continue; + } + list=(char **)rou_addlist((void **)list,strdup(line)); + } + } + break; + case 3 : //closing file + (void) fclose(relays); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +filename=rou_freestr(filename); +return list; + +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to list all file with a specific */ /* extension with the queue directory. */ /* Return a list or NULL if no file. */ diff --git a/lib/unieml.h b/lib/unieml.h index 23c993c..2cfb0da 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -131,6 +131,10 @@ extern FILE *eml_createqfile(char *qfilename,const char *ext); //procedure to close a file within the queue directory extern FILE *eml_closeqfile(FILE *qfile); +//Procedure to load the list of IP/Network from +//which incoming email can be relayed to another domain MX +extern char **eml_load_relayed(char *relayedfile); + //Procedure to list all file within queue directory //and with a specific extenstion extern char **eml_getqfilelist(char **dnames,const char *ext);