View | Details | Raw Unified | Return to bug 23811
Collapse All | Expand All

(-)src/Makefile.inc1 (+4 lines)
Lines 208-213 Link Here
208
INCDIRS=	arpa g++/std objc protocols readline rpc rpcsvc openssl \
208
INCDIRS=	arpa g++/std objc protocols readline rpc rpcsvc openssl \
209
		security ss
209
		security ss
210
210
211
.if defined(SENDMAIL_MILTER)
212
INCDIRS+=	sendmail/libmilter sendmail/sendmail
213
.endif
214
211
#
215
#
212
# buildworld
216
# buildworld
213
#
217
#
(-)src/etc/defaults/make.conf (+15 lines)
Lines 314-316 Link Here
314
#SENDMAIL_LDFLAGS=
314
#SENDMAIL_LDFLAGS=
315
#SENDMAIL_LDADD=
315
#SENDMAIL_LDADD=
316
#SENDMAIL_DPADD=
316
#SENDMAIL_DPADD=
317
#
318
# Sendmail Mail Filter API (Experimental):
319
#
320
# The sendmail Mail Filter API (Milter) is designed to allow third-party
321
# programs access to mail messages as they are being processed in order to
322
# filter meta-information and content.
323
#
324
# see src/contrib/sendmail/libmilter/README for more information.
325
#
326
# By enableing the following variable, the sendmail daemon is built so that
327
# it can talk to the mail filter daemons. libmilter.a, libsmutils.a and
328
# the sendmail headers are installed, so that mail filter daemons can be
329
# built.
330
#
331
#SENDMAIL_MILTER=	yes
(-)src/etc/defaults/rc.conf (+1 lines)
Lines 302-307 Link Here
302
usbd_flags=""		# Flags to usbd (if enabled).
302
usbd_flags=""		# Flags to usbd (if enabled).
303
sendmail_enable="YES"	# Run the sendmail daemon (or NO).
303
sendmail_enable="YES"	# Run the sendmail daemon (or NO).
304
sendmail_flags="-bd -q30m" # Flags to sendmail (if enabled)
304
sendmail_flags="-bd -q30m" # Flags to sendmail (if enabled)
305
sendmail_milter_startup="/usr/local/etc/rc.milter" # milter startup script dirs.
305
dumpdev="NO"		# Device name to crashdump to (or NO).
306
dumpdev="NO"		# Device name to crashdump to (or NO).
306
enable_quotas="NO"      # turn on quotas on startup (or NO).
307
enable_quotas="NO"      # turn on quotas on startup (or NO).
307
check_quotas="YES"	# Check quotas on startup (or NO).
308
check_quotas="YES"	# Check quotas on startup (or NO).
(-)src/etc/mtree/BSD.include.dist (+6 lines)
Lines 77-82 Link Here
77
    ..
77
    ..
78
    security
78
    security
79
    ..
79
    ..
80
    sendmail
81
        libmilter
82
        ..
83
        sendmail
84
        ..
85
    ..
80
    ss
86
    ss
81
    ..
87
    ..
82
    sys
88
    sys
(-)src/etc/mtree/BSD.local.dist (+2 lines)
Lines 10-15 Link Here
10
    etc
10
    etc
11
        rc.d
11
        rc.d
12
        ..
12
        ..
13
        rc.milter
14
        ..
13
    ..
15
    ..
14
    include
16
    include
15
    ..
17
    ..
(-)src/etc/rc (+25 lines)
Lines 442-447 Link Here
442
case ${sendmail_enable} in
442
case ${sendmail_enable} in
443
[Yy][Ee][Ss])
443
[Yy][Ee][Ss])
444
	if [ -r /etc/mail/sendmail.cf ]; then
444
	if [ -r /etc/mail/sendmail.cf ]; then
445
		# For each valid dir in $sendmail_milter_startup,
446
		# search for init scripts matching *.sh
447
		#
448
		# (Hmm.. maybe this code should be turned into a function
449
		# and shared between local_startup & sendmail_milter_startup)
450
		#
451
		case ${sendmail_milter_startup} in
452
		[Nn][Oo] | '')
453
			;;
454
		*)
455
		#	echo -n 'Sendmail Milter initialization:'
456
			for dir in ${sendmail_milter_startup}; do
457
				if [ -d "${dir}" ]; then
458
					for script in ${dir}/*.sh; do
459
						if [ -x "${script}" ]; then
460
							(set -T
461
							 trap 'exit 1' 2
462
							 ${script} start)
463
						fi
464
					done
465
				fi
466
			done
467
		#	echo .
468
			;;
469
		esac
445
		echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
470
		echo -n ' sendmail';	/usr/sbin/sendmail ${sendmail_flags}
446
	fi
471
	fi
447
	;;
472
	;;
(-)src/etc/rc.shutdown (+35 lines)
Lines 91-96 Link Here
91
	;;
91
	;;
92
esac
92
esac
93
93
94
case ${sendmail_enable} in
95
[Yy][Ee][Ss])
96
	# Should we shutdown sendmail daemon here also?
97
#	killall -TERM sendmail
98
99
	# for each valid dir in $sendmail_milter_startup, search for init scripts matching *.sh
100
	case ${sendmail_milter_startup} in
101
	[Nn][Oo] | '')
102
		;;
103
	*)
104
		for dir in ${sendmail_milter_startup}; do
105
			if [ -d "${dir}" ]; then
106
				for script in ${dir}/*.sh; do
107
					if [ -x "${script}" ]; then
108
						grep -wq stop "${script}" || \
109
						    oldmilterscripts="${oldmilterscripts} ${script}"
110
# XXX not yet
111
#						(set -T
112
#						 trap 'exit 1' 2
113
#						 ${script} stop)
114
					fi
115
				done
116
			fi
117
		done
118
		if [ ! -z "${oldmilterscripts}" ]; then
119
			echo 'You still seem to have old-style rc.milter scripts:'
120
			echo ${oldmilterscripts}
121
			echo 'Please change them to recognize the "stop" option.'
122
		fi
123
		echo .
124
		;;
125
	esac
126
	;;
127
esac
128
94
# Insert other shutdown procedures here
129
# Insert other shutdown procedures here
95
130
96
echo '.'
131
echo '.'
(-)src/lib/Makefile (+4 lines)
Lines 28-33 Link Here
28
	libposix1e libresolv librpcsvc libsmdb libsmutil libss \
28
	libposix1e libresolv librpcsvc libsmdb libsmutil libss \
29
	libstand ${_libtelnet} libusb ${_libvgl} libwrap libxpg4 liby libz
29
	libstand ${_libtelnet} libusb ${_libvgl} libwrap libxpg4 liby libz
30
30
31
.if defined(SENDMAIL_MILTER)
32
SUBDIR+= libmilter
33
.endif
34
31
.if exists(${.CURDIR}/csu/${MACHINE_ARCH}-${OBJFORMAT})
35
.if exists(${.CURDIR}/csu/${MACHINE_ARCH}-${OBJFORMAT})
32
_csu=csu/${MACHINE_ARCH}-${OBJFORMAT}
36
_csu=csu/${MACHINE_ARCH}-${OBJFORMAT}
33
.elif exists(${.CURDIR}/csu/${MACHINE_ARCH})
37
.elif exists(${.CURDIR}/csu/${MACHINE_ARCH})
(-)src/lib/libmilter/Makefile (+51 lines)
Line 0 Link Here
1
# $FreeBSD$
2
3
MAINTAINER=	gshapiro@FreeBSD.org
4
5
SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail
6
.PATH:	${SENDMAIL_DIR}/libmilter
7
8
CFLAGS+=-I${SENDMAIL_DIR}/src -I${SENDMAIL_DIR}/include
9
CFLAGS+=-DNEWDB -DNIS -DMAP_REGEX -DNOT_SENDMAIL -D_FFR_MILTER
10
11
# User customizations to the sendmail build environment
12
CFLAGS+=${SENDMAIL_CFLAGS}
13
14
LIB=	milter
15
16
SRCS+=	comm.c engine.c handler.c listener.c main.c signal.c \
17
	sm_gethost.c smfi.c
18
19
SM_HDRS=src/bf.h src/bf_portable.h src/bf_torek.h src/conf.h \
20
	src/sendmail.h src/sfsasl.h src/statusd_shm.h src/timers.h
21
22
M_HDRS=	libmilter/mfapi.h libmilter/milter.h
23
24
SM2_HDRS=sendmail/cdefs.h sendmail/errstring.h sendmail/mailstats.h \
25
	sendmail/pathnames.h sendmail/sendmail.h sendmail/useful.h
26
27
.for h in ${SM_HDRS}
28
SENDMAIL_HDRS+= ${SENDMAIL_DIR}/${h}
29
.endfor
30
31
.for h in ${M_HDRS}
32
MILTER_HDRS+= ${SENDMAIL_DIR}/include/${h}
33
.endfor
34
35
.for h in ${SM2_HDRS}
36
SENDMAIL2_HDRS+= ${SENDMAIL_DIR}/include/${h}
37
.endfor
38
39
beforeinstall:
40
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
41
	    ${SENDMAIL_HDRS} ${DESTDIR}/usr/include/sendmail
42
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
43
	    ${MILTER_HDRS} ${DESTDIR}/usr/include/sendmail/libmilter
44
	${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
45
		${SENDMAIL2_HDRS} ${DESTDIR}/usr/include/sendmail/sendmail
46
47
sample:
48
	cc -I/usr/include/sendmail -o sample sample.c -lmilter \
49
		/usr/lib/libsmutil.a -pthread
50
51
.include <bsd.lib.mk>
(-)src/lib/libmilter/sample.c (+233 lines)
Line 0 Link Here
1
/* A trivial filter that logs all email to a file. */
2
3
#include <sys/types.h>
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <string.h>
7
#include <sysexits.h>
8
#include <unistd.h>
9
10
#include "libmilter/mfapi.h"
11
12
typedef int bool;
13
14
#ifndef FALSE
15
# define FALSE	0
16
#endif /* ! FALSE*/
17
#ifndef TRUE
18
# define TRUE	1
19
#endif /* ! TRUE*/
20
21
struct mlfiPriv
22
{
23
	char	*mlfi_fname;
24
	FILE	*mlfi_fp;
25
};
26
27
#define MLFIPRIV	((struct mlfiPriv *) smfi_getpriv(ctx))
28
29
extern sfsistat	 mlfi_cleanup(SMFICTX *, bool);
30
31
sfsistat
32
mlfi_envfrom(ctx, envfrom)
33
	SMFICTX *ctx;
34
	char **envfrom;
35
{
36
	struct mlfiPriv *priv;
37
	int fd;
38
39
	/* allocate some private memory */
40
	priv = malloc(sizeof *priv);
41
	if (priv == NULL)
42
	{
43
		/* can't accept this message right now */
44
		return SMFIS_TEMPFAIL;
45
	}
46
	memset(priv, '\0', sizeof *priv);
47
48
	/* open a file to store this message */
49
	priv->mlfi_fname = strdup("/tmp/msg.XXXXXXXX");
50
	if (priv->mlfi_fname == NULL)
51
	{
52
		free(priv);
53
		return SMFIS_TEMPFAIL;
54
	}
55
	if ((fd = mkstemp(priv->mlfi_fname)) < 0 ||
56
	    (priv->mlfi_fp = fdopen(fd, "w+")) == NULL)
57
	{
58
		free(priv->mlfi_fname);
59
		free(priv);
60
		return SMFIS_TEMPFAIL;
61
	}
62
63
	/* save the private data */
64
	smfi_setpriv(ctx, priv);
65
66
	/* continue processing */
67
	return SMFIS_CONTINUE;
68
}
69
70
sfsistat
71
mlfi_header(ctx, headerf, headerv)
72
	SMFICTX *ctx;
73
	char *headerf;
74
	char *headerv;
75
{
76
	/* write the header to the log file */
77
	fprintf(MLFIPRIV->mlfi_fp, "%s: %s\r\n", headerf, headerv);
78
79
	/* continue processing */
80
	return SMFIS_CONTINUE;
81
}
82
83
sfsistat
84
mlfi_eoh(ctx)
85
	SMFICTX *ctx;
86
{
87
	/* output the blank line between the header and the body */
88
	fprintf(MLFIPRIV->mlfi_fp, "\r\n");
89
90
	/* continue processing */
91
	return SMFIS_CONTINUE;
92
}
93
94
sfsistat
95
mlfi_body(ctx, bodyp, bodylen)
96
	SMFICTX *ctx;
97
	u_char *bodyp;
98
	size_t bodylen;
99
{
100
	/* output body block to log file */
101
	if (fwrite(bodyp, bodylen, 1, MLFIPRIV->mlfi_fp) <= 0)
102
	{
103
		/* write failed */
104
		(void) mlfi_cleanup(ctx, FALSE);
105
		return SMFIS_TEMPFAIL;
106
	}
107
108
	/* continue processing */
109
	return SMFIS_CONTINUE;
110
}
111
112
sfsistat
113
mlfi_eom(ctx)
114
	SMFICTX *ctx;
115
{
116
	return mlfi_cleanup(ctx, TRUE);
117
}
118
119
sfsistat
120
mlfi_close(ctx)
121
	SMFICTX *ctx;
122
{
123
	return SMFIS_ACCEPT;
124
}
125
126
sfsistat
127
mlfi_abort(ctx)
128
	SMFICTX *ctx;
129
{
130
	return mlfi_cleanup(ctx, FALSE);
131
}
132
133
sfsistat
134
mlfi_cleanup(ctx, ok)
135
	SMFICTX *ctx;
136
	bool ok;
137
{
138
	sfsistat rstat = SMFIS_CONTINUE;
139
	struct mlfiPriv *priv = MLFIPRIV;
140
	char *p;
141
	char host[512];
142
	char hbuf[1024];
143
144
	if (priv == NULL)
145
		return rstat;
146
147
	/* close the archive file */
148
	if (priv->mlfi_fp != NULL && fclose(priv->mlfi_fp) == EOF)
149
	{
150
		/* failed; we have to wait until later */
151
		rstat = SMFIS_TEMPFAIL;
152
		(void) unlink(priv->mlfi_fname);
153
	}
154
	else if (ok)
155
	{
156
		/* add a header to the message announcing our presence */
157
		if (gethostname(host, sizeof host) < 0)
158
			strlcpy(host, "localhost", sizeof host);
159
		p = strrchr(priv->mlfi_fname, '/');
160
		if (p == NULL)
161
			p = priv->mlfi_fname;
162
		else
163
			p++;
164
		snprintf(hbuf, sizeof hbuf, "%s@%s", p, host);
165
		smfi_addheader(ctx, "X-Archived", hbuf);
166
	}
167
	else
168
	{
169
		/* message was aborted -- delete the archive file */
170
		(void) unlink(priv->mlfi_fname);
171
	}
172
173
	/* release private memory */
174
	free(priv->mlfi_fname);
175
	free(priv);
176
	smfi_setpriv(ctx, NULL);
177
178
	/* return status */
179
	return rstat;
180
}
181
182
struct smfiDesc smfilter =
183
{
184
	"SampleFilter",	/* filter name */
185
	SMFI_VERSION,	/* version code -- do not change */
186
	SMFIF_ADDHDRS,	/* flags */
187
	NULL,		/* connection info filter */
188
	NULL,		/* SMTP HELO command filter */
189
	mlfi_envfrom,	/* envelope sender filter */
190
	NULL,		/* envelope recipient filter */
191
	mlfi_header,	/* header filter */
192
	mlfi_eoh,	/* end of header */
193
	mlfi_body,	/* body block filter */
194
	mlfi_eom,	/* end of message */
195
	mlfi_abort,	/* message aborted */
196
	mlfi_close	/* connection cleanup */
197
};
198
199
200
int
201
main(argc, argv)
202
	int argc;
203
	char *argv[];
204
{
205
	int c;
206
	const char *args = "p:";
207
208
	/* Process command line options */
209
	while ((c = getopt(argc, argv, args)) != -1)
210
	{
211
		switch (c)
212
		{
213
		  case 'p':
214
			if (optarg == NULL || *optarg == '\0')
215
			{
216
				(void) fprintf(stderr, "Illegal conn: %s\n",
217
					       optarg);
218
				exit(EX_USAGE);
219
			}
220
			(void) smfi_setconn(optarg);
221
			break;
222
223
		}
224
	}
225
	if (smfi_register(smfilter) == MI_FAILURE)
226
	{
227
		fprintf(stderr, "smfi_register failed\n");
228
		exit(EX_UNAVAILABLE);
229
	}
230
	return smfi_main();
231
}
232
233
/* eof */
(-)src/lib/libmilter/sample.sh (+20 lines)
Line 0 Link Here
1
#!/bin/sh
2
# Sample Filter Startup Scipt
3
#
4
# $FreeBSD$
5
#
6
7
case "$1" in
8
9
start)
10
	# We need to remove the old sock connection
11
	# otherwise ./sample will not run.
12
	if [ -S /var/run/f1.sock ]
13
	then
14
		rm /var/run/f1.sock
15
	fi
16
	./sample -p local:/var/run/f1.sock &
17
	echo -n ' sample'
18
19
stop)
20
	killall -TERM sample
(-)src/lib/libsmutil/Makefile (-1 / +4 lines)
Lines 15-22 Link Here
15
15
16
SRCS+=	debug.c errstring.c lockfile.c safefile.c snprintf.c strl.c
16
SRCS+=	debug.c errstring.c lockfile.c safefile.c snprintf.c strl.c
17
17
18
INTERNALLIB=		true
19
NOPIC=			true
18
NOPIC=			true
19
20
.if !defined(SENDMAIL_MILTER)
21
INTERNALLIB=		true
20
INTERNALSTATICLIB=	true
22
INTERNALSTATICLIB=	true
23
.endif
21
24
22
.include <bsd.lib.mk>
25
.include <bsd.lib.mk>
(-)src/usr.sbin/sendmail/Makefile (+4 lines)
Lines 23-28 Link Here
23
CFLAGS+=-I${SMDIR} -I${SENDMAIL_DIR}/include
23
CFLAGS+=-I${SMDIR} -I${SENDMAIL_DIR}/include
24
CFLAGS+=${DBMDEF} ${NIS} -DNETINET6 -DTCPWRAPPERS ${MAPS}
24
CFLAGS+=${DBMDEF} ${NIS} -DNETINET6 -DTCPWRAPPERS ${MAPS}
25
25
26
.if defined(SENDMAIL_MILTER)
27
CFLAGS+= -D_FFR_MILTER
28
.endif
29
26
SRCS=	alias.c arpadate.c bf_torek.c clock.c collect.c conf.c control.c \
30
SRCS=	alias.c arpadate.c bf_torek.c clock.c collect.c conf.c control.c \
27
	convtime.c daemon.c deliver.c domain.c envelope.c err.c headers.c \
31
	convtime.c daemon.c deliver.c domain.c envelope.c err.c headers.c \
28
	macro.c main.c map.c mci.c milter.c mime.c parseaddr.c queue.c \
32
	macro.c main.c map.c mci.c milter.c mime.c parseaddr.c queue.c \

Return to bug 23811