From 6efe465ff579e71d68eed8c9aef04621cb9683a3 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 5 May 2025 20:39:43 -0400 Subject: [PATCH] Command ORGN ready to be implemented --- lib/devsoc.c | 7 ----- lib/devsoc.h | 7 +++++ lib/lvleml.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/lib/devsoc.c b/lib/devsoc.c index cc07e16..96a9a2b 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -23,13 +23,6 @@ #include "unitls.h" #include "devsoc.h" -//Need to have GNU_SOURCE define within CFLAGS -#ifdef AI_ALL -#define HINTFLG AI_ALL|AI_CANONNAME|AI_CANONIDN -#else /*AI_ALL is not defined in linux <= rh9 */ -#define HINTFLG AI_CANONNAME -#endif - #define MXCARIN 200 //maximun number of char within carpile typedef struct { diff --git a/lib/devsoc.h b/lib/devsoc.h index fcfd173..c8aad37 100644 --- a/lib/devsoc.h +++ b/lib/devsoc.h @@ -12,6 +12,13 @@ #include #include +//Need to have GNU_SOURCE define within CFLAGS +#ifdef AI_ALL +#define HINTFLG AI_ALL|AI_CANONNAME|AI_CANONIDN +#else /*AI_ALL is not defined in linux <= rh9 */ +#define HINTFLG AI_CANONNAME +#endif + //convenient adress structure typedef struct sockaddr SOCKADDR; diff --git a/lib/lvleml.c b/lib/lvleml.c index 181461b..5e61708 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -5,6 +5,10 @@ /* exchange. */ /* */ /********************************************************/ +#include +#include + +#include #include #include #include @@ -122,6 +126,89 @@ 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:dorgn" + +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 + 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); + 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 */ /* */ @@ -408,7 +495,7 @@ while (proceed==true) { CMDOK,contact->mainsesid); break; case c_orgn : - (void) transmit(contact,"%d 2.0.0 ORGN Debug", CMDOK); + (void) doorgn(contact,line); break; case c_quit : //QUIT SMTP protocol (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s", -- 2.47.3