From: Jean-Marc Pigeon (Delson) Date: Sun, 18 Aug 2024 02:14:44 +0000 (-0400) Subject: outil chkdns seems to be working X-Git-Tag: tag-0.4.2-end~14 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=fc21a367e360e5a46c3e05abd5e8497c4eb5b4b8;p=jmp%2Fmailleur outil chkdns seems to be working --- diff --git a/app/chkdns.c b/app/chkdns.c index 2cda539..189d804 100644 --- a/app/chkdns.c +++ b/app/chkdns.c @@ -24,15 +24,77 @@ */ /********************************************************/ /* */ +/* Procedure to extrac keywork 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)); +//Extracting keyword +(void) strcpy(keyword,line); +if ((ptr=strchr(keyword,' '))!=(char *)0) + *ptr='\000'; +if ((ptr=strchr(keyword,'\n'))!=(char *)0) + *ptr='\000'; + +//cleaning line +ptr=line+strlen(keyword); +(void) memmove(line,ptr,strlen(ptr)); +while (line[0]==' ') + (void) memmove(line,line+1,strlen(line+1)); +return strlen(keyword); +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to check domain/peerip status */ +/* */ +/********************************************************/ +static int checkstatus(char *domain,char *peerip,char *spfstr) + +{ +_Bool status; +int try; +SPFENU spf; +AFNTYP *afnnum; + +status=true; +try=0; +afnnum=afn_getipnum(peerip); +spf=spf_getstatus(&try,domain,afnnum); +if (strcmp(spfstr,spf_spfASCII(spf))!=0) + status=false; +afnnum=afn_freeipnum(afnnum); +return status; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to scan a line from the test file */ /* */ /********************************************************/ -static int scanline(FILE *fichier) +static int scanline(char *filename,FILE *fichier) { +#define MAX 300 + int status; int num; -char line[300]; +char line[MAX]; +char domain[MAX]; +char peerip[MAX]; +char spfstr[MAX]; status=0; num=0; @@ -44,9 +106,29 @@ while (fgets(line,sizeof(line),fichier)!=(char *)0) { *ptr='\000'; if (strlen(line)==0) continue; - (void) rou_alert(0,"JMPDBG line='%d' <%s>",num,line); + //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; + } + } +if (status!=0) { + (void) rou_alert(0,"SPF fail in file <%s> in line='%03d'", + filename,num); + (void) rou_alert(0,"\t for domain <%s> peerip=<%s>", + domain,peerip); } return status; + +#undef MAX } /* @@ -80,7 +162,10 @@ while (proceed==true) { } break; case 1 : //scan the file - (void) scanline(fichier); + (void) rou_alert(0,"scanning test file <%s>",rootname); + status=scanline(rootname,fichier); + if (status==0) + (void) rou_alert(0,"\t Test OK"); break; case 2 : //scan the file (void) fclose(fichier); @@ -111,7 +196,6 @@ int status; status=0; for (int i=0;iargc;i++) { - (void) fprintf(stdout,"Doing test pattern <%s>\n",params->argv[i]); (void) scantest(params->argv[i]); } return status; diff --git a/lib/gesspf.c b/lib/gesspf.c index be082a3..8c777a4 100644 --- a/lib/gesspf.c +++ b/lib/gesspf.c @@ -190,7 +190,6 @@ while (proceed==true) { if (mx!=(char *)0) { //always char *ptr; - (void) printf("JMPDBG mx value=<%s>\n",mx); if ((ptr=strchr(mx,'/'))!=(char *)0) { *ptr='\000'; cidr=atoi(ptr+1); @@ -552,8 +551,6 @@ spf=spf_permerr; list=(char *)0; phase=0; proceed=true; -(void) printf("JMPDBG try='%02d' domain=<%s> peerip=<%s>\n", - *try,domain,afnnum->strnumip); while (proceed==true) { switch (phase) { case 0 : //Are the parameters available diff --git a/lib/subrou.c b/lib/subrou.c index a159a2d..2f43ae0 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.4.2" -#define RELEASE "21" +#define RELEASE "22" //Public variables PUBLIC int debug=0; //debug level