From: Jean-Marc Pigeon (Delson) Date: Mon, 5 May 2025 00:40:37 +0000 (-0400) Subject: Able to load config file X-Git-Tag: tag-0.8~154 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=4ba35d4d0cb8e7dca4ea60601ac5b270e48ef79e;p=jmp%2Fmailleur Able to load config file --- diff --git a/Makefile b/Makefile index 8f7c322..190069c 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ TESTITER= 3 #testing feed FEEDPAR = \ -d3 \ + -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ $(TESTDIR)/$(DATATST)/feed*.tst \ @@ -129,6 +130,7 @@ tlsref: EMLPAR = \ -r $(TESTDIR) \ + -c ./conf/$(APPNAME).conf.dvl \ -d 3 \ $(TESTPROT):$(TESTIP):$(TESTPORT): diff --git a/app/emlrcvr.c b/app/emlrcvr.c index 9954594..6b5de8f 100644 --- a/app/emlrcvr.c +++ b/app/emlrcvr.c @@ -47,13 +47,14 @@ proceed=true; while (proceed==true) { switch (phase) { case 0 : //checking parameters - if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) { + if ((params=par_getparams(argc,argv,"c:d:fh:r:v"))==(ARGTYP *)0) { phase=999; //no need to go further } break; case 1 : //initialising process (void) prc_preptitle(argc,argv,environ); (void) rou_setappname(RECNAME); + (void) rou_loadconfig(config,true); (void) rou_modesubrou(true); (void) prc_modeuniprc(true); (void) sig_modeunisig(true); @@ -76,6 +77,7 @@ while (proceed==true) { (void) sig_modeunisig(false); (void) prc_modeuniprc(false); (void) rou_modesubrou(false); + (void) rou_loadconfig(config,false); break; default : //end of task proceed=false; diff --git a/conf/feeder.conf.dvl b/conf/feeder.conf.dvl new file mode 100644 index 0000000..0630506 --- /dev/null +++ b/conf/feeder.conf.dvl @@ -0,0 +1 @@ +#file used to set environement configuration diff --git a/conf/mailleur.conf b/conf/mailleur.conf index 0630506..b26d459 100644 --- a/conf/mailleur.conf +++ b/conf/mailleur.conf @@ -1 +1,7 @@ #file used to set environement configuration +#------------------------------------------------ +#Defining Certificate for the application +CA_ROOT = "/etc/pki/mailleur/certs/root-safe_CA.pem" +CA_CERT = "/etc/pki/mailleur/mailleur-chain-cert_x509.pem" +CA_KEY = "/etc/pki/mailleur/mailleur-key.pem" +#------------------------------------------------ diff --git a/conf/mailleur.conf.dvl b/conf/mailleur.conf.dvl new file mode 100644 index 0000000..f03c293 --- /dev/null +++ b/conf/mailleur.conf.dvl @@ -0,0 +1,8 @@ +#file used to set environment configuration +#Used for developpement purpose ONLY +#------------------------------------------------ +#Defining Certificate +CA_ROOT = "./certs/root-safe_CA.pem" +CA_CERT = "./certs/mailleur_server-chain-cert_x509.pem" +CA_KEY = "./certs/mailleur_server-key.pem" +#------------------------------------------------ diff --git a/lib/subrou.c b/lib/subrou.c index 22aaabb..389188f 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -588,6 +588,93 @@ if (doabort==true) #undef COREDELAY } /* + +*/ +/********************************************************/ +/* */ +/* Procedure to load the configuartion file */ +/* message and terminate application */ +/* */ +/********************************************************/ +PUBLIC void rou_loadconfig(char *conffile,_Bool load) + +{ +FILE *fichier; +char line[200]; +char *name; +char *value; +char *ptr; +int phase; +_Bool proceed; + +fichier=(FILE *)0; +(void) memset(line,'\000',sizeof(line)); +name=(char *)0; +value=(char *)0; +ptr=(char *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Opening the config file + if ((fichier=fopen(conffile,"r"))==(FILE *)0) { + (void) fprintf(stdout,"exiting!, Unable to open file <%s> (error=<%s>)\n", + conffile,strerror(errno)); + (void) exit(-1);//Big Trouble + } + break; + case 1 : //scanning file + (void) memset(line,'\000',sizeof(line)); + if ((ptr=fgets(line,sizeof(line)-1,fichier))==(char *)0) + phase=999; //scan terminated + break; + case 2 : //trimming line + if ((ptr=strchr(line,'#'))!=(char *)0) + *ptr='\000'; + if ((ptr=strrchr(line,'\n'))!=(char *)0) + *ptr='\000'; + if (strlen(line)==0) + phase=0; //next line + break; + case 3 : //Spliting data + if ((ptr=strchr(line,'='))==(char *)0) + phase=0; //line without '=' + break; + case 4 : //set name and value + name=line; + value=ptr+1; + *ptr='\000'; + while ((ptr=strrchr(name,' '))!=(char *)0) + *ptr='\000'; + while ((ptr=strrchr(name,'\t'))!=(char *)0) + *ptr='\000'; + while ((value[0]==' ')||(value[0]=='\t')) + value++; + //removing quote if present + if (value[0]=='"') + value++; + if ((ptr=strrchr(value,'"'))!=(char *)0) + *ptr='\000'; + //make sure we have data to set + if ((strlen(name)==0)||(strlen(value)==0)) + phase=0; //No name or value?? + break; + case 5 : //set name and value + if (load==true) + (void) setenv(name,value,true); + else + (void) unsetenv(name); + phase=0; + break; + default : //SAFE Guard + (void) fclose(fichier); + proceed=false; + break; + } + phase++; + } +} +/* ^L */ /********************************************************/ diff --git a/lib/subrou.h b/lib/subrou.h index 5c0b5fa..a647e8f 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -94,6 +94,9 @@ extern void rou_crash(const char *fmt,...); //with an explication message extern void rou_core_dump(const char *fmt,...); +//load/unload environement configuration +extern void rou_loadconfig(char *conffile,_Bool load); + //homework to be done before starting/stoping module. extern int rou_modesubrou(_Bool mode); diff --git a/lib/unipar.c b/lib/unipar.c index 7c9b609..f57bb53 100644 --- a/lib/unipar.c +++ b/lib/unipar.c @@ -14,6 +14,9 @@ #include "subrou.h" #include "unipar.h" +//application default config file +PUBLIC char config[200]="/etc/"APPNAME"/"APPNAME".conf"; + /* ^L */ @@ -45,6 +48,7 @@ static void usage_aid(char *name) (void) fprintf(stderr,"usage:\n "); (void) fprintf(stderr,"%s\t" "[-d debug] " + "[-c config] " "[-f] " "[-h] " "[-r root] " @@ -52,6 +56,7 @@ static void usage_aid(char *name) "\n",name); (void) fprintf(stderr,"\twhere:\n"); (void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n"); +(void) fprintf(stderr,"\t\t-c config\t: set config file\n"); (void) fprintf(stderr,"\t\t-f\t\t: start program in foreground (CLI) mode\n"); (void) fprintf(stderr,"\t\t-h\t\t: print this help message\n"); (void) fprintf(stderr,"\t\t-r root\t\t: root working directory\n"); @@ -111,6 +116,9 @@ else opterr=0; //no error message from getopt library routine while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) { switch(c) { + case 'c' : //config file + (void) memset(config,'\000',sizeof(config)); + (void) strncpy(config,optarg,sizeof(config)-1); case 'd' : //debug level debug=atoi(optarg); (void) rou_alert(1,"debug level is now '%d'",debug); diff --git a/lib/unipar.h b/lib/unipar.h index a66672b..124e51e 100644 --- a/lib/unipar.h +++ b/lib/unipar.h @@ -17,6 +17,8 @@ typedef struct { char **argv; //list of argument }ARGTYP; +extern char config[]; //Application config file + //free allocated memory used by a ARGTYP structure extern ARGTYP *par_freeparams(ARGTYP *params);