From: Jean-Marc Pigeon (Delson) Date: Mon, 30 Jun 2025 22:19:02 +0000 (-0400) Subject: Starting to implement subcnv module (string convertion) X-Git-Tag: tag-0.12~63 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=0d42f9a8ab4457df76cb120cab0b08648989a138;p=jmp%2Fmailleur Starting to implement subcnv module (string convertion) --- diff --git a/data-feed/feedxx.tst b/data-feed/feedxx.tst index f86395c..c3aeb9a 100644 --- a/data-feed/feedxx.tst +++ b/data-feed/feedxx.tst @@ -5,10 +5,10 @@ R:220 mailleur.example.com, ESMTP (cleartext) mailleur... #https://www.base64encode.org/ #-Usernanme 'webmaster@example.com' --> 'd2VibWFzdGVyQGV4YW1wbGUuY29t' #-password 'mailleur' --> 'bWFpbGxldXI=" -C-AUTH LOGIN d2VibWFzdGVyQGV4YW1wbGUuY29t -S-334 UGFzc3dvcmQ6 +S:AUTH LOGIN d2VibWFzdGVyQGV4YW1wbGUuY29t +R:334 UGFzc3dvcmQ6 #-le mot de passe est 'badpass' -C-bWFpbGxldXI= -S-535 1 authentication failed +S:bWFpbGxldXI= +R:535 1 authentication failed S:QUIT R:221 2.0.0 Bye, closing connection... diff --git a/lib/Makefile b/lib/Makefile index 69afed4..5ed5c29 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,7 +25,7 @@ OBJS= \ devlog.o devsoc.o devsql.o \ unidns.o unieml.o unipar.o \ uniprc.o unisig.o unisql.o unitls.o \ - subafn.o subrou.o + subafn.o subcnv.o subrou.o LIBS= \ libmar.a libpos.a @@ -44,7 +44,7 @@ modrec.o: \ modrec.h modrec.c lvleml.o: \ - subrou.h \ + subcnv.h subrou.h \ unieml.h unidns.h \ lvleml.h lvleml.c @@ -118,6 +118,9 @@ subrou.o: \ subafn.o: \ subafn.h subafn.c +subcnv.o: \ + subcnv.h subcnv.c + lvleml.h: \ devsoc.h devsql.h \ geseml.h gestcp.h @@ -148,6 +151,7 @@ libpos.a: unimar.o \ subrou.h \ unipos.h unipos.c @ $(CC) \ + $(CPPFLAGS) \ -DDATABASE=1 \ -Dwith_postgres \ -c \ @@ -159,6 +163,7 @@ libmar.a: unipos.o \ subrou.h \ unimar.h unimar.c @ $(CC) \ + $(CPPFLAGS) \ -DDATABASE=2 \ -Dwith_mysql \ -c \ @@ -177,7 +182,8 @@ toremake: Makefile #-------------------------------------------------------------------- CC = gcc LD = gcc -CFLAGS = -Wall -D_GNU_SOURCE \ +CPPFLAGS= -DPUBLIC='' +CFLAGS = -Wall -D_GNU_SOURCE \ $(OPTIME) LIBMAIL = libmail.a libmar.a libpos.a PAR = -j`/usr/bin/getconf _NPROCESSORS_ONLN` diff --git a/lib/gestcp.h b/lib/gestcp.h index 734a60c..43e5d99 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -25,7 +25,7 @@ typedef struct { }RMTTYP; //procedure to add a line to a buffer -PUBLIC char *tcp_addline(char *buffer,char *line); +extern char *tcp_addline(char *buffer,char *line); //read a line from contact up to CRLF extern int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr); diff --git a/lib/lvleml.c b/lib/lvleml.c index 39c5c8b..5aaf30e 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -19,6 +19,7 @@ #include #include "subrou.h" +#include "subcnv.h" #include "unieml.h" #include "devlog.h" #include "gestcp.h" @@ -37,7 +38,7 @@ static void freesessid(CONTYP *contact) { -if (contact->session!=(SESTYP *)0) { +if ((contact->session!=(SESTYP *)0)&&(contact->mailfrom!=(char *)0)) { contact->session->sfrom=strdup(contact->mailfrom); (void) sql_mngses(contact->sqlptr,sql_update,&(contact->session)); contact->session=sql_freeses(contact->session); @@ -301,6 +302,76 @@ return status; */ /********************************************************/ /* */ +/* Procedure to extract authentication info. */ +/* return a login sequence as */ +/* 'username password' if successful */ +/* NULL if unable to extract login */ +/* */ +/********************************************************/ +static void getauth(CONTYP *contact,char *buffer) + +{ +#define OPEP "lvleml.c:getauth," + +static char *vocloc[]={"plain ","login ",(char *)0}; +static char *logdat[]={"VXNlcm5hbWU6", //Username: in B64 + "UGFzc3dvcmQ6", //Password: in B64 + (char *)0}; +int code; +int phase; +_Bool proceed; + +code=-1; +phase=0; +(void) rou_alert(0,"%s JMPDBG got <%s>",OPEP,buffer); +proceed=(strlen(buffer)>0); +while (proceed==true) { + switch (phase) { + case 0 : //check the authentication type + for (code=0;vocloc[code]!=(char *)0;code++) { + if (strncasecmp(buffer,vocloc[code],strlen(vocloc[code]))==0) { + register int taille; + register char *ptr; + + taille=strlen(vocloc[code]); + ptr=buffer+taille; + (void) memcpy(buffer,ptr,taille); + break; + } + } + if (vocloc[code]==(char *)0) { + (void) rou_alert(0,"%s auth type <%s> unknown (Bug?)",OPEP,buffer); + (void) transmit(contact,true,"%d 5.7.0 bad authentication type",BADPAR); + phase=999; //Trouble Trouble + } + break; + case 1 : //working accoring auth mode + switch (code) { + case 0 : //plain auth + (void) rou_alert(0,"%s clean buffer=<%x>",OPEP,cnv_getb64(buffer)); + + break; + case 1 : //login auth + break; + default : //not yet implemented + (void) rou_alert(0,"%s auth type <%d> not yet implemented",OPEP); + break; + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } + +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ /* checking if local recipient is acceptable. */ /* */ /********************************************************/ @@ -1606,6 +1677,9 @@ while (proceed==true) { case c_mail : //MAIL FROM: checking originator (void) checkfrom(contact,line); break; + case c_auth : //Auth request + (void) getauth(contact,line); + break; case c_rcpt : //Doing rpt scanning if (checkto(contact,line)==false) { (void) sleep(penalty); //relaxing bad guys diff --git a/lib/subafn.c b/lib/subafn.c index 90bd415..0e986a3 100644 --- a/lib/subafn.c +++ b/lib/subafn.c @@ -15,8 +15,6 @@ #include "subafn.h" -#define PUBLIC //to specify public variable - /* */ diff --git a/lib/subcnv.c b/lib/subcnv.c new file mode 100644 index 0000000..164a721 --- /dev/null +++ b/lib/subcnv.c @@ -0,0 +1,117 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Define all routine to manage language string */ +/* conversion. */ +/* */ +/********************************************************/ +#include +#include +#include +#include +#include + +#include "subcnv.h" + +/* + +*/ +/********************************************************/ +/* */ +/* Routine to check if all char within a B64 */ +/* string are indeed Base-64 character. */ +/* */ +/********************************************************/ +static int checkb64(char *b64) + +{ +int ok; + +ok=true; +while ((*b64!='\000')&&(ok==true)) { + switch (*b64) { + case '+' : + case '/' : + case '=' : + break; + default : + if (isalnum(*b64)==0) { + ok=false; + *b64='\000'; + } + break; + } + b64++; + } +return ok; +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to convert an ASCII B64 sequence to a */ +/* plain ASCII sequence. */ +/* */ +/********************************************************/ +PUBLIC char *cnv_getb64(char *b64) + +{ +#define OPEP "subcnv.c:cnv_getb64," + +char *decoded; +BIO *mbio; +BIO *bbio; +int retour; + +(void) checkb64(b64); +decoded=(char *)calloc(strlen(b64)+3,sizeof(char)); +mbio=BIO_new(BIO_s_mem()); +bbio=BIO_new(BIO_f_base64()); +BIO_set_flags(bbio,BIO_FLAGS_BASE64_NO_NL); +bbio=BIO_push(bbio,mbio); +(void) BIO_write(mbio,b64,strlen(b64)); +(void) BIO_flush(mbio); +switch(retour=BIO_read(bbio,decoded,strlen(b64))) { + case -2 : + (void) fprintf(stderr,"%s Can't proceed! decoding <%s> (bug?)",OPEP,b64); + break; + case -1 : + case 0 : + (void) fprintf(stderr,"%s Need a retry! decoding <%s> (bug?)",OPEP,b64); + break; + default : + if (retour>0) { /*always */ + register int scan; + register int skip; + + scan=retour; + skip=strlen(IOBNULL); + while (scan>0) { + scan--; + if (decoded[scan]=='\000') { + register int taille; + char *new_decoded; + + taille=retour+skip+1; + if ((new_decoded=(char *)realloc(decoded,taille*sizeof(char)))!=(char *)0) { + decoded=new_decoded; + (void) memmove(decoded+scan+skip,decoded+scan+1,(retour-scan)+1); + (void) memmove(decoded+scan,IOBNULL,skip); + } + retour+=skip; + } + } + } + break; + } +if (retour<=0) { + (void) free(decoded); + decoded=(char *)0; + } +(void) BIO_free_all(bbio); +return decoded; + +#undef OPEP +} + diff --git a/lib/subcnv.h b/lib/subcnv.h new file mode 100644 index 0000000..037bb29 --- /dev/null +++ b/lib/subcnv.h @@ -0,0 +1,21 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/************************************************/ +/* */ +/* Define all routine to manage language */ +/* tring conversion. */ +/* */ +/************************************************/ +#ifndef SUBCNV +#define SUBCNV + +//base64 char 0 coding +#define IOBNULL "\\000" + +//Procedure to convert a plain ASCII B64 sequence +//to a plain ASCII sequence +extern char *cnv_getb64(char *b64); + +//Procedure to convert a plain ASCII sequence +//to an ASCII B64 sequence +extern char *cnv_setb64(const char *str); +#endif diff --git a/lib/subrou.h b/lib/subrou.h index 6c6718b..082890f 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -15,9 +15,7 @@ #define APPNAME "mailleur" //application name -#define PUBLIC //to specify public variable - -#define ITSOK 0 //to check errno against no error +#define ITSOK 0 //to check errno against no error //defining database #define #define USE_NODB 0 //No DB TYPE defined diff --git a/lib/unieml.c b/lib/unieml.c index a60bece..a7d51ee 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -29,6 +29,7 @@ typedef struct { //this list order by key length static VOCTYP vocsmtp[]={ + {c_auth,"AUTH"}, {c_data,"DATA"}, {c_ehlo,"EHLO"}, {c_helo,"HELO"}, diff --git a/lib/unieml.h b/lib/unieml.h index 96180b3..b738215 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -51,6 +51,7 @@ //list of keyword typedef enum { //list of SMTP protocol keyword + c_auth, //Requesting authentication c_data, //DATA email contents transfer request c_ehlo, //EHLO command c_helo, //Basic Helo command diff --git a/lib/unisql.c b/lib/unisql.c index e3796ce..ab41fc0 100644 --- a/lib/unisql.c +++ b/lib/unisql.c @@ -21,7 +21,7 @@ */ /************************************************/ /* */ -/* Procedure to convert an char sequence */ +/* Procedure to convert a char sequence */ /* from on char set to another. */ /* if successful return a new pointer */ /* */