]> SAFE projects GIT repository - jmp/mailleur/commitdiff
adding module unieml
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 1 Aug 2024 23:59:02 +0000 (19:59 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 1 Aug 2024 23:59:02 +0000 (19:59 -0400)
lib/Makefile
lib/gestcp.c
lib/subrou.c
lib/unieml.c [new file with mode: 0644]
lib/unieml.h [new file with mode: 0644]
lib/unisoc.c
lib/unisoc.h

index c1066dc6dfa1571484674533b2f7bfe64f293282..c6d8a47e7efe9ad7bb4b1f1e82f98e8018c1def9 100644 (file)
@@ -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
index f4d6909d32b370e3bc50332328893de4d4da5b2c..9a83ca9820355d965116703c725eb90c0762da58 100644 (file)
@@ -15,6 +15,7 @@
 #include        <unistd.h>
 
 #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);
index d7bd77164bee895966787bfa25a554a0769cca3e..cdae49828a07b96a04973a55be7e586a506d0caf 100644 (file)
@@ -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 (file)
index 0000000..428a442
--- /dev/null
@@ -0,0 +1,49 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Implement all routine to manage SMTP low level  */
+/*     exchange.                                       */
+/*                                                     */
+/********************************************************/
+#include        <stdbool.h>
+#include        <stdio.h>
+
+#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 (file)
index 0000000..e5194e4
--- /dev/null
@@ -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
index cbd05a520a2dc89d3dbce7e2b43f5d7fcc8f2a59..c787862014d005334ef5f0c4e35abfdf914c3a3a 100644 (file)
@@ -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
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
 /*     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                               */
index f1235e8e1d2c1e114ac5198d91e0e2634274b28a..bea272678d340f6b6d7aec9f5781b252616a4fb0 100644 (file)
@@ -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);