From: Jean-Marc Pigeon (Delson) Date: Thu, 10 Apr 2025 20:36:11 +0000 (-0400) Subject: Improving ehlo and helo parameter detection X-Git-Tag: tag-0.7~23 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=6d65af7beb93e5ed8d98380aabadee8020802478;p=jmp%2Fmailleur Improving ehlo and helo parameter detection --- diff --git a/Makefile b/Makefile index 0fc6095..bc56a69 100644 --- 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 #-------------------------------------------------------------------- diff --git a/lib/lvleml.c b/lib/lvleml.c index d2bbba7..659cd8e 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -101,19 +101,18 @@ if (contact!=(CONTYP *)0) { #undef FMT } /* - +^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 +} +/* + +*/ +/************************************************/ +/* */ +/* 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); diff --git a/lib/subrou.c b/lib/subrou.c index 44e121d..a576b76 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "51" +#define RELEASE "52" #define BRANCH "dvl" //Public variables diff --git a/lib/unieml.c b/lib/unieml.c index 8ea4232..79f4e1c 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -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; } } diff --git a/lib/unitls.c b/lib/unitls.c index 23354d0..b902347 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -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);