emlrec.o: emlrec.c \
../lib/modrec.h \
+ ../lib/unitls.h \
../lib/unisig.h \
../lib/uniprc.h \
../lib/unipar.h \
#include "unipar.h"
#include "uniprc.h"
#include "unisig.h"
+#include "unitls.h"
#include "modrec.h"
#define RECNAME "emlrcvr"
(void) rou_modesubrou(true);
(void) prc_modeuniprc(true);
(void) sig_modeunisig(true);
+ (void) tls_modeunitls(true);
(void) sig_trapsignal(true,sig_alrm);
break;
case 2 : //sett lock
(void) prc_cleantitle();
params=par_freeparams(params);
(void) sig_trapsignal(false,sig_alrm);
+ (void) tls_modeunitls(false);
(void) sig_modeunisig(false);
(void) prc_modeuniprc(false);
(void) rou_modesubrou(false);
(void) sig_modeunisig(true);
(void) sig_trapsignal(true,sig_alrm);
(void) rou_setappname(SORTER);
- (void) dns_set_local_smtp();
(void) rou_loadconfig(config,true);
(void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
if (foreground==false) {
break;
default : //end of task
params=par_freeparams(params);
- (void) dns_drop_local_smtp();
(void) rou_loadconfig(config,false);
(void) sig_trapsignal(false,sig_alrm);
(void) sig_modeunisig(false);
#file used to set environment configuration
#Used for developpement purpose ONLY
#------------------------------------------------
+#list of listening port to do SMTP protocole
+#format
+#protocol:ipnum:port:iteration[,protocol:ipnum:port:iteration]++
+#example
+#:ipnum::: -> smtp:ipnum:25:1
+#stmtps:ipnum:465:2 -> smtps protocol,port 465,2 iteration
+#SMTPPORTS = "::,:127.127.10.25:1025:,smtps:127.127.10.25:1026:1"
+#------------------------------------------------
#Defining SERVER mode Certificate data
CA_ROOT_SRV = "./certs/root-safe_CA.pem"
CA_CERT_SRV = "./certs/mailleur_server-chain-cert_x509.pem"
devsoc.o: \
subafn.h subrou.h \
- unieml.h uniprc.h unitls.h \
+ unieml.h uniprc.h \
devsoc.h devsoc.c
devsql.o: \
gesspf.h: \
subafn.h
+devsoc.h: \
+ unitls.h
uniprc.h: \
subrou.h
*/
/********************************************************/
/* */
-/* Procedure to parse an email protocol */
-/* */
-/********************************************************/
-PUBLIC PROTYP soc_getprotocol(const char *strproto)
-
-{
-static struct {
- PROTYP proto;
- const char *voca;
- }prolist[]={
- {pro_smtp,""},
- {pro_smtp,"smtp"},
- {pro_smtps,"smtps"},
- {pro_unknwn,(char *)0}
- };
-PROTYP proto;
-
-
-proto=pro_unknwn;
-for (int i=0;prolist[i].voca!=(char *)0;i++) {
- if (strcasecmp(strproto,prolist[i].voca)==0) {
- proto=prolist[i].proto;
- break;
- }
- }
-return proto;
-}
-/*
-\f
-*/
-/********************************************************/
-/* */
/* Procedure to free memory used by a bind */
/* definition. */
/* */
#include <stdbool.h>
#include <time.h>
+#include "unitls.h"
+
//convenient adress structure
typedef struct sockaddr SOCKADDR;
-//defining email protocol value.
-typedef enum {
- pro_smtp, //text SMTP protocol, in clear mode
- pro_starttls, //Text SMTP protocol, encrypted upon request
- pro_smtps, //Text SMTP protocol, text encrypted from start
- pro_unknwn //Protcole undefined
- }PROTYP;
-
-//default and debugging certificate for server mode
-extern const char *srvr_certs[3];
-
//reference to a socket definition
typedef void SOCPTR;
//reference to a output channel definition
typedef void OUTPTR;
-//procedure to parse an email protocol
-extern PROTYP soc_getprotocol(const char *strproto);
-
//procedure to free all memory used by a TCP socket
//definition (once closed)
extern SOCPTR **soc_freebindinf(SOCPTR **socptr);
sofar++;
switch (j) {
case 0 :
- if ((proto=soc_getprotocol(ptr))==pro_unknwn) {
+ if ((proto=tls_getprotocol(ptr))==pro_unknwn) {
(void) rou_alert(0,"%s, protocol unknown within config <%s>",
OPEP,argv[i]);
proto=pro_smtp;
return match;
#undef OPEP
}
-/*
-\f
-*/
-/********************************************************/
-/* */
-/* Procedure to collect IP binded to listen SMTP */
-/* port. */
-/* */
-/********************************************************/
-PUBLIC void dns_set_local_smtp()
-
-{
-#define OPEP "unidns.c:dns_set_local_smtp,"
-#define MXIP 20
-#define TCP "/proc/net/tcp"
-
-int numip;
-FILE *fichier;
-int phase;
-_Bool proceed;
-
-numip=0;
-fichier=(FILE *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
- switch (phase) {
- case 0 : //Opening the netstat directory
- if ((fichier=fopen(TCP,"r"))==(FILE *)0) {
- (void) rou_alert(0,"%s Unable to open <%s> (error=<%s>)",
- OPEP,strerror(errno));
- (void) rou_alert(0,"%s (not an linux system? exiting!)",OPEP);
- (void) exit(-1);//BIG BIG trouble
- }
- break;
- case 1 : //scanning netstat file
- int numline;
- char line[200];
-
- numline=0;
- local_ipv4=calloc(MXIP,sizeof(in_addr_t));
- while (fgets(line,sizeof(line),fichier)!=(char *)0) {
- int seq;
- int addr;
- int port;
-
- numline++;
- if (numline==1)
- continue; //discarding first line
- if (sscanf(line,"%d: %8x:%4x",&seq,&addr,&port)==3) {
- (void) rou_alert(0,"JMPDBG seq=%d addr=%x port=%d\n",seq,addr,port);
- numip++;
- }
- }
- break;
- case 2 : //closing file
- (void) fclose(fichier);
- break;
- default : //SAFE Guard
- proceed=false;
- break;
- }
- phase++;
- }
-
-#undef TCP
-#undef MXIP
-#undef OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/* */
-/* Procedure to free memory used by SMTP local IP */
-/* */
-/********************************************************/
-PUBLIC void dns_drop_local_smtp()
-
-{
-if (local_ipv4!=(in_addr_t *)0) {
- (void) free(local_ipv4);
- num_ipv4=0;
- local_ipv4=(in_addr_t *)0;
- }
-}
//of domain A record list
extern _Bool dns_matchiprec(char *hostname,AFNTYP *afnnum,int mask);
-//procedure to create the list of local IP used to listen
-//the smtp protocol
-extern void dns_set_local_smtp();
-
-//procedure to free the list of local IP used to listen
-//the smtp protocol
-extern void dns_drop_local_smtp();
-
//procedure to detect if a domain is served by a local
//smtp server
extern _Bool dns_is_domain_local(const char *domain);
#define SSL_CIPHER_LIST "DEFAULT"
static _Bool modopen; //module open/close status
+static LISTYP **binds; //Binding information
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to free LISTYP memory */
+/* */
+/********************************************************/
+static LISTYP *freelisten(LISTYP *listen)
+{
+if (listen!=(LISTYP *)0) {
+ listen->ipnum=rou_freestr(listen->ipnum);
+ (void) free(listen);
+ listen=(LISTYP *)0;
+ }
+return listen;
+}
/*
^L
*/
#undef OPEP
}
/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to parse an email protocol */
+/* */
+/********************************************************/
+PUBLIC PROTYP tls_getprotocol(const char *strproto)
+
+{
+static struct {
+ PROTYP proto;
+ const char *voca;
+ }prolist[]={
+ {pro_smtp,""},
+ {pro_smtp,"smtp"},
+ {pro_smtps,"smtps"},
+ {pro_unknwn,(char *)0}
+ };
+PROTYP proto;
+
+
+proto=pro_unknwn;
+for (int i=0;prolist[i].voca!=(char *)0;i++) {
+ if (strcasecmp(strproto,prolist[i].voca)==0) {
+ proto=prolist[i].proto;
+ break;
+ }
+ }
+return proto;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to parse an the SMTPPORTS env variable*/
+/* and build the LISTYP structure. */
+/* */
+/********************************************************/
+static void buildbinds()
+
+{
+#define OPEP "unitls.c,buildbinds,"
+#define DIP "0.0.0.0" //listening on all PORT
+#define DPORT "25" //Default SMTP port
+
+char *data;
+int phase;
+_Bool proceed;
+
+data=(char *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //Getting the SMTPPORTS variable
+ if ((data=getenv("SMTPPORTS"))==(char *)0)
+ data="smtp:0.0.0.0:25:2"; //default configuration
+ data=strdup(data);
+ break;
+ case 1 : //scanning sequence
+ char *seq;
+
+ seq=data;
+ while (seq!=(char *)0) {
+ PROTYP proto;
+ char *ipnum;
+ char *port;
+ int iter;
+ char *ptr;
+
+ ipnum=DIP;
+ port=DPORT;
+ iter=10;
+ if ((ptr=strchr(seq,','))!=(char *)0) {
+ *ptr='\000';
+ ptr++;
+ }
+ (void) rou_alert(0,"%s JMPDBG seq=<%s>",OPEP,seq);
+ for (int j=0;j<3;j++) {
+ char *sofar;
+
+ if ((sofar=strchr(seq,':'))==(char *)0)
+ break;
+ *sofar='\000';
+ sofar++;
+ switch (j) {
+ case 0 : //extracting protocol
+ if ((proto=tls_getprotocol(seq))==pro_unknwn) {
+ (void) rou_alert(0,"%s, protocol unknown within config <%s>",
+ OPEP,seq);
+ proto=pro_smtp;
+ }
+ break;
+ case 1 :
+ if (strlen(seq)>0)
+ ipnum=seq;
+ break;
+ case 2 :
+ if (strlen(seq)>0)
+ port=seq;
+ if (strlen(sofar)>0)
+ iter=atoi(sofar);
+ break;
+ }
+ seq=sofar;
+ }
+ (void) rou_alert(0,"%s JMP ipnum=<%s> port=<%s> iter='%d'",
+ OPEP,ipnum,port,iter);
+ seq=ptr;
+ }
+ break;
+ default : //SAFE Guard
+ (void) free(data);
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+
+#undef DPORT
+#undef DIP
+#undef OPEP
+}
+/*
^L
*/
/********************************************************/
case true :
(void) SSL_library_init();
(void) ERR_clear_error();
+ (void) buildbinds();
break;
case false :
+ (void) rou_freelist((void **)binds,(genfree_t)freelisten);
break;
default :
(void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
#include <stdbool.h>
#include <openssl/ssl.h>
+//defining email protocol value.
+typedef enum {
+ pro_smtp, //text SMTP protocol, in clear mode
+ pro_starttls, //Text SMTP protocol, encrypted upon request
+ pro_smtps, //Text SMTP protocol, text encrypted from start
+ pro_unknwn //Protcole undefined
+ }PROTYP;
+
+typedef struct { //structure about listening port
+ PROTYP proto; //Protocol to be used
+ char *ipnum; //binding IP number
+ int iter; //Number of binding iteration
+ }LISTYP;
+
typedef struct {
_Bool server; //SSL server/client mode
_Bool checkpeer;//Check peer certificate
//set socket as an tls socket
extern SSL *tls_setsocket(int handle,SSL_CTX *ctx);
+//getting binding information
+extern LISTYP **tls_get_bind_data();
+
//homework to be done before starting/stopping module.
extern int tls_modeunitls(_Bool mode);