]> SAFE projects GIT repository - jmp/mailleur/commitdiff
contact is now including delay timer
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 15:40:05 +0000 (11:40 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 8 Jul 2025 15:40:28 +0000 (11:40 -0400)
lib/lvleml.c
lib/lvleml.h

index 440d43b5c20925cf6af75d1fd84d92fbe7071436..b40fe0248bbb733f57eb367f1dd631a52df8bac5 100644 (file)
@@ -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);
index 0f69b07ab737e77187d5c32589d8bb799321d892..bac4e0637773c9d694d8be0c64fb120bdf42ef80 100644 (file)
@@ -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