From: Jean-Marc Pigeon Date: Thu, 27 Nov 2025 14:46:32 +0000 (-0500) Subject: Starting to implement eml_note function X-Git-Tag: tag-0.19~32 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=5bacd05cd3bde5c3fffff4a96d568e4450210e5c;p=jmp%2Fmailleur Starting to implement eml_note function --- diff --git a/lib/lvleml.c b/lib/lvleml.c index 6bc2fa4..5d41377 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -355,7 +355,8 @@ while (proceed==true) { case 1 : //checking credential if (srv->links>1) { status=ALREADY; - (void) eml_status(contact,status,NULL,"-4.5.6 Server already connected"); + (void) eml_note(contact,NULL,"%d 4.5.6 already connected",status); + (void) eml_transmit(contact,true,"%d 4.5.6 already connected",status); phase=999; //To many server connected } break; @@ -365,7 +366,7 @@ while (proceed==true) { const char *ninfo; cmt=srv->listing; - ninfo="-4.5.7 Originator server IP [%s] black listed <%s>"; + ninfo="%d 4.5.7 Originator server IP [%s] black listed <%s>"; if (cmt==(char *)0) cmt="credit too low"; (void) log_fprintlog(contact->logptr,false,"(Remote %s[%s] credit='%d' %s)", @@ -373,7 +374,8 @@ while (proceed==true) { contact->peerip, srv->credit,"too low"); status=BLCKLST; - (void) eml_status(contact,status,NULL,ninfo,contact->peerip,cmt); + (void) eml_note(contact,NULL,ninfo,status,contact->peerip,cmt); + (void) eml_transmit(contact,true,ninfo,status,contact->peerip,cmt); (void) setterminator(contact,"Remote server credit is too low"); phase=999; //To many server connected } @@ -588,10 +590,11 @@ for (int i=0;i<2;i++) { (void) eml_transmit(contact,true,"%d %s",SENDB64,logdat[i]); got=tcp_getline(contact->socptr,contact->delay,&line); if (got<=0) { - const char *ninfo=" 5.7.2 auth sequence missing"; + const char *ninfo="%d 5.7.2 auth sequence missing"; (void) strcpy(local,""); - (void) eml_status(contact,UKNUSER,NULL,ninfo); + (void) eml_note(contact,NULL,ninfo,UKNUSER); + (void) eml_transmit(contact,true,ninfo,UKNUSER); break; //exiting from loop } (void) log_fprintlog(contact->logptr,false,"%s",line); @@ -795,9 +798,10 @@ while (proceed==true) { break; case 1 : //check buffer if ((buffer==(char *)0)||(strlen(buffer)==0)) { - const char *ninfo=" 5.7.1 Missing auth type"; + const char *ninfo="%d 5.7.1 Missing auth type"; - (void) eml_status(contact,UKNUSER,NULL,ninfo); + (void) eml_note(contact,NULL,ninfo,UKNUSER); + (void) eml_transmit(contact,true,ninfo,UKNUSER); phase=999; //No need to go further } break; @@ -818,7 +822,8 @@ while (proceed==true) { static char *cmt="bad authentication type"; (void) rou_alert(0,"%s auth type <%s> unknown (Bug?)",OPEP,local); - (void) eml_status(contact,BADPAR,NULL," 5.7.2 %s",cmt); + (void) eml_note(contact,NULL,"%d 5.7.2 %s",BADPAR,cmt); + (void) eml_transmit(contact,true,"%d 5.7.2 %s",BADPAR,cmt); (void) setterminator(contact,cmt); phase=999; //Trouble Trouble } @@ -832,7 +837,8 @@ while (proceed==true) { static char *cmt="Unsafe PLAIN auth mode"; contact->credit-=2; - (void) eml_status(contact,FAILED,NULL," 5.7.3 %s",cmt); + (void) eml_note(contact,NULL,"%d 5.7.3 %s",FAILED,cmt); + (void) eml_transmit(contact,true,"%d 5.7.3 %s",FAILED,cmt); (void) setterminator(contact,cmt); } break; @@ -843,7 +849,8 @@ while (proceed==true) { static char *cmt="Unsafe LOGIN auth mode"; contact->credit-=2; - (void) eml_status(contact,FAILED,NULL," 5.7.3 %s",cmt); + (void) eml_note(contact,NULL,"%d 5.7.3 %s",FAILED,cmt); + (void) eml_transmit(contact,true,"%d 5.7.3 %s",FAILED,cmt); (void) setterminator(contact,cmt); } break; @@ -855,7 +862,8 @@ while (proceed==true) { (void) rou_alert(0,"%s auth type <%d> not yet implemented (Bug?!)", OPEP,code); - (void) eml_status(contact,FAILED,NULL," 5.7.5 %s",cmt); + (void) eml_note(contact,NULL,"%d 5.7.5 %s",FAILED,cmt); + (void) eml_transmit(contact,true,"%d 5.7.5 %s",FAILED,cmt); (void) setterminator(contact,cmt); phase=999; } @@ -872,12 +880,14 @@ while (proceed==true) { fmt=DISP"Auth Rejected status='%d' for user=<%s> pass=<%s>"; (void) log_fprintlog(contact->logptr,true,fmt,BADAUTH,auth,rmtpass); (void) sleep(2); - (void) eml_status(contact,BADAUTH,NULL," 5.7.4 wrong authentication"); + (void) eml_note(contact,NULL,"%d 5.7.4 wrong authentication",BADAUTH); + (void) eml_transmit(contact,true,"%d 5.7.4 wrong authentication",BADAUTH); contact->credit-=1; } else { (void) log_fprintlog(contact->logptr,true,fmt,auth); - (void) eml_status(contact,IDOK,NULL," 5.7.5 authentication successful"); + (void) eml_note(contact,NULL,"%d 5.7.5 authentication successful",IDOK); + (void) eml_transmit(contact,true,"%d 5.7.5 authentication successful",IDOK); contact->credit+=2; } } @@ -918,9 +928,10 @@ while (proceed==true) { switch (phase) { case 0 : //is user a local user if ((sql_mngusr(contact->sqlptr,sql_select,rcptto,&usr))==false) { - (void) eml_status(contact,UKNUSER,rcptto, - " 5.6.0 <%s> unknown user", - rcptto); + (void) eml_note(contact,rcptto,"%d 5.6.0 <%s> unknown user", + UKNUSER,rcptto); + (void) eml_transmit(contact,true,"%d 5.6.0 <%s> unknown user", + UKNUSER,rcptto); phase=999; //No user found in database } break; @@ -937,9 +948,10 @@ while (proceed==true) { break; case 2 : //is user lock? if (usr->lock==1) { - (void) eml_status(contact,EXPIRED,rcptto, - " 5.6.1 <%s> account lock", - rcptto); + (void) eml_note(contact,rcptto,"%d 5.6.1 <%s> account lock", + EXPIRED,rcptto); + (void) eml_transmit(contact,true,"%d 5.6.1 <%s> account lock", + EXPIRED,rcptto); phase=999; //No user found in database } break; @@ -950,20 +962,28 @@ while (proceed==true) { isok=true; break; case spf_fail : //Bad SPF - (void) eml_status(contact,FAILED,rcptto, - " 5.6.6 %s from IP=[%s]", - "Relaying not allowed", - contact->peerip); + (void) eml_note(contact,rcptto,"%d 5.6.6 %s from IP=[%s]", + FAILED,"Relaying not allowed", + contact->peerip); + (void) eml_transmit(contact,rcptto,"%d 5.6.6 %s from IP=[%s]", + FAILED,"Relaying not allowed", + contact->peerip); break; case spf_softfail : //Bad SPF - (void) eml_status(contact,FAILED,rcptto, - " 5.6.7 %s from IP=[%s]", - "SPF soft fail not allowed", - contact->peerip); + (void) eml_note(contact,rcptto,"%d 5.6.7 %s from IP=[%s]", + FAILED,"SPF soft fail not allowed", + contact->peerip); + (void) eml_transmit(contact,rcptto,"%d 5.6.7 %s from IP=[%s]", + FAILED,"SPF soft fail not allowed", + contact->peerip); break; default : //trouble trouble - (void) eml_status(contact,FAILED,rcptto, - " 5.6.8 %s (<%s> SPF unknown)", + (void) eml_note(contact,rcptto,"%d 5.6.8 %s (<%s> SPF unknown)", + FAILED, + "Originator domain BAD SPF definition", + contact->mailfrom); + (void) eml_transmit(contact,true,"%d 5.6.8 %s (<%s> SPF unknown)", + FAILED, "Originator domain BAD SPF definition", contact->mailfrom); break; @@ -1050,8 +1070,10 @@ while (proceed==true) { char *rcptto; (void) rou_asprintf(&rcptto,"%s@%s",rmtusr->userid,rmtusr->domain); - (void) eml_status(contact,NORELAY,rcptto," 2.8.0 %s for domain <%s>", - cmt,rmtusr->domain); + (void) eml_note(contact,rcptto,"%d 2.8.0 %s for domain <%s>", + NORELAY,cmt,rmtusr->domain); + (void) eml_transmit(contact,true,"%d 2.8.0 %s for domain <%s>", + NORELAY,cmt,rmtusr->domain); rcptto=rou_freestr(rcptto); } proceed=false; @@ -1208,8 +1230,10 @@ while (proceed==true) { good=true; break; default : //SAFE guard - if (good==false) - (void) eml_status(contact,BADPAR,NULL," 5.5.4 %s.",DETAIL); + if (good==false) { + (void) eml_note(contact,NULL,"%d 5.5.4 %s.",BADPAR,DETAIL); + (void) eml_transmit(contact,true,"%d 5.5.4 %s.",BADPAR,DETAIL); + } proceed=false; break; } @@ -1854,14 +1878,17 @@ while (proceed==true) { break; case 1 : //do we have an originator if ((rcptto==(char *)0)||(strlen(rcptto)==0)) { - (void) eml_status(contact,BADPAR,rcptto," 5.6.1 recipient not specified"); + (void) eml_note(contact,rcptto,"%d 5.6.1 recipient not specified",BADPAR); + (void) eml_transmit(contact,true,"%d 5.6.1 recipient not specified",BADPAR); phase=999; //no need to go further } break; case 2 : //check rcpt format if ((rcptto[0]!='<')||(rcptto[strlen(rcptto)-1]!='>')) { - (void) eml_status(contact,BADPAR,rcptto," 5.6.2 '%s' bad Format error", - rcptto); + (void) eml_note(contact,rcptto,"%d 5.6.2 '%s' bad Format error", + BADPAR,rcptto); + (void) eml_transmit(contact,true,"%d 5.6.2 '%s' bad Format error", + BADPAR,rcptto); phase=999; //no need to go further } rcptto[strlen(rcptto)-1]='\000'; @@ -2573,11 +2600,12 @@ va_end(args); */ /************************************************/ /* */ -/* Procedure to report the contact status */ -/* store this status within the database */ +/* Procedure to report the contact ongoing */ +/* informationn. store this information */ +/* within the database. */ /* */ /************************************************/ -PUBLIC void eml_status(CONTYP *contact,int actcode,char *rcpt,const char *fmt,...) +PUBLIC void eml_note(CONTYP *contact,char *rcpt,const char *fmt,...) { #define OPEP "lvleml.c:eml_status" @@ -2585,20 +2613,19 @@ PUBLIC void eml_status(CONTYP *contact,int actcode,char *rcpt,const char *fmt,.. va_list args; char **resp; char *report; -char *info; ACTTYP action; va_start(args,fmt); resp=(char **)0; (void) rou_vasprintf(&report,fmt,args); -(void) rou_asprintf(&info,"%d%s",actcode,report); -resp=(char **)rou_addlist((void **)resp,(void *)info); +resp=(char **)rou_addlist((void **)resp,(void *)report); (void) memset(&action,'\000',sizeof(ACTTYP)); -action.sessid=contact->session->sessid; action.code='X'; +action.sessid=contact->session->sessid; action.reverse=contact->peername; action.remoteip=contact->peerip; -action.sfrom=contact->mailfrom; +if (contact->mailfrom!=(char *)0) + action.sfrom=contact->mailfrom; if (contact->session->hfrom!=(char *)0) action.hfrom=contact->session->hfrom; if (contact->session->hsubject!=(char *)0) @@ -2607,9 +2634,7 @@ action.rcptto=rcpt; action.resp=resp; if (sql_mngact(contact->sqlptr,&action)==false) (void) rou_alert(0,"%s, unable to store report within database (bug?",OPEP); -(void) eml_transmit(contact,true,"%s",info); resp=(char **)rou_freelist((void **)resp,(genfree_t)rou_freestr); -report=rou_freestr(report); va_end(args); #undef OPEP diff --git a/lib/lvleml.h b/lib/lvleml.h index a9bba4c..c5b3d8e 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -48,7 +48,7 @@ typedef struct { extern void eml_transmit(CONTYP *contact,_Bool flush,const char *fmt,...); //To store connection status and transmit action code to remote -extern void eml_status(CONTYP *contact,int actcode,char *rcpt,const char *fmt,...); +extern void eml_note(CONTYP *contact,char *rcpt,const char *fmt,...); //procedure to extract line and proceed with peer contact extern int eml_docontact(CONTYP *contact); diff --git a/lib/modrec.c b/lib/modrec.c index cd8b4bd..cb5307e 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -188,7 +188,8 @@ while (proceed==true) { end="Found ip=[%s] already connected"; (void) rou_asprintf(&(contact->termend),end,contact->peerip); end="You have another connection still in progress"; - (void) eml_status(contact,NOTNOW,NULL,"%d 6.6.5 contact denied <%s>",end); + (void) eml_note(contact,NULL,"%d 6.6.5 contact denied <%s>",NOTNOW,end); + (void) eml_transmit(contact,true,"%d 6.6.5 contact denied <%s>",NOTNOW,end); contact->credit=-1; //small penalty (void) sleep(1); //To avoid avalanche phase=999; //no Need to go further @@ -209,7 +210,8 @@ while (proceed==true) { contact->termend=strdup(cmt); contact->credit=-1; (void) sleep(2); - (void) eml_status(contact,DATRJC,NULL,"%d 6.6.6 %s",cmt); + (void) eml_note(contact,NULL,"%d 6.6.6 %s",DATRJC,cmt); + (void) eml_transmit(contact,true,"%d 6.6.6 %s",DATRJC,cmt); phase=999; //rejecting remote first hand } srv=sql_freesrv(srv);