summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libmilter
diff options
context:
space:
mode:
authorgshapiro <gshapiro@FreeBSD.org>2001-01-21 22:17:06 +0000
committergshapiro <gshapiro@FreeBSD.org>2001-01-21 22:17:06 +0000
commit167a83e7b8733416154f871e39e86ba77eb1554d (patch)
tree4f725bdbff499cf7343d2eaeec15f8a0f0926140 /contrib/sendmail/libmilter
parentf84ac9120cb7d9f087e5dcb863c4bf25ba2985e6 (diff)
downloadFreeBSD-src-167a83e7b8733416154f871e39e86ba77eb1554d.zip
FreeBSD-src-167a83e7b8733416154f871e39e86ba77eb1554d.tar.gz
Import sendmail 8.11.2
Diffstat (limited to 'contrib/sendmail/libmilter')
-rw-r--r--contrib/sendmail/libmilter/Makefile.m49
-rw-r--r--contrib/sendmail/libmilter/README6
-rw-r--r--contrib/sendmail/libmilter/comm.c4
-rw-r--r--contrib/sendmail/libmilter/engine.c6
-rw-r--r--contrib/sendmail/libmilter/handler.c8
-rw-r--r--contrib/sendmail/libmilter/libmilter.h9
-rw-r--r--contrib/sendmail/libmilter/listener.c44
-rw-r--r--contrib/sendmail/libmilter/signal.c9
-rw-r--r--contrib/sendmail/libmilter/sm_gethost.c16
9 files changed, 88 insertions, 23 deletions
diff --git a/contrib/sendmail/libmilter/Makefile.m4 b/contrib/sendmail/libmilter/Makefile.m4
index 9ac7760..4b92464 100644
--- a/contrib/sendmail/libmilter/Makefile.m4
+++ b/contrib/sendmail/libmilter/Makefile.m4
@@ -7,9 +7,18 @@ SMSRCDIR= ifdef(`confSMSRCDIR', `confSMSRCDIR', `${SRCDIR}/sendmail')
PREPENDDEF(`confINCDIRS', `-I${SMSRCDIR} ')
bldPRODUCT_START(`library', `libmilter')
+define(`bldINSTALLABLE', `true')
define(`bldSOURCES', `main.c engine.c listener.c handler.c comm.c smfi.c signal.c sm_gethost.c ')
bldPUSH_SMLIB(`smutil')
+bldPUSH_INSTALL_TARGET(`install-mfapi')
bldPRODUCT_END
APPENDDEF(`confENVDEF', `-DNOT_SENDMAIL')
+divert(bldTARGETS_SECTION)
+# Install the API header file
+MFAPI= ${SRCDIR}/include/libmilter/mfapi.h
+install-mfapi: ${MFAPI}
+ ${INSTALL} ${MFAPI} ${DESTDIR}${INCLUDEDIR}
+divert(0)
+
bldFINISH
diff --git a/contrib/sendmail/libmilter/README b/contrib/sendmail/libmilter/README
index 486a268..ffe09c4 100644
--- a/contrib/sendmail/libmilter/README
+++ b/contrib/sendmail/libmilter/README
@@ -178,6 +178,10 @@ See the sendmail(8) manual page for more information.
| SOURCE FOR SAMPLE FILTER |
+--------------------------+
+Note that the filter below may not be thread safe on some operating
+systems. You should check your system man pages for the functions used
+below to verify the functions are thread safe.
+
/* A trivial filter that logs all email to a file. */
#include <sys/types.h>
@@ -412,4 +416,4 @@ main(argc, argv)
/* eof */
-$Revision: 8.9.2.1.2.12 $, Last updated $Date: 2000/09/19 19:40:13 $
+$Revision: 8.9.2.1.2.13 $, Last updated $Date: 2000/12/29 18:55:23 $
diff --git a/contrib/sendmail/libmilter/comm.c b/contrib/sendmail/libmilter/comm.c
index 31f432c..af1ee6d 100644
--- a/contrib/sendmail/libmilter/comm.c
+++ b/contrib/sendmail/libmilter/comm.c
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: comm.c,v 8.30.4.5 2000/08/14 09:04:47 gshapiro Exp $";
+static char id[] = "@(#)$Id: comm.c,v 8.30.4.6 2000/10/05 22:44:01 gshapiro Exp $";
#endif /* ! lint */
#if _FFR_MILTER
@@ -55,6 +55,7 @@ mi_rd_cmd(sd, timeout, cmd, rlen, name)
*cmd = '\0';
*rlen = 0;
+
if (sd >= FD_SETSIZE)
{
smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d",
@@ -62,6 +63,7 @@ mi_rd_cmd(sd, timeout, cmd, rlen, name)
*cmd = SMFIC_SELECT;
return NULL;
}
+
FD_Z;
i = 0;
while ((ret = select(sd + 1, &readset, NULL, &excset, timeout)) >= 1)
diff --git a/contrib/sendmail/libmilter/engine.c b/contrib/sendmail/libmilter/engine.c
index c2a3dc3..554631c 100644
--- a/contrib/sendmail/libmilter/engine.c
+++ b/contrib/sendmail/libmilter/engine.c
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: engine.c,v 8.67.4.14 2000/08/14 08:27:30 gshapiro Exp $";
+static char id[] = "@(#)$Id: engine.c,v 8.67.4.15 2000/12/29 19:43:10 gshapiro Exp $";
#endif /* ! lint */
#if _FFR_MILTER
@@ -381,7 +381,7 @@ sendreply(r, sd, timeout_ptr, ctx)
{
int ret = MI_SUCCESS;
- switch(r)
+ switch (r)
{
case SMFIS_CONTINUE:
ret = mi_wr_cmd(sd, timeout_ptr, SMFIR_CONTINUE, NULL, 0);
@@ -807,7 +807,7 @@ st_macros(g)
return _SMFIS_FAIL;
if ((argv = dec_argv(g->a_buf + 1, g->a_len - 1)) == NULL)
return _SMFIS_FAIL;
- switch(g->a_buf[0])
+ switch (g->a_buf[0])
{
case SMFIC_CONNECT:
i = CI_CONN;
diff --git a/contrib/sendmail/libmilter/handler.c b/contrib/sendmail/libmilter/handler.c
index f6e75e9..2ee5203 100644
--- a/contrib/sendmail/libmilter/handler.c
+++ b/contrib/sendmail/libmilter/handler.c
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: handler.c,v 8.19.4.2 2000/07/14 06:16:57 msk Exp $";
+static char id[] = "@(#)$Id: handler.c,v 8.19.4.3 2000/12/29 19:45:39 gshapiro Exp $";
#endif /* ! lint */
#if _FFR_MILTER
@@ -44,9 +44,15 @@ mi_handle_session(ctx)
return MI_FAILURE;
ret = mi_engine(ctx);
if (ValidSocket(ctx->ctx_sd))
+ {
(void) close(ctx->ctx_sd);
+ ctx->ctx_sd = INVALID_SOCKET;
+ }
if (ctx->ctx_reply != NULL)
+ {
free(ctx->ctx_reply);
+ ctx->ctx_reply = NULL;
+ }
if (ctx->ctx_privdata != NULL)
{
smi_log(SMI_LOG_WARN,
diff --git a/contrib/sendmail/libmilter/libmilter.h b/contrib/sendmail/libmilter/libmilter.h
index f43fd0e..358ba64 100644
--- a/contrib/sendmail/libmilter/libmilter.h
+++ b/contrib/sendmail/libmilter/libmilter.h
@@ -17,7 +17,7 @@
# define EXTERN
# define INIT(x) = x
# ifndef lint
-static char MilterlId[] = "@(#)$Id: libmilter.h,v 8.3.6.9 2000/09/01 00:49:04 ca Exp $";
+static char MilterlId[] = "@(#)$Id: libmilter.h,v 8.3.6.10 2000/11/20 21:15:36 ca Exp $";
# endif /* ! lint */
#else /* _DEFINE */
# define EXTERN extern
@@ -44,6 +44,13 @@ static char MilterlId[] = "@(#)$Id: libmilter.h,v 8.3.6.9 2000/09/01 00:49:04 ca
# define thread_create(ptid,wr,arg) pthread_create(ptid, NULL, wr, arg)
# define sthread_get_id() pthread_self()
+typedef pthread_mutex_t smutex_t;
+# define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0)
+# define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0)
+# define smutex_lock(mp) (pthread_mutex_lock(mp) == 0)
+# define smutex_unlock(mp) (pthread_mutex_unlock(mp) == 0)
+# define smutex_trylock(mp) (pthread_mutex_trylock(mp) == 0)
+
#include <sys/time.h>
/* version info */
diff --git a/contrib/sendmail/libmilter/listener.c b/contrib/sendmail/libmilter/listener.c
index c3ad445..8b1d952 100644
--- a/contrib/sendmail/libmilter/listener.c
+++ b/contrib/sendmail/libmilter/listener.c
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: listener.c,v 8.38.2.1.2.11 2000/09/01 00:49:04 ca Exp $";
+static char id[] = "@(#)$Id: listener.c,v 8.38.2.1.2.18 2000/12/29 19:44:28 gshapiro Exp $";
#endif /* ! lint */
#if _FFR_MILTER
@@ -47,7 +47,6 @@ mi_milteropen(conn, backlog, socksize, name)
char *p;
char *colon;
char *at;
- struct hostent *hp = NULL;
SOCKADDR addr;
if (conn == NULL || conn[0] == '\0')
@@ -299,6 +298,8 @@ mi_milteropen(conn, backlog, socksize, name)
}
else
{
+ struct hostent *hp = NULL;
+
hp = mi_gethostbyname(at, addr.sa.sa_family);
if (hp == NULL)
{
@@ -334,6 +335,9 @@ mi_milteropen(conn, backlog, socksize, name)
name, at, hp->h_addrtype);
return INVALID_SOCKET;
}
+# if _FFR_FREEHOSTENT && NETINET6
+ freehostent(hp);
+# endif /* _FFR_FREEHOSTENT && NETINET6 */
}
}
else
@@ -411,6 +415,8 @@ mi_thread_handle_wrapper(arg)
static socket_t listenfd = INVALID_SOCKET;
+static smutex_t L_Mutex;
+
/*
** MI_CLOSENER -- close listen socket
**
@@ -424,11 +430,13 @@ static socket_t listenfd = INVALID_SOCKET;
void
mi_closener()
{
+ (void) smutex_lock(&L_Mutex);
if (ValidSocket(listenfd))
{
(void) close(listenfd);
listenfd = INVALID_SOCKET;
}
+ (void) smutex_unlock(&L_Mutex);
}
/*
@@ -475,37 +483,56 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
smi_log(SMI_LOG_DEBUG,
"%s: Opening listen socket on conn %s",
smfi->xxfi_name, conn);
+ (void) smutex_init(&L_Mutex);
+ (void) smutex_lock(&L_Mutex);
listenfd = mi_milteropen(conn, backlog, &socksize, smfi->xxfi_name);
if (!ValidSocket(listenfd))
{
smi_log(SMI_LOG_FATAL,
"%s: Unable to create listening socket on conn %s",
smfi->xxfi_name, conn);
+ (void) smutex_unlock(&L_Mutex);
return MI_FAILURE;
}
clilen = socksize;
+
if (listenfd >= FD_SETSIZE)
{
smi_log(SMI_LOG_ERR, "%s: fd %d is larger than FD_SETSIZE %d",
smfi->xxfi_name, listenfd, FD_SETSIZE);
+ (void) smutex_unlock(&L_Mutex);
return MI_FAILURE;
}
+ (void) smutex_unlock(&L_Mutex);
while (mi_stop() == MILTER_CONT)
{
+ (void) smutex_lock(&L_Mutex);
+ if (!ValidSocket(listenfd))
+ {
+ (void) smutex_unlock(&L_Mutex);
+ break;
+ }
+
/* select on interface ports */
FD_ZERO(&readset);
- FD_SET((u_int) listenfd, &readset);
FD_ZERO(&excset);
+ FD_SET((u_int) listenfd, &readset);
FD_SET((u_int) listenfd, &excset);
chktime.tv_sec = MI_CHK_TIME;
chktime.tv_usec = 0;
r = select(listenfd + 1, &readset, NULL, &excset, &chktime);
if (r == 0) /* timeout */
+ {
+ (void) smutex_unlock(&L_Mutex);
continue; /* just check mi_stop() */
+ }
if (r < 0)
{
- if (errno == EINTR)
+ int err = errno;
+
+ (void) smutex_unlock(&L_Mutex);
+ if (err == EINTR)
continue;
ret = MI_FAILURE;
break;
@@ -514,11 +541,13 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
{
/* some error: just stop for now... */
ret = MI_FAILURE;
+ (void) smutex_unlock(&L_Mutex);
break;
}
connfd = accept(listenfd, (struct sockaddr *) &cliaddr,
&clilen);
+ (void) smutex_unlock(&L_Mutex);
if (!ValidSocket(connfd))
{
@@ -577,7 +606,7 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
if ((r = thread_create(&thread_id,
mi_thread_handle_wrapper,
- (void *) ctx)) != MI_SUCCESS)
+ (void *) ctx)) != 0)
{
smi_log(SMI_LOG_ERR,
"%s: thread_create() failed: %d",
@@ -596,8 +625,9 @@ mi_listener(conn, dbg, smfi, timeout, backlog)
}
if (ret != MI_SUCCESS)
mi_stop_milters(MILTER_ABRT);
- if (listenfd >= 0)
- (void) close(listenfd);
+ else
+ mi_closener();
+ (void) smutex_destroy(&L_Mutex);
return ret;
}
#endif /* _FFR_MILTER */
diff --git a/contrib/sendmail/libmilter/signal.c b/contrib/sendmail/libmilter/signal.c
index 9448d77..0bc5081 100644
--- a/contrib/sendmail/libmilter/signal.c
+++ b/contrib/sendmail/libmilter/signal.c
@@ -9,19 +9,12 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: signal.c,v 8.10.4.7 2000/09/01 00:49:04 ca Exp $";
+static char id[] = "@(#)$Id: signal.c,v 8.10.4.8 2000/11/20 21:15:37 ca Exp $";
#endif /* ! lint */
#if _FFR_MILTER
#include "libmilter.h"
-typedef pthread_mutex_t smutex_t;
-# define smutex_init(mp) (pthread_mutex_init(mp, NULL) == 0)
-# define smutex_destroy(mp) (pthread_mutex_destroy(mp) == 0)
-# define smutex_lock(mp) (pthread_mutex_lock(mp) == 0)
-# define smutex_unlock(mp) (pthread_mutex_unlock(mp) == 0)
-# define smutex_trylock(mp) (pthread_mutex_trylock(mp) == 0)
-
/*
** thread to handle signals
*/
diff --git a/contrib/sendmail/libmilter/sm_gethost.c b/contrib/sendmail/libmilter/sm_gethost.c
index fdbaebd..9541a93 100644
--- a/contrib/sendmail/libmilter/sm_gethost.c
+++ b/contrib/sendmail/libmilter/sm_gethost.c
@@ -9,7 +9,7 @@
*/
#ifndef lint
-static char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.2 2000/09/17 17:04:24 gshapiro Exp $";
+static char id[] = "@(#)$Id: sm_gethost.c,v 8.7.8.4 2000/12/19 04:26:33 gshapiro Exp $";
#endif /* ! lint */
#if _FFR_MILTER
@@ -61,6 +61,20 @@ getipnodebyname(name, family, flags, err)
_res.options &= ~RES_USE_INET6;
return h;
}
+
+# if _FFR_FREEHOSTENT
+void
+freehostent(h)
+ struct hostent *h;
+{
+ /*
+ ** Stub routine -- if they don't have getipnodeby*(),
+ ** they probably don't have the free routine either.
+ */
+
+ return;
+}
+# endif /* _FFR_FREEHOSTENT */
#endif /* NEEDSGETIPNODE && NETINET6 && __RES < 19990909 */
struct hostent *
OpenPOWER on IntegriCloud