From e68aba1272f74e5a039bae00847cbfdccf904a85 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 12 Aug 2024 14:51:11 -0400 Subject: [PATCH] Defining the session ID --- lib/gestcp.c | 4 +++- lib/gestcp.h | 2 ++ lib/lvleml.c | 3 ++- lib/subrou.c | 34 +++++++++++++++++++++++++++++++--- lib/subrou.h | 3 +++ lib/unieml.c | 27 +++++++++++++++++++++++++++ lib/unieml.h | 5 ++++- 7 files changed, 72 insertions(+), 6 deletions(-) diff --git a/lib/gestcp.c b/lib/gestcp.c index 65d692b..5e171e3 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -35,6 +35,7 @@ static CONTYP *freecontact(CONTYP *contact) #define OPEP "gesttcp.c:freecontact" if (contact!=(CONTYP *)0) { + contact->sessid=rou_freestr(contact->sessid); contact->fqdn=rou_freestr(contact->fqdn); contact->peerip=rou_freestr(contact->peerip); contact->locname=rou_freestr(contact->locname); @@ -201,13 +202,14 @@ 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(); 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 3 : //contact is good sending signon + case 3 : //contact is good, then sending a signon if (tcp_signon(contact)<=0) { contact=freecontact(contact); phase=999; //no contact diff --git a/lib/gestcp.h b/lib/gestcp.h index 8655c59..b820165 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -19,6 +19,8 @@ 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 }CONTYP; //read a line from contact up to CRLF diff --git a/lib/lvleml.c b/lib/lvleml.c index d56911f..e00e819 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -195,7 +195,8 @@ while (proceed==true) { proceed=doehlo(contact,line,parameter); break; case c_quit : //QUIT SMTP protocol - (void) transmit(contact,"%d 2.0.0 Bye, closing connection",QUITOK); + (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s", + QUITOK,contact->sessid); proceed=false; break; case c_starttls : //EHLO start encryptel link diff --git a/lib/subrou.c b/lib/subrou.c index 36f1e24..d69da94 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -4,6 +4,7 @@ /* Module for low level subroutine */ /* */ /********************************************************/ +#include #include #include #include @@ -19,8 +20,8 @@ //version definition -#define VERSION "0.4" -#define RELEASE "2" +#define VERSION "0.4.1" +#define RELEASE "1" //Public variables PUBLIC int debug=0; //debug level @@ -81,7 +82,7 @@ PUBLIC void rou_checkleak(_Bool onoff) static _Bool current=false; -if (current!=onoff) { +if ((debug>2)&&(current!=onoff)) { int status; char cmd[200]; @@ -105,6 +106,33 @@ if (current!=onoff) { */ /********************************************************/ /* */ +/* Procedure to return the current time */ +/* expressed with a millisecond precision starting */ +/* from the firt time it was called. */ +/* */ +/********************************************************/ +PUBLIC unsigned int rou_getmillisec() + +{ +struct timeval newtime; +(void) gettimeofday(&newtime,(struct timezone *)0); +return (unsigned int)((newtime.tv_usec/1000)); +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to transform the local system time in */ +/* ASCII time stamp. */ +/* Stored in STATIC memory area. */ +/* */ +/********************************************************/ +/* + +*/ +/********************************************************/ +/* */ /* Procedure to transform the local system time in */ /* ASCII time stamp. */ /* Stored in STATIC memory area. */ diff --git a/lib/subrou.h b/lib/subrou.h index 438fe57..2b2bce3 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 return the current number of milli-second +extern unsigned int rou_getmillisec(); + //transform local system time in ASCII stamp. extern char *rou_ascsysstamp(time_t curtime); diff --git a/lib/unieml.c b/lib/unieml.c index 9aebca3..4f9e437 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "subrou.h" #include "unieml.h" @@ -32,6 +33,32 @@ static VOCTYP vocsmtp[]={ */ /********************************************************/ /* */ +/* Procedure to format and return a dynamicaly */ +/* allocated char array filled with uniq session ID*/ +/* */ +/********************************************************/ +PUBLIC char *eml_getsessionid() + +{ +#define UFTIME "%Y%m%d%H%M%S" +#define UNIQUE "%05d-%s-%04d" + +time_t curtime; +char asctemps[100]; +char buffer[300]; + +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); +#undef UNIQUE +#undef UFTIME +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to return a protocol keywork code */ /* */ /********************************************************/ diff --git a/lib/unieml.h b/lib/unieml.h index c37cbcc..924ae8f 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -25,7 +25,10 @@ typedef enum { //list of SMTP protocol keyword c_unknown //key word unknown }CODTYP; -//conver keyword to CODTYP +//get a session unique id +extern char *eml_getsessionid(); + +//convert SMTP keyword to CODTYP extern CODTYP eml_getcode(char *keyword); //homework to be done before starting/stopping module. -- 2.47.3