]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement subcnv module (string convertion)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 30 Jun 2025 22:19:02 +0000 (18:19 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 30 Jun 2025 22:19:02 +0000 (18:19 -0400)
data-feed/feedxx.tst
lib/Makefile
lib/gestcp.h
lib/lvleml.c
lib/subafn.c
lib/subcnv.c [new file with mode: 0644]
lib/subcnv.h [new file with mode: 0644]
lib/subrou.h
lib/unieml.c
lib/unieml.h
lib/unisql.c

index f86395c82cea87da88b62986f97822c11a6a51a0..c3aeb9ab5d05648675d49946ffa337ca870c4b83 100644 (file)
@@ -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...
index 69afed401dcb3befa84d85660cf1d17ca5a30959..5ed5c29b9acede6024248f9c89b5edaa1fc9ad29 100644 (file)
@@ -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`
index 734a60cff76f0eed84910898e5de671bc7aa6174..43e5d99ffe2fbb7d50252aa91303c07d13893b19 100644 (file)
@@ -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);
index 39c5c8b8a57011caed276998de4f31bbcde328b8..5aaf30e19e044d8fe6ea241548be7c76dec7ba02 100644 (file)
@@ -19,6 +19,7 @@
 #include        <unistd.h>
 
 #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
index 90bd4159c826c9f5a974e77ee7441e01d12bcb71..0e986a3b85ab12ed8c0b29df3ef6c7608bf95313 100644 (file)
@@ -15,8 +15,6 @@
 
 #include       "subafn.h"
 
-#define PUBLIC                  //to specify public variable
-
 /*
 \f
 */
diff --git a/lib/subcnv.c b/lib/subcnv.c
new file mode 100644 (file)
index 0000000..164a721
--- /dev/null
@@ -0,0 +1,117 @@
+// 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
+}
+
diff --git a/lib/subcnv.h b/lib/subcnv.h
new file mode 100644 (file)
index 0000000..037bb29
--- /dev/null
@@ -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
index 6c6718b447cf59addd2c2fe8b5c365e570540edd..082890f4a688c63fa9e0392b1ded9adc8a6f3314 100644 (file)
@@ -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
index a60bece6affc7a7a45f4faf83a5c89b0dec97300..a7d51eeb925aa78dde905e1d8245c339a6f4745c 100644 (file)
@@ -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"},
index 96180b30e9e7b90f41e8fdf47d02d4109c928b87..b7382151ba6a4c86878af0506e6ac465d6d1f993 100644 (file)
@@ -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
index e3796ce9d55116b74cd80726415bed85c78d51ca..ab41fc070aabde828cb7500014f403e3a8209c9c 100644 (file)
@@ -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      */
 /*                                             */