]> SAFE projects GIT repository - jmp/mailleur/commitdiff
starting test using spf.zoo domain
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 Aug 2024 18:53:38 +0000 (14:53 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 Aug 2024 18:53:38 +0000 (14:53 -0400)
app/chkdns.c
lib/gesspf.c
lib/subafn.c
lib/subafn.h
lib/subrou.c

index 189d80475728930e32a3c94c32dac016a1c37310..cfa8553c19c46d159970bd4e19d5d99545cf9b1c 100644 (file)
@@ -71,8 +71,11 @@ status=true;
 try=0;
 afnnum=afn_getipnum(peerip);
 spf=spf_getstatus(&try,domain,afnnum);
-if (strcmp(spfstr,spf_spfASCII(spf))!=0) 
+if (strcmp(spfstr,spf_spfASCII(spf))!=0) {
+  (void) rou_alert(2,"expected SPF status=<%s>, got<%s>",
+                      spfstr,spf_spfASCII(spf));
   status=false;
+  }
 afnnum=afn_freeipnum(afnnum);
 return status;
 }
index 8c777a4f51b90b61aa098a7922dbf0298cb7b339..be272dab4a18f6f348eec4a7524cc72e680f1db5 100644 (file)
@@ -22,7 +22,7 @@
 
 typedef enum    {               //mechanism definition
         mch_all,                //"all"
-        mch_a,                  //'a'
+        mch_addr,               //'a'
         mch_exists,             //"existe"
         mch_include,            //"include"
         mch_ip4,                //"ip4"
@@ -45,7 +45,7 @@ static  _Bool modopen;          //module open/close status
 static void dbgspf(int dbg,char *proc,char *domain,AFNTYP *afnnum,char *seq,SPFENU status)
 
 {
-if (debug>-dbg) {
+if (debug>=dbg) {
   (void) rou_alert(dbg,"Origin=\"%s\"\n"
                        "\tCurrent SPF Value <%s>\n"
                        "\tPeer IP=[%s]\n"
@@ -156,6 +156,61 @@ return seq;
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to check the SPF A value againt the   */
+/*      current afnnum.                                 */
+/*      return true if successful.                      */
+/*                                                      */
+/********************************************************/
+static _Bool checkaddr(char *domain,AFNTYP *afnnum,char *addr)
+
+{
+#define OPEP    "gesspf.c:checkaddr"
+
+_Bool found;
+int cidr;
+char *addrdom;
+int phase;
+_Bool proceed;
+
+found=false;
+cidr=128;
+addrdom=domain;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //getting the list of MX
+      if (addrdom!=(char *)0) {      //always
+        char *ptr;
+
+        if ((ptr=strchr(addrdom,'/'))!=(char *)0) {
+          *ptr='\000';
+          cidr=atoi(ptr+1);
+          }
+        if ((ptr=strchr(addrdom,':'))!=(char *)0) {
+          *ptr='\000';
+          addrdom=ptr+1;
+          }
+        }
+      break;
+    case 1      :       //getting the list of MX for mxdomain
+      (void) printf("JMPDBG, checkaddr got <%s> cidr='%d'",addrdom,cidr);
+      break;
+    default     :       //SAFE guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return found;
+
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to check the SPF MX values againt the */
 /*      current afnnum.                                 */
 /*      return true if successful.                      */
@@ -228,6 +283,8 @@ while (proceed==true) {
                              OPEP,mxlist[i]->mxname);
             continue;
             }
+          (void) printf("JMPDBG addr=<%s> peer=<%s> cidr='%d'\n",
+                         addrnum->strnumip,afnnum->strnumip,cidr);
           switch (afn_cmpipnum(addrnum,afnnum,cidr)) {
             case false  :       //not found
               break;
@@ -386,6 +443,10 @@ while (proceed==true) {
         case mch_all            :       //usually last in sequence
           spf=locspf;
           break;
+        case mch_addr            :       //check IP addr
+          if (checkaddr(domain,afnnum,seq)==true)
+            spf=locspf;
+          break;
         case mch_mx             :       //This is a MX refrence
           if (checkmx(domain,afnnum,seq)==true)
             spf=locspf;
@@ -394,7 +455,7 @@ while (proceed==true) {
         case mch_ip6            :       //This is IPV6 number
           if (checkip(domain,afnnum,seq+1)==true)
             spf=locspf;
-          (void) dbgspf(2,"checkip",domain,afnnum,seq+1,spf);
+          (void) dbgspf(5,"checkip",domain,afnnum,seq+1,spf);
           break;
         case mch_include        :       //include sub domain
           if (seq[0]==':') {
@@ -468,7 +529,7 @@ while (proceed==true) {
           if (spf!=spf_neutral)
             break;      //Found a pass status,  breaking loop
           }
-        (void) dbgspf(2,"is_peerip_ok",domain,afnnum,ref,spf);
+        (void) dbgspf(5,"is_peerip_ok",domain,afnnum,ref,spf);
         }
       break;
     default     :       //SAFE Guard
index 70f83961e2aa844a049e9bf5b36678b4a978e5da..8da984009531afa0be2b06f1bbc866d16abb9ee9 100644 (file)
@@ -175,6 +175,7 @@ if (rp!=(struct addrinfo *)0) {
     }
   if (ptr!=(u_char *)0)
     (void) memmove(afnnum->ip,ptr,afnnum->afnmask/8);
+  afnnum->strnumip=afn_getstrip(afnnum);
   }
 return afnnum;
 }
@@ -210,7 +211,6 @@ while (proceed==true) {
       break;
     case 1     :       /*lets say ip format ok */
       afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
-      afnnum->strnumip=strdup(cleanipstr);
       afnnum->afntype=AF_INET;
       afnnum->afnmask=32;
       if (strchr(cleanipstr,':')==(char *)0) 
@@ -227,8 +227,13 @@ while (proceed==true) {
        cleanipstr=ZIPV4;
       break;
     case 4     :       //lets convert it
-      if (inet_pton(afnnum->afntype,cleanipstr,afnnum->ip)<=0) 
+      if (inet_pton(afnnum->afntype,cleanipstr,afnnum->ip)<=0)  {
        afnnum=afn_freeipnum(afnnum);
+        phase=999;      //no need to go further
+        }
+      break;
+    case 5     :       //lets convert it
+      afnnum->strnumip=afn_getstrip(afnnum);
       break;
     default    :       /*SAFE guard            */
       proceed=false;
@@ -239,6 +244,56 @@ while (proceed==true) {
 return afnnum;
 
 #undef  ZIPV4
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to normalize IP number format         */
+/*     Memory allocated need to be freed later         */
+/*     on.                                             */
+/*                                                      */
+/*                                                      */
+/********************************************************/
+char *afn_getstrip(AFNTYP *afnnum)
+
+{
+#define OPEP    "subafn.c:afn_getstrip"
+
+char *ipnorm;
+char buffer[300];
+
+ipnorm=(char *)0;
+(void) strcpy(buffer,"");
+if (afnnum!=(AFNTYP *)0) {
+  switch (afnnum->afntype) {
+    case AF_INET       :
+      (void) snprintf(buffer,sizeof(buffer),"%03d.%03d.%03d.%03d",
+                                            afnnum->ip[0],afnnum->ip[1],
+                                            afnnum->ip[2],afnnum->ip[3]);
+      break;
+    case AF_INET6      :
+      (void) snprintf(buffer,sizeof(buffer),"%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
+                                            "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+                                           afnnum->ip[0],afnnum->ip[1],
+                                           afnnum->ip[2],afnnum->ip[3],
+                                           afnnum->ip[4],afnnum->ip[5],
+                                           afnnum->ip[6],afnnum->ip[7],
+                                           afnnum->ip[8],afnnum->ip[9],
+                                           afnnum->ip[10],afnnum->ip[11],
+                                           afnnum->ip[12],afnnum->ip[13],
+                                           afnnum->ip[14],afnnum->ip[15]);
+      break;
+    default            :
+      (void) fprintf(stderr,"%s, unable to fin IP type (bug?)",OPEP);
+    } 
+  }
+if (strlen(buffer)>0)
+  ipnorm=strdup(buffer);
+return ipnorm;
+
 #undef  OPEP
 }
 /*
index 638713b3fc194cf7cf95206c6e237b85203b8dff..9363104adeb6ea925a0192842f67c15bcf4393af 100644 (file)
@@ -32,6 +32,10 @@ extern AFNTYP *afn_freeipnum(AFNTYP *afnnum);
 //IP number
 extern char *afn_stripnum(AFNTYP *afnnum);
 
+//procedure to extract a dynamic string with the
+//clean IP number from a AFNTYP struct.
+extern char *afn_getstrip(AFNTYP *afnnum);
+
 //procedure to convert a addrinfo struct to an 
 //IP number in AFNTYP structure.
 extern AFNTYP *afn_getaddrinfo(struct addrinfo *rp);
index 2f43ae02c2bd5352f2548001180e8de944536576..a88f64c21ad2a30bdec6863b081dcf43fbcd96f5 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.4.2"
-#define RELEASE "22"
+#define RELEASE "23"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level