#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);
/* 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
#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) {
}
break;
case 1 : //scan the file
- status=scanlines(tfile,fichier);
+ switch (scanlines(tfile,fichier,&numline)) {
+ }
break;
case 2 : //scan the file
(void) fclose(fichier);
#========================================================
#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