*/
/********************************************************/
/* */
+/* 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. */
/* */
/* definition. */
/* */
/********************************************************/
-PUBLIC SOCPTR **soc_mkbindinf(SOCPTR **socptr,const LISTYP *bind)
+PUBLIC SOCPTR **soc_mkbindinf(SOCPTR **socptr,PROTYP proto,
+ const char *ip,const char *port,int iteration)
{
SOCTYP *soc;
soc=newsocket();
-soc->proto=bind->proto;
-soc->ip=strdup(bind->afn->strnumip);
-soc->port=strdup(bind->port);
-soc->iteration=bind->iteration;
+soc->proto=proto;
+soc->ip=strdup(ip);
+soc->port=strdup(port);
+soc->iteration=iteration;
socptr=(SOCPTR **)rou_addlist((void **)socptr,(void *)soc);
return socptr;
}
//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)
//procedure to assign memory to be used by a TCP socket
//definition
-extern SOCPTR **soc_mkbindinf(SOCPTR **socptr,const LISTYP *bind);
+extern SOCPTR **soc_mkbindinf(SOCPTR **socptr,PROTYP proto,
+ const char *ip,const char *port,int iteration);
//procedure to open one exchange socket
//to connect a remote smtp server
/* -> smtps protocol,port 465,2 iteration */
/* */
/********************************************************/
-static int prepbinding(SOCPTR ***bindings)
+static int prepbinding(SOCPTR ***bindings,int argc,char *argv[])
{
-#define OPEP "modrec.c:prepbinding"
-
-const LISTYP **bind;
+#define OPEP "moderec.c:prepbinding"
*bindings=(SOCPTR **)0;
-if ((bind=tls_get_bind_data())==(const LISTYP **)0) {
- (void) rou_alert(0,"%s SMTPPORTS data fully missing (config?, bug?)",OPEP);
- (void) exit(-1);
- }
-while (*bind!=(LISTYP *)0) {
- *bindings=soc_mkbindinf(*bindings,*bind);
- bind++;
+for (int i=0;i<argc;i++) {
+ int iteration;
+ PROTYP proto;
+ char *ipnum;
+ char *port;
+ char *ptr;
+ char config[80];
+
+ (void) strncpy(config,argv[i],sizeof(config));
+ ptr=config;
+ iteration=1;
+ proto=pro_smtp;
+ ipnum=DFLTIP;
+ port=SMTPORT;
+ (void) rou_alert(0,"JMPDBG argv[%d]=<%s>",i,argv[i]);
+ for (int j=0;j<3;j++) {
+ char *sofar;
+
+ if ((sofar=strchr(ptr,':'))==(char *)0)
+ break;
+ *sofar='\000';
+ sofar++;
+ switch (j) {
+ case 0 :
+ if ((proto=soc_getprotocol(ptr))==pro_unknwn) {
+ (void) rou_alert(0,"%s, protocol unknown within config <%s>",
+ OPEP,argv[i]);
+ proto=pro_smtp;
+ }
+ break;
+ case 1 :
+ ipnum=ptr;
+ break;
+ case 2 :
+ if (strlen(ptr)>0)
+ port=ptr;
+ if (strlen(sofar)>0)
+ iteration=atoi(sofar);
+ break;
+ default :
+ (void) rou_alert(0,"%s, Code fault, '%d' unexpected value",OPEP,j);
+ break;
+ }
+ ptr=sofar;
+ }
+ *bindings=soc_mkbindinf(*bindings,proto,ipnum,port,iteration);
}
return rou_nbrlist(*bindings);
+
#undef OPEP
}
/*
/* Waiting and handling smtp request */
/* */
/********************************************************/
-PUBLIC void rec_handlesmtp()
+PUBLIC void rec_handlesmtp(int argc,char *argv[])
{
#define OPEP "modrec.c:rec_handlesmtp"
//(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //preparing iteration
- if ((nbrbind=prepbinding(&bindings))==0) {
+ if ((nbrbind=prepbinding(&bindings,argc,argv))==0) {
(void) rou_alert(0,"%s, No listening IP found (config?)",OPEP);
phase=999;
}
#include <stdbool.h>
//procedure to receive email from outside
-extern void rec_handlesmtp();
+extern void rec_handlesmtp(int argc,char *argv[]);
#endif
//alternate define SSL_CIPHER_LIST "ALL:!LOW"
#define SSL_CIPHER_LIST "DEFAULT"
-static _Bool modopen; //module open/close status
-static const LISTYP **binds; //Binding information
-static AFNTYP **afns; //Binding information as AFN
-/*
-^L
-*/
-/********************************************************/
-/* */
-/* Procedure to free LISTYP memory */
-/* */
-/********************************************************/
-static LISTYP *freelisten(LISTYP *listen)
-
-{
-if (listen!=(LISTYP *)0) {
- listen->afn=afn_freeipnum(listen->afn);
- listen->port=rou_freestr(listen->port);
- (void) free(listen);
- listen=(LISTYP *)0;
- }
-return listen;
-}
+static _Bool modopen; //module open/close status
+static AFNTYP **afns; //Binding information as AFN
/*
^L
*/
/* and build the LISTYP structure. */
/* */
/********************************************************/
-static void buildbinds()
+static void buildafns()
{
-#define OPEP "unitls.c,buildbinds,"
+#define OPEP "unitls.c,buildafns,"
#define DIP "0.0.0.0" //listening on all PORT
#define DPORT "25" //Default SMTP port
data=strdup(data);
break;
case 1 : //scanning sequence
+ char *ips;
char *seq;
+ ips=strdup("");
seq=data;
while (seq!=(char *)0) {
- LISTYP *list;
- PROTYP proto;
- AFNTYP **locafns;
- char *port;
- int iteration;
char *ptr;
- proto=pro_smtp;
- locafns=(AFNTYP **)0;
- port=DPORT;
- iteration=2;
if ((ptr=strchr(seq,','))!=(char *)0) {
*ptr='\000';
ptr++;
}
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;
- }
+ //forget about protocol
break;
case 1 :
- if (strlen(seq)==0)
- seq=DIP;
- if ((locafns=afn_getipnum(seq))==(AFNTYP **)0)
- (void) rou_alert(0,"%s, Not valid IP <%s> (config?)",OPEP,seq);
+ int taille;
+ char *ip;
+ char *newips;
+
+ ip=seq;
+ if (strlen(ip)==0)
+ ip=DIP;
+ taille=strlen(ips)+strlen(ip)+2;
+ newips=(char *)calloc(taille,sizeof(char));
+ (void) strcpy(newips,ips);
+ ips=rou_freestr(ips);
+ ips=newips;
+ if (strlen(ip)>0)
+ (void) strcat(ips,",");
+ (void) strcat(ips,ip);
break;
case 2 :
- if (strlen(seq)>0)
- port=seq;
- if ((sofar!=(char *)0)&&(strlen(sofar)>0))
- iteration=atoi(sofar);
+ //forget about port and itreations
break;
}
seq=sofar;
}
- if (locafns!=(AFNTYP **)0) {
- for (int i=0;locafns[i]!=(AFNTYP *)0;i++) {
- list=(LISTYP *)calloc(1,sizeof(LISTYP));
- list->proto=proto;
- list->port=strdup(port);;
- list->iteration=iteration;
- list->afn=locafns[i];
- (void) rou_alert(0,"%s JMDPBG adding <%s>",OPEP,list->afn->strnumip);
- binds=(const LISTYP **)rou_addlist((void **)binds,(void *)list);
- afns=(AFNTYP **)rou_addlist((void **)afns,(void *)locafns[i]);
- }
- (void) free(locafns);
- }
seq=ptr;
}
+ afns=afn_getipnum(ips);
+ ips=rou_freestr(ips);
break;
default : //SAFE Guard
(void) free(data);
*/
/********************************************************/
/* */
-/* Procedure to return the list of binding data */
-/* */
-/********************************************************/
-PUBLIC const LISTYP **tls_get_bind_data()
-
-{
-return binds;
-}
-/*
-^L
-*/
-/********************************************************/
-/* */
/* Procedure to return the AFN list of binding data*/
/* */
/********************************************************/
case true :
(void) SSL_library_init();
(void) ERR_clear_error();
- (void) buildbinds();
+ (void) buildafns();
break;
case false :
- (void) free(afns);
- (void) rou_freelist((void **)binds,(genfree_t)freelisten);
+ afns=(AFNTYP **)rou_freelist((void **)afns,(genfree_t)afn_freeipnum);
break;
default :
(void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
extern SSL *tls_setsocket(int handle,SSL_CTX *ctx);
//getting binding information
-extern const LISTYP **tls_get_bind_data();
+//extern const LISTYP **tls_get_bind_data();
//getting binding information as AFN structure
extern AFNTYP **tls_get_bind_afn();