From: Jean-Marc Pigeon (Delson) Date: Sun, 11 Aug 2024 19:23:30 +0000 (-0400) Subject: Adding helo entry X-Git-Tag: tag-0.4.1 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=6ec12ca3e636a5a4fb8acd5a62960de32c483b55;p=jmp%2Fmailleur Adding helo entry --- diff --git a/lib/lvleml.c b/lib/lvleml.c index cea9470..d56911f 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -45,7 +45,54 @@ va_end(args); /* if EHLO message is not accepted. */ /* */ /************************************************/ -static _Bool doehlo(CONTYP *contact,char *line) +static _Bool dohelo(CONTYP *contact,char *keyword,char *parameter) + +{ +#define OPEP "unieml.c:dohelo" +#define DETAIL "HELO argument is mandatory, closing connection" + +_Bool done; +int phase; +_Bool proceed; + +done=false; +phase=0; +proceed=true; +while (proceed==true) { + 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 + } + break; + case 1 : //thereis an FQDN + contact->fqdn=rou_freestr(contact->fqdn); + contact->fqdn=strdup(parameter); + (void) transmit(contact,"%d-%s ready, your IP=[%s]", + CMDOK,contact->locname,contact->peerip); + done=true; + break; + default : //SAFE guard + proceed=false; + break; + } + phase++; + } +return done; +#undef DETAIL +#undef OPEP +} +/* + +*/ +/************************************************/ +/* */ +/* Procedure to send an "HELO" message */ +/* if EHLO message is not accepted. */ +/* */ +/************************************************/ +static _Bool doehlo(CONTYP *contact,char *keyword,char *parameter) { static char *ehlostr[]= { @@ -58,35 +105,28 @@ static char *ehlostr[]= { }; #define OPEP "unieml.c:doehlo" -#define DETAIL "syntax error (domain part missing), disconnecting" +#define DETAIL "syntax error (domain part missing), closing connection" _Bool done; -char *fqdn; int strstart; int phase; _Bool proceed; done=false; -fqdn=(char *)0; strstart=0; phase=0; proceed=true; while (proceed==true) { switch (phase) { - case 0 : //Do we have - fqdn=strchr(line,' '); - if (fqdn!=(char *)0) { - while ((*fqdn==' ')||(*fqdn=='\t')) - fqdn++; - } - if ((fqdn==(char *)0)||(strlen(fqdn)==0)) { - (void) transmit(contact,"%d 5.5.4 %s",BADPAR,DETAIL); + case 0 : //Do we have a parameter + if ((parameter==(char *)0)||(strlen(parameter)==0)) { + (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(fqdn); + contact->fqdn=strdup(parameter); (void) transmit(contact,"%d-%s ready, your IP=[%s]", CMDOK,contact->locname,contact->peerip); (void) transmit(contact,"%d-SIZE %ld",CMDOK,MXMSIZE); @@ -130,16 +170,29 @@ status=1; proceed=true; while (proceed==true) { char *line; + char *parameter; TIMESPEC attend; attend.tv_sec=60; attend.tv_nsec=0; status=tcp_getline(contact,&attend,&line); + parameter=strchr(line,' '); + if (parameter==(char *)0) + parameter=strchr(line,'\t'); + if (parameter!=(char *)0) { + *parameter='\000'; + parameter++; + while ((*parameter==' ')||(*parameter=='\t')) + parameter++; + } if (status<=0) //timeout or trouble? break; //no need to go further switch (eml_getcode(line)) { + case c_helo : //HELO SMTP protocol + proceed=dohelo(contact,line,parameter); + break; case c_ehlo : //EHLO SMTP protocol - proceed=doehlo(contact,line); + proceed=doehlo(contact,line,parameter); break; case c_quit : //QUIT SMTP protocol (void) transmit(contact,"%d 2.0.0 Bye, closing connection",QUITOK); diff --git a/lib/subrou.c b/lib/subrou.c index 2299b97..36f1e24 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -20,7 +20,7 @@ //version definition #define VERSION "0.4" -#define RELEASE "1" +#define RELEASE "2" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unieml.c b/lib/unieml.c index 4f6c17c..9aebca3 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -21,6 +21,7 @@ typedef struct { //this list order by key length static VOCTYP vocsmtp[]={ + {c_helo,"HELO"}, {c_ehlo,"EHLO"}, {c_quit,"QUIT"}, {c_starttls,"STARTTLS"}, @@ -42,7 +43,7 @@ VOCTYP *ptr; code=c_unknown; for (ptr=vocsmtp;ptr->code!=c_unknown;ptr++) { - if (strncasecmp(ptr->key,keyword,strlen(ptr->key))==0) { + if (strncasecmp(ptr->key,keyword,strlen(keyword))==0) { code=ptr->code; break; } diff --git a/lib/unieml.h b/lib/unieml.h index 004d605..c37cbcc 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -18,6 +18,7 @@ //list of keyword typedef enum { //list of SMTP protocol keyword + c_helo, //Basic Helo command c_ehlo, //EHLO command c_quit, //quit exchange c_starttls, //Starting a TLS crypted link diff --git a/lib/unitls.h b/lib/unitls.h index e1de541..b26a85e 100644 --- a/lib/unitls.h +++ b/lib/unitls.h @@ -20,7 +20,6 @@ typedef struct { char *locport; //local Port number SSL_CTX *ctx; //SSL context SSL *ssl; //SSL link - //BIO *bio; //SSL Basic input output }TLSTYP; //procedure to open an tls channel