From 4369e34f037b888ecda0796c040eff3a384bb912 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sat, 5 Jul 2025 15:57:49 -0400 Subject: [PATCH] Starting to warite digmd5 tools application --- Makefile | 1 + app/chkspf.c | 2 +- app/res/maild.c | 167 ------------------------------------------------ lib/subcnv.h | 3 - lib/unidig.c | 8 +-- lib/unidig.h | 3 + tools/Makefile | 59 +++++++++++++++++ tools/digmd5.c | 81 +++++++++++++++++++++++ tools/toremake | 0 9 files changed, 149 insertions(+), 175 deletions(-) delete mode 100644 app/res/maild.c create mode 100644 tools/Makefile create mode 100644 tools/digmd5.c create mode 100644 tools/toremake diff --git a/Makefile b/Makefile index 5bd0a00..1d59772 100644 --- a/Makefile +++ b/Makefile @@ -239,6 +239,7 @@ install : SUBDIR = \ lib \ app \ + tools \ sql \ #-------------------------------------------------------------------- diff --git a/app/chkspf.c b/app/chkspf.c index 29918cf..c8b3224 100644 --- a/app/chkspf.c +++ b/app/chkspf.c @@ -18,7 +18,7 @@ #include "uniprc.h" #include "gesspf.h" -#define CHKSPF "chkspf" //SPF field validator +#define CHKSPF "chkspf" //application name /* diff --git a/app/res/maild.c b/app/res/maild.c deleted file mode 100644 index 3390888..0000000 --- a/app/res/maild.c +++ /dev/null @@ -1,167 +0,0 @@ -// vim: smarttab tabstop=8 shiftwidth=2 expandtab -/********************************************************/ -/* */ -/* Main SMTP Daemon */ -/* */ -/********************************************************/ -#include -#include -#include -#include -#include -#include - -#include "subrou.h" -#include "unipar.h" -#include "uniprc.h" -#include "unisig.h" - -/* - -*/ -/********************************************************/ -/* */ -/* Program main task */ -/* */ -/********************************************************/ -static void task(u_int iteration) - -{ -#define OPEP "maild.c:task" -char *emlrec; -char *argv[10]; -pid_t *pidlst; -int phase; -_Bool proceed; - -emlrec=rou_apppath("/usr/bin/emlrec"); -argv[0]=(char *)0; -pidlst=(pid_t *)calloc(iteration,sizeof(pid_t)); -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - case 0 : //looping forever email receiving processes - for (int i=0;i " - "(error=<%s>, system trouble?)", - OPEP,emlrec,strerror(errno)); - (void) sleep(2); //to avoid avalanche - } - (void) exit(1); //reached only if trouble - break; - default : - break; - } - } - (void) sleep(2); //next check in 5 second - if (hangup==false) //lets try again - phase--; //same phase - (void) prc_nozombie(); - break; - case 1 : //Terminating all remaining process - if (pidlst!=(pid_t *)0) { //always - u_int stillrun; - - stillrun=0; - for (int i=0;i0) { - (void) prc_nozombie(); - (void) sleep(2); - phase--; //let send signal again - } - } - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } -(void) free(pidlst); -#undef OPEP -} -/* - -*/ -/********************************************************/ -/* */ -/* Main routine */ -/* Start multiple SMTP daemon and make */ -/* sure there always ready to answer to */ -/* SMTP request. */ -/* */ -/********************************************************/ -int main(int argc,char *argv[]) - -{ -int status; -ARGTYP *params; -int phase; -_Bool proceed; - -status=0; -params=(ARGTYP *)0; -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - case 0 : //checking parameters - if ((params=par_getparams(argc,argv,"d:fhr:v"))==(ARGTYP *)0) { - phase=999; //no need to go further - } - break; - case 1 : //Need to go in background mode? - if (foreground==false) - if (prc_divedivedive()!=(pid_t)0) - proceed=false;//Dive mode - break; - case 2 : //initialising process - (void) prc_preptitle(argc,argv,environ); - (void) rou_modesubrou(true); - (void) prc_modeuniprc(true); - (void) sig_modeunisig(true); - (void) sig_trapsignal(true,sig_alrm); - break; - case 3 : //doing main tash - if (prc_locking(appname,true,5)==true) { - (void) task(1); - (void) prc_locking(appname,false,1); - } - break; - case 4 : //doing main tash - (void) prc_cleantitle(); - params=par_freeparams(params); - (void) sig_trapsignal(false,sig_alrm); - (void) sig_modeunisig(false); - (void) prc_modeuniprc(false); - (void) rou_modesubrou(false); - break; - default : //end of task - proceed=false; - break; - } - phase++; - } -(void) exit(status); -} diff --git a/lib/subcnv.h b/lib/subcnv.h index d3d728e..1fa90c2 100644 --- a/lib/subcnv.h +++ b/lib/subcnv.h @@ -11,9 +11,6 @@ //base64 char 0 coding #define IOBNULL "\\0" -//MD5 hashing result -typedef unsigned char MD5TYP[17]; - //Procedure to convert a plain ASCII B64 sequence //to a plain ASCII sequence extern char *cnv_getb64(char *b64); diff --git a/lib/unidig.c b/lib/unidig.c index ffb1866..cd14e10 100644 --- a/lib/unidig.c +++ b/lib/unidig.c @@ -46,7 +46,7 @@ while (proceed==true) { break; case 1 : //getting md5 context if ((mdctx=EVP_MD_CTX_new())==(EVP_MD_CTX *)0) { - (void) fprintf(stdout,"%s Unable to open MD5 context (System?)",OPEP); + (void) rou_alert(0,"%s Unable to open MD5 context (System?)",OPEP); phase=999; //no need to go further } break; @@ -98,15 +98,15 @@ while (proceed==true) { switch (phase) { case 0 : //do ve have good parameters if ((key==(const void *)0)||(seq==(unsigned char *)0)) { - (void) fprintf(stderr,"%s key or seq undefined (Bug?)",OPEP); + (void) rou_alert(0,"%s key or seq undefined (Bug?)",OPEP); phase=999; } break; case 1 : //computing sequence d5=HMAC(EVP_md5(),key,strlen(key),seq,strlen((const char *)seq),d5,&reslen); if (d5==(unsigned char *)0) { - (void) fprintf(stderr,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)", - OPEP,(char *)key,seq); + (void) rou_alert(0,"%s No MD5 for key=<%s> and seq=<%s> (Bug?)", + OPEP,(char *)key,seq); phase=999; } break; diff --git a/lib/unidig.h b/lib/unidig.h index 31e73c6..c040a54 100644 --- a/lib/unidig.h +++ b/lib/unidig.h @@ -8,6 +8,9 @@ #ifndef UNIDIG #define UNIDIG +//MD5 hashing result +typedef unsigned char MD5TYP[17]; + //procedure to convert a string to a 128 Bit sequence //as a string extern MD5TYP *dig_hashmd5(unsigned char *seq); diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..42d8a44 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,59 @@ +#-------------------------------------------------------------------- +#Executable generation area +#-------------------------------------------------------------------- +debug : + @ $(MAKE) OPTIME="-g" DEBUG="-DDEBUG" exe + @ echo "application compiled in '$@' mode now ready" + +prod : + @ $(MAKE) OPTIME="-g -O2" exe + @ echo "application compiled in '$@' mode now ready" + +exe : + $(MAKE) $(EXE) + + +clean : + - rm -fr *.o $(EXE) + - rm -fr ../bin/* + +#-------------------------------------------------------------------- +#Equivalences +#-------------------------------------------------------------------- +EXE= \ + digmd5 \ + +SRC= \ + digmd5.c + +#-------------------------------------------------------------------- +#definitions +#-------------------------------------------------------------------- +CC = gcc +LD = gcc -g +CFLAGS = -I ../lib -Wall $(OPTIME) +LIBMAIL = ../lib/libmail.a + +LIBS = $(LIBMAIL) \ + -luuid \ + -lcrypto \ + -lcrypt \ + -lssl \ + +#-------------------------------------------------------------------- +#Dependances +#-------------------------------------------------------------------- +digmd5 : toremake digmd5.o + @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) + +digmd5.o: digmd5.c \ + ../lib/unidig.h \ + ../lib/unipar.h \ + ../lib/uniprc.h \ + ../lib/subrou.h + +toremake: Makefile + touch toremake + - rm -f $(EXE) *.o + +#-------------------------------------------------------------------- diff --git a/tools/digmd5.c b/tools/digmd5.c new file mode 100644 index 0000000..a6d6b75 --- /dev/null +++ b/tools/digmd5.c @@ -0,0 +1,81 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Validation program to check DIGEST-MD5 Exchange */ +/* */ +/* Usage: */ +/* digmd5 secret_pass base64_string */ +/* */ +/********************************************************/ +#include +#include +#include +#include +#include + +#include "subrou.h" +#include "unidig.h" +#include "unipar.h" +#include "uniprc.h" + +#define DIGMD5 "digmd5" //application name +/* + +*/ +/********************************************************/ +/* */ +/* */ +/********************************************************/ +/* + +*/ +/********************************************************/ +/* */ +/* Main routine */ +/* Read the challenge response in base 64 */ +/* and check if the challange response is */ +/* OK. */ +/* */ +/********************************************************/ +int main(int argc,char *argv[]) + +{ +int status; +int phase; +ARGTYP *params; +_Bool proceed; + +status=0; +params=(ARGTYP *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //checking parameters + if ((params=par_getparams(argc,argv,"d:hr:v"))==(ARGTYP *)0) + phase=999; //no need to go further + break; + case 1 : //check if we have file to scan + if (params->argc!=2) { + (void) fprintf(stderr,"Unable to proceed with test\n"); + (void) fprintf(stderr,"\tthe test pattern number should be 2\n"); + status=-1; + phase=999; + } + break; + case 2 : + (void) rou_modesubrou(true); + (void) rou_setappname(DIGMD5); + (void) prc_preptitle(argc,argv,environ); + foreground=true; + break; + case 3 : //doing main task + break; + default : //end of task + proceed=false; + break; + } + phase++; + } +(void) exit(status); +} diff --git a/tools/toremake b/tools/toremake new file mode 100644 index 0000000..e69de29 -- 2.47.3