From 5784bc0410d9fe5f11cfe1253a5204e503d7db35 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 15 Jul 2025 19:57:53 -0400 Subject: [PATCH] Starting to implement contact->privilege enum --- lib/lvleml.c | 52 ++++++++++++++++++++++++++++++++++++---------------- lib/lvleml.h | 2 +- lib/unieml.h | 7 +++++++ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/lib/lvleml.c b/lib/lvleml.c index 9e5eef1..f047919 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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 } /* @@ -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); diff --git a/lib/lvleml.h b/lib/lvleml.h index 8e685e7..4e9d3c9 100644 --- a/lib/lvleml.h +++ b/lib/lvleml.h @@ -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 diff --git a/lib/unieml.h b/lib/unieml.h index 2cfb0da..a29c913 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -55,6 +55,13 @@ #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 -- 2.47.3