case 1 : //shutting down the TCP link
switch (soc->proto) {
case pro_smtp : //plain socket
+ break;
case pro_starttls : //plain socket + STARTTLS
- //nothing to do
+ if (soc->modtls==true) {
+ soc->tls=tls_closetls(soc->tls);
+ soc->modtls=false;
+ }
break;
case pro_smtps : //set secure socket
soc->tls=tls_closetls(soc->tls);
phase=999; //No contact!
break;
case 1 : //within forked process
- printf("New client [%s] connected\n",contact->peerip);
+ (void) prc_settitle("Processing incoming contact from [%s] on [%s:%s]",
+ contact->peerip,contact->locname,contact->locserv);
+ (void) rou_checkleak(true);
+ printf("New client [%s] connected pid='%05d'\n",contact->peerip,getpid());
break;
case 2 : //do contact
switch (eml_docontact(contact)) {
break;
case 3 : //connection terminated
contact=tcp_dropcontact(contact);
+ (void) rou_checkleak(false);
break;
default : //SAFE guard
proceed=false;
//version definition
-#define VERSION "0.3"
-#define RELEASE "42"
+#define VERSION "0.4"
+#define RELEASE "1"
//Public variables
PUBLIC int debug=0; //debug level
*/
/********************************************************/
/* */
+/* This procedure is working tandem with libleak */
+/* to detect memory leak within specfic part of */
+/* code. */
+/* Tools as valgrind can not be used as most of */
+/* the application is forked in daemon state. */
+/* memory leak must be detected on a "long" run */
+/* forgetting about parent process apparent leak. */
+/* (forked process are created with parent memory */
+/* copy) */
+/* */
+/********************************************************/
+PUBLIC void rou_checkleak(_Bool onoff)
+
+{
+#define ENABLE "/tmp/libleak.enabled"
+
+static _Bool current=false;
+
+if (current!=onoff) {
+ int status;
+ char cmd[200];
+
+ switch (onoff) {
+ case true :
+ (void) snprintf(cmd,sizeof(cmd),"echo %d >> %s",getpid(),ENABLE);
+ break;
+ case false :
+ (void) snprintf(cmd,sizeof(cmd),"sed -i '/%d/d' %s",getpid(),ENABLE);
+ break;
+ }
+ if ((status=system(cmd))!=0) {
+ (void) rou_alert(0,"status '%d' to memleak command <%s> (bug?)",status,cmd);
+ }
+ current=onoff;
+ }
+#undef ENABLE
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to transform the local system time in */
/* ASCII time stamp. */
/* Stored in STATIC memory area. */
/* */
/********************************************************/
-char *rou_ascsysstamp(time_t curtime)
+PUBLIC char *rou_ascsysstamp(time_t curtime)
{
#define TSTAMP "%a, %d %b %Y %T %z"
/* string, do not proceed if pointer is NULL. */
/* */
/********************************************************/
-char *rou_freestr(register char *str)
+PUBLIC char *rou_freestr(register char *str)
{
if (str!=(char *)0) {
//--- Routines implemented within subrou.c ---------
+//open/close memory leak detector.
+extern void rou_checkleak(_Bool onoff);
+
//transform local system time in ASCII stamp.
extern char *rou_ascsysstamp(time_t curtime);
tls->peerip=rou_freestr(tls->peerip);
tls->locip=rou_freestr(tls->locip);
tls->locport=rou_freestr(tls->locport);
- if (tls->ssl!=(SSL *)0)
- (void) free(tls->ssl);
+ if (tls->ssl!=(SSL *)0) {
+ (void) SSL_clear(tls->ssl);
+ (void) SSL_free(tls->ssl);
+ }
if (tls->ctx!=(SSL_CTX *)0)
(void) SSL_CTX_free(tls->ctx);
(void) free(tls);
char *locport; //local Port number
SSL_CTX *ctx; //SSL context
SSL *ssl; //SSL link
- BIO *bio; //SSL Basic input output
+ //BIO *bio; //SSL Basic input output
}TLSTYP;
//procedure to open an tls channel