]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Improving ehlo and helo parameter detection
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Apr 2025 20:36:11 +0000 (16:36 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Apr 2025 20:36:11 +0000 (16:36 -0400)
Makefile
lib/lvleml.c
lib/subrou.c
lib/unieml.c
lib/unitls.c

index 0fc6095453d17848ea1315670a23ba0a0df19ecc..bc56a695c7b5efb3243727ec0a5b689c607273b5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -159,6 +159,10 @@ norcvr     :
                        `cat $(LOCKDIR)/emlrcvr.lock`;  \
                 fi
 
+#to kill all remaining emlrcvr process
+killall        :
+         @ kill -9 emlrcvr
+
 #--------------------------------------------------------------------
 #test procedure
 #--------------------------------------------------------------------
index d2bbba7899fb247f03046d40aa512a70e9e1f5a9..659cd8e56fe5b8c4543c17297a45f9e6d1208f9d 100644 (file)
@@ -101,19 +101,18 @@ if (contact!=(CONTYP *)0) {
 #undef  FMT
 }
 /*
-\f
+^L
 */
-/************************************************/
-/*                                             */
-/*     Procedure to send an "HELO" message     */
-/*     if EHLO message is not accepted.        */
-/*                                             */
-/************************************************/
-static _Bool dohelo(CONTYP *contact,char *parameter)
+/********************************************************/
+/*                                                      */
+/*     Procedure to check if helo or ehlo paratmeter   */
+/*      is a correct one                                */
+/*                                                      */
+/********************************************************/
+static _Bool isgoodfqdn(CONTYP *contact,char *parameter)
 
 {
-#define        OPEP    "lvleml.c:dohelo"
-#define DETAIL  "HELO argument is mandatory, closing connection"
+#define        OPEP    "lvleml.c:isgoodfqdn"
 
 _Bool done;
 int phase;
@@ -123,20 +122,26 @@ done=false;
 phase=0;
 proceed=true;
 while (proceed==true) {
+  (void) rou_alert(0,"JMPDBG %s phase='%d' parm=<%s>",OPEP,phase,parameter);
   switch (phase) {
-    case 0      :       //checking need parameter
-      if ((parameter==(char *)0)||(strlen(parameter)==0)) {
-        (void) transmit(contact,"%d 5.5.4 %s.",BADPAR,DETAIL);
-        phase=999;      //Trouble trouble
-        }
+    case 0      :       //checking if we have a parameter
+      if ((parameter==(char *)0)||(strlen(parameter)==0)) 
+        phase=999;      //no parameter
       break;
-    case 1      :       //thereis an FQDN
+    case 1      :       //do we have space
+      if ((parameter[0]!=' ')&&(parameter[0]!='\t'))
+        phase=999;      //parameter wrong format
+      break;
+    case 2      :       //cleaning space character
+      while ((parameter[0]==' ')||(parameter[0]=='\t'))
+        parameter++;
+      if (strlen(parameter)==0)
+        phase=999;      //no parameter?
+      break;
+    case 3      :       //seems to be a good fqdn
       contact->fqdn=rou_freestr(contact->fqdn);
       contact->fqdn=strdup(parameter);
-      (void) transmit(contact,"%d-%s ready, your IP/FQDN=[%s/%s]",
-                              CMDOK,contact->locname,
-                              contact->peerip,contact->peername);
-      done=true;
+      done=true; 
       break;
     default     :       //SAFE guard
       proceed=false;
@@ -145,6 +150,32 @@ while (proceed==true) {
   phase++;
   }
 return done;
+#undef  OPEP
+}
+/*
+\f
+*/
+/************************************************/
+/*                                             */
+/*     Procedure to send an "HELO" message     */
+/*     if EHLO message is not accepted.        */
+/*                                             */
+/************************************************/
+static _Bool dohelo(CONTYP *contact,char *parameter)
+
+{
+#define        OPEP    "lvleml.c:dohelo"
+#define DETAIL  "HELO argument is mandatory, closing connection"
+
+_Bool done;
+
+if ((done=isgoodfqdn(contact,parameter))==false) 
+  (void) transmit(contact,"%d 5.5.4 %s.",BADPAR,DETAIL);
+else
+  (void) transmit(contact,"%d %s ready, your IP/FQDN=[%s/%s]",
+                           CMDOK,contact->locname,
+                           contact->peerip,contact->peername);
+return done;
 #undef  DETAIL
 #undef  OPEP
 }
@@ -185,22 +216,21 @@ strstart=0;
 phase=0;
 proceed=true;
 while (proceed==true) {
+  (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //Do we have a parameter
-      if ((parameter==(char *)0)||(strlen(parameter)==0)) {
+      if ((done=isgoodfqdn(contact,parameter))==false) {
         (void) transmit(contact,"%d 5.5.4 %s.",BADPAR,DETAIL);
         phase=999;      //Trouble trouble
         }
       break;
     case 1      :       //thereis an FQDN
-      contact->fqdn=rou_freestr(contact->fqdn);
-      contact->fqdn=strdup(parameter);
+      if (contact->tlsok==true)
+        strstart++;
       (void) transmit(contact,"%d-%s ready, your IP/FQDN=[%s/%s]",
                               CMDOK,contact->locname,
                               contact->peerip,contact->peername);
       (void) transmit(contact,"%d-SIZE %ld",CMDOK,MXMSIZE);
-      if (contact->tlsok==true)
-        strstart++;
       for (int i=strstart;ehlostr[i]!=(char *)0;i++) {
         (void) transmit(contact,"%d%s",CMDOK,ehlostr[i]);
         }
@@ -311,6 +341,7 @@ PUBLIC int eml_docontact(CONTYP *contact)
 
 {
 #define OPEP    "lvleml.c:eml_docontact"
+
 int status;
 int got;
 int delay;
@@ -320,7 +351,7 @@ status=1;
 got=0;
 delay=300;      //5 minutes standard delay
 if (debug>1) 
-  delay/=30;     //10 sec in debug mode
+  delay/=10;     //30 sec in debug mode
 proceed=true;
 (void) signon(contact);
 while (proceed==true) {
@@ -360,10 +391,8 @@ while (proceed==true) {
       proceed=doehlo(contact,line);
       break;
     case c_quit         :       //QUIT SMTP protocol
-      //(void) rou_alert(0,"%s JMPDBG sleep started",OPEP);
       (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",    
                               QUITOK,contact->mainsesid);
-      //(void) rou_alert(0,"%s JMPDBG Bye transmitted",OPEP);
       status=1;                 //every thing fine
       proceed=false;
       break;
@@ -392,7 +421,12 @@ while (proceed==true) {
     case c_unknown      :       //uknown keyword
       (void) rou_alert(0,"Command <%s> from [%s] is unknown (config?)",
                          line,contact->peerip);
-      (void) transmit(contact,"%d 5.5.1 command <%s> is unknown",CMDBAD,line);
+      (void) transmit(contact,"%d-5.5.1 command <%s> is unknown",CMDBAD,line);
+      (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",    
+                              QUITOK,contact->mainsesid);
+      status=-1;                 //remote is a trouble maker
+      proceed=false;
+      (void) rou_alert(0,"%s JMPDBG should ho out",OPEP);
       break;
     default             : 
       (void) rou_alert(0,"Unable to find keyword for <%s> (Bug?)",OPEP,line);
index 44e121dadfe332ac6585a0c059195a03ac7549ef..a576b7650b85e16c831ffffbfe48765f87dd3691 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "51"
+#define RELEASE "52"
 #define BRANCH "dvl"
 
 //Public variables
index 8ea4232892c6a8c5a1d8b933dd541b6697cdb8d1..79f4e1c433491008cda2a8af1d29166d031b968e 100644 (file)
@@ -88,15 +88,15 @@ CODTYP code;
 VOCTYP *ptr;
 
 code=c_unknown;
+  (void) rou_alert(0,"JMDPBG keywork1=<%s>",keyword);
 for (ptr=vocsmtp;ptr->code!=c_unknown;ptr++) {
   if (strncasecmp(ptr->key,keyword,strlen(ptr->key))==0) {
     char *par;
 
     code=ptr->code;
     par=keyword+strlen(ptr->key);
-    while ((*par==' ')||(*par=='\t'))
-      par++;
     (void) strcpy(keyword,par);
+    (void) rou_alert(0,"JMDPBG keywork2=<%s>",keyword);
     break;
     }
   }
index 23354d09b6bdef7a608234b061abb922530acc93..b90234756829b4d0528aa632a14c25d810b5a6b0 100644 (file)
@@ -432,6 +432,7 @@ while (proceed==true) {
     case 3      :       //Setting the TLS channel actif
       switch (server) {
         case false  :   //mode client
+          (void) rou_alert(0,"%s JMPDBG should be in client mode",OPEP);
           break;
         case true   :   //mode server
           (void) SSL_set_accept_state(tls->ssl);