]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement contact->privilege enum
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 15 Jul 2025 23:57:53 +0000 (19:57 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 15 Jul 2025 23:57:53 +0000 (19:57 -0400)
lib/lvleml.c
lib/lvleml.h
lib/unieml.h

index 9e5eef10c1e5a1e2779135627b5efbe0dcba559d..f047919d1bd973262856054ff67babb696236d71 100644 (file)
@@ -29,6 +29,7 @@
 #include       "geseml.h"
 #include       "lvleml.h"
 
+#define RELAYS  "RELAYABLE"
 /*
 ^L
 */
@@ -280,7 +281,7 @@ while (proceed==true) {
                            contact->peername,contact->peerip,contact->mailfrom);
       break;
     case 1      :       //Inserting the Receive information
-      if (contact->authenticated==true
+      if (contact->privilege==rel_authentic
         esmtp="ESMTPA";
       (void) fprintf(data,"\tby %s ([%s:%s]/%s-%s) with %s\n",
                           contact->locname,
@@ -534,7 +535,8 @@ if ((received==(char *)0)||(strlen(received)==0)) {
 else 
   decoded=cnv_getb64(received);
 if (decoded!=(char *)0) {
-  contact->authenticated=checklogin(contact,rmtpass,decoded);
+  if (checklogin(contact,rmtpass,decoded)==true)
+    contact->privilege=rel_authentic;
   decoded=rou_freestr(decoded);
   }
 
@@ -578,8 +580,10 @@ for (int i=0;i<2;i++) {
      }
   line=rou_freestr(line);
   }
-if (strlen(local)>0)
-  contact->authenticated=checklogin(contact,rmtpass,local);
+if (strlen(local)>0) {
+  if (checklogin(contact,rmtpass,local)==true)
+    contact->privilege=rel_authentic;
+  }
 }
 /*
 ^L
@@ -713,7 +717,8 @@ while (proceed==true) {
         (void) rou_alert(0,"%s Unable to get the hash response (Bug!)",OPEP);
         break;
         }
-      contact->authenticated=(strcmp(HA0,resp->response)==0);
+      if (strcmp(HA0,resp->response)==0)
+        contact->privilege=rel_authentic;
       HA0=rou_freestr(HA0);
       }
       break;
@@ -822,7 +827,7 @@ while (proceed==true) {
 
       fmt="    Auth accepted for user=<%s>";
       auth=contact->authname;
-      if (contact->authenticated==false) {
+      if (contact->privilege!=rel_authentic) {
         fmt="    Auth Rejected status='%d' for user=<%s> pass=<%s>";
         (void) log_fprintlog(contact->logptr,true,fmt,BADAUTH,auth,rmtpass);
         (void) sleep(2);
@@ -841,7 +846,7 @@ while (proceed==true) {
   phase++;
   }
 rmtpass=rou_freestr(rmtpass);
-return contact->authenticated;
+return (contact->privilege==rel_authentic);
 #undef  OPEP
 }
 /*
@@ -1372,6 +1377,8 @@ return isok;
 static _Bool checkfrom(CONTYP *contact,char *mailfrom)
 
 {
+#define OPEP    "lvleml.c:checkfrom,"
+
 _Bool success;
 _Bool proceed;
 int status;
@@ -1408,16 +1415,26 @@ while (proceed==true) {
       (void) memmove(mailfrom,mailfrom+1,strlen(mailfrom));
       break;
     case 3      :       //check if contact authenticated
-      if (contact->authenticated==true)
-        phase++;        //No need to check remote "credits
-      break;
-    case 4      :       //check remote credit
-      if ((status=checkcredit(contact))!=CMDOK) {
-        (void) transmit(contact,true,"%d 5.5.3 Closing connection",status);
-        phase=999;      //bad credit not need to go further
+      switch (contact->privilege) {
+        case rel_authentic      :       //User was authenticated
+          break;
+        case rel_isrelay        :       //Remote IP is relay
+          break;
+        case rel_plain          :
+          if ((status=checkcredit(contact))!=CMDOK) {
+            (void) transmit(contact,true,"%d 5.5.3 Closing connection",status);
+            phase=999;      //bad credit not need to go further
+            }
+          break;
+        default :
+          (void) rou_alert(0,"%s unexpected priviliged='%d' (Bug?)",
+                              OPEP,contact->privilege);
+            (void) transmit(contact,true,"%d 5.5.3 Closing connection",FAILED);
+            phase=999;      //bad credit not need to go further
+          break;
         }
       break;
-    case 5      :       //everything ok
+    case 4      :       //everything ok
       contact->mailfrom=strdup(mailfrom);
       (void) transmit(contact,true,"%d 2.1.3 %s.. sender ok",
                                     CMDOK,contact->mailfrom);
@@ -1430,6 +1447,8 @@ while (proceed==true) {
   phase++;
   }
 return success;
+
+#undef  OPEP
 }
 /*
 \f
@@ -2326,7 +2345,7 @@ while (proceed==true) {
         }
       break;
     case 2      :       //loading the relayable IP list
-      contact->relayok=eml_load_relayed(getenv("RELAYABLE"));
+      contact->relayok=eml_load_relayed(getenv(RELAYS));
       break;
     case 3      :       //waiting from contact
       if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
@@ -2338,6 +2357,7 @@ while (proceed==true) {
     case 4      :       //Preparing contact
       contact->mainsesid=eml_getmainsesid();
       contact->delay=MXDELAY;
+      contact->privilege=rel_plain;     //Standard connection
       if (debug>1) 
         contact->delay/=10;     //30 sec in debug mode
       (void) getsessid(contact);
index 8e685e79ab03116b40430cc08d358f0aaf456a4f..4e9d3c9eada2b58e808a8056053ccee9abf4c290 100644 (file)
@@ -21,7 +21,7 @@ typedef struct  {
         int delay;              //communication max delay
         char *fqdn;             //fully qualified domain from peer
         char *locip;            //socket local IP num
-        _Bool authenticated;    //Link is authenticated
+        RELTYP privilege;       //onnection privilege
         char *authname;         //Link is authenticated name
         AFNTYP **localafn;      //local IP as an AFNUM
         char *locname;          //socket local hostname
index 2cfb0da73f8a602d8a3e260529d868ff04c63400..a29c91373702fee7f9b2b3492ba3c3743a3513f5 100644 (file)
 #define EMLPORT "25"            //Default SMTP email port
 #define WAITRMT 60              //how long to wait answer from remote SMTP
 
+typedef enum    {               //list of email relayable status
+        rel_authentic,          //connection/user is authenticated
+        rel_isrelay,            //remote IP is relayable
+        rel_plain,              //remote IP is a "plain" stranger
+        rel_unknown             //Wrong status
+        }RELTYP;
+
 //list of keyword
 typedef enum    {               //list of SMTP protocol keyword
         c_auth,                 //Requesting authentication