]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding DNS local extraction
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 11 Jun 2025 00:27:45 +0000 (20:27 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 11 Jun 2025 00:27:45 +0000 (20:27 -0400)
app/sender.c
app/sorter.c
lib/lvleml.c
lib/lvleml.h
lib/unidns.c
lib/unidns.h

index e91caad64ecad481c4b1ff7a413d45a24b4f99a3..ab4f33ec1537f0914c1694a3f160dd67ad1365e4 100644 (file)
@@ -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;
index 0c0ee74edcb6d5d7eb31ee0810361376050b1227..901577bc9386621adc09d372dd20328e97d2b068 100644 (file)
@@ -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);
index a479bc43e9a20c3c6d06480b0733fb68c7150668..473596346ebd160fe541d3ee09c7909ea0203fa6 100644 (file)
@@ -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)
+
+{
+}
+
index 966807b542f674fc747c77efb9b18a807ad34d94..da5882bfe3935c6678e59f057914e799e7f0dc7a 100644 (file)
@@ -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
index f98c596edd3be4a239dc12a47b91956eb75b5368..adac29bb50dbdf07b00f8fbf06fac14fb5ba5d6b 100644 (file)
@@ -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
+
 /*
 \f
 */
@@ -464,3 +468,89 @@ else {
 return match;
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     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
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     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;
+  }
+}
index 7b8ee83e672dd9c2d482d9f2b7e25561c436285e..0ddf7a8e163283abd427c2e35f42cb2253b87574 100644 (file)
@@ -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