]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Using AFNTYP within unidns module
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 15 Aug 2024 23:20:13 +0000 (19:20 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 15 Aug 2024 23:20:13 +0000 (19:20 -0400)
app/Makefile
app/chkdns.c
lib/Makefile
lib/subafn.c
lib/subafn.h
lib/subrou.c
lib/unidns.c
lib/unidns.h

index 18bdbc5d72a26ac179d36df7f73debc5e9027255..ce27d5e42e1744d92f4eb3f94ea15d9e021be11e 100644 (file)
@@ -55,6 +55,7 @@ chkdns        :  toremake chkdns.o
 
 chkdns.o:  chkdns.c                            \
           ../lib/unidns.h                      \
+          ../lib/subafn.h                      \
           ../lib/subrou.h
 
 emlrec.o:  emlrec.c                            \
index 5326d88052964c4d9ac605c3f2ca7e05e00c487d..04b228df8543a7d6b29be0de1c45bed2a88adf7b 100644 (file)
@@ -11,6 +11,7 @@
 #include       <unistd.h>
 
 #include       "subrou.h"
+#include       "subafn.h"
 #include       "unidns.h"
 
 /*
@@ -29,12 +30,14 @@ int main(int argc,char *argv[])
 {
 int status;
 int try;
+AFNTYP *afnnum;
 char *curname;
 int phase;
 _Bool proceed;
 
 status=0;
 try=0;
+afnnum=(AFNTYP *)0;
 if ((curname=strrchr(argv[0],'/'))==(char *)0)
   curname=argv[0];
 else
@@ -49,24 +52,34 @@ while (proceed==true) {
       (void) rou_setappname(curname);
       if (argc<2) {
         (void) rou_alert(0,"%s need 2 arguments (domain,IP)",appname);
-        for (int i=1;i<optind;i++) 
+        for (int i=1;i<=argc;i++) 
           (void) rou_alert(0,"\targ[%d]=<%s>",i,argv[i]);
         phase=999;
         }
       break;
-    case 1      :       //initialising process
+    case 1      :       //checking IP
+      if ((afnnum=afn_getipnum(argv[2]))==(AFNTYP *)0) {
+        (void) rou_alert(0,"%s is not an IP (aborting)",argv[2]);
+        phase=999;
+        }
+      break;
+    case 2      :       //initialisation
+      (void) afn_modesubafn(true);
       (void) rou_modesubrou(true);
       break;
-    case 2      :       //doing main tash
-      if (argv[1]!=(char *)0) { //always
+    case 3      :       //doing main tash
+      if (argc>1) {     //always
         SPFENU spf;
 
-        spf=dns_get_spf_status(&try,argv[1],argv[2]);
+        afnnum=afn_getipnum(argv[2]);
+        spf=dns_get_spf_status(&try,argv[1],afnnum);
         (void) rou_alert(0,"%s %s ==> %s",argv[1],argv[2],dns_spfASCII(spf));
         }
       break;
-    case 3      :       //doing main tash
+    case 4      :       //doing main tash
       (void) rou_modesubrou(false);
+      (void) afn_modesubafn(false);
+      afnnum=afn_freeipnum(afnnum);
       break;
     default     :       //end of task
       proceed=false;
index e0109c3036ed4f7cbcd2894e7779d0a33d074dcd..9ad5484f5e26e6b10d26344382233c2df1b6917a 100644 (file)
@@ -98,6 +98,9 @@ gestcp.h:                                     \
           subrou.h                             \
           devlog.h devsoc.h
 
+unidns.h:                                      \
+          subafn.h
+
 uniprc.h:                                      \
           subrou.h
 
index f2892aa49f4f2f82b62c9c1b21ee80e28ebbd887..c7e57ef0913ac4248cf50e7da2d7c1f711240e8f 100644 (file)
@@ -28,6 +28,8 @@ PUBLIC AFNTYP *afn_freeipnum(AFNTYP *afnnum)
 
 {
 if (afnnum!=(AFNTYP *)0) {
+  if (afnnum->strnumip!=(char *)0)
+    (void) free(afnnum->strnumip);
   (void) free(afnnum);
   afnnum=(AFNTYP *)0;
   }
@@ -132,6 +134,7 @@ while (proceed==true) {
       break;
     case 1     :       /*lets say ip format ok */
       afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP));
+      afnnum->strnumip=strdup(cleanipstr);
       afnnum->afntype=AF_INET;
       afnnum->afnmask=32;
       if (strchr(cleanipstr,':')==(char *)0) 
index f25f296cd0ebe892622d66aa4462ca0a9da60b53..bd5b160217b1b1e8fd7301bf48f297d79d30b6a5 100644 (file)
 #define        AFT sizeof(struct in6_addr)
 
 typedef        struct  {
-       int afntype;    /*IP type               */
-       int afnmask;    /*IP Mask               */
-       u_char ip[AFT]; /*IP number             */
+        char *strnumip; //IP in string format   
+       int afntype;    //IP type
+       int afnmask;    //IP Mask
+       u_char ip[AFT]; //IP number
        }AFNTYP;
 
 //procedure to free memory used by an AFNTYP structure
index 8b86a47cad1df92053094fb49a8db259362e20bc..c75ff11bdb64ab7505e85da2fbeb2b0833ab41e3 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.4.2"
-#define RELEASE "10"
+#define RELEASE "11"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index 909576b8351a07b354a9fabeb0c009e109f31ecf..d76f1b0ab4c6f346fd5d3d5b171ee9e31b6cb3ff 100644 (file)
@@ -13,7 +13,6 @@
 #include        <string.h>
 #include        <unistd.h>
 
-#include       "subafn.h"
 #include       "subrou.h"
 #include       "unidns.h"
 
@@ -50,12 +49,12 @@ static  _Bool modopen;          //module open/close status
 /*     Procedure to display SPF debug information      */
 /*                                                      */
 /********************************************************/
-static void dbgspf(int dbg,char *peerip,char *seq,SPFENU status)
+static void dbgspf(int dbg,AFNTYP *afnnum,char *seq,SPFENU status)
 
 {
 if (debug>-dbg) {
   (void) rou_alert(dbg,"Current SPF Value <%s>\n\tIP=[%s]\n\tSPF=<%s>",
-                        dns_spfASCII(status),peerip,seq);
+                        dns_spfASCII(status),afnnum->strnumip,seq);
   }
 }
 /*
@@ -165,13 +164,13 @@ return seq;
 /*      spf sequence                                    */
 /*                                                      */
 /********************************************************/
-static _Bool checkip(char *peerip,char *seq)
+static _Bool checkip(AFNTYP *afnnum,char *seq)
 
 {
 _Bool bingo;
 
 bingo=false;
-(void) printf("JMPDBG checkip peerip=<%s> seq=<%s>\n",peerip,seq);
+(void) printf("JMPDBG checkip peerip=<%s> seq=<%s>\n",afnnum->strnumip,seq);
 return bingo;
 }
 /*
@@ -183,7 +182,7 @@ return bingo;
 /*      sequence contents                               */
 /*                                                      */
 /********************************************************/
-static SPFENU checkseq(int *try,char *seq,char *peerip,SPFENU spf)
+static SPFENU checkseq(int *try,char *seq,AFNTYP *afnnum,SPFENU spf)
 
 {
 #define OPEP    "unidns.c:checkseq"
@@ -226,13 +225,13 @@ while (proceed==true) {
           spf=locspf;
           break;
         case mch_ip4            :       //include sub domain
-          if (checkip(peerip,seq+1)==true)
+          if (checkip(afnnum,seq+1)==true)
             spf=locspf;
           break;
         case mch_include        :       //include sub domain
           if (seq[0]==':') {
             (*try)++;
-            spf=dns_get_spf_status(try,seq+1,peerip);
+            spf=dns_get_spf_status(try,seq+1,afnnum);
             }
           else {
             (void) rou_alert(0,"%s wrong SPF include seq <%s> (SPF format?)",
@@ -507,7 +506,7 @@ return infspf;
 /*      spf allowed IP                                  */
 /*                                                      */
 /********************************************************/
-static SPFENU is_peerip_ok(int *try,char *peerip,char *spfrec)
+static SPFENU is_peerip_ok(int *try,AFNTYP *afnnum,char *spfrec)
 
 {
 #define OPEP    "unidns.c:is_peerip_ok"
@@ -534,14 +533,14 @@ while (proceed==true) {
       break;
     case 2      :       //making sure spfrec is an SPF1
       spfrec+=strlen(SPF1);
-      (void) dbgspf(2,peerip,spfrec,spf);
+      (void) dbgspf(2,afnnum,spfrec,spf);
       if (strlen(spfrec)>0) {
         char *seq;
 
         while ((seq=getspfseq(spfrec))!=(char *)0) {
           spfrec=strstr(spfrec,seq);
           spfrec+=strlen(seq);
-          spf=checkseq(try,seq,peerip,spf);
+          spf=checkseq(try,seq,afnnum,spf);
           seq=rou_freestr(seq);
           if (spf!=spf_neutral)
             break;      //Found a status breaking loop
@@ -613,7 +612,7 @@ return ascii;
 /*      domain name and and an IP.                      */
 /*                                                      */
 /********************************************************/
-PUBLIC SPFENU dns_get_spf_status(int *try,char *domain,char *peerip)
+PUBLIC SPFENU dns_get_spf_status(int *try,char *domain,AFNTYP *afnnum)
 
 {
 #define OPEP    "unidns.c:dns_get_spf_status"
@@ -628,11 +627,12 @@ spf=spf_permerr;
 list=(char **)0;
 phase=0;
 proceed=true;
-(void) printf("JMPDBG try='%02d' domain=<%s> peerip=<%s>\n",*try,domain,peerip);
+(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
-      if ((domain==(char *)0)||(peerip==(char *)0)) {
+      if ((domain==(char *)0)||(afnnum==(AFNTYP *)0)) {
         (void) rou_alert(0,"%s missing one or both needed argument",OPEP);
         phase=999;      //trouble trouble
         }
@@ -655,7 +655,7 @@ while (proceed==true) {
         }
       break;
     case 4      :       //gett the spf LIST related to SPF
-      spf=is_peerip_ok(try,peerip,list[0]);
+      spf=is_peerip_ok(try,afnnum,list[0]);
       list=(char **)rou_freelist((void **)list,(freehandler_t)rou_freestr);
       break;
     default     :       //SAFE guard
index ed3d677f7f4272be7c78e25330626856232e9823..4c8342a38edcb6541a987c33414e7f39c608d625 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef        UNIDNS
 #define UNIDNS
 
+#include        "subafn.h"
+
 typedef        enum    {
        spf_pass,       //OK if condition apply
        spf_fail,       //NOK if condition apply
@@ -23,7 +25,7 @@ typedef       enum    {
 extern const char *dns_spfASCII(SPFENU spf);
 
 //get the SPF status for a specific domain and a remote peer IP
-extern SPFENU dns_get_spf_status(int *try,char *domain,char *peerip);
+extern SPFENU dns_get_spf_status(int *try,char *domain,AFNTYP *afnnum);
 
 //homework to be done before starting/stopping module.
 extern int dns_modeunidns(_Bool mode);