]> SAFE projects GIT repository - jmp/mailleur/commitdiff
starting to scan spf.tst
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 18 Sep 2024 19:02:49 +0000 (15:02 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 18 Sep 2024 19:02:49 +0000 (15:02 -0400)
app/emlval.c
data-tst/spf.tst
lib/subrou.c

index 91a99e3132658e2ba7208c3e8e814be1f10dd328..8bffafa94baa5b500194182e51ca3e23f4c05c86 100644 (file)
 #include       "gesspf.h"
 
 #define VALNAME "emlval"        //validator application
+
+//vocabulary enum
+typedef enum    {
+      voc_start,                //"start"
+      voc_end,                  //"end"
+      voc_include,              //"include"
+      voc_unknown               //unknown keys
+      }voc_enum;
+
+//vocabulary    (Must be in sync withvoc_enum list)
+char *vocable[]={
+      "start",
+      "end",
+      "include",
+      (char *)0
+      };
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to detect vocabulary                  */
+/*                                                     */
+/********************************************************/
+static voc_enum getvoc(char *keyword)
+
+{
+voc_enum voc;
+
+voc=voc_unknown;
+if (keyword!=(char *)0) {
+  char **ptr;
+  
+  ptr=vocable;
+  for (int i=0;(*ptr)!=(char *)0;i++,ptr++) {
+    if (strcmp(*ptr,keyword)==0) {
+      voc=(voc_enum)i;
+      break;
+      }
+    }
+  }
+return voc;
+}
 /*
 \f
 */
 /*     Procedure to extrac keywork from line           */
 /*                                                     */
 /********************************************************/
+static size_t cleanline(FILE *fichier,char *line,size_t max,int *numline)
+
+{
+size_t got;
+
+got=(size_t)0;
+(void) strcpy(line,"");
+while (got==(size_t)0) {
+  char *ptr;
+
+  if (fgets(line,max,fichier)==(char *)0) 
+    break;
+  (*numline)++;
+  if ((ptr=strchr(line,'#'))!=(char *)0)
+    *ptr='\000';
+  if ((ptr=strchr(line,'\n'))!=(char *)0)
+    *ptr='\000';
+  if ((ptr=strchr(line,'\r'))!=(char *)0)
+    *ptr='\000';
+  //replacing HT by space
+  while ((ptr=strchr(line,'\t'))!=(char *)0)
+    *ptr=' ';
+  //removing head space
+  while (line[0]==' ')
+    (void) memmove(line,line+1,strlen(line+1));
+  got=strlen(line);
+  }
+return got;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to extract keyword from line           */
+/*                                                     */
+/********************************************************/
 static int getkeyword(char *keyword,char *line)
 
 {
 char *ptr;
 
 (void) strcpy(keyword,"");
-
 //removing head space
 while (line[0]==' ')
   (void) memmove(line,line+1,strlen(line+1)+1);
@@ -84,55 +163,30 @@ return status;
 /*     Procedure to scan a line from the test file     */
 /*                                                     */
 /********************************************************/
-static int scanlines(char *testname,FILE *fichier)
+static int scanlines(char *testname,FILE *fichier,int *numline)
 
 {
+#define OPEP    "emlval.c:scanlines"
 #define MAX     300
 
-static  char *noneed="#\n\r";
-
 int status;
-int num;
 char line[MAX];
-char domain[MAX];
-char peerip[MAX];
-char spfstr[MAX];
 
 status=0;
-num=0;
-while (fgets(line,sizeof(line),fichier)!=(char *)0) {
-  char *ptr;
+while (cleanline(fichier,line,sizeof(line),numline)>0) {
+  char keyword[MAX];
 
-  num++;
-  for (int i=0;i<strlen(noneed);i++) {
-    if ((ptr=strchr(line,noneed[i]))!=(char *)0)
-      *ptr='\000';
-    }
-  if (strlen(line)==0)
-    continue;
-  //replacing HT by space
-  while ((ptr=strchr(line,'\t'))!=(char *)0)
-    *ptr=' ';
-  //removing head space
-  while (line[0]==' ')
-    (void) memmove(line,line+1,strlen(line+1));
-  (void) getkeyword(domain,line);
-  (void) getkeyword(peerip,line);
-  (void) getkeyword(spfstr,line);
-  if (checkstatus(domain,peerip,spfstr)==false) {
-    status=-1; 
-    break;
+  (void) getkeyword(keyword,line);
+  switch (getvoc(keyword)) {
+    default     :
+      (void) rou_alert(0,"%s JMPDBG keyword=<%s>",OPEP,keyword);
+      break;
     }
   }
-if (status!=0) {
-  (void) rou_alert(0,"SPF fail in file <%s> in line='%03d'",
-                      testname,num);
-  (void) rou_alert(0,"\t for domain <%s> peerip=<%s>",
-                     domain,peerip);
-  }
 return status;
 
 #undef  MAX
+#undef  OPEP
 }
 /*
 \f
@@ -149,11 +203,13 @@ static int scantest(char *tfile)
 #define OPEP    "emlval.c:scantest"
 
 _Bool status;
+int numline;
 FILE *fichier;
 int phase;
 _Bool proceed;
 
 status=false;
+numline=0;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -167,7 +223,8 @@ while (proceed==true) {
         }
       break;
     case 1      :       //scan the file
-      status=scanlines(tfile,fichier);
+      switch (scanlines(tfile,fichier,&numline)) {
+        }
       break;
     case 2      :       //scan the file
       (void) fclose(fichier);
index 7f86a2eed79d1e48666aebea714a4eb1d239f8cf..665f30e20a7a09d10a504f7517c4ad13437afa14 100644 (file)
@@ -1,37 +1,37 @@
 #========================================================
 #data to check if SPF are properly seen
 #NOTE: this test rely on the fact
-#"zoo.dns" is accessible via DNS request.
+#"emlvac.safe.ca.dns" is accessible via DNS request.
 #========================================================
 start: SPF
 #--------------------------------------------------A------
 #Checking MX
-S:     chkmx.spf.zoo           127.0.0.255
-R:     OK                      #Acceptable IP number
-S:     chkmx.spf.zoo           127.0.0.1
-R:     BAD                     #wrong MX ip number
+S:     chkmx.spf.emlvac.safe.ca                127.0.0.255
+R:     OK                                      #Acceptable IP number
+S:     chkmx.spf.emlvac.safe.ca                127.0.0.1
+R:     BAD                                     #wrong MX ip number
 #Checking IP4 
-S:     chkip4.spf.zoo          127.0.1.255
+S:     chkip4.spf.emlvac.safe.ca               127.0.1.255
 R:     OK
-S:     chkip4.spf.zoo          127.0.1.1
-R:     BAD                     #out of range IP4
+S:     chkip4.spf.emlvac.safe.ca               127.0.1.1
+R:     BAD                                     #out of range IP4
 #Checking IP6 
-S:     chkip6.spf.zoo          0:0:0:0:0:ffff:127.0.2.255
+S:     chkip6.spf.emlvac.safe.ca               0:0:0:0:0:ffff:127.0.2.255
 R:     OK
-S:     chkip6.spf.zoo          2607:180:1000:795b::127.0.2.1 
+S:     chkip6.spf.emlvac.safe.ca               2607:180:1000:795b::127.0.2.1 
 R:     BAD     
 ##checking addr
-S:     chkaddr.spf.zoo         127.0.1.255
+S:     chkaddr.spf.emlvac.safe.ca              127.0.1.255
 R:     OK
-S:     chkaddr.spf.zoo         127.0.1.1
+S:     chkaddr.spf.emlvac.safe.ca              127.0.1.1
 R:     BAD     
-S:     chkaddr.spf.zoo         2607:180:1000:795b::127.0.2.255
+S:     chkaddr.spf.emlvac.safe.ca              2607:180:1000:795b::127.0.2.255
 R:     OK
-S:     chkaddr.spf.zoo         2607:180:1000:795b::127.0.2.1
+S:     chkaddr.spf.emlvac.safe.ca              2607:180:1000:795b::127.0.2.1
 R:     BAD     
-S:     chkaddr.spf.zoo         127.0.3.255
+S:     chkaddr.spf.emlvac.safe.ca              127.0.3.255
 R:     OK
-S:     chkaddr.spf.zoo         127.0.3.1
+S:     chkaddr.spf.emlvac.safe.ca              127.0.3.1
 R:     BAD     
 #--------------------------------------------------------
 end: SPF
index 9d0a65c9b799a6fe70f4141199e28cb66223d89c..e247b9ff8f3b02e97f567e321e88fecc62d9d895 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.4.2"
-#define RELEASE "30"
+#define RELEASE "31"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level