From f3b349f1dfa5c24fff238bb20b687e0e10ea4d44 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sat, 3 May 2025 10:07:09 -0400 Subject: [PATCH] idirect crypted channel (smtps) is working fine --- lib/devsoc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- lib/devsoc.h | 6 ++++++ lib/lvleml.c | 21 ++++++++------------- lib/lvleml.h | 2 +- 4 files changed, 59 insertions(+), 16 deletions(-) diff --git a/lib/devsoc.c b/lib/devsoc.c index 3411a04..d24c324 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -1309,7 +1309,7 @@ return data; /* Procedure to close and release exchange socket */ /* */ /********************************************************/ -SOCPTR *soc_release(SOCPTR *socptr) +PUBLIC SOCPTR *soc_release(SOCPTR *socptr) { #define OPEP "devsoc.c:soc_release" @@ -1374,7 +1374,7 @@ return socptr; /* crypted channel, return true is successful. */ /* */ /********************************************************/ -_Bool soc_starttls(SOCPTR *socptr) +PUBLIC _Bool soc_starttls(SOCPTR *socptr) { _Bool ok; @@ -1402,3 +1402,45 @@ if ((soc!=(SOCTYP *)0)&&(soc->modtls==false)) { } return ok; } +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to return true if sthe socket is */ +/* in crypted mode. */ +/* */ +/********************************************************/ +PUBLIC _Bool soc_iscrypted(SOCPTR *socptr) + +{ +_Bool iscrypted; + +iscrypted=false; +if (socptr!=(SOCPTR *)0) + iscrypted=((SOCTYP *)socptr)->modtls; +return iscrypted; +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to return the socket mode as a string */ +/* */ +/********************************************************/ +PUBLIC const char *soc_getstrmode(SOCPTR *socptr) + +{ +const char *mode; +SOCTYP *soc; + +mode="Unknown"; +soc=(SOCTYP *)socptr; +if (soc!=(SOCTYP *)0) { + mode="cleartext"; + if (soc->modtls==true) + mode="crypted"; + } +return mode; +} diff --git a/lib/devsoc.h b/lib/devsoc.h index d8cffbe..15df1db 100644 --- a/lib/devsoc.h +++ b/lib/devsoc.h @@ -78,4 +78,10 @@ extern SOCPTR *soc_release(SOCPTR *socptr); //procedure to initiate crypted mode on plain channel extern _Bool soc_starttls(SOCPTR *socptr); +//return flag true if socet is in crypted mode +extern _Bool soc_iscrypted(SOCPTR *socptr); + +//return line socket mode (cleartext, crypted) +extern const char *soc_getstrmode(SOCPTR *socptr); + #endif diff --git a/lib/lvleml.c b/lib/lvleml.c index 7f9d092..8d9da03 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -81,18 +81,16 @@ va_end(args); static void signon(CONTYP *contact) { -#define FMT "%d %s ESMTP %s%s-%s; %s" +#define FMT "%d %s ESMTP (%s) %s-%s; %s" if (contact!=(CONTYP *)0) { - char strcrypt[20]; + const char *mode; char signon[100]; - (void) strcpy(strcrypt,""); - if (contact->tlsok==true) - (void) strcpy(strcrypt,"(crypted) "); + mode=soc_getstrmode(contact->socptr); (void) snprintf(signon,sizeof(signon),FMT, SIGNON,contact->locname, - strcrypt, + mode, appname, rou_getversion(), rou_ascsysstamp(time((time_t *)0))); @@ -112,13 +110,11 @@ if (contact!=(CONTYP *)0) { static void linkready(CONTYP *contact) { -char *crypted; +const char *mode; -crypted="cleartext"; -if (contact->tlsok==true) - crypted="crypted"; +mode=soc_getstrmode(contact->socptr); (void) transmit(contact,"%d-%s, link (%s) ready, your IP/FQDN=[%s/%s]", - CMDOK,contact->locname,crypted, + CMDOK,contact->locname,mode, contact->peerip,contact->peername); } /* @@ -246,7 +242,7 @@ while (proceed==true) { case 1 : //thereis an FQDN (void) linkready(contact); (void) transmit(contact,"%d-SIZE %ld",CMDOK,MXMSIZE); - if (contact->tlsok==true) + if (soc_iscrypted(contact->socptr)==true) strstart++; for (int i=strstart;ehlostr[i]!=(char *)0;i++) { (void) transmit(contact,"%d%s",CMDOK,ehlostr[i]); @@ -423,7 +419,6 @@ while (proceed==true) { case c_starttls : //EHLO start encryptel link switch (soc_starttls(contact->socptr)) { case true : //link now in TLS crypted mode - contact->tlsok=true; (void) transmit(contact,"%d Link now encrypted",CMDOK); (void) rou_alert(0,"%s, CMDOK sent",OPEP); break; diff --git a/lib/lvleml.h b/lib/lvleml.h index 5bde91b..28e9158 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -12,7 +12,7 @@ typedef struct { SOCPTR *socptr; //established contact context - _Bool tlsok; //link is in crypted mode + //_Bool tlsok; //link is in crypted mode char *fqdn; //fully qualified domain from peer char *locname; //socket local hostname char *locserv; //local service port -- 2.47.3