#include "uniprc.h"
#include "gestcp.h"
-/*
-^L
-*/
-/********************************************************/
-/* */
-/* Procedure to free memory used by contact */
-/* */
-/********************************************************/
-static CONTYP *freecontact(CONTYP *contact)
-
-{
-#define OPEP "gestcp.c:freecontact"
-
-if (contact!=(CONTYP *)0) {
- contact->logptr=log_closelog(contact->logptr);
- contact->cursesid=rou_freestr(contact->cursesid);
- contact->mainsesid=rou_freestr(contact->mainsesid);
- contact->fqdn=rou_freestr(contact->fqdn);
- contact->peername=rou_freestr(contact->peername);
- contact->peerip=rou_freestr(contact->peerip);
- contact->locname=rou_freestr(contact->locname);
- contact->locserv=rou_freestr(contact->locserv);
- (void) free(contact);
- contact=(CONTYP *)0;
- }
-return contact;
-#undef OPEP
-}
/*
^L
*/
sent=soc_writebuffer(socptr,buffer,tosend);
return sent;
}
-/*
-^L
-*/
-/********************************************************/
-/* */
-/* Procedure to wait for a remote client. */
-/* return all reference to the established contact.*/
-/* */
-/********************************************************/
-PUBLIC CONTYP *tcp_getcontact(SOCPTR *socptr,int pos)
-
-{
-#define OPEP "gestcp.c:tcp_getcontact"
-#define MXCARIN 200 //maximun number of char
- //within carpile
-
-CONTYP *contact;
-int phase;
-_Bool proceed;
-
-contact=(CONTYP *)0;
-phase=0;
-proceed=true;
-while (proceed==true) {
- switch (phase){
- case 0 : //check for binding
- if (socptr==(SOCPTR *)0) {
- (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
- phase=999; //not going further
- }
- break;
- case 1 : //waiting from contact
- contact=calloc(1,sizeof(CONTYP));
- if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
- (void) rou_alert(0,"%s Unable to open contact",OPEP);
- contact=freecontact(contact);
- phase=999; //no contact
- }
- break;
- case 2 : //Preparing contact
- contact->mainsesid=eml_getmainsesid();
- contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
- contact->locname=soc_getaddrinfo(contact->socptr,true,true);
- contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
- contact->peername=soc_getaddrinfo(contact->socptr,false,true);
- contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
- contact->logptr=log_openlog(contact->mainsesid,true);
- break;
- case 3 : //check contact validity
- if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
- (void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
- contact=freecontact(contact);
- phase=999; //no identity
- }
- break;
- case 4 : //contact is good, then sending a signon
- (void) log_fprintlog(contact->logptr,false,"SID: %s -> Contact open",
- contact->mainsesid);
- break;
- default : //SAFE guard
- proceed=false;
- break;
- }
- phase++;
- }
-return contact;
-#undef MXCARIN
-#undef OPEP
-}
-/*
-^L
-*/
-/********************************************************/
-/* */
-/* Procedure to wait for a remote client. */
-/* return all reference to contact. */
-/* */
-/********************************************************/
-PUBLIC CONTYP *tcp_dropcontact(CONTYP *contact)
-
-{
-#define OPEP "gestcp.c:tcp_dropcontact"
-
-int phase;
-_Bool proceed;
-
-phase=0;
-proceed=true;
-while (proceed==true) {
- switch (phase){
- case 0 : //check for binding
- if (contact==(CONTYP *)0) {
- (void) rou_alert(0,"%s Contact pointer is NULL (Bug!?)",OPEP);
- phase=999; //not going further
- }
- break;
- case 1 : //properly closing remote contact
- (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
- contact->peerip,contact->locserv);
- contact->socptr=soc_release(contact->socptr);
- break;
- case 2 : //freeing contact memory
- contact=freecontact(contact);
- break;
- default : //SAFE guard
- proceed=false;
- break;
- }
- phase++;
- }
-return contact;
-#undef OPEP
-}
#include "devlog.h"
#include "devsoc.h"
-typedef struct {
- SOCPTR *socptr; //established contact context
- _Bool tlsok; //link is in crypted mode
- char *fqdn; //fully qualified domain from peer
- char *locname; //socket local hostname
- char *locserv; //local service port
- char *peerip; //socket remote peer IP
- char *peername; //socket remote peer FQDN
- int numreset; //number of SMTP reset received
- char *mainsesid;//session main ID
- char *cursesid; //current session ID
- char *mailfrom; //current mail from originator
- LOGPTR *logptr; //reference to session log
- }CONTYP;
-
//read a line from contact up to CRLF
extern int tcp_getline(SOCPTR *socptr,TIMESPEC *attend,char **lineptr);
//Transmit formated data to the contact channel
extern int tcp_write(SOCPTR *socptr,char *buffer,int tosend);
-//wait for an incoming contact
-extern CONTYP *tcp_getcontact(SOCPTR *socptr,int pos);
-
-//drop contact established by remote
-extern CONTYP *tcp_dropcontact(CONTYP *contact);
-
#endif
/* */
/********************************************************/
#include <stdbool.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lvleml.h"
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to free memory used by contact */
+/* */
+/********************************************************/
+static CONTYP *freecontact(CONTYP *contact)
+
+{
+#define OPEP "gestcp.c:freecontact"
+
+if (contact!=(CONTYP *)0) {
+ contact->logptr=log_closelog(contact->logptr);
+ contact->cursesid=rou_freestr(contact->cursesid);
+ contact->mainsesid=rou_freestr(contact->mainsesid);
+ contact->fqdn=rou_freestr(contact->fqdn);
+ contact->peername=rou_freestr(contact->peername);
+ contact->peerip=rou_freestr(contact->peerip);
+ contact->locname=rou_freestr(contact->locname);
+ contact->locserv=rou_freestr(contact->locserv);
+ (void) free(contact);
+ contact=(CONTYP *)0;
+ }
+return contact;
+#undef OPEP
+}
/*
^L
*/
phase=0;
while (proceed==true) {
switch (phase) {
- case 0 : //do we have already a from
+ case 0 : //do we have an originator
+ if ((mailfrom==(char *)0)||(strlen(mailfrom)<3)) {
+ (void) transmit(contact,"%d 5.5.0 %s %s originator not specified",
+ BADPAR,MAILF,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,"%d 5.5.1 %s %s already specified as originator",
- BADPAR,MAILF,contact->mailfrom);
+ (void) transmit(contact,"%d 5.5.1 %s '%s' %s",
+ BADPAR,MAILF,contact->mailfrom,
+ "was previously defined as originator"
+ );
phase=999; //no need to go further
}
break;
- case 1 : //clean mailfrom
+ case 2 : //check from format
+ if ((mailfrom[0]!='<')||(mailfrom[strlen(mailfrom)-1]!='>')) {
+ (void) transmit(contact,"%d 5.5.2 %s %s Format error",
+ BADPAR,MAILF,mailfrom);
+ phase=999; //no need to go further
+ }
+ mailfrom[strlen(mailfrom)-1]='\000';
+ (void) memmove(mailfrom,mailfrom+1,strlen(mailfrom));
break;
- case 2 : //everything ok
+ case 3 : //everything ok
contact->mailfrom=strdup(mailfrom);
- (void) transmit(contact,"%d 2.1.0 %s.. sender ok",
+ (void) transmit(contact,"%d 2.1.3 %s.. sender ok",
CMDOK,contact->mailfrom);
break;
default : //SAFE guard
return status;
#undef OPEP
}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to wait for a remote client. */
+/* return all reference to the established contact.*/
+/* */
+/********************************************************/
+PUBLIC CONTYP *eml_getcontact(SOCPTR *socptr,int pos)
+
+{
+#define OPEP "lvleml.c:eml_getcontact"
+#define MXCARIN 200 //maximun number of char
+ //within carpile
+
+CONTYP *contact;
+int phase;
+_Bool proceed;
+
+contact=(CONTYP *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase){
+ case 0 : //check for binding
+ if (socptr==(SOCPTR *)0) {
+ (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
+ phase=999; //not going further
+ }
+ break;
+ case 1 : //waiting from contact
+ contact=calloc(1,sizeof(CONTYP));
+ if ((contact->socptr=soc_accept(socptr,pos))==(SOCPTR *)0) {
+ (void) rou_alert(0,"%s Unable to open contact",OPEP);
+ contact=freecontact(contact);
+ phase=999; //no contact
+ }
+ break;
+ case 2 : //Preparing contact
+ contact->mainsesid=eml_getmainsesid();
+ contact->cursesid=eml_getcursesid(contact->mainsesid,contact->numreset);
+ contact->locname=soc_getaddrinfo(contact->socptr,true,true);
+ contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
+ contact->peername=soc_getaddrinfo(contact->socptr,false,true);
+ contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
+ contact->logptr=log_openlog(contact->mainsesid,true);
+ break;
+ case 3 : //check contact validity
+ if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
+ (void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
+ contact=freecontact(contact);
+ phase=999; //no identity
+ }
+ break;
+ case 4 : //contact is good, then sending a signon
+ (void) log_fprintlog(contact->logptr,false,"SID: %s -> Contact open",
+ contact->mainsesid);
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return contact;
+#undef MXCARIN
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to wait for a remote client. */
+/* return all reference to contact. */
+/* */
+/********************************************************/
+PUBLIC CONTYP *eml_dropcontact(CONTYP *contact)
+
+{
+#define OPEP "lvleml.c:eml_dropcontact"
+
+int phase;
+_Bool proceed;
+
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase){
+ case 0 : //check for binding
+ if (contact==(CONTYP *)0) {
+ (void) rou_alert(0,"%s Contact pointer is NULL (Bug!?)",OPEP);
+ phase=999; //not going further
+ }
+ break;
+ case 1 : //properly closing remote contact
+ (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
+ contact->peerip,contact->locserv);
+ contact->socptr=soc_release(contact->socptr);
+ break;
+ case 2 : //freeing contact memory
+ contact=freecontact(contact);
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return contact;
+#undef OPEP
+}
#include "gestcp.h"
+typedef struct {
+ SOCPTR *socptr; //established contact context
+ _Bool tlsok; //link is in crypted mode
+ char *fqdn; //fully qualified domain from peer
+ char *locname; //socket local hostname
+ char *locserv; //local service port
+ char *peerip; //socket remote peer IP
+ char *peername; //socket remote peer FQDN
+ int numreset; //number of SMTP reset received
+ char *mainsesid;//session main ID
+ char *cursesid; //current session ID
+ char *mailfrom; //current mail from originator
+ LOGPTR *logptr; //reference to session log
+ }CONTYP;
+
+
//procedure to extract line and proceed with peer contact
extern int eml_docontact(CONTYP *contact);
+//wait for an incoming contact
+extern CONTYP *eml_getcontact(SOCPTR *socptr,int pos);
+
+//drop contact established by remote
+extern CONTYP *eml_dropcontact(CONTYP *contact);
#endif
while (proceed==true) {
switch (phase) {
case 0 : //waiting contact
- if ((contact=tcp_getcontact(socptr,pos))==(CONTYP *)0)
+ if ((contact=eml_getcontact(socptr,pos))==(CONTYP *)0)
phase=999; //No contact!
break;
case 1 : //within forked process
}
break;
case 3 : //connection terminated
- contact=tcp_dropcontact(contact);
+ contact=eml_dropcontact(contact);
(void) rou_checkleak(false);
break;
default : //SAFE guard