]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Working on binding configuration (SMTPPORTS)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 11 Jun 2025 11:16:14 +0000 (07:16 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 11 Jun 2025 11:16:14 +0000 (07:16 -0400)
12 files changed:
app/Makefile
app/emlrcvr.c
app/sorter.c
conf/mailleur.conf.dvl
lib/Makefile
lib/devsoc.c
lib/devsoc.h
lib/modrec.c
lib/unidns.c
lib/unidns.h
lib/unitls.c
lib/unitls.h

index 5cf54de70ed00402d30d8dcbb3dab63b67f365dd..c1f5913f16dc66e81a5bb8106e66dcc7e46f9b33 100644 (file)
@@ -72,6 +72,7 @@ chkspf.o:  chkspf.c                           \
 
 emlrec.o:  emlrec.c                            \
           ../lib/modrec.h                      \
+          ../lib/unitls.h                      \
           ../lib/unisig.h                      \
           ../lib/uniprc.h                      \
           ../lib/unipar.h                      \
index bcfd6d2c7cf8fd4f4e4c8a680b966216e874a0e3..b87e9bdef069ac890b9a2247162aafa4701f8915 100644 (file)
@@ -14,6 +14,7 @@
 #include       "unipar.h"
 #include       "uniprc.h"
 #include       "unisig.h"
+#include       "unitls.h"
 #include       "modrec.h"
 
 #define RECNAME "emlrcvr"
@@ -58,6 +59,7 @@ while (proceed==true) {
       (void) rou_modesubrou(true);
       (void) prc_modeuniprc(true);
       (void) sig_modeunisig(true);
+      (void) tls_modeunitls(true);
       (void) sig_trapsignal(true,sig_alrm);
       break;
     case 2      :       //sett lock
@@ -81,6 +83,7 @@ while (proceed==true) {
       (void) prc_cleantitle();
       params=par_freeparams(params);
       (void) sig_trapsignal(false,sig_alrm);
+      (void) tls_modeunitls(false);
       (void) sig_modeunisig(false);
       (void) prc_modeuniprc(false);
       (void) rou_modesubrou(false);
index ac0e5923c6538d02944d752994b0befad984a533..7363a83c15e9ad4b3b86aeb9ab6716581b0cad7e 100644 (file)
@@ -123,7 +123,6 @@ 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) {
@@ -154,7 +153,6 @@ while (proceed==true) {
       break;
     default     :       //end of task
       params=par_freeparams(params);
-      (void) dns_drop_local_smtp();
       (void) rou_loadconfig(config,false);
       (void) sig_trapsignal(false,sig_alrm);
       (void) sig_modeunisig(false);
index 7a9c9ff994065bbbb84c2b0b4c215ddc744a4764..8b6ab889fb5db287930f3eba845ad96118f59da6 100644 (file)
@@ -1,6 +1,14 @@
 #file used to set environment configuration
 #Used for developpement purpose ONLY
 #------------------------------------------------
+#list of listening port to do SMTP protocole
+#format
+#protocol:ipnum:port:iteration[,protocol:ipnum:port:iteration]++
+#example
+#:ipnum:::             -> smtp:ipnum:25:1
+#stmtps:ipnum:465:2    -> smtps protocol,port 465,2 iteration
+#SMTPPORTS     =       "::,:127.127.10.25:1025:,smtps:127.127.10.25:1026:1"
+#------------------------------------------------
 #Defining SERVER mode Certificate data
 CA_ROOT_SRV    =       "./certs/root-safe_CA.pem"
 CA_CERT_SRV    =       "./certs/mailleur_server-chain-cert_x509.pem"
index 1810d86ad92e6b8963b10531f17ab06df0432bd9..e4589fd527f62403dfc4c37b31b0f6242a5364c3 100644 (file)
@@ -65,7 +65,7 @@ devlog.o:                                     \
 
 devsoc.o:                                      \
           subafn.h subrou.h                    \
-          unieml.h uniprc.h unitls.h           \
+          unieml.h uniprc.h                    \
           devsoc.h devsoc.c
 
 devsql.o:                                      \
@@ -118,6 +118,8 @@ gestcp.h:                                   \
 
 gesspf.h:                                      \
           subafn.h
+devsoc.h:                                      \
+          unitls.h
 
 uniprc.h:                                      \
           subrou.h
index 2a3ba4914139756c4e692426cfea54116a7498cb..47ee9469088dba6e483c54b30447b606bb3997cb 100644 (file)
@@ -566,38 +566,6 @@ return handle;
 */
 /********************************************************/
 /*                                                     */
-/*     Procedure to parse an email protocol            */
-/*                                                     */
-/********************************************************/
-PUBLIC PROTYP soc_getprotocol(const char *strproto)
-
-{
-static struct  {
-                PROTYP proto;
-                const char *voca;
-                }prolist[]={
-                          {pro_smtp,""},
-                          {pro_smtp,"smtp"},
-                          {pro_smtps,"smtps"},
-                          {pro_unknwn,(char *)0}
-                          };
-PROTYP proto;
-
-
-proto=pro_unknwn;
-for (int i=0;prolist[i].voca!=(char *)0;i++) {
-  if (strcasecmp(strproto,prolist[i].voca)==0) {
-    proto=prolist[i].proto;
-    break;
-    }
-  }
-return proto;
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                     */
 /*     Procedure to free memory used by a bind         */
 /*     definition.                                     */
 /*                                                     */
index 7e6eb223f77cecd470546c0bcca060277b1e499e..d8df075771634ad540b3dce11fcd4bfaa8346175 100644 (file)
 #include        <stdbool.h>
 #include        <time.h>
 
+#include        "unitls.h"
+
 //convenient adress structure
 typedef struct sockaddr SOCKADDR;
 
-//defining email protocol value.
-typedef enum    {
-        pro_smtp,       //text SMTP protocol, in clear mode
-        pro_starttls,   //Text SMTP protocol, encrypted upon request
-        pro_smtps,      //Text SMTP protocol, text encrypted from start
-        pro_unknwn      //Protcole undefined
-        }PROTYP;
-
-//default and debugging certificate for server mode
-extern const char *srvr_certs[3];
-
 //reference to a socket definition
 typedef void SOCPTR;
 
 //reference to a output channel definition
 typedef void OUTPTR;
 
-//procedure to parse an email protocol 
-extern PROTYP soc_getprotocol(const char *strproto);
-
 //procedure to free all memory used by a TCP socket
 //definition (once closed) 
 extern SOCPTR **soc_freebindinf(SOCPTR **socptr);
index d0236f701373ea31970a43272f9cb581228c70ec..7c9d6ee161f8f342aaee4c9b8ff0d0d8a6d7c85b 100644 (file)
@@ -71,7 +71,7 @@ for (int i=0;i<argc;i++) {
     sofar++;
     switch (j) {
       case 0    :
-        if ((proto=soc_getprotocol(ptr))==pro_unknwn) {
+        if ((proto=tls_getprotocol(ptr))==pro_unknwn) {
           (void) rou_alert(0,"%s, protocol unknown within config <%s>",
                              OPEP,argv[i]);
           proto=pro_smtp;
index ef9d65c93dda683a7ac4e30914fc28bf1711f401..ad398ab47825f15f9dad0778a7e98b93d6416673 100644 (file)
@@ -468,89 +468,3 @@ 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) rou_alert(0,"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 0ddf7a8e163283abd427c2e35f42cb2253b87574..74b3306dd609a5502cd002ec866ca1b372735453 100644 (file)
@@ -31,14 +31,6 @@ 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);
index b12514c9fc7172bbfcc673489cf8bd9c58c99895..4077e57566726d83d0c7fee96303ce930de94b17 100644 (file)
 #define SSL_CIPHER_LIST "DEFAULT"
 
 static  _Bool modopen;          //module open/close status
+static  LISTYP **binds;         //Binding information
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to free LISTYP memory                 */
+/*                                                      */
+/********************************************************/
+static LISTYP *freelisten(LISTYP *listen)
 
+{
+if (listen!=(LISTYP *)0) {
+  listen->ipnum=rou_freestr(listen->ipnum);
+  (void) free(listen);
+  listen=(LISTYP *)0;
+  }
+return listen;
+}
 /*
 ^L
 */
@@ -357,6 +375,132 @@ while (proceed==true) {
 #undef  OPEP
 }
 /*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to parse an email protocol            */
+/*                                                     */
+/********************************************************/
+PUBLIC PROTYP tls_getprotocol(const char *strproto)
+
+{
+static struct  {
+                PROTYP proto;
+                const char *voca;
+                }prolist[]={
+                          {pro_smtp,""},
+                          {pro_smtp,"smtp"},
+                          {pro_smtps,"smtps"},
+                          {pro_unknwn,(char *)0}
+                          };
+PROTYP proto;
+
+
+proto=pro_unknwn;
+for (int i=0;prolist[i].voca!=(char *)0;i++) {
+  if (strcasecmp(strproto,prolist[i].voca)==0) {
+    proto=prolist[i].proto;
+    break;
+    }
+  }
+return proto;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to parse an the SMTPPORTS env variable*/
+/*      and build the LISTYP structure.                 */
+/*                                                     */
+/********************************************************/
+static void buildbinds()
+
+{
+#define OPEP    "unitls.c,buildbinds,"
+#define DIP     "0.0.0.0"       //listening on all PORT
+#define DPORT   "25"            //Default SMTP port
+
+char *data;
+int phase;
+_Bool proceed;
+
+data=(char *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //Getting the SMTPPORTS variable
+      if ((data=getenv("SMTPPORTS"))==(char *)0) 
+        data="smtp:0.0.0.0:25:2";       //default configuration
+      data=strdup(data);
+      break;
+    case 1      :       //scanning sequence
+      char *seq;
+
+      seq=data;
+      while (seq!=(char *)0) {
+        PROTYP proto;
+        char *ipnum;
+        char *port;
+        int iter;
+        char *ptr;
+
+        ipnum=DIP;
+        port=DPORT;
+        iter=10;
+        if ((ptr=strchr(seq,','))!=(char *)0) {
+          *ptr='\000';
+          ptr++;
+          }
+        (void) rou_alert(0,"%s JMPDBG seq=<%s>",OPEP,seq);
+        for (int j=0;j<3;j++) {
+          char *sofar;
+
+          if ((sofar=strchr(seq,':'))==(char *)0)
+            break;
+          *sofar='\000';
+          sofar++;
+          switch (j) {
+            case 0      :       //extracting protocol
+              if ((proto=tls_getprotocol(seq))==pro_unknwn) {
+                (void) rou_alert(0,"%s, protocol unknown within config <%s>",
+                                   OPEP,seq);
+                proto=pro_smtp;
+                }
+              break;
+            case 1      :       
+              if (strlen(seq)>0)
+                ipnum=seq;
+              break;
+            case 2      :       
+              if (strlen(seq)>0)
+                port=seq;
+              if (strlen(sofar)>0)
+                iter=atoi(sofar);
+              break;
+            }
+          seq=sofar;
+          }
+        (void) rou_alert(0,"%s JMP ipnum=<%s> port=<%s> iter='%d'",
+                            OPEP,ipnum,port,iter);
+        seq=ptr;
+        }
+      break;
+    default     :       //SAFE Guard
+      (void) free(data);
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+
+#undef  DPORT
+#undef  DIP
+#undef  OPEP
+}
+/*
 ^L
 */
 /********************************************************/
@@ -1140,8 +1284,10 @@ if (mode!=modopen) {
     case true     :
       (void) SSL_library_init();
       (void) ERR_clear_error();
+      (void) buildbinds();
       break;
     case false    :
+      (void) rou_freelist((void **)binds,(genfree_t)freelisten);
       break;
     default       :
       (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
index 5a052817d6e7eaf69d1cd7411c377ad14e9776b9..48c57c725187261b49f394d838808bd6c98423a1 100644 (file)
 #include        <stdbool.h>
 #include        <openssl/ssl.h>
 
+//defining email protocol value.
+typedef enum    {
+        pro_smtp,       //text SMTP protocol, in clear mode
+        pro_starttls,   //Text SMTP protocol, encrypted upon request
+        pro_smtps,      //Text SMTP protocol, text encrypted from start
+        pro_unknwn      //Protcole undefined
+        }PROTYP;
+
+typedef struct  {       //structure about listening port
+        PROTYP proto;   //Protocol to be used
+        char *ipnum;    //binding IP number
+        int iter;       //Number of binding iteration
+        }LISTYP;
+
 typedef struct  {
         _Bool server;   //SSL server/client mode
         _Bool checkpeer;//Check peer certificate
@@ -60,6 +74,9 @@ extern int tls_check_peer(TLSTYP *tls);
 //set socket as an tls socket
 extern SSL *tls_setsocket(int handle,SSL_CTX *ctx);
 
+//getting binding information
+extern LISTYP **tls_get_bind_data();
+
 //homework to be done before starting/stopping module.
 extern int tls_modeunitls(_Bool mode);