From 8d1e5b0899af5595711b9c772f26909da5d3ebfd Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Thu, 1 Aug 2024 19:59:02 -0400 Subject: [PATCH] adding module unieml --- lib/Makefile | 7 +++ lib/gestcp.c | 3 + lib/subrou.c | 2 +- lib/unieml.c | 49 +++++++++++++++++ lib/unieml.h | 16 ++++++ lib/unisoc.c | 152 +++++++++++++++++---------------------------------- lib/unisoc.h | 8 +-- 7 files changed, 128 insertions(+), 109 deletions(-) create mode 100644 lib/unieml.c create mode 100644 lib/unieml.h diff --git a/lib/Makefile b/lib/Makefile index c1066dc..c6d8a47 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -18,6 +18,7 @@ clean : OBJS= \ modrec.o \ gestcp.o \ + unieml.o \ unipar.o uniprc.o unisig.o unisoc.o \ subrou.o @@ -36,8 +37,14 @@ modrec.o: \ gestcp.o: \ subrou.h \ + unieml.h \ + uniprc.h \ + unisig.h \ gestcp.h gestcp.c +unieml.o: \ + unieml.h unieml.c + unipar.o: \ subrou.h \ unipar.h unipar.c diff --git a/lib/gestcp.c b/lib/gestcp.c index f4d6909..9a83ca9 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -15,6 +15,7 @@ #include #include "subrou.h" +#include "unieml.h" #include "unisig.h" #include "uniprc.h" #include "gestcp.h" @@ -206,8 +207,10 @@ if (mode!=modopen) { (void) soc_modeunisoc(mode); (void) sig_modeunisig(mode); (void) prc_modeuniprc(mode); + (void) eml_modeunieml(mode); break; case false : + (void) eml_modeunieml(mode); (void) sig_modeunisig(mode); (void) prc_modeuniprc(mode); (void) soc_modeunisoc(mode); diff --git a/lib/subrou.c b/lib/subrou.c index d7bd771..cdae498 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -19,7 +19,7 @@ //version definition #define VERSION "0.3" -#define RELEASE "13" +#define RELEASE "14" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unieml.c b/lib/unieml.c new file mode 100644 index 0000000..428a442 --- /dev/null +++ b/lib/unieml.c @@ -0,0 +1,49 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Implement all routine to manage SMTP low level */ +/* exchange. */ +/* */ +/********************************************************/ +#include +#include + +#include "unieml.h" + +static _Bool modopen; //module open/close status + +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to "open/close" module and do */ +/* homework purpose */ +/* return zero if everything right */ +/* */ +/********************************************************/ +int eml_modeunieml(_Bool mode) + +{ +#define OPEP "unidoc.c:soc_modeunisoc" + +int status; + +status=0; +if (mode!=modopen) { + switch ((int)mode) { + case true : + break; + case false : + break; + default : + (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):", + OPEP,(int)mode); + status=-1; + break; + } + modopen=mode; + } +return status; +#undef OPEP +} diff --git a/lib/unieml.h b/lib/unieml.h new file mode 100644 index 0000000..e5194e4 --- /dev/null +++ b/lib/unieml.h @@ -0,0 +1,16 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Define all routine to manage SMTP low level */ +/* exchange. */ +/* */ +/********************************************************/ +#ifndef UNIEML +#define UNIEML + +#define SIGNON 220 //signon information + +//homework to be done before starting/stopping module. +extern int eml_modeunieml(_Bool mode); + +#endif diff --git a/lib/unisoc.c b/lib/unisoc.c index cbd05a5..c787862 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -17,7 +17,6 @@ #include "subrou.h" #include "unisoc.h" -#include "unisoc.h" //Need to have GNU_SOURCE define within CFLAGS #ifdef AI_ALL @@ -140,6 +139,56 @@ return handle; */ /********************************************************/ /* */ +/* Procedure fine the hostname related to an */ +/* address, if local is true return the local */ +/* hostname. */ +/* */ +/********************************************************/ +PUBLIC char *soc_getaddrname(int handle,_Bool local,const char *unknown) + +{ +#define OPEP "unisoc.c:soc_getaddrname" + +char *name; +struct sockaddr connip; +socklen_t taille; +int status; +char host[NI_MAXHOST]; + +name=(char *)unknown; +if (name==(char *)0) + name="NO_HOST_NAME"; +taille=sizeof(connip); +if (local==true) { + if ((status=getsockname(handle,&connip,&taille))==0) { + if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NAMEREQD)==0) + name=host; + } + } +else { + if ((status=getpeername(handle,&connip,&taille))==0) { + if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NUMERICHOST)==0) + name=host; + } + } +if (status<0) { + switch (errno) { + case ENOTCONN : //other side just vanished + break; + default : + (void) rou_alert(0,"%s, Unable to find reverse (local=%d, error=<%s>)", + OPEP,local,strerror(errno)); + break; + } + } +return strdup(name); +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to free memory used by a bind */ /* definition. */ /* */ @@ -309,107 +358,6 @@ while (proceed==true) { */ /********************************************************/ /* */ -/* Procedure to bind to a set of socket and return */ -/* true if all socket are open ready. */ -/* */ -/********************************************************/ -PUBLIC _Bool soc_mulopen(SOCTYP **bindings) - -{ -#define OPEP "unisoc.c:soc_mulopen" - -_Bool ready; -uid_t gid; -uid_t uid; -int phase; -_Bool proceed; - -ready=false; -gid=getegid(); //let be back to root if needed -uid=geteuid(); //to open device on < 1024 por -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - case 0 : //checking if the point is ready; - if (bindings==(SOCTYP **)0) { - (void) rou_alert(0,"%s bindings list pointer is NULL (Bug!?)",OPEP); - phase=999; //not going further - } - break; - case 1 : // - break; - if ((setegid(getgid())<0)||(seteuid(getuid())<0)) { - (void) rou_core_dump("%s, Unable to get root privilege! " - "(program config? error=<%s>)", - OPEP,strerror(errno)); - //program is crashing HARD - } - break; - case 2 : //binding on all interface - ready=true; - while (*bindings!=(SOCTYP *)0) { - if (soc_openbinding(*bindings)==false) - ready=false; //Trouble? Unable to open channel - bindings++; - } - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } -(void) setegid(gid); //set back the user,group ID -(void) seteuid(uid); -return ready; -#undef OPEP -} -/* -^L -*/ -/********************************************************/ -/* */ -/* Procedure to close all socket previously binded */ -/* */ -/********************************************************/ -PUBLIC void soc_mulclose(SOCTYP **bindings) - -{ -#define OPEP "unisoc.c:soc_mulclose" - -int phase; -_Bool proceed; - -phase=0; -proceed=true; -while (proceed==true) { - switch (phase) { - case 0 : //checking if the point is ready; - if (bindings==(SOCTYP **)0) { - (void) rou_alert(0,"%s bindings list pointer is NULL (Bug!?)",OPEP); - phase=999; //not going further - } - break; - case 1 : // - while (*bindings!=(SOCTYP *)0) { - (void) soc_closebinding(*bindings); - bindings++; - } - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } -#undef OPEP -} -/* -^L -*/ -/********************************************************/ -/* */ /* Procedure to wait an accept a connexion comming */ /* from a remote client. */ /* return the handle */ diff --git a/lib/unisoc.h b/lib/unisoc.h index f1235e8..bea2726 100644 --- a/lib/unisoc.h +++ b/lib/unisoc.h @@ -33,6 +33,8 @@ typedef struct { pid_t waiter; //binding manager }SOCTYP; +//procedure to get peer or local name related to a socket +extern char *soc_getaddrname(int handle,_Bool local,const char *unknown); //procedure to free all memory used by a TCP socket //definition (once closed) @@ -49,12 +51,6 @@ extern _Bool soc_openbinding(SOCTYP *binding); //procedure to close ONE socket extern void soc_closebinding(SOCTYP *binding); -//all socket are open in binding mode -extern _Bool soc_mulopen(SOCTYP **bindings); - -//procedure to close all sockets -extern void soc_mulclose(SOCTYP **bindings); - //procedure to wait and accept remote connexion extern int soc_accept(SOCTYP *binding,SOCKADDR *addr); -- 2.47.3