From 0f6bc01dfb06a5a1e7a591ed9aa071b05fc1a71a Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Wed, 14 Aug 2024 10:09:52 -0400 Subject: [PATCH] Starting main test program chkdns --- app/chkdns.c | 23 ++++++++++++++++++++- lib/subrou.c | 2 +- lib/unidns.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unidns.h | 16 +++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/app/chkdns.c b/app/chkdns.c index 16d349d..375963d 100644 --- a/app/chkdns.c +++ b/app/chkdns.c @@ -1,11 +1,13 @@ // vim: smarttab tabstop=8 shiftwidth=2 expandtab /********************************************************/ /* */ -/* Main SMTP Daemon */ +/* Validation program to check SPF extraction */ +/* library. */ /* */ /********************************************************/ #include #include +#include #include #include "subrou.h" @@ -26,20 +28,39 @@ int main(int argc,char *argv[]) { int status; +char *curname; int phase; _Bool proceed; status=0; +if ((curname=strrchr(argv[0],'/'))==(char *)0) + curname=argv[0]; +else + curname++; phase=0; proceed=true; while (proceed==true) { switch (phase) { case 0 : //checking parameters + foreground=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 (void) rou_modesubrou(true); break; case 2 : //doing main tash + if (argv[1]!=(char *)0) { //always + SPFENU spf; + + spf=dns_get_spf_status(argv[1],argv[2]); + (void) rou_alert(0,"%s %s ==> %s",argv[1],argv[2],dns_spfascii(spf)); + } break; case 3 : //doing main tash (void) rou_modesubrou(false); diff --git a/lib/subrou.c b/lib/subrou.c index 93186e7..1b53784 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.4.2" -#define RELEASE "1" +#define RELEASE "2" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unidns.c b/lib/unidns.c index 8052851..13ad64d 100644 --- a/lib/unidns.c +++ b/lib/unidns.c @@ -15,6 +15,63 @@ static _Bool modopen; //module open/close status +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to return the SPF status string value */ +/* */ +/********************************************************/ +PUBLIC const char *dns_spfascii(SPFENU spf) + +{ +static char *spfascii[]= + { + "spf_pass", + "spf_fail", + "spf_softfail", + "spf_neutral", + "spf_timeout", + "spf_missing", + "spf_unknown" + }; + +const char *ascii; + +ascii="Unset (Bug?)"; +switch (spf) { + case spf_pass : + case spf_fail : + case spf_softfail : + case spf_neutral : + case spf_timeout : + case spf_missing : + case spf_unknown : + ascii=spfascii[spf]; + break; + default : + break; + } +return ascii; +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to get the SPF status according a */ +/* domain name and and an IP. */ +/* */ +/********************************************************/ +PUBLIC SPFENU dns_get_spf_status(char *domain,char *peerip) + +{ +SPFENU spf; + +spf=spf_unknown; +return spf; +} /* ^L */ diff --git a/lib/unidns.h b/lib/unidns.h index fbfdbd9..9b37cba 100644 --- a/lib/unidns.h +++ b/lib/unidns.h @@ -8,6 +8,22 @@ #ifndef UNIDNS #define UNIDNS +typedef enum { + spf_pass, //OK if condition apply + spf_fail, //NOK if condition apply + spf_softfail, //Msg origin is dubious + spf_neutral, //same status as no SPF + spf_timeout, //no answer within time + spf_missing, //SPF not found + spf_unknown //Unknown SPF directive + }SPFENU; + +//procedure to return spf status as an ASCII string +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(char *domain,char *peerip); + //homework to be done before starting/stopping module. extern int dns_modeunidns(_Bool mode); -- 2.47.3