From a619c9e29c1ce17663877c8937e2ae73ab02d791 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Wed, 18 Sep 2024 15:02:49 -0400 Subject: [PATCH] starting to scan spf.tst --- app/emlval.c | 131 ++++++++++++++++++++++++++++++++++------------- data-tst/spf.tst | 32 ++++++------ lib/subrou.c | 2 +- 3 files changed, 111 insertions(+), 54 deletions(-) diff --git a/app/emlval.c b/app/emlval.c index 91a99e3..8bffafa 100644 --- a/app/emlval.c +++ b/app/emlval.c @@ -19,6 +19,49 @@ #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 + }; +/* + +*/ +/********************************************************/ +/* */ +/* 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; +} /* */ @@ -27,13 +70,49 @@ /* 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; +} +/* + +*/ +/********************************************************/ +/* */ +/* 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",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 } /* @@ -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); diff --git a/data-tst/spf.tst b/data-tst/spf.tst index 7f86a2e..665f30e 100644 --- a/data-tst/spf.tst +++ b/data-tst/spf.tst @@ -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 diff --git a/lib/subrou.c b/lib/subrou.c index 9d0a65c..e247b9f 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -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 -- 2.47.3