]> SAFE projects GIT repository - jmp/mailleur/commitdiff
working on double connection detection
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 10 Aug 2025 11:26:22 +0000 (07:26 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 10 Aug 2025 11:26:22 +0000 (07:26 -0400)
Makefile.dbg
app/scanner.c
data-feed/feed20.tst [new file with mode: 0644]
data-feed/feed21.tst [new file with mode: 0644]
lib/gessql.c
lib/gessql.h
lib/lvleml.c
lib/modrec.c

index af27a0e0f587050edf0c683e4b42c8fccb4a496a..88be5ddd45e1249ded0b493cb5a5c3742665285d 100644 (file)
@@ -12,7 +12,7 @@ TESTPORT=     1025
 #TESTPROT=     smtps
 EXTIP  =       safemail3.safe.ca
 EXTPORT =      25
-TESTITER=      1
+TESTITER=      2
 
 DBGPAR =                                               \
           -r $(TESTDIR)                                \
index 0ecce7b6ff7ec56da089f279d7e6c0ad123a5d6f..f92ac79eb73782c56fad6ca947ceefdda562c2a2 100644 (file)
@@ -79,7 +79,6 @@ while (proceed==true) {
       srv->reverse=dns_get_reverse_addr(reversip);
       break;
     case 3      :       //updating record according blacklisting
-      srv->credit=0;
       srv->lastscan=time((time_t *)0);
       if (dnsblk!=(BLKTYP **)0) {
         int delta;
diff --git a/data-feed/feed20.tst b/data-feed/feed20.tst
new file mode 100644 (file)
index 0000000..4f98f24
--- /dev/null
@@ -0,0 +1,11 @@
+#very simple  test to feed SMTP server
+#====================================================
+T:(feed20) Testing double connectopm
+R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
+#====================================================
+S:HELO example.com
+R:250 mailleur.example.com, link (cleartext) ready,...
+C:WAIT 120     $wait "forever"
+S:QUIT
+R:221 2.0.0 Bye, closing connection...
+#-------------------------------------------------------------------------
diff --git a/data-feed/feed21.tst b/data-feed/feed21.tst
new file mode 100644 (file)
index 0000000..da5c4cf
--- /dev/null
@@ -0,0 +1,14 @@
+#very simple  test to feed SMTP server
+#====================================================
+T:(feed20) Testing double connectopm
+R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
+#====================================================
+S:HELO example.com
+R:250 mailleur.example.com, link (cleartext) ready,...
+S:MAIL FROM: <trouble@mailref1.example.com>
+R:250 2.1.3 trouble@mailref1.example.com sender ok
+S:RCPT TO: <user1@mailref1.example.com>
+R:250 2.6.4 Address accepted <user1@mailref1.example.com>
+S:QUIT
+R:221 2.0.0 Bye, closing connection...
+#-------------------------------------------------------------------------
index fff68c09ee63f0d235d490330564bb2ca7d7e296..d2fc1d3b94ec9c9a235f262e51cef191e81a270d 100644 (file)
@@ -674,7 +674,7 @@ return isok;
 /*      IP connection number.                           */
 /*                                                      */
 /********************************************************/
-PUBLIC _Bool sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta)
+PUBLIC int sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta)
 
 {
 #define OPEP    "gessql.c:sql_newconnect,"
@@ -682,43 +682,55 @@ PUBLIC _Bool sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta)
 static const char *upd="UPDATE %s SET links=links+%d,lastupdate=now() WHERE remoteip='%s'";
 static const char *ins="INSERT INTO %s (remoteip) values('%s')";
 
-_Bool done;
+int connect;
+SRVTYP *srv;
 int phase;
 _Bool proceed;
 
-done=true;
+connect=-1;
+srv=(SRVTYP *)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
-    case 0      :       //updating remotes record with links
-      if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1) {
-        phase=999;      //done no probleme
-        }
-      break; 
-    case 1      :       //record does not exist
-      done=false;
+    case 0      :       //lets lock table access
       if (sql_lock(sqlptr,RMTTBL)==false) {
         (void) rou_alert(0,"%s Unable to lock %s table",OPEP,RMTTBL);
-        phase=999;      //Unable to lock table
-        }      
-      break; 
-    case 2      :       //was record created in the meantime?
-      done=true;
-      if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1) {
-        phase++;        //yes, no need to create it again
+        phase=999;      //Unable to lock table!!!!
         }
+      break;
+    case 1      :       //updating remotes record with links
+      if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==0) 
+        phase++;        //Record not existing
       break; 
-    case 3      :       //Let create a record
+    case 2      :       //Let create a record
       if (sql_request(sqlptr,ins,RMTTBL,rmtip)!=1) {
         (void) rou_alert(0,"%s Unable to create entry "
                            "for remote ip <%s> in table <%s> (DB trouble?)",
                             OPEP,rmtip,RMTTBL);
-        done=false;
-        phase=999;      //Unable to lock table
+        phase+=2;
+        }
+      break;
+    case 3      :       //Let update the record
+      if (sql_request(sqlptr,ins,RMTTBL,rmtip)!=1) {
+        (void) rou_alert(0,"%s Unable to create entry "
+                           "for remote ip <%s> in table <%s> (DB trouble?)",
+                            OPEP,rmtip,RMTTBL);
+        phase++;        //No need to return get the connexion number
+        }
+      break; 
+    case 4      :       //lets find the the number of connection
+      if (sql_mngremote(sqlptr,sql_select,rmtip,&srv)==false) {
+        (void) rou_alert(0,"%s Unable to get record "
+                           "for remote ip <%s> in table <%s> (DB trouble?)",
+                            OPEP,rmtip,RMTTBL);
+        }
+      else {
+        connect=srv->links;
+        srv=sql_freesrv(srv);
         }
       break; 
-    case 4      :       //unlock database
+    case 5      :       //unlock database
       (void) sql_unlock(sqlptr,true);
       break; 
     default     :       //SAFE Guard
@@ -727,7 +739,7 @@ while (proceed==true) {
     }
   phase++;
   }
-return done;
+return connect;
 
 #undef  OPEP
 }
index 9b09d28a41804501621244e708407f10824bdd12..a0e224b5d1a2bf14997fcf84152feafcd299da8d 100644 (file)
@@ -25,7 +25,7 @@ extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *key,USRTYP **usr);
 extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses);
 
 //Procedure to increment (or decrement) the remoteip links number
-extern _Bool sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta);
+extern int sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta);
 
 //procedure to extract the information about remotes server
 extern _Bool sql_mngremote(SQLPTR *sqlptr,SQLENUM action,char *key,SRVTYP **srv);
index 04ba667bbfa77bda31376957a89ba608bac20159..b16194ef07c0aa41d0810b33e7c2a1694c232bb4 100644 (file)
@@ -1494,7 +1494,7 @@ while (proceed==true) {
         }
       break;
     case 1      :       //we have good ip, lets disconnect previous
-      if (sql_newconnect(contact->sqlptr,contact->peerip,-1)==false) {
+      if (sql_newconnect(contact->sqlptr,contact->peerip,-1)<0) {
         (void) rou_alert(0,"%s Unable to update database remotes table (system?)"
                            OPEP);
         phase=999;
@@ -1530,9 +1530,9 @@ while (proceed==true) {
         }
       break;
     case 4      :       //let update links
-      if (sql_newconnect(contact->sqlptr,rmtip,1)==false) {
-        (void) rou_alert(0,"%s <%s> Unable to increase links number! (Testing?)",
-                            OPEP,rmtip);
+      if (sql_newconnect(contact->sqlptr,rmtip,1)!=1) {
+        (void) rou_alert(0,"%s <%s> Too many '%d' links! (Testing?)",
+                            OPEP,rmtip,sql_newconnect(contact->sqlptr,rmtip,0));
         phase=999;
         }
       break;
index 08c934754ade85aafca9c71bf526075d23679a9d..87967602062ce40a33d84a0d3fe044e0616efaa2 100644 (file)
@@ -179,7 +179,9 @@ while (proceed==true) {
         phase=999;      //No contact!
       break;
     case 1      :       //check if remote link is acceptable
-      if (sql_newconnect(contact->sqlptr,contact->peerip,1)==false) {
+      (void) rou_alert(0,"%s JMPDBG Checking if double connection",OPEP);
+      if (sql_newconnect(contact->sqlptr,contact->peerip,1)!=1) {
+        (void) rou_alert(0,"%s JMPDBG found double connection",OPEP);
         contact->credit-=1;
         phase++;        //connection rejected
         }