From 8df3f862d1ec46c7970426c8e2a0375476566df0 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sat, 12 Jul 2025 11:13:18 -0400 Subject: [PATCH] Start to work on scanner --- app/scanner.c | 229 +++++++++++++++++++++++++++++++++++++++++++++++ sql/mailleur.sql | 2 +- 2 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 app/scanner.c diff --git a/app/scanner.c b/app/scanner.c new file mode 100644 index 0000000..8f5d3a9 --- /dev/null +++ b/app/scanner.c @@ -0,0 +1,229 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* SMTP protocol domain destination sorter */ +/* Used to take the trans directive and generate */ +/* a todo list a email to be send. */ +/* */ +/* */ +/********************************************************/ +#include +#include +#include +#include + +#include "subrou.h" +#include "unidns.h" +#include "unieml.h" +#include "unipar.h" +#include "uniprc.h" +#include "unisig.h" +#include "geseml.h" + +/* + +*/ +/********************************************************/ +/* */ +/* procedure to scan all files */ +/* */ +/********************************************************/ +static _Bool scantrans(const char *ext,_Bool todo) + +{ +#define OPEP "sorter.c:scantrans," + +_Bool action; +char **fname; +TRATYP **trans; +int phase; +_Bool proceed; + +action=false; +fname=(char **)0; +trans=(TRATYP **)0; +phase=0; +proceed=true; +while (proceed==true) { + //(void) fprintf(stdout,"%s JMPDBG phase='%d' ext=<%s>\n",OPEP,phase,ext); + switch (phase) { + case 0 : //Getting the list of file + fname=eml_getqfilelist(fname,ext); + if (fname==(char **)0) + phase=999; //Nothing to do + break; + case 1 : //Building the "trans" list + action=true; + if (fname!=(char **)0) { //always + char **ptr; + + ptr=fname; + while (*ptr!=(char *)0) { + FILE *qfile; + + (void) rou_alert(5,"%s fame=<%s>",OPEP,*ptr); + if ((qfile=eml_openqfile(*ptr,(const char *)0))!=(FILE *)0) { + trans=eml_scanqfile(trans,qfile); + (void) eml_closeqfile(qfile); + (void) eml_deleteqfile(*ptr); + } + ptr++; + } + trans=eml_freeall_tra(trans); + fname=(char **)rou_freelist((void *)fname,(genfree_t)rou_freestr); + } + break; + case 2 : //scanning translit + switch (todo) { + case true : //Doing todo file + (void) eml_todoqfile(trans); + break; + case false : + (void) eml_doneqfile(trans); + break; + } + trans=eml_freeall_tra(trans); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +#undef OPEP +return action; +} +/* + +*/ +/********************************************************/ +/* */ +/* sorter central task */ +/* */ +/********************************************************/ +static void sorting() + +{ +#define OPEP "sorter.c:sorting," +#define TSLEEP 10 + +_Bool action; +int delay; +int phase; +_Bool proceed; + +action=false; +delay=1; +phase=0; +proceed=true; +while (proceed==true) { + //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase); + switch (phase) { + case 0 : //Locking access + if (prc_locking(appname,true,5)==false) { + (void) rou_alert(0,"%s Unable to lock %s exclusif acccess (system?)", + OPEP,appname); + proceed=false; + } + break; + case 1 : //got signal + action=false; + if ((hangup==true)||((reload==true))) { + (void) rou_alert(0,"%s got hangup or reload signal",OPEP); + phase=999; + } + break; + case 2 : //got signal + action|=scantrans(EXTRANS,true); + break; + case 3 : //got signal + action|=scantrans(EXDONE,false); + break; + case 4 : //one passe only? + if (foreground==true) + phase=999; //Immediate ending + break; + case 5 : //lets time pass according "busy" + delay=TSLEEP; + if (action==true) + delay=1; + (void) sleep(delay); + phase=0; //Looping + break; + default : //SAFE Guard + (void) prc_locking(appname,false,1); + proceed=false; + break; + } + phase++; + } + +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Main routine */ +/* Start a channel to a remote ip.port */ +/* read file and transmit contecnts to */ +/* remote SMTP server. */ +/* */ +/********************************************************/ +int main(int argc,char *argv[]) + +{ +#define OPEP "sorter.c:main," + +int status; +ARGTYP *params; +int phase; +_Bool proceed; + +status=0; +params=(ARGTYP *)0; +phase=0; +proceed=true; +while (proceed==true) { + //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase); + switch (phase) { + case 0 : //checking parameters + if ((params=par_getparams(argc,argv,"c:d:fhi:r:v"))==(ARGTYP *)0) { + proceed=false; //no need to go further + } + break; + case 1 : //Preparing scan + (void) rou_setappname(SORTER); + (void) rou_modesubrou(true); + (void) prc_chgid(argv[0]); + (void) sig_modeunisig(true); + (void) sig_trapsignal(true,sig_alrm); + (void) rou_loadconfig(config,true); + break; + case 2 : //checking if we need to go background + if (foreground==false) { + if (prc_divedivedive()!=0) + phase=999; //direct exit + } + break; + case 3 : //checking if we need to go background + (void) sorting(); + break; + default : //end of task + params=par_freeparams(params); + (void) rou_loadconfig(config,false); + (void) sig_trapsignal(false,sig_alrm); + (void) sig_modeunisig(false); + (void) rou_modesubrou(false); + (void) closelog(); + proceed=false; + break; + } + phase++; + } +(void) exit(status); + +#undef TSLEEP +#undef OPEP +} diff --git a/sql/mailleur.sql b/sql/mailleur.sql index 42cdce1..7e968fc 100644 --- a/sql/mailleur.sql +++ b/sql/mailleur.sql @@ -103,7 +103,7 @@ GRANT SELECT ON sessions TO mailapache; CREATE TABLE remotes ( remoteip TEXTUNIQUE, //remote IP number lastscan DBTIMESTAMP //record last update - DFLT NULL, + DFLT '1970-01-01', lastupdate DBTIMESTAMP //record creation DFLT NOW(), credit INTEGER //Remote IP current credit (-100..+100) -- 2.47.3