From fd36e33c6b7d6cd8582ed1cea0d7d0ea8b385294 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Thu, 15 Aug 2024 19:20:13 -0400 Subject: [PATCH] Using AFNTYP within unidns module --- app/Makefile | 1 + app/chkdns.c | 25 +++++++++++++++++++------ lib/Makefile | 3 +++ lib/subafn.c | 3 +++ lib/subafn.h | 7 ++++--- lib/subrou.c | 2 +- lib/unidns.c | 30 +++++++++++++++--------------- lib/unidns.h | 4 +++- 8 files changed, 49 insertions(+), 26 deletions(-) diff --git a/app/Makefile b/app/Makefile index 18bdbc5..ce27d5e 100644 --- a/app/Makefile +++ b/app/Makefile @@ -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 \ diff --git a/app/chkdns.c b/app/chkdns.c index 5326d88..04b228d 100644 --- a/app/chkdns.c +++ b/app/chkdns.c @@ -11,6 +11,7 @@ #include #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",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; diff --git a/lib/Makefile b/lib/Makefile index e0109c3..9ad5484 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -98,6 +98,9 @@ gestcp.h: \ subrou.h \ devlog.h devsoc.h +unidns.h: \ + subafn.h + uniprc.h: \ subrou.h diff --git a/lib/subafn.c b/lib/subafn.c index f2892aa..c7e57ef 100644 --- a/lib/subafn.c +++ b/lib/subafn.c @@ -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) diff --git a/lib/subafn.h b/lib/subafn.h index f25f296..bd5b160 100644 --- a/lib/subafn.h +++ b/lib/subafn.h @@ -17,9 +17,10 @@ #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 diff --git a/lib/subrou.c b/lib/subrou.c index 8b86a47..c75ff11 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -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 diff --git a/lib/unidns.c b/lib/unidns.c index 909576b..d76f1b0 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -13,7 +13,6 @@ #include #include -#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 diff --git a/lib/unidns.h b/lib/unidns.h index ed3d677..4c8342a 100644 --- a/lib/unidns.h +++ b/lib/unidns.h @@ -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); -- 2.47.3