#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...
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
modrec.h modrec.c
lvleml.o: \
- subrou.h \
+ subcnv.h subrou.h \
unieml.h unidns.h \
lvleml.h lvleml.c
subafn.o: \
subafn.h subafn.c
+subcnv.o: \
+ subcnv.h subcnv.c
+
lvleml.h: \
devsoc.h devsql.h \
geseml.h gestcp.h
subrou.h \
unipos.h unipos.c
@ $(CC) \
+ $(CPPFLAGS) \
-DDATABASE=1 \
-Dwith_postgres \
-c \
subrou.h \
unimar.h unimar.c
@ $(CC) \
+ $(CPPFLAGS) \
-DDATABASE=2 \
-Dwith_mysql \
-c \
#--------------------------------------------------------------------
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`
}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);
#include <unistd.h>
#include "subrou.h"
+#include "subcnv.h"
#include "unieml.h"
#include "devlog.h"
#include "gestcp.h"
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);
*/
/********************************************************/
/* */
+/* 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. */
/* */
/********************************************************/
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
#include "subafn.h"
-#define PUBLIC //to specify public variable
-
/*
\f
*/
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Define all routine to manage language string */
+/* conversion. */
+/* */
+/********************************************************/
+#include <openssl/bio.h>
+#include <openssl/evp.h>
+#include <ctype.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "subcnv.h"
+
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* 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;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* 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
+}
+
--- /dev/null
+// 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
#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
//this list order by key length
static VOCTYP vocsmtp[]={
+ {c_auth,"AUTH"},
{c_data,"DATA"},
{c_ehlo,"EHLO"},
{c_helo,"HELO"},
//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
*/
/************************************************/
/* */
-/* Procedure to convert an char sequence */
+/* Procedure to convert a char sequence */
/* from on char set to another. */
/* if successful return a new pointer */
/* */