#include "subcnv.h"
#include "unidig.h"
#include "unieml.h"
+#include "uniprc.h"
#include "devlog.h"
#include "gestcp.h"
#include "gessql.h"
*/
/********************************************************/
/* */
-/* Procedure to transmit a string to the remot peer*/
-/* */
-/********************************************************/
-static void transmit(CONTYP *contact,_Bool flush,const char *fmt,...)
-
-{
-va_list args;
-char *line;
-
-va_start(args,fmt);
-line=(char *)0;
-if (rou_vasprintf(&line,fmt,args)>0) {
- (void) log_fprintlog(contact->logptr,true,"%s",line);
- contact->transout=tcp_addline(contact->transout,line);
- }
-if (flush==true) {
- (void) tcp_write(contact->socptr,contact->transout);
- contact->transout=rou_freestr(contact->transout);
- }
-line=rou_freestr(line);
-va_end(args);
-}
-/*
-^L
-*/
-/********************************************************/
-/* */
/* Procedure to send the signon once the contact */
/* with peer is detected. */
/* */
APPNAME,
rou_getversion(),
rou_ascsysstamp(time((time_t *)0)));
- (void) transmit(contact,true,"%s",signon);
+ (void) eml_transmit(contact,true,"%s",signon);
}
#undef FMT
}
sepa='-';
}
mode=soc_getstrmode(contact->socptr);
-(void) transmit(contact,flush,"%d%c%s, link (%s) ready, your IP/FQDN=[%s/%s]",
- CMDOK,sepa,contact->locname,mode,
- contact->peerip,contact->peername);
+(void) eml_transmit(contact,flush,"%d%c%s, link (%s) ready, your IP/FQDN=[%s/%s]",
+ CMDOK,sepa,contact->locname,mode,
+ contact->peerip,contact->peername);
}
/*
^L
case 1 : //checking credential
if (srv->links>1) {
status=ALREADY;
- (void) transmit(contact,true,"%d-4.5.6 Server already connected",status);
+ (void) eml_transmit(contact,true,"%d-4.5.6 Server already connected",
+ status);
phase=999; //To many server connected
}
break;
srv->credit,"too low");
(void) setterminator(contact,"Remote server credit is too low");
status=BLCKLST;
- (void) transmit(contact,true,"%d-4.5.7 Originator server IP [%s] black listed <%s>",
- status,contact->peerip,cmt);
+ (void) eml_transmit(contact,true,"%d-4.5.7 Originator server IP "
+ "[%s] black listed <%s>",
+ status,contact->peerip,cmt);
phase=999; //To many server connected
}
break;
int got;
line=(char *)0;
- (void) transmit(contact,true,"%d 5.7.1 Please provide auth sequence",SENDB64);
+ (void) eml_transmit(contact,true,"%d 5.7.1 Please provide auth sequence",SENDB64);
got=tcp_getline(contact->socptr,contact->delay,&line);
if (got>0) {
(void) log_fprintlog(contact->logptr,false,"%s",line);
int got;
(void) strcat(local,IOBNULL);
- (void) transmit(contact,true,"%d %s",SENDB64,logdat[i]);
+ (void) eml_transmit(contact,true,"%d %s",SENDB64,logdat[i]);
got=tcp_getline(contact->socptr,contact->delay,&line);
if (got<=0) {
(void) strcpy(local,"");
- (void) transmit(contact,true,"%d 5.7.2 auth sequence missing",UKNUSER);
+ (void) eml_transmit(contact,true,"%d 5.7.2 auth sequence missing",UKNUSER);
break; //exiting from loop
}
(void) log_fprintlog(contact->logptr,false,"%s",line);
char *b64;
b64=cnv_setb64(challenge);
- (void) transmit(contact,true,"%d %s",SENDB64,b64);
+ (void) eml_transmit(contact,true,"%d %s",SENDB64,b64);
b64=rou_freestr(b64);
}
break;
}
(void) rou_asprintf(&rspauth,"rspauth=%s",HAS);
b64=cnv_setb64(rspauth);
- (void) transmit(contact,true,"%d %s",SENDB64,b64);
+ (void) eml_transmit(contact,true,"%d %s",SENDB64,b64);
b64=rou_freestr(b64);
rspauth=rou_freestr(rspauth);
HAS=rou_freestr(HAS);
switch (phase) {
case 0 : //are we encrypted and on the right port
if (soc_iscrypted(contact->socptr)==false) {
- (void) transmit(contact,true,"%d 5.7.0 no authentication on clear chanel",
- FAILED);
+ (void) eml_transmit(contact,true,"%d 5.7.0 no authentication on "
+ "clear chanel",FAILED);
phase=999; //No need to go further
}
break;
case 1 : //check buffer
if ((buffer==(char *)0)||(strlen(buffer)==0)) {
- (void) transmit(contact,true,"%d 5.7.1 Missing auth type",FAILED);
+ (void) eml_transmit(contact,true,"%d 5.7.1 Missing auth type",FAILED);
phase=999; //No need to go further
}
break;
}
if (vocloc[code]==(char *)0) {
(void) rou_alert(0,"%s auth type <%s> unknown (Bug?)",OPEP,local);
- (void) transmit(contact,true,"%d 5.7.2 bad authentication type",BADPAR);
+ (void) eml_transmit(contact,true,"%d 5.7.2 bad authentication type",BADPAR);
phase=999; //Trouble Trouble
}
break;
if (soc_iscrypted(contact->socptr)==true)
(void) get_auth_plain(contact,local,&rmtpass);
else
- (void) transmit(contact,true,"%d 5.7.3 Unsafe PLAIN auth mode",FAILED);
+ (void) eml_transmit(contact,true,"%d 5.7.3 Unsafe PLAIN auth mode",
+ FAILED);
break;
case 1 : //AUTH LOGIN
if (soc_iscrypted(contact->socptr)==true)
(void) get_auth_login(contact,&rmtpass);
else
- (void) transmit(contact,true,"%d 5.7.4 Unsafe LOGIN auth mode",FAILED);
+ (void) eml_transmit(contact,true,"%d 5.7.4 Unsafe LOGIN auth mode",
+ FAILED);
break;
case 2 : //AUTH DIGEST-MD5
(void) get_auth_digest_md5(contact,&rmtpass);
break;
default : //not yet implemented
- (void) transmit(contact,true,"%d 5.7.5 Unknown auth mode",FAILED);
+ (void) eml_transmit(contact,true,"%d 5.7.5 Unknown auth mode",FAILED);
(void) rou_alert(0,"%s auth type <%d> not yet implemented",OPEP);
phase=999;
break;
fmt=DISP"Auth Rejected status='%d' for user=<%s> pass=<%s>";
(void) log_fprintlog(contact->logptr,true,fmt,BADAUTH,auth,rmtpass);
(void) sleep(2);
- (void) transmit(contact,true,"%d 5.7.4 authentication failed",BADAUTH);
+ (void) eml_transmit(contact,true,"%d 5.7.4 authentication failed",BADAUTH);
}
else {
(void) log_fprintlog(contact->logptr,true,fmt,auth);
- (void) transmit(contact,true,"%d 5.7.5 Authentication successful",IDOK);
+ (void) eml_transmit(contact,true,"%d 5.7.5 Authentication successful",IDOK);
}
}
break;
switch (phase) {
case 0 : //is user a local user
if ((sql_mngusr(contact->sqlptr,sql_select,rcptto,&usr))==false) {
- (void) transmit(contact,true,"%d 5.6.5 <%s> unknown user",UKNUSER,rcptto);
+ (void) eml_transmit(contact,true,"%d 5.6.5 <%s> unknown user",
+ UKNUSER,rcptto);
phase=999; //No user found in database
}
break;
case 1 : //is user lock?
if (usr->lock==1) {
- (void) transmit(contact,true,"%d 5.6.6 <%s> account lock",EXPIRED,rcptto);
+ (void) eml_transmit(contact,true,"%d 5.6.6 <%s> account lock",
+ EXPIRED,rcptto);
phase=999; //No user found in database
}
break;
default : //SAFE Guard
if (remotegood==false) {
- (void) transmit(contact,true,"%d 2.7.0 %s for domain <%s>",
- NORELAY,cmt,rmtusr->domain);
+ (void) eml_transmit(contact,true,"%d 2.7.0 %s for domain <%s>",
+ NORELAY,cmt,rmtusr->domain);
}
proceed=false;
break;
char *cmt;
cmt="RCPT first. transaction protocol command out of sequence";
- (void) transmit(contact,true,"%d 5.5.0 %s",BADSEQ,cmt);
+ (void) eml_transmit(contact,true,"%d 5.5.0 %s",BADSEQ,cmt);
done=true; //lets say DATA will be issued
proceed=false; //No recipients
}
break;
case 3 : //sending 'go ahead' to remote
(void) clock_gettime(CLOCK_REALTIME,&start);
- (void) transmit(contact,true,"%d 3.5.0 %s",
- DATAOK,"End data with <CR><LF>.<CR><LF>");
+ (void) eml_transmit(contact,true,"%d 3.5.0 %s",
+ DATAOK,"End data with <CR><LF>.<CR><LF>");
break;
case 4 : //get incoming line, detect 'single dot' as end
while (completed==false) {
(void) snprintf(duration,sizeof(duration),"%d.%03d",delta/1000,delta%1000);
contact->session->duration=strdup(duration);;
fmt="%d-3.5.3 Session ID=<%s>";
- (void) transmit(contact,false,fmt,CMDOK,contact->session->sessid);
+ (void) eml_transmit(contact,false,fmt,CMDOK,contact->session->sessid);
fmt="%d-3.5.3 data stream received: %d Kbytes within %s seconds)";
- (void) transmit(contact,false,fmt,CMDOK,total,duration);
+ (void) eml_transmit(contact,false,fmt,CMDOK,total,duration);
fmt="%d 3.5.3 Message accepted for delivery";
- (void) transmit(contact,true,fmt,CMDOK,contact->session->sessid);
+ (void) eml_transmit(contact,true,fmt,CMDOK,contact->session->sessid);
done=true;
proceed=false; //task done
break;
default : //SAFE guard
- (void) transmit(contact,true,"%d 5.5.4 %s",
- DATRJC,"Server does not accept mail");
+ (void) eml_transmit(contact,true,"%d 5.5.4 Server does not accept mail",
+ DATRJC);
proceed=false;
break;
}
_Bool done;
if ((done=isgoodfqdn(contact,parameter))==false)
- (void) transmit(contact,true,"%d 5.5.4 %s.",BADPAR,DETAIL);
+ (void) eml_transmit(contact,true,"%d 5.5.4 %s.",BADPAR,DETAIL);
else
(void) linkready(contact,false);
return done;
switch (phase) {
case 0 : //Do we have a parameter
if ((done=isgoodfqdn(contact,parameter))==false) {
- (void) transmit(contact,true,"%d 5.5.4 %s.",BADPAR,DETAIL);
+ (void) eml_transmit(contact,true,"%d 5.5.4 %s.",BADPAR,DETAIL);
phase=999; //Trouble trouble
}
break;
continue;
break;
}
- (void) transmit(contact,false,"%d%c%s",CMDOK,space,ehlo[i].str);
+ (void) eml_transmit(contact,false,"%d%c%s",CMDOK,space,ehlo[i].str);
}
- (void) transmit(contact,true,"");
+ (void) eml_transmit(contact,true,"");
done=true;
break;
default : //SAFE guard
switch (phase) {
case 0 : //do we have an originator
if ((mailfrom==(char *)0)||(strlen(mailfrom)<3)) {
- (void) transmit(contact,true,"%d 5.5.0 <%s> originator not specified",
- BADPAR,mailfrom);
+ (void) eml_transmit(contact,true,"%d 5.5.0 <%s> originator not specified",
+ BADPAR,mailfrom);
phase=999; //no need to go further
}
break;
case 1 : //do we have already a from
if (contact->mailfrom!=(char *)0) {
- (void) transmit(contact,true,"%d 5.5.1 '%s' %s",
- BADPAR,contact->mailfrom,
- "was previously defined as originator");
+ (void) eml_transmit(contact,true,"%d 5.5.1 '%s' %s",
+ BADPAR,contact->mailfrom,
+ "was previously defined as originator");
phase=999; //no need to go further
}
break;
break;
case 3 : //check from format
if ((mailfrom[0]!='<')||(mailfrom[strlen(mailfrom)-1]!='>')) {
- (void) transmit(contact,true,"%d 5.5.3 '%s' bad Format error",
- BADPAR,mailfrom);
+ (void) eml_transmit(contact,true,"%d 5.5.3 '%s' bad Format error",
+ BADPAR,mailfrom);
phase=999; //no need to go further
}
mailfrom[strlen(mailfrom)-1]='\000';
case rel_plain : //remote IP is plain
if ((status=checkcredit(contact))!=CMDOK) {
contact->credit=-1; //found bad guy.
- (void) transmit(contact,true,"%d 5.5.4 Closing connection",status);
+ (void) eml_transmit(contact,true,"%d 5.5.4 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.5 Closing connection",FAILED);
- phase=999; //bad credit not need to go further
+ (void) eml_transmit(contact,true,"%d 5.5.5 Closing connection",FAILED);
+ phase=999; //bad credit not need to go further
break;
}
break;
case 5 : //everything ok
contact->mailfrom=strdup(mailfrom);
- (void) transmit(contact,true,"%d 2.1.3 %s sender ok",
- CMDOK,contact->mailfrom);
+ (void) eml_transmit(contact,true,"%d 2.1.3 %s sender ok",
+ CMDOK,contact->mailfrom);
success=true;
break;
default : //SAFE guard
switch (phase) {
case 0 : //do we have a mailfrom
if ((contact->mailfrom==(char *)0)||(strlen(contact->mailfrom)==0)) {
- (void) transmit(contact,true,"%d 5.6.0 Bad sequence of commands.",BADSEQ);
+ (void) eml_transmit(contact,true,"%d 5.6.0 Bad sequence of commands.",
+ BADSEQ);
phase=999; //no need to go further
}
break;
case 1 : //do we have an originator
if ((rcptto==(char *)0)||(strlen(rcptto)==0)) {
- (void) transmit(contact,true,"%d 5.6.1 recipient not specified",BADPAR);
+ (void) eml_transmit(contact,true,"%d 5.6.1 recipient not specified",
+ BADPAR);
phase=999; //no need to go further
}
break;
case 2 : //check rcpt format
if ((rcptto[0]!='<')||(rcptto[strlen(rcptto)-1]!='>')) {
- (void) transmit(contact,true,"%d 5.6.2 '%s' bad Format error",
- BADPAR,rcptto);
+ (void) eml_transmit(contact,true,"%d 5.6.2 '%s' bad Format error",
+ BADPAR,rcptto);
phase=999; //no need to go further
}
rcptto[strlen(rcptto)-1]='\000';
case 3 : //checking rcptto format
neu=eml_isemailok(rcptto,&report);
if (neu==(RCPTYP *)0) {
- (void) transmit(contact,true,"%d 5.6.3 %s",NOTEML,report);
+ (void) eml_transmit(contact,true,"%d 5.6.3 %s",NOTEML,report);
report=rou_freestr(report);
phase=999; //no need to go further
}
break;
case 4 : //Do we have a domain MX
if (setlocdom(contact,neu)==false) {
- (void) transmit(contact,true,"%d 5.6.4 %s (domain=%s)",
- MISSMX,
- "No valid MX found for recipient domain name",
- neu->domain);
+ (void) eml_transmit(contact,true,"%d 5.6.4 %s (domain=%s)",
+ MISSMX,
+ "No valid MX found for recipient "
+ "domain name",neu->domain);
phase=999; //no need to go further
}
break;
phase=999;
break;
default :
- (void) transmit(contact,true,"%d 5.6.5 %s (domain=%s,code='%c')",
- FAILED,
- "system error with domain status",
- neu->domain,neu->code);
+ (void) eml_transmit(contact,true,"%d 5.6.5 %s (domain=%s,code='%c')",
+ FAILED,
+ "system error with domain status",
+ neu->domain,neu->code);
phase=999; //no need to go further
break;
}
}
break;
case 7 : //everything ok
- (void) transmit(contact,true,"%d 2.6.4 %s <%s>",CMDOK,detail,rcptto);
+ (void) eml_transmit(contact,true,"%d 2.6.4 %s <%s>",CMDOK,detail,rcptto);
success=true;
break;
default : //SAFE guard
{
#define LOCSEQ "2.1.0"
-(void) transmit(contact,true,"%d-%s flushed session %s",
- CMDOK,LOCSEQ,contact->session->sessid);
+(void) eml_transmit(contact,true,"%d-%s flushed session %s",
+ CMDOK,LOCSEQ,contact->session->sessid);
(void) freesessid(contact);
contact->numreset++;
(void) getsessid(contact);
contact->recipients=(RCPTYP **)rou_freelist((void **)(contact->recipients),
(genfree_t)eml_freerecipient);
contact->mailfrom=rou_freestr(contact->mailfrom);
-(void) transmit(contact,true,"%d %s opening new session %s",
- CMDOK,LOCSEQ,contact->session->sessid);
+(void) eml_transmit(contact,true,"%d %s opening new session %s",
+ CMDOK,LOCSEQ,contact->session->sessid);
return true;
#undef LOCSEQ
*/
/********************************************************/
/* */
+/* Procedure to transmit a string to the remot peer*/
+/* */
+/********************************************************/
+PUBLIC void eml_transmit(CONTYP *contact,_Bool flush,const char *fmt,...)
+
+{
+va_list args;
+char *line;
+
+va_start(args,fmt);
+line=(char *)0;
+if (rou_vasprintf(&line,fmt,args)>0) {
+ (void) log_fprintlog(contact->logptr,true,"%s",line);
+ contact->transout=tcp_addline(contact->transout,line);
+ }
+if (flush==true) {
+ (void) tcp_write(contact->socptr,contact->transout);
+ contact->transout=rou_freestr(contact->transout);
+ }
+line=rou_freestr(line);
+va_end(args);
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
/* Procedure to proceed with peer exchange */
/* 5 return values: */
/* 1 exiting via "quit" */
proceed=doehlo(contact,line);
break;
case c_noop : //No Operation
- (void) transmit(contact,true,"%d 2.0.0 OK, %s",
- CMDOK,contact->mainsesid);
+ (void) eml_transmit(contact,true,"%d 2.0.0 OK, %s",
+ CMDOK,contact->mainsesid);
break;
case c_quit : //QUIT SMTP protocol
contact->credit++; //clean disconnect
(void) setterminator(contact,"QUIT received");
- (void) transmit(contact,true,"%d 2.0.0 Bye, closing connection CNT=%s",
- QUITOK,contact->mainsesid);
+ (void) eml_transmit(contact,true,"%d 2.0.0 Bye, closing connection CNT=%s",
+ QUITOK,contact->mainsesid);
status=1; //every thing fine
proceed=false;
break;
case c_starttls : //EHLO start encrypted link in server mode
(void) usleep(100000);
(void) soc_purge(contact->socptr,contact->peerip);
- (void) transmit(contact,true,"%d 2.0.0 Ready to start TLS",SIGNON);
+ (void) eml_transmit(contact,true,"%d 2.0.0 Ready to start TLS",SIGNON);
switch (soc_starttls(contact->socptr,true)) {
case true : { //link now in TLS crypted mode (server mode)
int level;
break;
case false : //unable to establish link
(void) setterminator(contact,"starttls not successful");
- (void) transmit(contact,true,"%d 5.3.3 command starttls not successful",
- CMDBAD);
+ (void) eml_transmit(contact,true,"%d 5.3.3 command starttls not "
+ "successful",CMDBAD);
status=-1;
proceed=false;
break;
contact->credit-=2; //Trying to confuse server?
(void) rou_alert(0,"SMTP Command <%s> from [%s] is unknown (config?)",
line,contact->peerip);
- (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321",
- CMDBAD);
- (void) transmit(contact,true,"%d-5.5.1 https://www.rfc-editor.org",CMDBAD);
- (void) transmit(contact,true,"%d 5.5.1 session %s is still running",
- CMDBAD,contact->mainsesid);
+ (void) eml_transmit(contact,true,"%d-5.5.1 Unrecognized command, "
+ "see RFC 5321",CMDBAD);
+ (void) eml_transmit(contact,true,"%d-5.5.1 https://www.rfc-editor.org",
+ CMDBAD);
+ (void) eml_transmit(contact,true,"%d 5.5.1 session %s is still running",
+ CMDBAD,contact->mainsesid);
break;
default :
contact->credit-=10; //Trying to bug server
(void) rou_alert(0,"%s Unable to find entry for code='%d' (Bug?)",OPEP,code);
- (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321",
- CMDBAD);
- (void) transmit(contact,true,"%d 2.0.0 Bug!, closing connection "
- "Immediatly (%s)",
- QUITOK,contact->mainsesid);
+ (void) eml_transmit(contact,true,"%d-5.5.1 Unrecognized command, "
+ "see RFC 5321",CMDBAD);
+ (void) eml_transmit(contact,true,"%d 2.0.0 Bug!, closing connection "
+ "Immediatly (%s)",
+ QUITOK,contact->mainsesid);
status=-1; //remote is a trouble maker
status=-3;
proceed=false;
}
break;
case 7 : //contact is good, then sending a signon
+ (void) prc_settitle("%s, incoming contact from [%s] on [%s:%s]",
+ appname,contact->peerip,
+ contact->locname,contact->locserv);
(void) log_fprintlog(contact->logptr,true,"Start CNT=%s",contact->mainsesid);
(void) log_fprintlog(contact->logptr,false,"(Contact open from [%s] to "
"[%s:%s])",