From 413a1039a5391686c8b630fbc64ef961bf8c0608 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 6 May 2025 19:21:49 -0400 Subject: [PATCH] Start to implement rcptto command --- data-tst/xxfeed.tst | 2 +- lib/lvleml.c | 151 +++++++++++++++++--------------------------- lib/unieml.c | 4 +- 3 files changed, 61 insertions(+), 96 deletions(-) diff --git a/data-tst/xxfeed.tst b/data-tst/xxfeed.tst index d4972c4..ba9621c 100644 --- a/data-tst/xxfeed.tst +++ b/data-tst/xxfeed.tst @@ -10,7 +10,7 @@ R:250-mailleur.example.com, link (cleartext) ready, your IP/FQDN=[127.127.0.2/fe S:MAIL FROM: R:250 2.1.3 postmaster@example.com.. sender ok S:RCPT TO: -R:250 Address accepted +R:250 2.6.2 Address accepted #------------------------------------------------------------------------- #-sending data C:DATA diff --git a/lib/lvleml.c b/lib/lvleml.c index 73a6225..6b3deeb 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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; +} +/* + +*/ +/************************************************/ +/* */ /* 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; diff --git a/lib/unieml.c b/lib/unieml.c index 40d4efd..2bedf6f 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -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 } -- 2.47.3