From: Jean-Marc Pigeon (Delson) Date: Sat, 26 Jul 2025 18:02:25 +0000 (-0400) Subject: Updating remote record with credit X-Git-Tag: tag-0.14~10 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=79729ea38790fe4f1b39bfd80e2e67d073c49d0b;p=jmp%2Fmailleur Updating remote record with credit --- diff --git a/lib/devsql.c b/lib/devsql.c index 9fa6c81..f02c99f 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -368,7 +368,7 @@ return (SQLPTR *)sql; /* format (data-base compatible). */ /* */ /********************************************************/ -PUBLIC const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp) +PUBLIC char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp) { #define OPEP "devsql.c:sql_fromunixtime," @@ -393,7 +393,7 @@ if (sqlptr!=(SQLPTR *)0) { break; } } -return unixdate; +return strdup(unixdate); #undef OPEP } diff --git a/lib/devsql.h b/lib/devsql.h index 05ecb23..1332fda 100644 --- a/lib/devsql.h +++ b/lib/devsql.h @@ -31,7 +31,7 @@ extern SQLPTR *sql_opensql(); extern SQLPTR *sql_closesql(SQLPTR *sqlptr); //converting a time to a database representation -extern const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp); +extern char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp); //converting a database time representation to unix time extern time_t sql_tounixtime(SQLPTR *sqlptr,const char *date); diff --git a/lib/gessql.c b/lib/gessql.c index 9b27df7..cde27d0 100644 --- a/lib/gessql.c +++ b/lib/gessql.c @@ -431,17 +431,20 @@ static _Bool update_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP *srv) { #define OPEP "gessql.c:update_remote," -static const char *upd= "UPDATE "RMTTBL - " SET lastscan='%s',credit=%d,listing=%s,reverse=%s" - " WHERE remoteip='%s'"; +static const char *upd= "UPDATE "RMTTBL"SET " + "lastscan='%s',lastupdate='%s'," + "credit=%d,listing=%s,reverse=%s " + "WHERE remoteip='%s'"; _Bool isok; -const char *lastscan; +char *lastscan; +char *update; char *listing; char *reverse; isok=true; lastscan=sql_fromunixtime(sqlptr,srv->lastscan); +update=sql_fromunixtime(sqlptr,srv->update); listing=sql_gooddata(sqlptr,srv->listing); reverse=sql_gooddata(sqlptr,srv->reverse); if (sql_request(sqlptr,upd,lastscan,srv->credit,listing,reverse,srv->rmtip)!=1) { @@ -451,6 +454,8 @@ if (sql_request(sqlptr,upd,lastscan,srv->credit,listing,reverse,srv->rmtip)!=1) } reverse=rou_freestr(reverse); listing=rou_freestr(listing); +update=rou_freestr(update); +lastscan=rou_freestr(lastscan); return isok; #undef OPEP diff --git a/lib/lvleml.c b/lib/lvleml.c index b8af381..2b3a967 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -548,7 +548,7 @@ else decoded=cnv_getb64(received); if (decoded!=(char *)0) { if (checklogin(contact,rmtpass,decoded)==true) { - contact->credits+=2; + contact->credit+=2; contact->privilege=rel_authentic; } decoded=rou_freestr(decoded); @@ -596,7 +596,7 @@ for (int i=0;i<2;i++) { } if (strlen(local)>0) { if (checklogin(contact,rmtpass,local)==true) { - contact->credits+=2; + contact->credit+=2; contact->privilege=rel_authentic; } } @@ -734,7 +734,7 @@ while (proceed==true) { break; } if (strcmp(HA0,resp->response)==0) { - contact->credits+=3; //very good authentication + contact->credit+=3; //very good authentication contact->privilege=rel_authentic; } HA0=rou_freestr(HA0); @@ -971,7 +971,7 @@ while (proceed==true) { break; case rel_plain : cmt="No relay accepted"; - contact->credits-=2; //Trying to abuse server + contact->credit-=2; //Trying to abuse server phase=999; //not relayable break; default : @@ -2404,7 +2404,7 @@ while (proceed==true) { } (void) log_fprintlog(contact->logptr,true,"Contact terminated (credit='%d'); " "condition=<%s>", - contact->credits,str); + contact->credit,str); //(void) rou_alert(0,"%s exit status='%d'",OPEP,status); break; //no need to go further @@ -2426,7 +2426,7 @@ while (proceed==true) { CMDOK,contact->mainsesid); break; case c_quit : //QUIT SMTP protocol - contact->credits++; //clean disconnect + contact->credit++; //clean disconnect (void) transmit(contact,true,"%d 2.0.0 Bye, closing connection CNT=%s", QUITOK,contact->mainsesid); status=1; //every thing fine @@ -2474,7 +2474,7 @@ while (proceed==true) { } break; case c_unknown : //unknown keyword - contact->credits-=2; //Trying to confuse server? + contact->credit-=2; //Trying to confuse server? (void) rou_alert(0,"SMTP Command <%s> from [%s] is unknown (config?)", line,contact->peerip); (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321", @@ -2484,7 +2484,7 @@ while (proceed==true) { CMDBAD,contact->mainsesid); break; default : - contact->credits-=10; //Trying to bug server + contact->credit-=10; //Trying to bug server (void) rou_alert(0,"%s Unable to find entry for code='%d' (Bug?)",OPEP,code); (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321", CMDBAD); @@ -2537,7 +2537,7 @@ while (proceed==true) { case 1 : //connecting to database contact=(CONTYP *)calloc(1,sizeof(CONTYP)); contact->sqlptr=sql_opensql(); - contact->credits=0; + contact->credit=0; if (contact->sqlptr==(SQLPTR *)0) { (void) rou_alert(0,"%s Unable to contact database",OPEP); (void) sleep(2);//delay to avoid avalanche @@ -2591,7 +2591,7 @@ while (proceed==true) { case 6 : //checking if remote IP is relayable if (afn_is_ip_relayable(contact->peerip,contact->relayok)==true) { contact->privilege=rel_isrelay; //IP is relayable - contact->credits++; + contact->credit++; } break; case 7 : //contact is good, then sending a signon @@ -2632,9 +2632,11 @@ PUBLIC CONTYP *eml_dropcontact(CONTYP *contact) { #define OPEP "lvleml.c:eml_dropcontact" +SRVTYP *srv; int phase; _Bool proceed; +srv=(SRVTYP *)0; phase=0; proceed=true; while (proceed==true) { @@ -2646,12 +2648,28 @@ while (proceed==true) { phase=999; //not going further } break; - case 1 : //properly closing remote contact + case 1 : //getting the remote server information + if (sql_mngremote(contact->sqlptr,sql_select,contact->peerip,&srv)==false) { + (void) rou_alert(0,"%s Unable to get remote [%s] data (Bug!?)", + OPEP,contact->peerip); + phase++; //No need to do update + } + break; + case 2 : //Updating remote server data + srv->credit+=contact->credit; + srv->update=time((time_t *)0); + if (sql_mngremote(contact->sqlptr,sql_update,contact->peerip,&srv)==false) { + (void) rou_alert(0,"%s Unable to UPDATE remote [%s] data (Bug!?)", + OPEP,contact->peerip); + } + srv=sql_freesrv(srv); + break; + case 3 : //properly closing remote contact (void) rou_alert(0,"Contact from peer <%s> to port <%s> terminated", contact->peerip,contact->locserv); contact->socptr=soc_release(contact->socptr); break; - case 2 : //freeing contact memory + case 4 : //freeing contact memory contact=freecontact(contact); break; default : //SAFE guard diff --git a/lib/lvleml.h b/lib/lvleml.h index 21d0b01..505eaf1 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -20,7 +20,7 @@ typedef struct { SQLPTR *sqlptr; //established contact database access int delay; //communication max delay char *fqdn; //fully qualified domain from peer - int credits; //Credits to be added or removed from contact + int credit; //Credits to be added or removed from contact RELTYP privilege; //onnection privilege char *authname; //Link is authenticated name AFNTYP **localafns; //local IP as an AFNUM diff --git a/lib/modrec.c b/lib/modrec.c index f8001b7..8955f3f 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -185,7 +185,7 @@ while (proceed==true) { break; case 2 : //check if remote link is acceptable if (sql_newconnect(contact->sqlptr,contact->peerip,1)==false) { - contact->credits-=1; + contact->credit-=1; phase=999; //connection rejected } break; @@ -213,7 +213,7 @@ while (proceed==true) { default : //SAFE guard if (contact!=(CONTYP *)0) { (void) log_fprintlog(contact->logptr,true," (%s, credit='%d')", - "Contact terminated",contact->credits); + "Contact terminated",contact->credit); (void) sql_newconnect(contact->sqlptr,contact->peerip,-1); contact=eml_dropcontact(contact); }