From: Jean-Marc Pigeon (Delson) Date: Sun, 8 Jun 2025 07:42:45 +0000 (-0400) Subject: Starting to do ehlo command X-Git-Tag: tag-0.8~57 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=90c706ecb317cb9be2163ce5e002f58f7d1db6a6;p=jmp%2Fmailleur Starting to do ehlo command --- diff --git a/app/feeder.c b/app/feeder.c index c027ef4..01592bd 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -87,23 +87,6 @@ static void report(int numline,char *line,char *trouble) (void) rou_alert(0,"\t'%s'",line); } /* - -*/ -/********************************************************/ -/* */ -/* Procedure to send a line to remote */ -/* */ -/********************************************************/ -static int dooutgoing(SOCPTR *socptr,char *line) - -{ -int count; - -count=soc_writebuffer(socptr,line,strlen(line)); -count+=soc_writebuffer(socptr,"\r\n",2); -return count; -} -/* ^L */ /************************************************/ @@ -161,7 +144,7 @@ while (proceed==true) { //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase); switch (phase) { case 0 : //Transmit "DATA" to remote - if (dooutgoing(fd->socptr,action)!=(strlen(action)+2)) + if (tcp_write(fd->socptr,action)!=(strlen(action)+2)) phase=999; //Unable to send STARTTLS sequence break; case 1 : //Get DATA command status @@ -195,14 +178,14 @@ while (proceed==true) { case 'D' : //pure data if ((strcmp(data+2,".")==0)&&(empty==true)) (void) strcat(data,"."); - (void) dooutgoing(fd->socptr,data+2); + (void) tcp_write(fd->socptr,data+2); empty=(strlen(data+2)==0); break; case 'C' : //data marker switch (data[2]) { case '.' : //end of data marker - (void) dooutgoing(fd->socptr,""); - (void) dooutgoing(fd->socptr,"."); + (void) tcp_write(fd->socptr,""); + (void) tcp_write(fd->socptr,"."); completed=true; break; case 'T' : //timer data @@ -211,7 +194,7 @@ while (proceed==true) { isnow=time((time_t *)0); (void) snprintf(ed,sizeof(ed),"Date: %s",rou_ascsysstamp(isnow)); - (void) dooutgoing(fd->socptr,ed); + (void) tcp_write(fd->socptr,ed); break; default : //unexpected data marker (void) rou_alert(0,"%s Unexpected data marker <%s> (Bug?)", @@ -265,7 +248,7 @@ proceed=true; while (proceed==true) { switch (phase) { case 0 : //Sending START TLS command - if (dooutgoing(socptr,action)!=(strlen(action)+2)) + if (tcp_write(socptr,action)!=(strlen(action)+2)) phase=999; //Unable to send STARTTLS sequence break; case 1 : //Get STARTTLS command status @@ -568,7 +551,7 @@ while (proceed==true) { status=doincoming(fd->socptr,*numline,line); break; case 'S' : //sending data - (void) dooutgoing(fd->socptr,line); + (void) tcp_write(fd->socptr,line); break; case 'T' : //Get the test titre status=strncpy(testname,line,sizeof(testname)); diff --git a/lib/gestcp.c b/lib/gestcp.c index 5c7d17e..eaeabd2 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -92,17 +92,23 @@ return got; */ /********************************************************/ /* */ -/* Procedure to write buffer on the socket output */ +/* Procedure to write a string on the socket output*/ /* return the number of char sent on channel. */ /* */ /********************************************************/ -PUBLIC int tcp_write(SOCPTR *socptr,char *buffer,int tosend) +PUBLIC int tcp_write(SOCPTR *socptr,char *buffer) { int sent; sent=-1; -if (socptr!=(SOCPTR *)0) - sent=soc_writebuffer(socptr,buffer,tosend); +if (socptr!=(SOCPTR *)0) { + int taille; + + taille=strlen(buffer); + if (taille>0) + sent=soc_writebuffer(socptr,buffer,taille); + sent+=soc_writebuffer(socptr,CRLF,strlen(CRLF)); + } return sent; } diff --git a/lib/gestcp.h b/lib/gestcp.h index 6962c50..dfdb579 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -19,6 +19,6 @@ extern int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr); //Transmit formated data to the contact channel -extern int tcp_write(SOCPTR *socptr,char *buffer,int tosend); +extern int tcp_write(SOCPTR *socptr,char *buffer); #endif diff --git a/lib/lvleml.c b/lib/lvleml.c index 274e04c..127fcea 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -130,8 +130,7 @@ va_start(args,fmt); line=(char *)0; if (rou_vasprintf(&line,fmt,args)>0) { (void) log_fprintlog(contact->logptr,true,"%s",line); - (void) tcp_write(contact->socptr,line,strlen(line)); - (void) tcp_write(contact->socptr,CRLF,strlen(CRLF)); + (void) tcp_write(contact->socptr,line); (void) free(line); } va_end(args); @@ -687,7 +686,7 @@ return true; /* Return the SMTP status code. */ /* */ /********************************************************/ -static _Bool get_smtp_reply(RMTTYP *rmt,int wait) +static int get_smtp_reply(RMTTYP *rmt,int wait) { int code; @@ -724,6 +723,53 @@ return code; */ /********************************************************/ /* */ +/* Procedure to to send ehlo (or helo) to remote */ +/* MX server. */ +/* Return true if succesfull */ +/* */ +/********************************************************/ +static _Bool greetings_rmt(RMTTYP *rmt) + +{ +_Bool done; +int phase; +_Bool proceed; + +done=false; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Sending EHLO + char cmt[100]; + + (void) snprintf(cmt,sizeof(cmt),"EHLO %s",rmt->domain); + (void) tcp_write(rmt->socptr,cmt); + (void) log_fprintlog(rmt->logptr,false,cmt); + break; + case 1 : //waiting for ehlo reply + switch (get_smtp_reply(rmt,WAITRMT)) { + case CMDOK : //So fare, so good + done=true; + phase=999; + break; + default : //Trouble + break; + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return done; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to connect to the remote SMTP server */ /* */ /********************************************************/ @@ -780,7 +826,11 @@ while (proceed==true) { break; } break; - case 3 : //establishing secured link + case 3 : //send greetings + if (greetings_rmt(rmt)==false) + phase=999; //greeting not successful! + break; + case 4 : //establishing secured link break; default : //SAFE Guard proceed=false;