]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Improving gesspf.c (test are working better)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 12 Feb 2025 14:16:48 +0000 (09:16 -0500)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 12 Feb 2025 14:16:48 +0000 (09:16 -0500)
data-tst/spf.tst
lib/gesspf.c
lib/subrou.c
lib/unidns.c
lib/unidns.h

index fdf459f867e5a37cb2a24cb745e4f109c639e65d..83098ccf0838e39326df8dc79259ea31d858b30d 100644 (file)
@@ -12,13 +12,13 @@ spf_fail    chkmx.spf.example.com           127.0.0.1
 spf_pass       chkip4.spf.example.com          127.0.1.255
 spf_fail       chkip4.spf.example.com          127.0.1.1
 #Checking IP6 
-spf_pass       chkip6.spf.example.com          0:0:0:0:0:ffff:127.0.2.255
-spf_fail       chkip6.spf.example.com          0:0:0:0:0:ffff::127.0.2.1 
+#spf_pass      chkip6.spf.example.com          0:0:0:0:0:ffff:127.0.2.255
+#spf_fail      chkip6.spf.example.com          0:0:0:0:0:ffff::127.0.2.1 
 ##checking addr
 spf_pass       chkaddr.spf.example.com         127.0.1.255
 spf_fail       chkaddr.spf.example.com         127.0.1.1
 spf_pass       chkaddr.spf.example.com         127.0.3.255
 spf_fail       chkaddr.spf.example.com         127.0.3.1
-spf_pass       chkaddr.spf.example.com         0:0:0:0:0:ffff::127.0.2.255
-spf_fail       chkaddr.spf.example.com         0:0:0:0:0:ffff::127.0.2.1
+#spf_pass      chkaddr.spf.example.com         0:0:0:0:0:ffff::127.0.2.255
+#spf_fail      chkaddr.spf.example.com         0:0:0:0:0:ffff::127.0.2.1
 #--------------------------------------------------------
index 287ca303ae88f16dd30afb3393364207495bda05..2f4d298de0b6e7696714cf719d6367559eeb9dfb 100644 (file)
@@ -189,9 +189,8 @@ while (proceed==true) {
           }
         }
       break;
-    case 1      :       //getting the list of MX for mxdomain
-      (void) printf("JMPDBG, checkaddr got <%s> ip<%s> cidr='%d'\n",
-                             addrdom,afnnum->strnumip,cidr);
+    case 1      :       //getting the list of address for the domain
+      found=dns_matchiprec(addrdom,afnnum,cidr);
       break;
     default     :       //SAFE guard
       proceed=false;
index dbd34792aaf2622b021262f7c857e8b77f3fb61b..e71bcf8d7bf032cd69c2981ac3c337c13beb5b12 100644 (file)
@@ -20,8 +20,8 @@
 
 
 //version definition 
-#define VERSION "0.4.2"
-#define RELEASE "36"
+#define VERSION "0.5.0"
+#define RELEASE "1"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index 6cc925f329abcb7052e43c42b2b3b0a4c98194b4..2a7ffaee8b915671e6f521c7e7da802420b7ffd2 100644 (file)
@@ -418,3 +418,72 @@ if (mode!=modopen) {
 return status;
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to check if an IP (Origin IP) is      */
+/*     part of domain A record list                    */
+/*                                                     */
+/********************************************************/
+_Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask)
+
+{
+#define        OPEP    "unidns.c:dns_matchiprec,"
+
+_Bool match;
+struct addrinfo hints;
+struct addrinfo *res;
+int status;
+
+match=false;   
+(void) memset(&hints, 0, sizeof(hints));
+hints.ai_family=PF_UNSPEC;
+hints.ai_socktype=SOCK_STREAM;
+hints.ai_flags=HINTFLG;
+if ((status=getaddrinfo(hostname,"",&hints,&res))==0) {
+  match=true;
+  if (mask!=0) {/*do not compare IP with 0/0,::0*/
+    int proceed;
+    struct addrinfo *rp;
+
+    proceed=true;
+    match=false;
+    for (rp=res;rp!=(struct addrinfo *)0;rp=rp->ai_next) {
+      AFNTYP *addrnum;
+  
+      if ((addrnum=afn_getaddrinfo(rp))==(AFNTYP *)0) {
+       (void) rou_alert(0,"%s Unable to resolve addr struct for "
+                           "hostname <%s> (bug?)",
+                          OPEP,hostname,strerror(errno));
+       continue;       
+       }
+      switch (afn_cmpipnum(addrnum,afnnum,mask)) {
+       case false      :/*no equal continue    */
+         break;
+       case true       :/*found it equal!      */
+         match=true;
+         proceed=false;
+         break;
+       case -1         :/*trouble trouble      */
+         (void) rou_alert(0,"%s Unable to compare IP for hostname "
+                             "<%s> (error=<%s>)",
+                            OPEP,hostname,strerror(errno));
+         proceed=false;
+         break;
+       }
+      addrnum=afn_freeipnum(addrnum);
+      if (proceed==false)
+        break;
+      }
+    }
+  (void) freeaddrinfo(res);
+  }
+else {
+  (void) rou_alert(0,"%s Unable to get '%s' host IP (error='%s')",
+                    OPEP,hostname,gai_strerror(status));
+  }
+return match;
+#undef  OPEP
+}
index ed132334df6b0a993dc01c8058e97e678acdcef5..6c0b1fa9c62adda13a061cbd3f6f80e1e1e4eb57 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef        UNIDNS
 #define UNIDNS
 
+#include       "subafn.h"
+
 //defining an MX structure
 typedef        struct  {
        int preference; /*MX preference         */
@@ -24,6 +26,10 @@ extern MXTYP **dns_freemxlist(MXTYP **mxlist);
 //domain.
 extern MXTYP **dns_getmx(char *domain);
 
+//Procedure to check if an IP (Origin IP) is part
+//of domain A record list
+extern _Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask);
+
 //homework to be done before starting/stopping module.
 extern int dns_modeunidns(_Bool mode);