]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Start to implement rcptto command
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 6 May 2025 23:21:49 +0000 (19:21 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 6 May 2025 23:21:49 +0000 (19:21 -0400)
data-tst/xxfeed.tst
lib/lvleml.c
lib/unieml.c

index d4972c4a49163efd31e1edc43ae3c2d873b35666..ba9621c5879fcfe71076e5b3953816d74cc8825f 100644 (file)
@@ -10,7 +10,7 @@ R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/fe
 S:MAIL FROM: <postmaster@example.com>
 R:250 2.1.3 postmaster@example.com.. sender ok
 S:RCPT TO: <postmaster@example.com>
-R:250 Address accepted
+R:250 2.6.2 Address accepted
 #-------------------------------------------------------------------------
 #-sending data
 C:DATA
index 73a6225a7fca8738dc5559345589749a72b63a9f..6b3deebc47da50f59126b3185daaf837cafb227a 100644 (file)
@@ -126,93 +126,6 @@ mode=soc_getstrmode(contact->socptr);
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to override remote IP number, ORGN is */
-/*      used in debug mode test ONLY.                   */
-/*                                                      */
-/********************************************************/
-static void doorgn(CONTYP *contact,char *newip)
-
-{
-#define OPEP    "lvleml.c:doorgn,"
-
-struct addrinfo *res;
-int phase;
-_Bool proceed;
-
-res=(struct addrinfo *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
-  //(void) rou_alert(0,"JMPDBG %s phase='%d' parm=<%s>",OPEP,phase,newip);
-  switch (phase) {
-    case 0      :       //checking if we have a parameter
-      while ((*newip==' ')||(*newip=='\t'))
-        newip++;        //removing unneeded space
-      if (strlen(newip)==0) {
-        (void) rou_alert(0,"%s, newip not specified (debug?)",OPEP);
-        phase=999;      //No need to go further
-        }
-      break;
-    case 1      :       //Getting Override HOST
-      if (strlen(newip)>0) {    //always
-        int status;
-        struct addrinfo hints;
-
-        (void) memset(&hints,'\000',sizeof(hints));
-        hints.ai_family=PF_UNSPEC;
-        hints.ai_socktype=SOCK_STREAM;
-        hints.ai_flags=HINTFLG;
-        status=getaddrinfo(newip,"",&hints,&res);
-        if (status!=0) {        
-          (void) transmit(contact,"%d 5.5.4 <%s> is not an IP number",BADPAR,newip);
-          phase=999;    //no need to go further
-          }
-        }
-      break;
-    case 2      :       //setting new remote name
-      if (res!=(struct addrinfo *)0) {  //always
-        int namestat;
-        char host[NI_MAXHOST];
-
-        (void) strcpy(host,"No.Reverse");
-        namestat=getnameinfo(res->ai_addr,res->ai_addrlen,
-                             host,sizeof(host),(char *)0,0,NI_NAMEREQD);
-        switch (namestat) {
-          case 0                :
-          case EAI_AGAIN        :
-          case EAI_NONAME       :
-            contact->peerip=rou_freestr(contact->peerip); 
-            contact->peername=rou_freestr(contact->peername); 
-            contact->peerip=strdup(newip);
-            contact->peername=strdup(host);
-            (void) transmit(contact,"%d 2.9.9 New peer [%s/%s] set",    
-                                    CMDOK,newip,host);
-            break;
-          default               :
-            (void) rou_alert(0,"%s, Unexpected namestat='%d' (IP=<%s>) (bug?)",
-                                OPEP,namestat,newip);
-            (void) transmit(contact,"%d 5.5.4 Bug! with <%s>",BADPAR,newip);
-            phase=999;  //Trouble trouble
-            break;
-          }
-        }
-      break;
-    default     :       //SAFE guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-if (res!=(struct addrinfo *)0) 
-  (void) freeaddrinfo(res);
-
-#undef  OPEP
-}
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
 /*     Procedure to check if helo or ehlo paratmeter   */
 /*      is a correct one                                */
 /*                                                      */
@@ -401,6 +314,54 @@ return success;
 */
 /************************************************/
 /*                                             */
+/*     Procedure to manage a "RCPT TO:"        */
+/*      ommand from the SMTP client.            */
+/*                                             */
+/************************************************/
+static _Bool checkto(CONTYP *contact,char *rcptto)
+
+{
+_Bool success;
+_Bool proceed;
+int phase;
+
+success=false;
+proceed=true;
+phase=0;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //do we have an originator
+      if ((rcptto==(char *)0)||(strlen(rcptto)<3)) {
+        (void) transmit(contact,"%d 5.6.0 <%s> recipient not specified",
+                                 BADPAR,rcptto);
+        phase=999;      //no need to go further
+        }
+      break;
+    case 1      :       //check rcpt format
+      if ((rcptto[0]!='<')||(rcptto[strlen(rcptto)-1]!='>')) {
+        (void) transmit(contact,"%d 5.6.1 '%s' bad Format error",
+                                 BADPAR,rcptto);
+        phase=999;      //no need to go further
+        }
+      rcptto[strlen(rcptto)-1]='\000'; 
+      (void) memmove(rcptto,rcptto+1,strlen(rcptto));
+      break;
+    case 2      :       //everything ok
+      (void) transmit(contact,"%d 2.6.2 Address accepted",CMDOK);
+      break;
+    default     :       //SAFE guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return success;
+}
+/*
+\f
+*/
+/************************************************/
+/*                                             */
 /*     Procedure to reset the current session  */
 /*                                             */
 /************************************************/
@@ -447,6 +408,7 @@ proceed=true;
 (void) signon(contact);
 while (proceed==true) {
   char *line;
+  CODTYP code;
 
   line=(char *)0;
   got=tcp_getline(contact->socptr,delay,&line);
@@ -474,7 +436,8 @@ while (proceed==true) {
     break;              //no need to go further
     }
   (void) log_fprintlog(contact->logptr,false,"%s",line);
-  switch (eml_getcode(line)) {
+  code=eml_getcode(line);
+  switch (code) {
     case c_helo         :       //HELO SMTP protocol
       proceed=dohelo(contact,line);
       break;
@@ -485,9 +448,6 @@ while (proceed==true) {
       (void) transmit(contact,"%d 2.0.0 OK, %s",    
                               CMDOK,contact->mainsesid);
       break;
-    case c_orgn         :
-      (void) doorgn(contact,line);
-      break;
     case c_quit         :       //QUIT SMTP protocol
       (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",    
                               QUITOK,contact->mainsesid);
@@ -495,9 +455,11 @@ while (proceed==true) {
       proceed=false;
       break;
     case c_mail         :       //MAIL FROM: checking originator
-      (void) rou_alert(0,"JMPDBG parameter=<%s>",line);
       (void) checkfrom(contact,line);
       break;
+    case c_rcpt         :       //Doing rpt scanning
+      (void) checkto(contact,line);
+      break;
     case c_rset         :       //Doing session reset
       proceed=doreset(contact,line);
       break;
@@ -524,8 +486,9 @@ while (proceed==true) {
                               CMDBAD,contact->mainsesid);
       break;
     default             : 
-      (void) rou_alert(0,"Unable to find keyword for <%s> (Bug?)",OPEP,line);
-      (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",    
+      (void) rou_alert(0,"%s Unable to find entry for code='%d' (Bug?)",OPEP,code);
+      (void) transmit(contact,"%d-5.5.1 Unrecognized command, see RFC 5321",CMDBAD);
+      (void) transmit(contact,"%d 2.0.0 Bug!, closing connection Immediatly (%s)",    
                               QUITOK,contact->mainsesid);
       status=-1;                 //remote is a trouble maker
       status=-3;
index 40d4efd8781a8fd3b438719c202edd8066e99fe2..2bedf6f09814ed42c17d937518a29085dd5227d5 100644 (file)
@@ -92,7 +92,7 @@ CODTYP code;
 VOCTYP *ptr;
 
 code=c_unknown;
-for (ptr=vocsmtp;ptr->code!=c_unknown;ptr++) {
+for (ptr=vocsmtp;ptr->key!=(char *)0;ptr++) {
   if (strncasecmp(ptr->key,keyword,strlen(ptr->key))==0) {
     char *par;
 
@@ -108,5 +108,7 @@ for (ptr=vocsmtp;ptr->code!=c_unknown;ptr++) {
     break;
     }
   }
+(void) rou_alert(0,"%s JMPDBG code='%d'",OPEP,code);
 return code;
+#undef  OPEP
 }