]> SAFE projects GIT repository - jmp/mailleur/commitdiff
check mailfrom originator format
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 18 Mar 2025 14:02:49 +0000 (10:02 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 18 Mar 2025 14:02:49 +0000 (10:02 -0400)
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c
lib/lvleml.h
lib/modrec.c

index ce68f3422b5d4065dc7be72822533ef5dd6f8d4f..2c34b416021512c4fede87b92fbe755fcb8c99f9 100644 (file)
 #include        "uniprc.h"
 #include        "gestcp.h"
 
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
-/*     Procedure to free memory used by contact        */
-/*                                                      */
-/********************************************************/
-static CONTYP *freecontact(CONTYP *contact)
-
-{
-#define OPEP    "gestcp.c:freecontact"
-
-if (contact!=(CONTYP *)0) {
-  contact->logptr=log_closelog(contact->logptr);
-  contact->cursesid=rou_freestr(contact->cursesid);
-  contact->mainsesid=rou_freestr(contact->mainsesid);
-  contact->fqdn=rou_freestr(contact->fqdn);
-  contact->peername=rou_freestr(contact->peername);
-  contact->peerip=rou_freestr(contact->peerip);
-  contact->locname=rou_freestr(contact->locname);
-  contact->locserv=rou_freestr(contact->locserv);
-  (void) free(contact);
-  contact=(CONTYP *)0;
-  }
-return contact;
-#undef OPEP
-}
 /*
 ^L
 */
@@ -128,116 +100,3 @@ if (socptr!=(SOCPTR *)0)
   sent=soc_writebuffer(socptr,buffer,tosend);
 return sent;
 }
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
-/*     Procedure to wait for a remote client.          */
-/*      return all reference to the established contact.*/
-/*                                                      */
-/********************************************************/
-PUBLIC CONTYP *tcp_getcontact(SOCPTR *socptr,int pos)
-
-{
-#define OPEP    "gestcp.c:tcp_getcontact"
-#define MXCARIN 200             //maximun number of char 
-                                //within carpile
-
-CONTYP *contact;
-int phase;
-_Bool proceed;
-
-contact=(CONTYP *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
-  switch (phase){
-    case 0      :       //check for binding
-      if (socptr==(SOCPTR *)0) {
-        (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
-        phase=999;      //not going further
-        }
-      break;
-    case 1      :       //waiting from contact
-      contact=calloc(1,sizeof(CONTYP));
-      if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
-        (void) rou_alert(0,"%s Unable to open contact",OPEP);
-        contact=freecontact(contact);
-        phase=999;      //no contact 
-        }
-      break;
-    case 2      :       //Preparing contact
-      contact->mainsesid=eml_getmainsesid();
-      contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
-      contact->locname=soc_getaddrinfo(contact->socptr,true,true);
-      contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
-      contact->peername=soc_getaddrinfo(contact->socptr,false,true);
-      contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
-      contact->logptr=log_openlog(contact->mainsesid,true);
-      break;
-    case 3      :       //check contact validity
-      if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
-        (void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
-        contact=freecontact(contact);
-        phase=999;      //no identity
-        }
-      break;
-    case 4      :       //contact is good, then sending a signon
-      (void) log_fprintlog(contact->logptr,false,"SID: %s -> Contact open",
-                                                      contact->mainsesid);
-      break;
-    default     :       //SAFE guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-return contact;
-#undef  MXCARIN
-#undef  OPEP
-}
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
-/*     Procedure to wait for a remote client.          */
-/*      return all reference to contact.                 */
-/*                                                      */
-/********************************************************/
-PUBLIC CONTYP *tcp_dropcontact(CONTYP *contact)
-
-{
-#define OPEP    "gestcp.c:tcp_dropcontact"
-
-int phase;
-_Bool proceed;
-
-phase=0;
-proceed=true;
-while (proceed==true) {
-  switch (phase){
-    case 0      :       //check for binding
-      if (contact==(CONTYP *)0) {
-        (void) rou_alert(0,"%s Contact pointer is NULL (Bug!?)",OPEP);
-        phase=999;      //not going further
-        }
-      break;
-    case 1      :       //properly closing remote contact
-      (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
-                          contact->peerip,contact->locserv);
-      contact->socptr=soc_release(contact->socptr);
-      break;
-    case 2      :       //freeing contact memory
-      contact=freecontact(contact);              
-      break;
-    default     :       //SAFE guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-return contact;
-#undef  OPEP
-}
index 30c1ab3f8e14085d20e618204d9496aa77146aa7..82c7ba3039328a19bff818d5680182eaa4dba862 100644 (file)
 #include        "devlog.h"
 #include        "devsoc.h"
 
-typedef struct  {
-        SOCPTR *socptr; //established contact context
-        _Bool tlsok;    //link is in crypted mode
-        char *fqdn;     //fully qualified domain from peer
-        char *locname;  //socket local hostname
-        char *locserv;  //local service port
-        char *peerip;   //socket remote peer IP
-        char *peername; //socket remote peer FQDN
-        int numreset;   //number of SMTP reset received
-        char *mainsesid;//session main ID
-        char *cursesid; //current session ID
-        char *mailfrom; //current mail from originator
-        LOGPTR *logptr; //reference to session log
-        }CONTYP;
-
 //read a line from contact up to CRLF
 extern int tcp_getline(SOCPTR *socptr,TIMESPEC *attend,char **lineptr);
 
 //Transmit formated data to the contact channel
 extern int tcp_write(SOCPTR *socptr,char *buffer,int tosend);
 
-//wait for an incoming contact
-extern CONTYP *tcp_getcontact(SOCPTR *socptr,int pos);
-
-//drop contact established by remote
-extern CONTYP *tcp_dropcontact(CONTYP *contact);
-
 #endif
index 5205cb9e09d3613be62f6589194a72dbf72777aa..824b66e85b534311e8be2f957878781555f4f31d 100644 (file)
@@ -6,6 +6,7 @@
 /*                                                     */
 /********************************************************/
 #include        <stdbool.h>
+#include        <stdlib.h>
 #include        <stdio.h>
 #include        <string.h>
 
 #include       "lvleml.h"
 
 
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to free memory used by contact        */
+/*                                                      */
+/********************************************************/
+static CONTYP *freecontact(CONTYP *contact)
+
+{
+#define OPEP    "gestcp.c:freecontact"
+
+if (contact!=(CONTYP *)0) {
+  contact->logptr=log_closelog(contact->logptr);
+  contact->cursesid=rou_freestr(contact->cursesid);
+  contact->mainsesid=rou_freestr(contact->mainsesid);
+  contact->fqdn=rou_freestr(contact->fqdn);
+  contact->peername=rou_freestr(contact->peername);
+  contact->peerip=rou_freestr(contact->peerip);
+  contact->locname=rou_freestr(contact->locname);
+  contact->locserv=rou_freestr(contact->locserv);
+  (void) free(contact);
+  contact=(CONTYP *)0;
+  }
+return contact;
+#undef OPEP
+}
 /*
 ^L
 */
@@ -203,18 +232,34 @@ proceed=true;
 phase=0;
 while (proceed==true) {
   switch (phase) {
-    case 0      :       //do we have already a from
+    case 0      :       //do we have an originator
+      if ((mailfrom==(char *)0)||(strlen(mailfrom)<3)) {
+        (void) transmit(contact,"%d 5.5.0 %s %s originator not specified",
+                                 BADPAR,MAILF,mailfrom);
+        phase=999;      //no need to go further
+        }
+      break;
+    case 1      :       //do we have already a from
       if (contact->mailfrom!=(char *)0) {
-        (void) transmit(contact,"%d 5.5.1 %s %s already specified as originator",
-                                 BADPAR,MAILF,contact->mailfrom);
+        (void) transmit(contact,"%d 5.5.1 %s '%s' %s",
+                                BADPAR,MAILF,contact->mailfrom,
+                                "was previously defined as originator"
+                                );
         phase=999;      //no need to go further
         }
       break;
-    case 1      :       //clean mailfrom
+    case 2      :       //check from format
+      if ((mailfrom[0]!='<')||(mailfrom[strlen(mailfrom)-1]!='>')) {
+        (void) transmit(contact,"%d 5.5.2 %s %s Format error",
+                                 BADPAR,MAILF,mailfrom);
+        phase=999;      //no need to go further
+        }
+      mailfrom[strlen(mailfrom)-1]='\000'; 
+      (void) memmove(mailfrom,mailfrom+1,strlen(mailfrom));
       break;
-    case 2      :       //everything ok
+    case 3      :       //everything ok
       contact->mailfrom=strdup(mailfrom);
-      (void) transmit(contact,"%d 2.1.0 %s.. sender ok",
+      (void) transmit(contact,"%d 2.1.3 %s.. sender ok",
                                CMDOK,contact->mailfrom);
       break;
     default     :       //SAFE guard
@@ -323,3 +368,116 @@ while (proceed==true) {
 return status;
 #undef  OPEP
 }
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to wait for a remote client.          */
+/*      return all reference to the established contact.*/
+/*                                                      */
+/********************************************************/
+PUBLIC CONTYP *eml_getcontact(SOCPTR *socptr,int pos)
+
+{
+#define OPEP    "lvleml.c:eml_getcontact"
+#define MXCARIN 200             //maximun number of char 
+                                //within carpile
+
+CONTYP *contact;
+int phase;
+_Bool proceed;
+
+contact=(CONTYP *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase){
+    case 0      :       //check for binding
+      if (socptr==(SOCPTR *)0) {
+        (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
+        phase=999;      //not going further
+        }
+      break;
+    case 1      :       //waiting from contact
+      contact=calloc(1,sizeof(CONTYP));
+      if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
+        (void) rou_alert(0,"%s Unable to open contact",OPEP);
+        contact=freecontact(contact);
+        phase=999;      //no contact 
+        }
+      break;
+    case 2      :       //Preparing contact
+      contact->mainsesid=eml_getmainsesid();
+      contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
+      contact->locname=soc_getaddrinfo(contact->socptr,true,true);
+      contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
+      contact->peername=soc_getaddrinfo(contact->socptr,false,true);
+      contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
+      contact->logptr=log_openlog(contact->mainsesid,true);
+      break;
+    case 3      :       //check contact validity
+      if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
+        (void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
+        contact=freecontact(contact);
+        phase=999;      //no identity
+        }
+      break;
+    case 4      :       //contact is good, then sending a signon
+      (void) log_fprintlog(contact->logptr,false,"SID: %s -> Contact open",
+                                                      contact->mainsesid);
+      break;
+    default     :       //SAFE guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return contact;
+#undef  MXCARIN
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to wait for a remote client.          */
+/*      return all reference to contact.                 */
+/*                                                      */
+/********************************************************/
+PUBLIC CONTYP *eml_dropcontact(CONTYP *contact)
+
+{
+#define OPEP    "lvleml.c:eml_dropcontact"
+
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase){
+    case 0      :       //check for binding
+      if (contact==(CONTYP *)0) {
+        (void) rou_alert(0,"%s Contact pointer is NULL (Bug!?)",OPEP);
+        phase=999;      //not going further
+        }
+      break;
+    case 1      :       //properly closing remote contact
+      (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
+                          contact->peerip,contact->locserv);
+      contact->socptr=soc_release(contact->socptr);
+      break;
+    case 2      :       //freeing contact memory
+      contact=freecontact(contact);              
+      break;
+    default     :       //SAFE guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return contact;
+#undef  OPEP
+}
index 12f51e34b86fbd8662fa49990ae5fa35775c53e7..5bde91b6fad4b237f20a47174696bfa513e6bc48 100644 (file)
 
 #include        "gestcp.h"
 
+typedef struct  {
+        SOCPTR *socptr; //established contact context
+        _Bool tlsok;    //link is in crypted mode
+        char *fqdn;     //fully qualified domain from peer
+        char *locname;  //socket local hostname
+        char *locserv;  //local service port
+        char *peerip;   //socket remote peer IP
+        char *peername; //socket remote peer FQDN
+        int numreset;   //number of SMTP reset received
+        char *mainsesid;//session main ID
+        char *cursesid; //current session ID
+        char *mailfrom; //current mail from originator
+        LOGPTR *logptr; //reference to session log
+        }CONTYP;
+
+
 //procedure to extract line and proceed with peer contact
 extern int eml_docontact(CONTYP *contact);
 
+//wait for an incoming contact
+extern CONTYP *eml_getcontact(SOCPTR *socptr,int pos);
+
+//drop contact established by remote
+extern CONTYP *eml_dropcontact(CONTYP *contact);
 #endif
index b23bba806d40b711c6a6f428c7f6908c47a0fafd..ba1022d550065e43eb6792dbf74af6f0938797a8 100644 (file)
@@ -123,7 +123,7 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //waiting contact
-      if ((contact=tcp_getcontact(socptr,pos))==(CONTYP *)0)
+      if ((contact=eml_getcontact(socptr,pos))==(CONTYP *)0)
         phase=999;      //No contact!
       break;
     case 1      :       //within forked process
@@ -146,7 +146,7 @@ while (proceed==true) {
         }
       break;
     case 3      :       //connection terminated
-      contact=tcp_dropcontact(contact);
+      contact=eml_dropcontact(contact);
       (void) rou_checkleak(false);
       break;
     default     :       //SAFE guard