From a9dee4c3a2a77b5c551aa62b9b4f0dd3d8d2fef5 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 12 Aug 2024 20:06:40 -0400 Subject: [PATCH] Rset fonction is working, updating cursesid --- lib/gestcp.c | 6 ++++-- lib/gestcp.h | 3 ++- lib/lvleml.c | 22 +++++++++++++++++++++- lib/subrou.c | 37 +++++++++++++++++++++++++++++++------ lib/subrou.h | 3 +++ lib/unieml.c | 30 ++++++++++++++++++++++++++---- lib/unieml.h | 6 +++++- lib/unitls.c | 1 + 8 files changed, 93 insertions(+), 15 deletions(-) diff --git a/lib/gestcp.c b/lib/gestcp.c index 5e171e3..3c1a08f 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -35,7 +35,8 @@ static CONTYP *freecontact(CONTYP *contact) #define OPEP "gesttcp.c:freecontact" if (contact!=(CONTYP *)0) { - contact->sessid=rou_freestr(contact->sessid); + contact->cursesid=rou_freestr(contact->cursesid); + contact->mainsesid=rou_freestr(contact->mainsesid); contact->fqdn=rou_freestr(contact->fqdn); contact->peerip=rou_freestr(contact->peerip); contact->locname=rou_freestr(contact->locname); @@ -202,7 +203,8 @@ while (proceed==true) { contact->locname=soc_getaddrinfo(contact->socptr,true,true); contact->locserv=soc_getaddrinfo(contact->socptr,true,false); contact->peerip=soc_getaddrinfo(contact->socptr,false,true); - contact->sessid=eml_getsessionid(); + contact->mainsesid=eml_getmainsesid(); + contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset); if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) { (void) rou_alert(0,"%s Unable to establish contact entities",OPEP); contact=freecontact(contact); diff --git a/lib/gestcp.h b/lib/gestcp.h index b820165..ad822e7 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -19,8 +19,9 @@ typedef struct { char *locname; //socket local hostname char *locserv; //local service port char *peerip; //socket remote peer IP - char *sessid; //current session ID int numreset; //number of SMTP reset received + char *mainsesid;//session main ID + char *cursesid; //current session ID }CONTYP; //read a line from contact up to CRLF diff --git a/lib/lvleml.c b/lib/lvleml.c index e00e819..905f4d0 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -148,6 +148,23 @@ return done; #undef OPEP } /* + +*/ +/************************************************/ +/* */ +/* Procedure to rset the current session */ +/* */ +/************************************************/ +static _Bool dorset(CONTYP *contact,char *keyword,char *parameter) + +{ +(void) transmit(contact,"%d 2.0.0 Flushed session %s",CMDOK,contact->cursesid); +contact->numreset++; +contact->cursesid=rou_freestr(contact->cursesid); +contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset); +return true; +} +/* ^L */ /********************************************************/ @@ -196,9 +213,12 @@ while (proceed==true) { break; case c_quit : //QUIT SMTP protocol (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s", - QUITOK,contact->sessid); + QUITOK,contact->mainsesid); proceed=false; break; + case c_rset : //Doing session reset + proceed=dorset(contact,line,parameter); + break; case c_starttls : //EHLO start encryptel link switch (soc_starttls(contact->socptr,contact->peerip)) { case true : //link now in TLS crypted mode diff --git a/lib/subrou.c b/lib/subrou.c index d69da94..f995dd4 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.4.1" -#define RELEASE "1" +#define RELEASE "2" //Public variables PUBLIC int debug=0; //debug level @@ -106,6 +106,35 @@ if ((debug>2)&&(current!=onoff)) { */ /********************************************************/ /* */ +/* Procedure to assign enough memory to format */ +/* a string. */ +/* Known as asprintf in GNU_SOURCE. */ +/* */ +/********************************************************/ +PUBLIC int rou_asprintf(char **str,const char *fmt,...) + +{ +va_list args; +int taille; +char loc[10]; + +va_start(args,fmt); +if ((taille=vsnprintf(loc,4,fmt,args))>0) { + va_list argssup; + + va_start(argssup,fmt); + *str=calloc(taille+2,sizeof(char)); + taille=vsnprintf(*str,taille+1,fmt,argssup); + va_end(argssup); + } +va_end(args); +return taille; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to return the current time */ /* expressed with a millisecond precision starting */ /* from the firt time it was called. */ @@ -309,16 +338,12 @@ PUBLIC char *rou_apppath(const char *path) { char *root; char *newpath; -int taille; -char loc[300]; root=""; newpath=(char *)0; if (rootdir!=(char *)0) root=rootdir; -taille=snprintf(loc,sizeof(loc),"%s%s",root,path); -newpath=(char *)calloc(taille+3,sizeof(char)); -(void) sprintf(newpath,"%s%s",root,path); +(void) rou_asprintf(&newpath,"%s%s",root,path); return newpath; } /* diff --git a/lib/subrou.h b/lib/subrou.h index 2b2bce3..acd5598 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -31,6 +31,9 @@ extern char *appname; //application "official" name //open/close memory leak detector. extern void rou_checkleak(_Bool onoff); +//procedure to assign memory according a format and parameter list +extern int rou_asprintf(char **str,const char *fmt,...); + //procedure to return the current number of milli-second extern unsigned int rou_getmillisec(); diff --git a/lib/unieml.c b/lib/unieml.c index 4f9e437..6e98a93 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -25,6 +25,7 @@ static VOCTYP vocsmtp[]={ {c_helo,"HELO"}, {c_ehlo,"EHLO"}, {c_quit,"QUIT"}, + {c_rset,"RSET"}, {c_starttls,"STARTTLS"}, {c_unknown,(const char *)0} }; @@ -37,20 +38,23 @@ static VOCTYP vocsmtp[]={ /* allocated char array filled with uniq session ID*/ /* */ /********************************************************/ -PUBLIC char *eml_getsessionid() +PUBLIC char *eml_getmainsesid() { #define UFTIME "%Y%m%d%H%M%S" #define UNIQUE "%05d-%s-%04d" +char *sesid; time_t curtime; char asctemps[100]; -char buffer[300]; + + +sesid=(char *)0; curtime=time((time_t)0); (void) strftime(asctemps,sizeof(asctemps),UFTIME,localtime(&curtime)); -(void) snprintf(buffer,sizeof(buffer),UNIQUE,getpid(),asctemps,rou_getmillisec()); -return strdup(buffer); +(void) rou_asprintf(&sesid,UNIQUE,getpid(),asctemps,rou_getmillisec()); +return sesid; #undef UNIQUE #undef UFTIME } @@ -59,6 +63,24 @@ return strdup(buffer); */ /********************************************************/ /* */ +/* Procedure to format and return a dynamicaly */ +/* allocated char array with the current seesion ID*/ +/* */ +/********************************************************/ +PUBLIC char *eml_getcursesid(char *mainsesid,int numreset) + +{ +char *sesid; + +sesid=(char *)0; +(void) rou_asprintf(&sesid,"%s-%04d",mainsesid,numreset); +return sesid; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to return a protocol keywork code */ /* */ /********************************************************/ diff --git a/lib/unieml.h b/lib/unieml.h index 924ae8f..b168b0b 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -21,12 +21,16 @@ typedef enum { //list of SMTP protocol keyword c_helo, //Basic Helo command c_ehlo, //EHLO command c_quit, //quit exchange + c_rset, //resetting session c_starttls, //Starting a TLS crypted link c_unknown //key word unknown }CODTYP; //get a session unique id -extern char *eml_getsessionid(); +extern char *eml_getmainsesid(); + +//get the current session ID +extern char *eml_getcursesid(char *mainid,int numreset); //convert SMTP keyword to CODTYP extern CODTYP eml_getcode(char *keyword); diff --git a/lib/unitls.c b/lib/unitls.c index f8efe35..9aecd74 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -582,6 +582,7 @@ if (tls!=(TLSTYP *)0) { (void) rou_alert(0,"%s Unexpected SSL_read error='%d'", OPEP,SSL_get_error(tls->ssl,0)); (void) showtlserror(tls,0,"show SSL error",OPEP); + got=-1; break; } break; -- 2.47.3