From ab5e7868ba24817ff749c2c5ad0772601337d417 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 8 Jul 2025 11:40:05 -0400 Subject: [PATCH] contact is now including delay timer --- lib/lvleml.c | 45 +++++++++++++++++++++++---------------------- lib/lvleml.h | 1 + 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/lvleml.c b/lib/lvleml.c index 440d43b..b40fe02 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -318,7 +318,7 @@ return status; /* mode, return "decoded", NULL if not extracted */ /* */ /********************************************************/ -static char *get_auth_plain(CONTYP *contact,int delay,char *received) +static char *get_auth_plain(CONTYP *contact,char *received) { #define OPEP "lvleml.c:get_auth_plain," @@ -332,7 +332,7 @@ if ((received==(char *)0)||(strlen(received)==0)) { line=(char *)0; (void) transmit(contact,true,"%d 5.7.1 Please provide auth sequence",SENDB64); - got=tcp_getline(contact->socptr,delay,&line); + got=tcp_getline(contact->socptr,contact->delay,&line); if (got>0) { (void) log_fprintlog(contact->logptr,false,"%s",line); decoded=cnv_getb64(line); @@ -356,7 +356,7 @@ return decoded; /* the exchange with the remote sereur */ /* */ /********************************************************/ -static char *get_auth_cram_md5(CONTYP *contact,int delay) +static char *get_auth_cram_md5(CONTYP *contact) { #define OPEP "lvleml.c:get_auth_cram_md5," @@ -400,7 +400,7 @@ while (proceed==true) { case 2 : { //getting the challenge answer char *line; - if (tcp_getline(contact->socptr,delay,&line)>0) { + if (tcp_getline(contact->socptr,contact->delay,&line)>0) { char *res; res=cnv_getb64(line); @@ -475,7 +475,7 @@ return decoded; /* */ /* */ /********************************************************/ -static char *get_auth_digest_md5(CONTYP *contact,int delay) +static char *get_auth_digest_md5(CONTYP *contact) { #define OPEP "lvleml.c:get_auth_digest_md5," @@ -515,7 +515,7 @@ while (proceed==true) { case 2 : { //getting the challenge answer char *line; - if (tcp_getline(contact->socptr,delay,&line)>0) { + if (tcp_getline(contact->socptr,contact->delay,&line)>0) { //if a clear text QUIT is received because of deep trouble if (strcasecmp(line,"QUIT")!=0) { char *res; @@ -569,7 +569,7 @@ while (proceed==true) { int count; line=(char *)0; - count=tcp_getline(contact->socptr,delay,&line); + count=tcp_getline(contact->socptr,contact->delay,&line); if (count<0) (void) rou_alert(0,"%s delay expired to get remote empty line (network?)", OPEP); @@ -617,7 +617,7 @@ return decoded; /* mode, return "decoded", NULL if not extracted */ /* */ /********************************************************/ -static char *get_auth_login(CONTYP *contact,int delay) +static char *get_auth_login(CONTYP *contact) { static char *logdat[]={"VXNlcm5hbWU6", //Username: in B64 @@ -635,7 +635,7 @@ for (int i=0;i<2;i++) { (void) strcat(local,IOBNULL); (void) transmit(contact,true,"%d %s",SENDB64,logdat[i]); - got=tcp_getline(contact->socptr,delay,&line); + got=tcp_getline(contact->socptr,contact->delay,&line); if (got<=0) { (void) strcpy(local,""); (void) transmit(contact,true,"%d 5.7.2 auth sequence missing",UKNUSER); @@ -763,7 +763,7 @@ return isok; /* NULL if unable to extract login */ /* */ /********************************************************/ -static _Bool getauth(CONTYP *contact,int delay,char *buffer) +static _Bool getauth(CONTYP *contact,char *buffer) { #define OPEP "lvleml.c:getauth," @@ -822,21 +822,21 @@ while (proceed==true) { switch (code) { case 0 : //AUTH PLAIN if (soc_iscrypted(contact->socptr)==true) - decoded=get_auth_plain(contact,delay,local); + decoded=get_auth_plain(contact,local); else (void) transmit(contact,true,"%d 5.7.3 Unsafe PLAIN auth mode",FAILED); break; case 1 : //AUTH LOGIN if (soc_iscrypted(contact->socptr)==true) - decoded=get_auth_login(contact,delay); + decoded=get_auth_login(contact); else (void) transmit(contact,true,"%d 5.7.3 Unsafe LOGIN auth mode",FAILED); break; case 2 : //AUTH CRAM-MD5 - decoded=get_auth_cram_md5(contact,delay); + decoded=get_auth_cram_md5(contact); break; case 3 : //AUTH DIGEST-MD5 - decoded=get_auth_digest_md5(contact,delay); + decoded=get_auth_digest_md5(contact); break; default : //not yet implemented (void) transmit(contact,true,"%d 5.7.3 Unknown auth mode",FAILED); @@ -2152,16 +2152,12 @@ PUBLIC int eml_docontact(CONTYP *contact) int status; int got; -int delay; -int penalty; +int penalty; //answer time penalty, in case of wrong auth _Bool proceed; status=1; got=0; -delay=300; //5 minutes standard delay penalty=1; -if (debug>1) - delay/=10; //30 sec in debug mode proceed=true; (void) signon(contact); while (proceed==true) { @@ -2169,13 +2165,14 @@ while (proceed==true) { CODTYP code; line=(char *)0; - got=tcp_getline(contact->socptr,delay,&line); + got=tcp_getline(contact->socptr,contact->delay,&line); if (got<=0) { //timeout or trouble? char str[100]; switch (got) { case 0 : //timeout - (void) snprintf(str,sizeof(str),"No data from remote within %d sec",delay); + (void) snprintf(str,sizeof(str),"No data from remote within %d sec", + contact->delay); break; case -1 : //signal received (void) snprintf(str,sizeof(str),"Signal Received"); @@ -2221,7 +2218,7 @@ while (proceed==true) { (void) checkfrom(contact,line); break; case c_auth : //Auth request - if (getauth(contact,delay,line)==false) + if (getauth(contact,line)==false) proceed=false; //Authentication failed break; case c_rcpt : //Doing rpt scanning @@ -2288,6 +2285,7 @@ PUBLIC CONTYP *eml_getcontact(SOCPTR *socptr,int pos) #define OPEP "lvleml.c:eml_getcontact" #define MXCARIN 200 //maximun number of char //within carpile +#define MXDELAY 300 //maximun waiting time 5 minutes standard delay CONTYP *contact; int phase; @@ -2325,6 +2323,9 @@ while (proceed==true) { break; case 3 : //Preparing contact contact->mainsesid=eml_getmainsesid(); + contact->delay=MXDELAY; + if (debug>1) + contact->delay/=10; //30 sec in debug mode (void) getsessid(contact); contact->locname=soc_getaddrinfo(contact->socptr,true,true); contact->locip=soc_getaddrinfo(contact->socptr,true,false); diff --git a/lib/lvleml.h b/lib/lvleml.h index 0f69b07..bac4e06 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -18,6 +18,7 @@ typedef struct { SOCPTR *socptr; //established contact socket context SQLPTR *sqlptr; //established contact database access + int delay; //communication max delay char *fqdn; //fully qualified domain from peer char *locip; //socket local IP num _Bool authenticated; //Link is authenticated -- 2.47.3