]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding procedure eml_status to store contact status within data-base
authorJean-Marc Pigeon <jmp@safe.c>
Tue, 25 Nov 2025 14:11:26 +0000 (09:11 -0500)
committerJean-Marc Pigeon <jmp@safe.c>
Tue, 25 Nov 2025 14:11:26 +0000 (09:11 -0500)
lib/lvleml.c
lib/lvleml.h
lib/modrec.c

index c01bb62c36e124eeda7d5fd5679d0b546a5636c0..08bf4416e2e3920e4fc0f361e566acbacae9a35e 100644 (file)
@@ -199,52 +199,6 @@ while (proceed==true) {
   phase++;
   }
 return done;
-#undef  OPEP
-}
-/*
-\f
-*/
-/************************************************/
-/*                                             */
-/*     Procedure to report the contact status  */
-/*      store this status within the database   */
-/*                                             */
-/************************************************/
-static void note_status(CONTYP *contact,int smtpcode,char *rcpt,const char *fmt,...)
-
-{
-#define OPEP    "lvleml.c:note_status"
-
-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",smtpcode,report);
-resp=(char **)rou_addlist((void **)resp,(void *)info);
-(void) memset(&action,'\000',sizeof(ACTTYP));
-action.sessid=contact->session->sessid;
-action.code='X';
-action.reverse=contact->peername;
-action.remoteip=contact->peerip;
-action.sfrom=contact->mailfrom;
-if (contact->session->hfrom!=(char *)0)
-  action.hfrom=contact->session->hfrom;
-if (contact->session->hsubject!=(char *)0)
-  action.hsubject=contact->session->hsubject;
-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
 }
 /*
@@ -401,7 +355,7 @@ while (proceed==true) {
     case 1      :       //checking credential
       if (srv->links>1) {
         status=ALREADY;
-        (void) note_status(contact,status,NULL,"-4.5.6 Server already connected");
+        (void) eml_status(contact,status,NULL,"-4.5.6 Server already connected");
         phase=999;      //To many server connected
         }
       break;
@@ -419,7 +373,7 @@ while (proceed==true) {
                                                     contact->peerip,
                                                     srv->credit,"too low");
         status=BLCKLST;
-        (void) note_status(contact,status,NULL,ninfo,contact->peerip,cmt);
+        (void) eml_status(contact,status,NULL,ninfo,contact->peerip,cmt);
         (void) setterminator(contact,"Remote server credit is too low");
         phase=999;      //To many server connected
         }
@@ -637,7 +591,7 @@ for (int i=0;i<2;i++) {
      const char *ninfo=" 5.7.2 auth sequence missing";
 
      (void) strcpy(local,"");
-     (void) note_status(contact,UKNUSER,NULL,ninfo);
+     (void) eml_status(contact,UKNUSER,NULL,ninfo);
      break;                 //exiting from loop
      }
   (void) log_fprintlog(contact->logptr,false,"%s",line);
@@ -840,7 +794,7 @@ while (proceed==true) {
     case 0      :               //are we encrypted and on the right port
       if (soc_iscrypted(contact->socptr)==false) {
         static char *cmt="no authentication allowed on clear chanel";
-        (void) note_status(contact,FAILED,NULL," 5.7.0 %s",cmt);
+        (void) eml_status(contact,FAILED,NULL," 5.7.0 %s",cmt);
         (void) setterminator(contact,cmt);
         contact->credit-=1;     //"Bad boy"
         phase=999;              //No need to go further 
@@ -850,7 +804,7 @@ while (proceed==true) {
       if ((buffer==(char *)0)||(strlen(buffer)==0)) {
         const char *ninfo=" 5.7.1 Missing auth type";
 
-        (void) note_status(contact,UKNUSER,NULL,ninfo);
+        (void) eml_status(contact,UKNUSER,NULL,ninfo);
         phase=999;      //No need to go further 
         }
       break;
@@ -871,7 +825,7 @@ while (proceed==true) {
         static char *cmt="bad authentication type";
 
         (void) rou_alert(0,"%s auth type <%s> unknown (Bug?)",OPEP,local);
-        (void) note_status(contact,BADPAR,NULL," 5.7.2 %s",cmt);
+        (void) eml_status(contact,BADPAR,NULL," 5.7.2 %s",cmt);
         (void) setterminator(contact,cmt);
         phase=999;      //Trouble Trouble
         }
@@ -913,12 +867,12 @@ 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) note_status(contact,BADAUTH,NULL," 5.7.4 wrong authentication");
+        (void) eml_status(contact,BADAUTH,NULL," 5.7.4 wrong authentication");
         contact->credit-=1;
         }
       else {
         (void) log_fprintlog(contact->logptr,true,fmt,auth);
-        (void) note_status(contact,IDOK,NULL," 5.7.5 authentication successful");
+        (void) eml_status(contact,IDOK,NULL," 5.7.5 authentication successful");
         contact->credit+=2;
         }
       }
@@ -959,7 +913,7 @@ while (proceed==true) {
   switch (phase) {
     case 0      :       //is user a local user
       if ((sql_mngusr(contact->sqlptr,sql_select,rcptto,&usr))==false) {
-        (void) note_status(contact,UKNUSER,rcptto,
+        (void) eml_status(contact,UKNUSER,rcptto,
                                            " 5.6.0 <%s> unknown user",
                                            rcptto);
         phase=999;      //No user found in database
@@ -978,7 +932,7 @@ while (proceed==true) {
       break;
     case 2      :       //is user lock?
       if (usr->lock==1) {
-        (void) note_status(contact,EXPIRED,rcptto,
+        (void) eml_status(contact,EXPIRED,rcptto,
                                            " 5.6.1 <%s> account lock",
                                            rcptto);
         phase=999;      //No user found in database
@@ -991,19 +945,19 @@ while (proceed==true) {
           isok=true;       
           break;
         case spf_fail           :       //Bad SPF
-          (void) note_status(contact,FAILED,rcptto,
+          (void) eml_status(contact,FAILED,rcptto,
                                             " 5.6.6 %s from IP=[%s]",
                                             "Relaying not allowed",
                                             contact->peerip);
           break;
         case spf_softfail       :       //Bad SPF
-          (void) note_status(contact,FAILED,rcptto,
+          (void) eml_status(contact,FAILED,rcptto,
                                             " 5.6.7 %s from IP=[%s]",
                                             "SPF soft fail not allowed",
                                             contact->peerip);
           break;
         default                 :       //trouble trouble
-          (void) note_status(contact,FAILED,rcptto,
+          (void) eml_status(contact,FAILED,rcptto,
                                             " 5.6.8 %s (<%s> SPF unknown)",
                                             "Originator domain BAD SPF definition",
                                             contact->mailfrom);
@@ -1091,7 +1045,7 @@ while (proceed==true) {
         char *rcptto;
 
         (void) rou_asprintf(&rcptto,"%s@%s",rmtusr->userid,rmtusr->domain);
-        (void) note_status(contact,NORELAY,rcptto," 2.8.0 %s for domain <%s>",
+        (void) eml_status(contact,NORELAY,rcptto," 2.8.0 %s for domain <%s>",
                                                   cmt,rmtusr->domain);
         rcptto=rou_freestr(rcptto);
         }
@@ -1250,7 +1204,7 @@ while (proceed==true) {
       break;
     default     :       //SAFE guard
       if (good==false) 
-        (void) note_status(contact,BADPAR,NULL," 5.5.4 %s.",DETAIL);
+        (void) eml_status(contact,BADPAR,NULL," 5.5.4 %s.",DETAIL);
       proceed=false;
       break;
     }
@@ -1895,13 +1849,13 @@ while (proceed==true) {
       break;
     case 1      :       //do we have an originator
       if ((rcptto==(char *)0)||(strlen(rcptto)==0)) {
-        (void) note_status(contact,BADPAR,rcptto," 5.6.1 recipient not specified");
+        (void) eml_status(contact,BADPAR,rcptto," 5.6.1 recipient not specified");
         phase=999;      //no need to go further
         }
       break;
     case 2      :       //check rcpt format
       if ((rcptto[0]!='<')||(rcptto[strlen(rcptto)-1]!='>')) {
-        (void) note_status(contact,BADPAR,rcptto," 5.6.2 '%s' bad Format error",
+        (void) eml_status(contact,BADPAR,rcptto," 5.6.2 '%s' bad Format error",
                                                  rcptto);
         phase=999;      //no need to go further
         }
@@ -1911,14 +1865,14 @@ while (proceed==true) {
     case 3      :       //checking rcptto format
       neu=eml_isemailok(rcptto,&report);
       if (neu==(RCPTYP *)0) {
-        (void) note_status(contact,NOTEML,rcptto," 5.6.3 %s",report);
+        (void) eml_status(contact,NOTEML,rcptto," 5.6.3 %s",report);
         report=rou_freestr(report);
         phase=999;      //no need to go further
         }
       break;
     case 4      :       //Do we have a domain MX
       if (setlocdom(contact,neu)==false) {
-        (void) note_status(contact,MISSMX,rcptto," 5.6.4 %s (domain=%s)",
+        (void) eml_status(contact,MISSMX,rcptto," 5.6.4 %s (domain=%s)",
                                                  "No valid MX found for recipient "
                                                  "domain name",neu->domain);
         phase=999;      //no need to go further
@@ -1950,7 +1904,7 @@ while (proceed==true) {
         }
       break;
     case 7      :       //everything ok
-      (void) note_status(contact,CMDOK,rcptto," 5.6.7 %s <%s>",detail,rcptto);
+      (void) eml_status(contact,CMDOK,rcptto," 5.6.7 %s <%s>",detail,rcptto);
       success=true;
       break;
     default     :       //SAFE guard
@@ -2610,6 +2564,52 @@ line=rou_freestr(line);
 va_end(args);
 }
 /*
+\f
+*/
+/************************************************/
+/*                                             */
+/*     Procedure to report the contact status  */
+/*      store this status within the database   */
+/*                                             */
+/************************************************/
+PUBLIC void eml_status(CONTYP *contact,int actcode,char *rcpt,const char *fmt,...)
+
+{
+#define OPEP    "lvleml.c:eml_status"
+
+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);
+(void) memset(&action,'\000',sizeof(ACTTYP));
+action.sessid=contact->session->sessid;
+action.code='X';
+action.reverse=contact->peername;
+action.remoteip=contact->peerip;
+action.sfrom=contact->mailfrom;
+if (contact->session->hfrom!=(char *)0)
+  action.hfrom=contact->session->hfrom;
+if (contact->session->hsubject!=(char *)0)
+  action.hsubject=contact->session->hsubject;
+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
+}
+/*
 ^L
 */
 /********************************************************/
index 864f533c453008684553409d8b3aaaa8064c664a..a9bba4c59d502cebc8bc25afe20bc431a3ee74b7 100644 (file)
@@ -47,6 +47,9 @@ typedef struct  {
 //Procedure to transmit data on the contact channel
 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,...);
+
 //procedure to extract line and proceed with peer contact
 extern int eml_docontact(CONTYP *contact);
 
index e0189ab5054215b0b459c185ef0cb8a059f2f7d2..cd8b4bd225bdde546551a9e3e741049a47ed0449 100644 (file)
@@ -188,7 +188,7 @@ 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_transmit(contact,true,"%d contact denied <%s>",NOTNOW,end);
+        (void) eml_status(contact,NOTNOW,NULL,"%d 6.6.5 contact denied <%s>",end);
         contact->credit=-1;     //small penalty
         (void) sleep(1);        //To avoid avalanche
         phase=999;              //no Need to go further
@@ -209,7 +209,7 @@ while (proceed==true) {
           contact->termend=strdup(cmt);
           contact->credit=-1;
           (void) sleep(2);
-          (void) eml_transmit(contact,true,"%d 6.6.6 %s",DATRJC,cmt);
+          (void) eml_status(contact,DATRJC,NULL,"%d 6.6.6 %s",cmt);
           phase=999;    //rejecting remote first hand
           }
         srv=sql_freesrv(srv);