]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Command ORGN ready to be implemented
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 6 May 2025 00:39:43 +0000 (20:39 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 6 May 2025 00:39:43 +0000 (20:39 -0400)
lib/devsoc.c
lib/devsoc.h
lib/lvleml.c

index cc07e16315d673052aa5bf5795a84ebfb971320a..96a9a2b8626a48bb31bef5094c0fb847c88030eb 100644 (file)
 #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  {
index fcfd173d2724c0433b8226e87902dc88a5978927..c8aad3723e46d95157c9393eec8f32d42f54fa63 100644 (file)
 #include        <stdbool.h>
 #include        <time.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
+
 //convenient adress structure
 typedef struct sockaddr SOCKADDR;
 
index 181461b05dab5b4840a3c6ae4b553874204cbe82..5e61708bba71d7cb9c5fdd0bd3f3f2170b98982f 100644 (file)
@@ -5,6 +5,10 @@
 /*     exchange.                                       */
 /*                                                     */
 /********************************************************/
+#include        <arpa/inet.h>
+#include        <sys/types.h>
+
+#include        <netdb.h>
 #include        <stdbool.h>
 #include        <stdlib.h>
 #include        <stdio.h>
@@ -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",