#TESTPROT= smtps
EXTIP = safemail3.safe.ca
EXTPORT = 25
-TESTITER= 1
+TESTITER= 2
DBGPAR = \
-r $(TESTDIR) \
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;
--- /dev/null
+#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...
+#-------------------------------------------------------------------------
--- /dev/null
+#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...
+#-------------------------------------------------------------------------
/* 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,"
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
}
phase++;
}
-return done;
+return connect;
#undef OPEP
}
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);
}
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;
}
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;
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
}