]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Changeing the mkprepbinding is done
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 21 Jun 2025 16:54:58 +0000 (12:54 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 21 Jun 2025 16:54:58 +0000 (12:54 -0400)
lib/devsoc.c
lib/devsoc.h
lib/modrec.c
lib/modrec.h
lib/unitls.c
lib/unitls.h

index 77ba270a6021ef76a40a21ff9a8e49f03fa138f5..77f0cfe0cf2243b5e7d24ee730f3dae64a1c0527 100644 (file)
@@ -566,6 +566,38 @@ 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.                                     */
 /*                                                     */
@@ -595,16 +627,17 @@ return socptr;
 /*     definition.                                     */
 /*                                                     */
 /********************************************************/
-PUBLIC SOCPTR **soc_mkbindinf(SOCPTR **socptr,const LISTYP *bind)
+PUBLIC SOCPTR **soc_mkbindinf(SOCPTR **socptr,PROTYP proto,
+                              const char *ip,const char *port,int iteration)
 
 {
 SOCTYP *soc;
 
 soc=newsocket();
-soc->proto=bind->proto;
-soc->ip=strdup(bind->afn->strnumip);
-soc->port=strdup(bind->port);
-soc->iteration=bind->iteration;
+soc->proto=proto;
+soc->ip=strdup(ip);
+soc->port=strdup(port);
+soc->iteration=iteration;
 socptr=(SOCPTR **)rou_addlist((void **)socptr,(void *)soc);
 return socptr;
 }
index 7e73072c50143bf08f51dd5356c680e0cbbc1d25..5158b308c2d1bd49994ea837d7d5648b9b6daa88 100644 (file)
@@ -20,8 +20,8 @@ typedef struct sockaddr SOCKADDR;
 //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) 
@@ -29,7 +29,8 @@ extern SOCPTR **soc_freebindinf(SOCPTR **socptr);
 
 //procedure to assign memory to be used by a TCP socket
 //definition
-extern SOCPTR **soc_mkbindinf(SOCPTR **socptr,const LISTYP *bind);
+extern SOCPTR **soc_mkbindinf(SOCPTR **socptr,PROTYP proto,
+                              const char *ip,const char *port,int iteration);
 
 //procedure to open one exchange socket
 //to connect a remote smtp server
index fe57f20e6bc3a5b57e53423eb9aca27066aef687..2be48bea1df17e47b1fca362dc5e7c7a210707fd 100644 (file)
 /*              -> smtps protocol,port 465,2 iteration  */
 /*                                                     */
 /********************************************************/
-static int prepbinding(SOCPTR ***bindings)
+static int prepbinding(SOCPTR ***bindings,int argc,char *argv[])
 
 {
-#define OPEP    "modrec.c:prepbinding"
-
-const LISTYP **bind;
+#define OPEP    "moderec.c:prepbinding"
 
 *bindings=(SOCPTR **)0;
-if ((bind=tls_get_bind_data())==(const LISTYP **)0) {
-  (void) rou_alert(0,"%s SMTPPORTS data fully missing (config?, bug?)",OPEP);
-  (void) exit(-1);
-  }
-while (*bind!=(LISTYP *)0) {
-  *bindings=soc_mkbindinf(*bindings,*bind);
-  bind++;
+for (int i=0;i<argc;i++) {
+  int iteration;
+  PROTYP proto;
+  char *ipnum;
+  char *port;
+  char *ptr;
+  char config[80];
+
+  (void) strncpy(config,argv[i],sizeof(config));
+  ptr=config;
+  iteration=1;
+  proto=pro_smtp; 
+  ipnum=DFLTIP;
+  port=SMTPORT;
+  (void) rou_alert(0,"JMPDBG argv[%d]=<%s>",i,argv[i]);
+  for (int j=0;j<3;j++) {
+    char *sofar;
+
+    if ((sofar=strchr(ptr,':'))==(char *)0) 
+      break;
+    *sofar='\000';
+    sofar++;
+    switch (j) {
+      case 0    :
+        if ((proto=soc_getprotocol(ptr))==pro_unknwn) {
+          (void) rou_alert(0,"%s, protocol unknown within config <%s>",
+                             OPEP,argv[i]);
+          proto=pro_smtp;
+          }
+        break;
+      case 1    :
+        ipnum=ptr;
+        break;
+      case 2    :
+        if (strlen(ptr)>0) 
+          port=ptr;
+        if (strlen(sofar)>0) 
+          iteration=atoi(sofar);
+        break;
+      default   :
+        (void) rou_alert(0,"%s, Code fault, '%d' unexpected value",OPEP,j);
+        break;
+      }
+    ptr=sofar;
+    }
+  *bindings=soc_mkbindinf(*bindings,proto,ipnum,port,iteration);
   }
 return rou_nbrlist(*bindings);
+
 #undef  OPEP
 }
 /*
@@ -272,7 +310,7 @@ while (proceed==true) {
 /*      Waiting and handling smtp request               */
 /*                                                     */
 /********************************************************/
-PUBLIC void rec_handlesmtp()
+PUBLIC void rec_handlesmtp(int argc,char *argv[])
 
 {
 #define OPEP    "modrec.c:rec_handlesmtp"
@@ -295,7 +333,7 @@ while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //preparing iteration
-      if ((nbrbind=prepbinding(&bindings))==0) {
+      if ((nbrbind=prepbinding(&bindings,argc,argv))==0) {
         (void) rou_alert(0,"%s, No listening IP found (config?)",OPEP);
         phase=999;
         }
index 01be0b79f858920c7e6716018c2fe7b4f5cd27a5..e13e74759269524858ef5c7255acb16ac0f1b974 100644 (file)
@@ -10,6 +10,6 @@
 #include        <stdbool.h>
 
 //procedure to receive email from outside
-extern void rec_handlesmtp();
+extern void rec_handlesmtp(int argc,char *argv[]);
 
 #endif
index 04ec5882242ee59efcb5f5a0ad8205761f00200c..f2b75e978260d7597418fc4580d34fbfe9e13c12 100644 (file)
 //alternate define SSL_CIPHER_LIST       "ALL:!LOW"
 #define SSL_CIPHER_LIST "DEFAULT"
 
-static  _Bool modopen;          //module open/close status
-static const  LISTYP **binds;   //Binding information
-static        AFNTYP **afns;    //Binding information as AFN
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
-/*     Procedure to free LISTYP memory                 */
-/*                                                      */
-/********************************************************/
-static LISTYP *freelisten(LISTYP *listen)
-
-{
-if (listen!=(LISTYP *)0) {
-  listen->afn=afn_freeipnum(listen->afn);
-  listen->port=rou_freestr(listen->port);
-  (void) free(listen);
-  listen=(LISTYP *)0;
-  }
-return listen;
-}
+static  _Bool modopen;    //module open/close status
+static  AFNTYP **afns;    //Binding information as AFN
 /*
 ^L
 */
@@ -418,10 +398,10 @@ return proto;
 /*      and build the LISTYP structure.                 */
 /*                                                     */
 /********************************************************/
-static void buildbinds()
+static void buildafns()
 
 {
-#define OPEP    "unitls.c,buildbinds,"
+#define OPEP    "unitls.c,buildafns,"
 #define DIP     "0.0.0.0"       //listening on all PORT
 #define DPORT   "25"            //Default SMTP port
 
@@ -440,21 +420,14 @@ while (proceed==true) {
       data=strdup(data);
       break;
     case 1      :       //scanning sequence
+      char *ips;
       char *seq;
 
+      ips=strdup("");
       seq=data;
       while (seq!=(char *)0) {
-        LISTYP *list;
-        PROTYP proto;
-        AFNTYP **locafns;
-        char *port;
-        int iteration;
         char *ptr;
 
-        proto=pro_smtp;
-        locafns=(AFNTYP **)0;
-        port=DPORT;
-        iteration=2;
         if ((ptr=strchr(seq,','))!=(char *)0) {
           *ptr='\000';
           ptr++;
@@ -468,42 +441,35 @@ while (proceed==true) {
             }
           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;
-                }
+              //forget about protocol
               break;
             case 1      :       
-              if (strlen(seq)==0)
-                seq=DIP;
-              if ((locafns=afn_getipnum(seq))==(AFNTYP **)0)
-                (void) rou_alert(0,"%s, Not valid IP <%s> (config?)",OPEP,seq);
+              int taille;
+              char *ip;
+              char *newips;
+
+              ip=seq;
+              if (strlen(ip)==0) 
+                ip=DIP;
+              taille=strlen(ips)+strlen(ip)+2;
+              newips=(char *)calloc(taille,sizeof(char));
+              (void) strcpy(newips,ips);
+              ips=rou_freestr(ips);
+              ips=newips;
+              if (strlen(ip)>0)
+                (void) strcat(ips,",");
+              (void) strcat(ips,ip);
               break;
             case 2      :       
-              if (strlen(seq)>0)
-                port=seq;
-              if ((sofar!=(char *)0)&&(strlen(sofar)>0))
-                iteration=atoi(sofar);
+              //forget about port and itreations
               break;
             }
           seq=sofar;
           }
-        if (locafns!=(AFNTYP **)0) {
-          for (int i=0;locafns[i]!=(AFNTYP *)0;i++) {
-            list=(LISTYP *)calloc(1,sizeof(LISTYP));
-            list->proto=proto;
-            list->port=strdup(port);;
-            list->iteration=iteration;
-            list->afn=locafns[i];
-            (void) rou_alert(0,"%s JMDPBG adding <%s>",OPEP,list->afn->strnumip);
-            binds=(const LISTYP **)rou_addlist((void **)binds,(void *)list);
-            afns=(AFNTYP **)rou_addlist((void **)afns,(void *)locafns[i]);
-            }
-          (void) free(locafns);
-          }
         seq=ptr;
         }
+      afns=afn_getipnum(ips);
+      ips=rou_freestr(ips);
       break;
     default     :       //SAFE Guard
       (void) free(data);
@@ -1288,19 +1254,6 @@ return ssl;
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to return the list of binding data    */
-/*                                                      */
-/********************************************************/
-PUBLIC const LISTYP **tls_get_bind_data()
-
-{
-return binds;
-}
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
 /*     Procedure to return the AFN list of binding data*/
 /*                                                      */
 /********************************************************/
@@ -1333,11 +1286,10 @@ if (mode!=modopen) {
     case true     :
       (void) SSL_library_init();
       (void) ERR_clear_error();
-      (void) buildbinds();
+      (void) buildafns();
       break;
     case false    :
-      (void) free(afns);
-      (void) rou_freelist((void **)binds,(genfree_t)freelisten);
+      afns=(AFNTYP **)rou_freelist((void **)afns,(genfree_t)afn_freeipnum);
       break;
     default       :
       (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
index d4356ca0c7ffee7fab10b8b97e0693e6ec4e36f7..44d0539b9d063af03968bd010a8e1775faf932ac 100644 (file)
@@ -78,7 +78,7 @@ extern int tls_check_peer(TLSTYP *tls);
 extern SSL *tls_setsocket(int handle,SSL_CTX *ctx);
 
 //getting binding information
-extern const LISTYP **tls_get_bind_data();
+//extern const LISTYP **tls_get_bind_data();
 
 //getting binding information as AFN structure
 extern AFNTYP **tls_get_bind_afn();