]> SAFE projects GIT repository - jmp/mailleur/commitdiff
outil chkdns seems to be working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 Aug 2024 02:14:44 +0000 (22:14 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 18 Aug 2024 02:14:44 +0000 (22:14 -0400)
app/chkdns.c
lib/gesspf.c
lib/subrou.c

index 2cda53976e122d5747ec440ea77b58f710b6ae9d..189d80475728930e32a3c94c32dac016a1c37310 100644 (file)
 */
 /********************************************************/
 /*                                                     */
+/*     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);
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     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;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
 /*     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
 }
 /*
 \f
@@ -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;i<params->argc;i++) {
-  (void) fprintf(stdout,"Doing test pattern <%s>\n",params->argv[i]);
   (void) scantest(params->argv[i]);
   }
 return status;
index be082a3e152bc7b97d743d7f5a72d03f66929ab0..8c777a4f51b90b61aa098a7922dbf0298cb7b339 100644 (file)
@@ -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
index a159a2d25e0dc59bcbfe703adc6eb0cf76e61f53..2f43ae02c2bd5352f2548001180e8de944536576 100644 (file)
@@ -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