]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to warite digmd5 tools application
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 5 Jul 2025 19:57:49 +0000 (15:57 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 5 Jul 2025 19:57:49 +0000 (15:57 -0400)
Makefile
app/chkspf.c
app/res/maild.c [deleted file]
lib/subcnv.h
lib/unidig.c
lib/unidig.h
tools/Makefile [new file with mode: 0644]
tools/digmd5.c [new file with mode: 0644]
tools/toremake [new file with mode: 0644]

index 5bd0a0073524d7c53d101709cf4e0371c2d3b6ce..1d59772a9cbe9bba0675db64bdbf5e19a91f8108 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -239,6 +239,7 @@ install     :
 SUBDIR =                                               \
           lib                                          \
           app                                          \
+          tools                                        \
           sql                                          \
 
 #--------------------------------------------------------------------
index 29918cf261bdd2a83763c4e292bd769b0f2b4624..c8b3224496e437296e4676e09e17bbf0c4ea4ede 100644 (file)
@@ -18,7 +18,7 @@
 #include       "uniprc.h"
 #include       "gesspf.h"
 
-#define CHKSPF "chkspf"        //SPF field validator
+#define CHKSPF "chkspf"        //application name
 
 /*
 \f
diff --git a/app/res/maild.c b/app/res/maild.c
deleted file mode 100644 (file)
index 3390888..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-// vim: smarttab tabstop=8 shiftwidth=2 expandtab
-/********************************************************/
-/*                                                     */
-/*     Main SMTP Daemon                                */
-/*                                                     */
-/********************************************************/
-#include       <errno.h>
-#include       <signal.h>
-#include       <stdlib.h>
-#include       <stdio.h>
-#include       <string.h>
-#include       <unistd.h>
-
-#include       "subrou.h"
-#include       "unipar.h"
-#include       "uniprc.h"
-#include       "unisig.h"
-
-/*
-\f
-*/
-/********************************************************/
-/*                                                     */
-/*      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<iteration;i++) {
-        if (pidlst[i]!=(pid_t)0) {
-          if (prc_checkprocess(pidlst[i])==true) 
-            continue;
-          }
-        switch (pidlst[i]=fork()) {
-          case -1       :       //trouble trouble?
-            pidlst[i]=(pid_t)0;
-            break;
-          case  0       :
-            (void) rou_alert(0,"Should execv \"%s\"",emlrec);
-            if (execv(emlrec,argv)<0) {
-              (void) rou_alert(0,"%s, Unable to exec command <%s> "
-                                 "(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;i<iteration;i++) {
-          if (pidlst[i]==(pid_t)0)
-            continue;
-          if (prc_checkprocess(pidlst[i])==true) {
-            (void) kill(pidlst[i],SIGQUIT);
-            stillrun++;
-            }
-          else
-            pidlst[i]=(pid_t)0;
-          }
-        if (stillrun>0) {
-          (void) prc_nozombie();
-          (void) sleep(2);
-          phase--;       //let send signal again
-          }
-        }
-      break;
-    default     :       //SAFE Guard
-      proceed=false;
-      break;
-    }
-  phase++;
-  }
-(void) free(pidlst);
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                     */
-/*     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);
-}
index d3d728e8a33c0960d72319c7ac2868f75c88dda1..1fa90c209dac8aee7d0359542a126e20c1ab20a8 100644 (file)
@@ -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);
index ffb1866cba8f121b262cb26e7fd7e9fa177ed436..cd14e109e691f3034ac99ef0328f6e50da87f4ff 100644 (file)
@@ -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;
index 31e73c6638bd22adc38358254b862dfcc7012272..c040a54d03d3a4df0eaf000d1b9874c8d749dafd 100644 (file)
@@ -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 (file)
index 0000000..42d8a44
--- /dev/null
@@ -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 (file)
index 0000000..a6d6b75
--- /dev/null
@@ -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       <errno.h>
+#include       <stdio.h>
+#include       <stdlib.h>
+#include       <string.h>
+#include       <unistd.h>
+
+#include       "subrou.h"
+#include       "unidig.h"
+#include       "unipar.h"
+#include       "uniprc.h"
+
+#define         DIGMD5  "digmd5"        //application name
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*                                                     */
+/********************************************************/
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     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 (file)
index 0000000..e69de29