#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);
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);
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
#undef OPEP
}
/*
+\f
+*/
+/************************************************/
+/* */
+/* 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
*/
/********************************************************/
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
//version definition
#define VERSION "0.4.1"
-#define RELEASE "1"
+#define RELEASE "2"
//Public variables
PUBLIC int debug=0; //debug level
*/
/********************************************************/
/* */
+/* 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;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to return the current time */
/* expressed with a millisecond precision starting */
/* from the firt time it was called. */
{
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;
}
/*
//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();
{c_helo,"HELO"},
{c_ehlo,"EHLO"},
{c_quit,"QUIT"},
+ {c_rset,"RSET"},
{c_starttls,"STARTTLS"},
{c_unknown,(const char *)0}
};
/* 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
}
*/
/********************************************************/
/* */
+/* 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 */
/* */
/********************************************************/
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);
(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;