aboutsummaryrefslogtreecommitdiffstats
path: root/smtpd
diff options
context:
space:
mode:
Diffstat (limited to 'smtpd')
-rw-r--r--smtpd/Makefile7
-rw-r--r--smtpd/Makefile.am165
-rw-r--r--smtpd/aliases.c13
-rw-r--r--smtpd/auth.c6
-rw-r--r--smtpd/auth_bsd.c12
-rw-r--r--smtpd/auth_pwd.c9
-rw-r--r--smtpd/bounce.c6
-rw-r--r--smtpd/compress_backend.c6
-rw-r--r--smtpd/compress_gzip.c6
-rw-r--r--smtpd/config.c35
-rw-r--r--smtpd/control.c20
-rw-r--r--smtpd/delivery.c6
-rw-r--r--smtpd/delivery_filename.c13
-rw-r--r--smtpd/delivery_maildir.c6
-rw-r--r--smtpd/delivery_mbox.c8
-rw-r--r--smtpd/delivery_mda.c6
-rw-r--r--smtpd/dns.c14
-rw-r--r--smtpd/enqueue.c6
-rw-r--r--smtpd/envelope.c12
-rw-r--r--smtpd/expand.c12
-rw-r--r--smtpd/filter_api.c4
-rw-r--r--smtpd/forward.c6
-rw-r--r--smtpd/iobuf.c2
-rw-r--r--smtpd/ioev.c8
-rw-r--r--smtpd/libsmtpdfilter/Makefile19
-rw-r--r--smtpd/lka.c16
-rw-r--r--smtpd/lka_session.c13
-rw-r--r--smtpd/log.c9
-rw-r--r--smtpd/log.h2
-rw-r--r--smtpd/makemap.84
-rw-r--r--smtpd/makemap.c37
-rw-r--r--smtpd/makemap/Makefile25
-rw-r--r--smtpd/map.c6
-rw-r--r--smtpd/map_db.c12
-rw-r--r--smtpd/map_file.c6
-rw-r--r--smtpd/map_static.c6
-rw-r--r--smtpd/mda.c22
-rw-r--r--smtpd/mfa.c35
-rw-r--r--smtpd/mfa_session.c8
-rw-r--r--smtpd/mta.c14
-rw-r--r--smtpd/mta_session.c10
-rw-r--r--smtpd/parse.y46
-rw-r--r--smtpd/parser.c20
-rw-r--r--smtpd/parser.h14
-rw-r--r--smtpd/queue.c21
-rw-r--r--smtpd/queue_backend.c6
-rw-r--r--smtpd/queue_fsqueue.c11
-rw-r--r--smtpd/queue_ram.c6
-rw-r--r--smtpd/ruleset.c8
-rw-r--r--smtpd/scheduler.c7
-rw-r--r--smtpd/scheduler_backend.c6
-rw-r--r--smtpd/scheduler_ramqueue.c6
-rw-r--r--smtpd/smtp.c27
-rw-r--r--smtpd/smtp_session.c8
-rw-r--r--smtpd/smtpctl.c12
-rw-r--r--smtpd/smtpctl/Makefile27
-rw-r--r--smtpd/smtpd.815
-rw-r--r--smtpd/smtpd.c94
-rw-r--r--smtpd/smtpd.conf18
-rw-r--r--smtpd/smtpd.conf.54
-rw-r--r--smtpd/smtpd.h34
-rw-r--r--smtpd/smtpd/Makefile53
-rw-r--r--smtpd/smtpfilter.c2
-rw-r--r--smtpd/ssl.c19
-rw-r--r--smtpd/ssl_privsep.c2
-rw-r--r--smtpd/stat_backend.c6
-rw-r--r--smtpd/stat_ramstat.c5
-rw-r--r--smtpd/tree.c4
-rw-r--r--smtpd/user.c6
-rw-r--r--smtpd/user_pwd.c6
-rw-r--r--smtpd/util.c33
-rw-r--r--smtpd/waitq.c6
72 files changed, 835 insertions, 329 deletions
diff --git a/smtpd/Makefile b/smtpd/Makefile
deleted file mode 100644
index 98cb2c8c..00000000
--- a/smtpd/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $OpenBSD: Makefile,v 1.9 2009/03/18 01:56:52 jacekm Exp $
-
-.include <bsd.own.mk>
-
-SUBDIR = makemap smtpd smtpctl
-
-.include <bsd.subdir.mk>
diff --git a/smtpd/Makefile.am b/smtpd/Makefile.am
new file mode 100644
index 00000000..5bcda8c5
--- /dev/null
+++ b/smtpd/Makefile.am
@@ -0,0 +1,165 @@
+# In OpenBSD, smtpd's files are installed this way:
+#
+# /etc/mail/smtpd.conf
+# /usr/bin/mailq --> /usr/sbin/mailwrapper --> /usr/sbin/smtpctl
+# /usr/bin/newaliases --> /usr/sbin/mailwrapper --> /usr/libexec/smtpd/makemap
+# /usr/libexec/mail.local
+# /usr/sbin/makemap --> /usr/sbin/mailwrapper --> /usr/libexec/smtpd/makemap
+# /usr/sbin/smtpctl
+# /usr/sbin/smtpd
+#
+#
+# For OpenSMTPD portable, here's where files are installed:
+# (assuming PREFIX=/usr/local)
+#
+# /usr/local/etc/smtpd.conf
+# /usr/local/bin/mailq --> /usr/sbin/smtpctl
+# /usr/local/bin/newaliases --> /usr/local/libexec/opensmtpd-portable/makemap
+# /usr/local/libexec/mail.local
+# /usr/local/sbin/makemap --> /usr/local/libexec/opensmtpd-portable/makemap
+# /usr/local/sbin/smtpctl
+# /usr/local/sbin/smtpd
+
+sbin_PROGRAMS= smtpd smtpctl
+pkglibexec_PROGRAMS= makemap
+
+makemap_SOURCES= parse.y makemap.c aliases.c expand.c log.c util.c map.c \
+ map_static.c map_db.c map_file.c tree.c
+
+makemap_CFLAGS= -DNO_IO
+
+smtpd_SOURCES= aliases.c auth.c bounce.c compress_backend.c config.c \
+ control.c delivery.c dns.c envelope.c expand.c \
+ forward.c iobuf.c ioev.c lka.c lka_session.c log.c map.c\
+ mda.c mfa.c mfa_session.c mta.c mta_session.c parse.y \
+ queue.c queue_backend.c ruleset.c \
+ scheduler.c scheduler_backend.c smtp.c smtp_session.c \
+ smtpd.c ssl.c ssl_privsep.c stat_backend.c tree.c \
+ user.c util.c
+# backends
+smtpd_SOURCES+= auth_bsd.c
+smtpd_SOURCES+= auth_pwd.c
+smtpd_SOURCES+= compress_gzip.c
+smtpd_SOURCES+= delivery_filename.c
+smtpd_SOURCES+= delivery_maildir.c
+smtpd_SOURCES+= delivery_mbox.c
+smtpd_SOURCES+= delivery_mda.c
+smtpd_SOURCES+= map_db.c
+smtpd_SOURCES+= map_file.c
+smtpd_SOURCES+= map_static.c
+smtpd_SOURCES+= queue_fsqueue.c
+smtpd_SOURCES+= queue_ram.c
+smtpd_SOURCES+= scheduler_ramqueue.c
+smtpd_SOURCES+= stat_ramstat.c
+#smtpd_SOURCES+= stat_sqlite.c
+smtpd_SOURCES+= user_pwd.c
+
+# resolver
+smtpd_SOURCES+= ../contrib/lib/libc/asr/asr.c \
+ ../contrib/lib/libc/asr/asr_debug.c \
+ ../contrib/lib/libc/asr/asr_utils.c \
+ ../contrib/lib/libc/asr/gethostnamadr_async.c \
+ ../contrib/lib/libc/asr/res_send_async.c \
+ ../contrib/lib/libc/asr/getaddrinfo_async.c \
+ ../contrib/lib/libc/asr/getnameinfo_async.c
+
+smtpd_CFLAGS= -DIO_SSL -DASR_OPT_THREADSAFE=0
+
+smtpctl_SOURCES= enqueue.c parser.c log.c envelope.c \
+ queue_backend.c queue_fsqueue.c \
+ smtpctl.c util.c \
+ compress_backend.c compress_gzip.c
+
+smtpctl_CFLAGS= -DNO_IO
+
+INCLUDES= -I$(top_srcdir)/openbsd-compat \
+ -I$(top_srcdir)/contrib/lib/libc/asr
+
+LIBCOMPAT= $(top_builddir)/openbsd-compat/libopenbsd-compat.a
+
+LDADD= $(LIBCOMPAT)
+
+# need to define _GNU_SOURCE to get:
+# EAI_NODATA defined
+# {v,}asprintf
+# setres{g,u}id
+CFLAGS+= -D_GNU_SOURCE
+CPPFLAGS= -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@
+
+PATHS= -DSMTPD_CONFDIR=\"$(sysconfdir)\" \
+ -DPATH_SMTPCTL=\"$(sbindir)/smtpctl\" \
+ -DPATH_MAILLOCAL=\"$(libexecdir)/mail.local\"
+
+MANPAGES= aliases.5.out forward.5.out makemap.8.out \
+ newaliases.8.out smtpctl.8.out smtpd.8.out \
+ smtpd.conf.5.out
+MANPAGES_IN= aliases.5 forward.5 makemap.8 \
+ newaliases.8 smtpctl.8 smtpd.8 \
+ smtpd.conf.5
+
+CONFIGFILES= smtpd.conf.out
+CONFIGFILES_IN= smtpd.conf
+
+EXTRA_DIST= filter_api.h iobuf.h ioev.h log.h parser.h smtpd.h \
+ ../contrib/lib/libc/asr/asr.h \
+ ../contrib/lib/libc/asr/asr_private.h \
+ $(CONFIGFILES_IN) $(MANPAGES_IN)
+
+PATHSUBS= -e 's|/etc/mail/|$(sysconfdir)/|g' \
+ -e 's|/usr/libexec|$(libexecdir)|g' \
+ -e 's|/var/run/smtpd.sock|$(sockdir)/smtpd.sock|g'
+
+FIXPATHSCMD= $(SED) $(PATHSUBS)
+
+$(MANPAGES): $(MANPAGES_IN)
+ if test "$(MANTYPE)" = "cat"; then \
+ manpage=$(srcdir)/`echo $@ | sed 's/\.[1-9]\.out$$/\.0/'`; \
+ else \
+ manpage=$(srcdir)/`echo $@ | sed 's/\.out$$//'`; \
+ fi; \
+ if test "$(MANTYPE)" = "man"; then \
+ $(FIXPATHSCMD) $${manpage} | $(AWK) -f $(srcdir)/mdoc2man.awk > $@; \
+ else \
+ $(FIXPATHSCMD) $${manpage} > $@; \
+ fi
+
+$(CONFIGFILES): $(CONFIGFILES_IN)
+ conffile=`echo $@ | sed 's/.out$$//'`; \
+ $(FIXPATHSCMD) $(srcdir)/$${conffile} > $@
+
+
+# smtpd.conf
+# newaliases makemap
+install-exec-hook: $(CONFIGFILES) $(MANPAGES)
+ $(MKDIR_P) $(DESTDIR)$(sysconfdir)
+ $(MKDIR_P) $(DESTDIR)$(bindir)
+ $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)5
+ $(MKDIR_P) $(DESTDIR)$(mandir)/$(mansubdir)8
+
+ @if [ ! -f $(DESTDIR)$(sysconfdir)/smtpd.conf ]; then \
+ $(INSTALL) -m 644 smtpd.conf.out $(DESTDIR)$(sysconfdir)/smtpd.conf; \
+ else \
+ echo "$(DESTDIR)$(sysconfdir)/smtpd.conf already exists, install will not overwrite"; \
+ fi
+
+ ln -f $(DESTDIR)$(sbindir)/smtpctl$(EXEEXT) \
+ $(DESTDIR)$(bindir)/mailq$(EXEEXT);
+
+ ln -f $(DESTDIR)$(pkglibexecdir)/makemap$(EXEEXT) \
+ $(DESTDIR)$(bindir)/newaliases$(EXEEXT);
+
+ ln -f $(DESTDIR)$(pkglibexecdir)/makemap$(EXEEXT) \
+ $(DESTDIR)$(sbindir)/makemap$(EXEEXT);
+
+ $(INSTALL) -m 644 aliases.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/aliases.5
+ $(INSTALL) -m 644 forward.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/forward.5
+ $(INSTALL) -m 644 makemap.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/makemap.8
+ $(INSTALL) -m 644 newaliases.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/newaliases.8
+ $(INSTALL) -m 644 smtpctl.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/smtpctl.8
+ $(INSTALL) -m 644 smtpd.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/smtpd.8
+ $(INSTALL) -m 644 smtpd.conf.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/smtpd.conf.5
+
+
+uninstall-hook:
+ rm $(DESTDIR)$(bindir)/newaliases$(EXEEXT) \
+ $(DESTDIR)$(sbindir)/makemap$(EXEEXT)
diff --git a/smtpd/aliases.c b/smtpd/aliases.c
index 4827c8d3..7d0a0af6 100644
--- a/smtpd/aliases.c
+++ b/smtpd/aliases.c
@@ -16,20 +16,27 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <ctype.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include "imsg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_UTIL_H
#include <util.h>
+#endif
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
#include "smtpd.h"
#include "log.h"
diff --git a/smtpd/auth.c b/smtpd/auth.c
index 0c54f781..a694f16b 100644
--- a/smtpd/auth.c
+++ b/smtpd/auth.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/auth_bsd.c b/smtpd/auth_bsd.c
index b9aba84e..d0fbb6fb 100644
--- a/smtpd/auth_bsd.c
+++ b/smtpd/auth_bsd.c
@@ -16,14 +16,18 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#ifdef BSD_AUTH
#include <bsd_auth.h>
+#endif
#include <event.h>
#include <imsg.h>
#include <stdio.h>
@@ -39,5 +43,9 @@ struct auth_backend auth_backend_bsd = {
static int
auth_bsd(char *username, char *password)
{
+#ifdef BSD_AUTH
return auth_userokay(username, NULL, "auth-smtp", password);
+#else
+ return 0;
+#endif
}
diff --git a/smtpd/auth_pwd.c b/smtpd/auth_pwd.c
index 1e44f72a..49df634c 100644
--- a/smtpd/auth_pwd.c
+++ b/smtpd/auth_pwd.c
@@ -16,13 +16,18 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#ifdef HAVE_CRYPT_H
+#include <crypt.h> /* needed for crypt() */
+#endif
#include <event.h>
#include <imsg.h>
#include <pwd.h>
diff --git a/smtpd/bounce.c b/smtpd/bounce.c
index e2f09e61..297c748e 100644
--- a/smtpd/bounce.c
+++ b/smtpd/bounce.c
@@ -18,9 +18,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/compress_backend.c b/smtpd/compress_backend.c
index 802adf77..d3c60d6a 100644
--- a/smtpd/compress_backend.c
+++ b/smtpd/compress_backend.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/compress_gzip.c b/smtpd/compress_gzip.c
index 2d388268..8256fce1 100644
--- a/smtpd/compress_gzip.c
+++ b/smtpd/compress_gzip.c
@@ -17,9 +17,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/config.c b/smtpd/config.c
index c4d77c8a..05e2542c 100644
--- a/smtpd/config.c
+++ b/smtpd/config.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -220,3 +222,32 @@ config_peers(struct peer *p, uint peercount)
}
}
}
+
+#ifdef VALGRIND
+void free_peers(void)
+{
+ u_int i;
+
+ for (i = 0; i < PROC_COUNT; i++)
+ if (env->sc_ievs[i])
+ free(env->sc_ievs[i]);
+}
+
+void free_pipes(void)
+{
+ u_int i;
+ u_int j;
+
+ for (i = 0; i < PROC_COUNT; i++)
+ for (j = 0; j < PROC_COUNT; j++) {
+
+ if (i >= j || env->sc_instances[i] == 0 ||
+ env->sc_instances[j] == 0)
+ continue;
+
+ free(env->sc_pipes[i][j]);
+ free(env->sc_pipes[j][i]);
+
+ }
+}
+#endif
diff --git a/smtpd/control.c b/smtpd/control.c
index a00b0ac7..b575f483 100644
--- a/smtpd/control.c
+++ b/smtpd/control.c
@@ -18,9 +18,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/socket.h>
@@ -30,7 +32,8 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
-#include <imsg.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -267,6 +270,13 @@ control(void)
static void
control_shutdown(void)
{
+#ifdef VALGRIND
+ child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: control process exiting");
unlink(SMTPD_SOCKET);
_exit(0);
@@ -292,7 +302,7 @@ control_accept(int listenfd, short event, void *arg)
struct sockaddr_un sun;
struct ctl_conn *c;
- if (getdtablesize() - getdtablecount() < CONTROL_FD_RESERVE)
+ if (available_fds(CONTROL_FD_RESERVE))
goto pause;
len = sizeof(sun);
@@ -346,7 +356,7 @@ control_close(struct ctl_conn *c)
stat_backend->decrement("control.session", 1);
- if (getdtablesize() - getdtablecount() < CONTROL_FD_RESERVE)
+ if (available_fds(CONTROL_FD_RESERVE))
return;
if (!event_pending(&control_state.ev, EV_READ, NULL)) {
diff --git a/smtpd/delivery.c b/smtpd/delivery.c
index 1f959276..26757dd3 100644
--- a/smtpd/delivery.c
+++ b/smtpd/delivery.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/delivery_filename.c b/smtpd/delivery_filename.c
index d0aa28bf..52238ade 100644
--- a/smtpd/delivery_filename.c
+++ b/smtpd/delivery_filename.c
@@ -16,9 +16,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h> /* Needed for flock */
+#endif
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -70,7 +75,11 @@ delivery_filename_open(struct deliver *deliver)
error("open");
if (fstat(fd, &sb) < 0)
error("fstat");
+#ifndef HAVE_STAT_ST_FLAGS
if (S_ISREG(sb.st_mode) && flock(fd, LOCK_EX) < 0)
+#else
+ if (S_ISREG(sb.st_flags) && flock(fd, LOCK_EX) < 0)
+#endif
error("flock");
fp = fdopen(fd, "a");
if (fp == NULL)
diff --git a/smtpd/delivery_maildir.c b/smtpd/delivery_maildir.c
index 493cbce2..66ebefde 100644
--- a/smtpd/delivery_maildir.c
+++ b/smtpd/delivery_maildir.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/delivery_mbox.c b/smtpd/delivery_mbox.c
index 28002d8f..153bb285 100644
--- a/smtpd/delivery_mbox.c
+++ b/smtpd/delivery_mbox.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -36,7 +38,9 @@
#include "smtpd.h"
#include "log.h"
+#ifndef PATH_MAILLOCAL
#define PATH_MAILLOCAL "/usr/libexec/mail.local"
+#endif
extern char **environ;
diff --git a/smtpd/delivery_mda.c b/smtpd/delivery_mda.c
index 9568bdfb..e4509479 100644
--- a/smtpd/delivery_mda.c
+++ b/smtpd/delivery_mda.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/dns.c b/smtpd/dns.c
index c3dad9f7..c167fe32 100644
--- a/smtpd/dns.c
+++ b/smtpd/dns.c
@@ -18,10 +18,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/tree.h>
-#include <sys/queue.h>
+#include "sys-tree.h"
+#include "sys-queue.h"
#include <sys/uio.h>
#include <netinet/in.h>
@@ -29,7 +31,9 @@
#include <arpa/nameser.h>
#include <event.h>
-#include <imsg.h>
+#include <netdb.h>
+#include <resolv.h>
+#include "imsg.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -145,7 +149,7 @@ dns_async(struct imsgev *asker, int type, struct dns *query)
return;
case IMSG_DNS_PTR:
s->as = getnameinfo_async((struct sockaddr*)&query->ss,
- query->ss.ss_len,
+ SS_LEN(&query->ss),
s->query.host, sizeof(s->query.host), NULL, 0, 0, NULL);
stat_increment("lka.session.cname", 1);
if (s->as == NULL) {
@@ -325,7 +329,7 @@ next:
dns_reply(query, IMSG_DNS_HOST);
s->mxfound++;
}
- freeaddrinfo(ar.ar_addrinfo);
+ asr_freeaddrinfo(ar.ar_addrinfo);
}
s->as = NULL;
diff --git a/smtpd/enqueue.c b/smtpd/enqueue.c
index 2254a74c..abdbce51 100644
--- a/smtpd/enqueue.c
+++ b/smtpd/enqueue.c
@@ -17,10 +17,12 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/param.h>
-#include <sys/queue.h>
+#include "sys-queue.h"
#include <sys/socket.h>
-#include <sys/tree.h>
+#include "sys-tree.h"
#include <sys/types.h>
#include <ctype.h>
diff --git a/smtpd/envelope.c b/smtpd/envelope.c
index 09009487..f56b32e4 100644
--- a/smtpd/envelope.c
+++ b/smtpd/envelope.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -31,7 +33,7 @@
#include <errno.h>
#include <event.h>
#include <fcntl.h>
-#include <imsg.h>
+#include "imsg.h"
#include <inttypes.h>
#include <libgen.h>
#include <pwd.h>
@@ -508,14 +510,18 @@ ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf)
return 0;
ssin6.sin6_family = AF_INET6;
memcpy(ss, &ssin6, sizeof(ssin6));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss->ss_len = sizeof(struct sockaddr_in6);
+#endif
}
else {
if (inet_pton(AF_INET, buf, &ssin.sin_addr) != 1)
return 0;
ssin.sin_family = AF_INET;
memcpy(ss, &ssin, sizeof(ssin));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss->ss_len = sizeof(struct sockaddr_in);
+#endif
}
return 1;
}
diff --git a/smtpd/expand.c b/smtpd/expand.c
index b2b2113c..a5720b54 100644
--- a/smtpd/expand.c
+++ b/smtpd/expand.c
@@ -17,9 +17,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -28,6 +30,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_UTIL_H
+#include <util.h>
+#endif
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
#include "smtpd.h"
#include "log.h"
diff --git a/smtpd/filter_api.c b/smtpd/filter_api.c
index 789cb58e..fc377cec 100644
--- a/smtpd/filter_api.c
+++ b/smtpd/filter_api.c
@@ -16,8 +16,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
+#include "sys-queue.h"
#include <sys/uio.h>
#include <err.h>
diff --git a/smtpd/forward.c b/smtpd/forward.c
index ff1a5580..3464bce0 100644
--- a/smtpd/forward.c
+++ b/smtpd/forward.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/iobuf.c b/smtpd/iobuf.c
index 227e41fc..3b4a91bc 100644
--- a/smtpd/iobuf.c
+++ b/smtpd/iobuf.c
@@ -15,6 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/uio.h>
diff --git a/smtpd/ioev.c b/smtpd/ioev.c
index 4905c108..b07d2708 100644
--- a/smtpd/ioev.c
+++ b/smtpd/ioev.c
@@ -15,8 +15,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/param.h>
-#include <sys/queue.h>
+#include "sys-queue.h"
#include <sys/socket.h>
#include <err.h>
@@ -588,10 +590,10 @@ io_connect(struct io *io, const struct sockaddr *sa, const struct sockaddr *bsa)
io_set_blocking(sock, 0);
io_set_linger(sock, 0);
- if (bsa && bind(sock, bsa, bsa->sa_len) == -1)
+ if (bsa && bind(sock, bsa, SA_LEN(bsa)) == -1)
goto fail;
- if (connect(sock, sa, sa->sa_len) == -1)
+ if (connect(sock, sa, SA_LEN(sa)) == -1)
if (errno != EINPROGRESS)
goto fail;
diff --git a/smtpd/libsmtpdfilter/Makefile b/smtpd/libsmtpdfilter/Makefile
deleted file mode 100644
index 6c627f47..00000000
--- a/smtpd/libsmtpdfilter/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
-<<<<<<< HEAD
-# $OpenBSD: Makefile,v 1.2 2012/06/16 16:16:09 chl Exp $
-=======
-# $OpenBSD: Makefile,v 1.3 2012/08/02 13:38:39 okan Exp $
->>>>>>> master
-
-.PATH: ${.CURDIR}/..
-
-LIB= smtpdfilter
-SRCS= filter_api.c
-DEBUGLIBS= no
-NOPROFILE= yes
-NOPIC= yes
-
-install:
- @echo -n
-
-.include <bsd.own.mk>
-.include <bsd.lib.mk>
diff --git a/smtpd/lka.c b/smtpd/lka.c
index eb412c50..19c68ec0 100644
--- a/smtpd/lka.c
+++ b/smtpd/lka.c
@@ -17,9 +17,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/wait.h>
@@ -30,7 +32,9 @@
#include <err.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include <netdb.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <pwd.h>
#include <resolv.h>
#include <signal.h>
@@ -247,6 +251,12 @@ lka_sig_handler(int sig, short event, void *p)
void
lka_shutdown(void)
{
+#ifdef VALGRIND
+ child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
log_info("info: lookup agent exiting");
_exit(0);
}
diff --git a/smtpd/lka_session.c b/smtpd/lka_session.c
index e207cd94..aa7080e2 100644
--- a/smtpd/lka_session.c
+++ b/smtpd/lka_session.c
@@ -17,9 +17,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/wait.h>
@@ -29,7 +31,7 @@
#include <ctype.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include "imsg.h"
#include <resolv.h>
#include <pwd.h>
#include <signal.h>
@@ -317,6 +319,11 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
/* no aliases found, query forward file */
lks->rule = rule;
lks->node = xn;
+
+#ifdef VALGRIND
+ bzero(&fwreq, sizeof(fwreq));
+#endif
+
fwreq.id = lks->id;
(void)strlcpy(fwreq.as_user, xn->u.user, sizeof(fwreq.as_user));
imsg_compose_event(env->sc_ievs[PROC_PARENT],
diff --git a/smtpd/log.c b/smtpd/log.c
index c5738952..89346497 100644
--- a/smtpd/log.c
+++ b/smtpd/log.c
@@ -16,9 +16,11 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -30,6 +32,8 @@
#include <string.h>
#include <syslog.h>
#include <time.h>
+#include <unistd.h> /* getpid */
+
#include "log.h"
@@ -77,6 +81,7 @@ vlog(int pri, const char *fmt, va_list ap)
char *nfmt;
if (debug) {
+ fprintf(stderr, "%d: ", getpid());
/* best effort in out of mem situations */
if (asprintf(&nfmt, "%s\n", fmt) == -1) {
vfprintf(stderr, fmt, ap);
diff --git a/smtpd/log.h b/smtpd/log.h
index ce2e454e..86bbbfa3 100644
--- a/smtpd/log.h
+++ b/smtpd/log.h
@@ -16,6 +16,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "openbsd-compat.h"
+
void log_init(int);
void log_verbose(int);
void log_warn(const char *, ...)
diff --git a/smtpd/makemap.8 b/smtpd/makemap.8
index fe08a98a..bab64466 100644
--- a/smtpd/makemap.8
+++ b/smtpd/makemap.8
@@ -85,8 +85,8 @@ In addition to adding an entry to the primary domain map,
one must add a filter rule that accepts mail for the domain
map, for example:
.Bd -literal -offset indent
-map primary "/etc/mail/primary"
-accept for domain map primary deliver to mbox
+map "primary" { source db "/etc/mail/primary.db" }
+accept for domain map "primary" deliver to mbox
.Ed
.Sh VIRTUAL DOMAINS
Virtual domains are kept in maps.
diff --git a/smtpd/makemap.c b/smtpd/makemap.c
index 746c9216..ab0b3cf8 100644
--- a/smtpd/makemap.c
+++ b/smtpd/makemap.c
@@ -17,15 +17,26 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h> /* Needed for flock */
+#endif
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/tree.h>
-#include <sys/queue.h>
+#include "sys-tree.h"
+#include "sys-queue.h"
#include <sys/param.h>
#include <sys/socket.h>
-#include <db.h>
#include <ctype.h>
+#ifdef HAVE_DB_H
+#include <db.h>
+#elif defined(HAVE_DB1_DB_H)
+#include <db1/db.h>
+#elif defined(HAVE_DB_185_H)
+#include <db_185.h>
+#endif
#include <err.h>
#include <errno.h>
#include <event.h>
@@ -34,13 +45,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <util.h>
#include <unistd.h>
+#ifdef HAVE_UTIL_H
+#include <util.h>
+#endif
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
#include "smtpd.h"
#include "log.h"
-#define PATH_ALIASES "/etc/mail/aliases"
+#define PATH_ALIASES SMTPD_CONFDIR "/aliases"
extern char *__progname;
@@ -188,7 +204,16 @@ main(int argc, char *argv[])
if (mkstemp(dbname) == -1)
err(1, "mkstemp");
- db = dbopen(dbname, O_EXLOCK|O_RDWR|O_SYNC, 0644, dbtype, NULL);
+/* XXX */
+#ifndef O_EXLOCK
+#define O_EXLOCK 0
+#endif
+ /* Depending on the Linux distrib, sometimes dbopen() flags
+ * O_SYNC must be avoid, and O_TRUNC have to be used
+ * XXX: it should be properly checked and handled in configure script */
+
+ /* db = dbopen(dbname, O_EXLOCK|O_RDWR|O_SYNC, 0644, dbtype, NULL); */
+ db = dbopen(dbname, O_EXLOCK|O_RDWR|O_TRUNC, 0644, dbtype, NULL);
if (db == NULL) {
warn("dbopen: %s", dbname);
goto bad;
diff --git a/smtpd/makemap/Makefile b/smtpd/makemap/Makefile
deleted file mode 100644
index 5fe4e87e..00000000
--- a/smtpd/makemap/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# $OpenBSD: Makefile,v 1.16 2012/10/14 11:58:23 gilles Exp $
-
-.PATH: ${.CURDIR}/..
-
-PROG= makemap
-BINOWN= root
-
-BINMODE?=555
-
-BINDIR= /usr/libexec/smtpd
-MAN= makemap.8 newaliases.8
-
-CFLAGS+= -g3 -ggdb -I${.CURDIR}/..
-CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS+= -Wmissing-declarations
-CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
-CFLAGS+= -Wsign-compare -Wbounded
-CFLAGS+= -DNO_IO
-
-SRCS= parse.y makemap.c aliases.c expand.c log.c util.c map.c \
- map_static.c map_db.c map_file.c tree.c
-
-DPADD+= ${LIBUTIL} ${LIBCRYPTO}
-LDADD+= -lutil -lcrypto
-.include <bsd.prog.mk>
diff --git a/smtpd/map.c b/smtpd/map.c
index a5558be9..4a2a0be9 100644
--- a/smtpd/map.c
+++ b/smtpd/map.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/map_db.c b/smtpd/map_db.c
index afbd2e1c..baac882e 100644
--- a/smtpd/map_db.c
+++ b/smtpd/map_db.c
@@ -16,13 +16,21 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
+#ifdef HAVE_DB_H
#include <db.h>
+#elif defined(HAVE_DB1_DB_H)
+#include <db1/db.h>
+#elif defined(HAVE_DB_185_H)
+#include <db_185.h>
+#endif
#include <ctype.h>
#include <err.h>
#include <event.h>
diff --git a/smtpd/map_file.c b/smtpd/map_file.c
index b867f9fc..2ce6d811 100644
--- a/smtpd/map_file.c
+++ b/smtpd/map_file.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/map_static.c b/smtpd/map_static.c
index 9f998243..2df69cfa 100644
--- a/smtpd/map_static.c
+++ b/smtpd/map_static.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/mda.c b/smtpd/mda.c
index 8002298b..83a4995f 100644
--- a/smtpd/mda.c
+++ b/smtpd/mda.c
@@ -19,9 +19,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -29,7 +31,8 @@
#include <err.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <inttypes.h>
#include <pwd.h>
#include <signal.h>
@@ -38,7 +41,9 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
+#if defined(HAVE_STRNVIS) && defined(HAVE_VIS_H)
#include <vis.h>
+#endif
#include "smtpd.h"
#include "log.h"
@@ -100,6 +105,10 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
uint32_t id;
int n;
+#ifdef VALGRIND
+ bzero(&deliver, sizeof(deliver));
+#endif
+
if (iev->proc == PROC_QUEUE) {
switch (imsg->hdr.type) {
@@ -327,6 +336,13 @@ mda_sig_handler(int sig, short event, void *p)
static void
mda_shutdown(void)
{
+#ifdef VALGRIND
+ child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: mail delivery agent exiting");
_exit(0);
}
diff --git a/smtpd/mfa.c b/smtpd/mfa.c
index 921d7505..297a06b5 100644
--- a/smtpd/mfa.c
+++ b/smtpd/mfa.c
@@ -17,17 +17,20 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/wait.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <err.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -168,6 +171,13 @@ mfa_shutdown(void)
pid = waitpid(WAIT_MYPGRP, NULL, 0);
} while (pid != -1 || (pid == -1 && errno == EINTR));
+#ifdef VALGRIND
+ child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: mail filter exiting");
_exit(0);
}
@@ -244,6 +254,10 @@ mfa_test_connect(struct envelope *e)
{
struct submit_status ss;
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
ss.id = e->session_id;
ss.code = 530;
ss.envelope = *e;
@@ -256,6 +270,10 @@ mfa_test_helo(struct envelope *e)
{
struct submit_status ss;
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
ss.id = e->session_id;
ss.code = 530;
ss.envelope = *e;
@@ -268,6 +286,10 @@ mfa_test_mail(struct envelope *e)
{
struct submit_status ss;
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
ss.id = e->session_id;
ss.code = 530;
ss.u.maddr = e->sender;
@@ -298,6 +320,10 @@ mfa_test_rcpt(struct envelope *e)
{
struct submit_status ss;
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
ss.id = e->session_id;
ss.code = 530;
ss.u.maddr = e->rcpt;
@@ -417,8 +443,7 @@ mfa_fork_filter(struct filter *filter)
/* filter */
dup2(sockpair[0], STDIN_FILENO);
- if (closefrom(STDERR_FILENO + 1) < 0)
- exit(1);
+ closefrom(STDERR_FILENO + 1);
execl(filter->path, filter->name, NULL);
exit(1);
diff --git a/smtpd/mfa_session.c b/smtpd/mfa_session.c
index e63864d6..db079ab4 100644
--- a/smtpd/mfa_session.c
+++ b/smtpd/mfa_session.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/wait.h>
@@ -28,7 +30,7 @@
#include <ctype.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include "imsg.h"
#include <resolv.h>
#include <signal.h>
#include <stdio.h>
diff --git a/smtpd/mta.c b/smtpd/mta.c
index 4e414c07..b0121a2b 100644
--- a/smtpd/mta.c
+++ b/smtpd/mta.c
@@ -19,9 +19,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -32,6 +34,7 @@
#include <imsg.h>
#include <inttypes.h>
#include <netdb.h>
+#include <grp.h> /* needed for setgroups */
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -209,6 +212,13 @@ mta_sig_handler(int sig, short event, void *p)
static void
mta_shutdown(void)
{
+#ifdef VALGRIND
+ child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: mail transfer agent exiting");
_exit(0);
}
diff --git a/smtpd/mta_session.c b/smtpd/mta_session.c
index 9ad17e64..25681189 100644
--- a/smtpd/mta_session.c
+++ b/smtpd/mta_session.c
@@ -19,9 +19,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -270,6 +272,10 @@ mta_enter_state(struct mta_session *s, int newstate)
int max_reuse;
ssize_t q;
+#ifdef VALGRIND
+ bzero(&batch, sizeof(batch));
+#endif
+
again:
oldstate = s->state;
diff --git a/smtpd/parse.y b/smtpd/parse.y
index 52a5a192..b8ef9a6e 100644
--- a/smtpd/parse.y
+++ b/smtpd/parse.y
@@ -22,9 +22,12 @@
*/
%{
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include <sys/time.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -39,16 +42,19 @@
#include <errno.h>
#include <event.h>
#include <ifaddrs.h>
-#include <imsg.h>
+#include "imsg.h"
#include <inttypes.h>
#include <netdb.h>
#include <paths.h>
#include <pwd.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifdef HAVE_UTIL_H
#include <util.h>
+#endif
#include "smtpd.h"
#include "log.h"
@@ -120,7 +126,7 @@ typedef struct {
%token AS QUEUE COMPRESSION SIZE LISTEN ON ANY PORT EXPIRE
%token MAP HASH LIST SINGLE SSL SMTPS CERTIFICATE
-%token DB LDAP FILE DOMAIN SOURCE
+%token DB LDAP FILE_ DOMAIN SOURCE
%token RELAY BACKUP VIA DELIVER TO MAILDIR MBOX HOSTNAME
%token ACCEPT REJECT INCLUDE ERROR MDA FROM FOR
%token ARROW AUTH TLS LOCAL VIRTUAL TAG ALIAS FILTER KEY
@@ -419,7 +425,7 @@ main : QUEUE compression {
*/
;
-mapsource : SOURCE FILE STRING {
+mapsource : SOURCE FILE_ STRING {
strlcpy(map->m_src, "file", sizeof map->m_src);
if (strlcpy(map->m_config, $3, sizeof(map->m_config))
>= sizeof(map->m_config))
@@ -919,7 +925,7 @@ lookup(char *s)
{ "deliver", DELIVER },
{ "domain", DOMAIN },
{ "expire", EXPIRE },
- { "file", FILE },
+ { "file", FILE_ },
{ "filter", FILTER },
{ "for", FOR },
{ "from", FROM },
@@ -936,7 +942,7 @@ lookup(char *s)
{ "mbox", MBOX },
{ "mda", MDA },
{ "on", ON },
- { "plain", FILE },
+ { "plain", FILE_ },
{ "port", PORT },
{ "queue", QUEUE },
{ "reject", REJECT },
@@ -1463,7 +1469,9 @@ host_v4(const char *s, in_port_t port)
h = xcalloc(1, sizeof(*h), "host_v4");
sain = (struct sockaddr_in *)&h->ss;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
sain->sin_len = sizeof(struct sockaddr_in);
+#endif
sain->sin_family = AF_INET;
sain->sin_addr.s_addr = ina.s_addr;
sain->sin_port = port;
@@ -1484,7 +1492,9 @@ host_v6(const char *s, in_port_t port)
h = xcalloc(1, sizeof(*h), "host_v6");
sin6 = (struct sockaddr_in6 *)&h->ss;
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
sin6->sin6_len = sizeof(struct sockaddr_in6);
+#endif
sin6->sin6_family = AF_INET6;
sin6->sin6_port = port;
memcpy(&sin6->sin6_addr, &ina6, sizeof(ina6));
@@ -1532,13 +1542,17 @@ host_dns(const char *s, const char *tag, const char *cert,
if (res->ai_family == AF_INET) {
sain = (struct sockaddr_in *)&h->ss;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
sain->sin_len = sizeof(struct sockaddr_in);
+#endif
sain->sin_addr.s_addr = ((struct sockaddr_in *)
res->ai_addr)->sin_addr.s_addr;
sain->sin_port = port;
} else {
sin6 = (struct sockaddr_in6 *)&h->ss;
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
sin6->sin6_len = sizeof(struct sockaddr_in6);
+#endif
memcpy(&sin6->sin6_addr, &((struct sockaddr_in6 *)
res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
sin6->sin6_port = port;
@@ -1610,14 +1624,18 @@ interface(const char *s, const char *tag, const char *cert,
case AF_INET:
sain = (struct sockaddr_in *)&h->ss;
*sain = *(struct sockaddr_in *)p->ifa_addr;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
sain->sin_len = sizeof(struct sockaddr_in);
+#endif
sain->sin_port = port;
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)&h->ss;
*sin6 = *(struct sockaddr_in6 *)p->ifa_addr;
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
sin6->sin6_len = sizeof(struct sockaddr_in6);
+#endif
sin6->sin6_port = port;
break;
@@ -1659,6 +1677,10 @@ set_localaddrs(void)
map_add(m, "0.0.0.0/0", NULL);
map_add(m, "::/0", NULL);
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
if (getifaddrs(&ifap) == -1)
fatal("getifaddrs");
@@ -1672,14 +1694,18 @@ set_localaddrs(void)
case AF_INET:
sain = (struct sockaddr_in *)&ss;
*sain = *(struct sockaddr_in *)p->ifa_addr;
+#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
sain->sin_len = sizeof(struct sockaddr_in);
+#endif
map_add(m, ss_to_text(&ss), NULL);
break;
case AF_INET6:
sin6 = (struct sockaddr_in6 *)&ss;
*sin6 = *(struct sockaddr_in6 *)p->ifa_addr;
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
sin6->sin6_len = sizeof(struct sockaddr_in6);
+#endif
map_add(m, ss_to_text(&ss), NULL);
break;
}
@@ -1737,6 +1763,11 @@ bad:
int
is_if_in_group(const char *ifname, const char *groupname)
{
+#ifndef OpenBSD
+ if (strcmp(groupname, "all") == 0)
+ return (1);
+ return (0);
+#else
unsigned int len;
struct ifgroupreq ifgr;
struct ifg_req *ifg;
@@ -1774,4 +1805,5 @@ is_if_in_group(const char *ifname, const char *groupname)
end:
close(s);
return ret;
+#endif
}
diff --git a/smtpd/parser.c b/smtpd/parser.c
index c93386de..0789c193 100644
--- a/smtpd/parser.c
+++ b/smtpd/parser.c
@@ -18,10 +18,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <event.h>
@@ -33,20 +35,6 @@
#include "parser.h"
-enum token_type {
- NOTOKEN,
- ENDTOKEN,
- KEYWORD,
- VARIABLE
-};
-
-struct token {
- enum token_type type;
- const char *keyword;
- int value;
- const struct token *next;
-};
-
static const struct token t_log[];
static const struct token t_main[];
static const struct token t_pause[];
diff --git a/smtpd/parser.h b/smtpd/parser.h
index 01227026..1197cfe4 100644
--- a/smtpd/parser.h
+++ b/smtpd/parser.h
@@ -45,4 +45,18 @@ struct parse_result {
const char *data;
};
+enum token_type {
+ NOTOKEN,
+ ENDTOKEN,
+ KEYWORD,
+ VARIABLE
+};
+
+struct token {
+ enum token_type type;
+ const char *keyword;
+ int value;
+ const struct token *next;
+};
+
struct parse_result *parse(int, char *[]);
diff --git a/smtpd/queue.c b/smtpd/queue.c
index fd8d74a7..f021d069 100644
--- a/smtpd/queue.c
+++ b/smtpd/queue.c
@@ -18,16 +18,20 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <err.h>
#include <event.h>
-#include <imsg.h>
+#include <fcntl.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <inttypes.h>
#include <libgen.h>
#include <pwd.h>
@@ -59,6 +63,10 @@ queue_imsg(struct imsgev *iev, struct imsg *imsg)
uint64_t id;
uint32_t msgid;
+#ifdef VALGRIND
+ bzero(&ss, sizeof(ss));
+#endif
+
if (iev->proc == PROC_SMTP) {
e = imsg->data;
@@ -356,6 +364,13 @@ queue_sig_handler(int sig, short event, void *p)
static void
queue_shutdown(void)
{
+#ifdef VALGRIND
+// child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: queue handler exiting");
_exit(0);
}
diff --git a/smtpd/queue_backend.c b/smtpd/queue_backend.c
index bf9b02b0..55ab56fd 100644
--- a/smtpd/queue_backend.c
+++ b/smtpd/queue_backend.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/queue_fsqueue.c b/smtpd/queue_fsqueue.c
index 0eccad4e..65da871a 100644
--- a/smtpd/queue_fsqueue.c
+++ b/smtpd/queue_fsqueue.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -533,7 +535,12 @@ fsqueue_qwalk(void *hdl, uint64_t *evpid)
break;
if (e->fts_namelen != 16)
break;
+#if HAVE_STRUCT_STAT_ST_MTIM
if (timespeccmp(&e->fts_statp->st_mtim, &startup, >))
+#endif
+#if HAVE_STRUCT_STAT_ST_MTIMSPEC
+ if (timespeccmp(&e->fts_statp->st_mtimspec, &startup, >))
+#endif
break;
tmp = NULL;
*evpid = strtoull(e->fts_name, &tmp, 16);
diff --git a/smtpd/queue_ram.c b/smtpd/queue_ram.c
index ea5d6346..d979611c 100644
--- a/smtpd/queue_ram.c
+++ b/smtpd/queue_ram.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/ruleset.c b/smtpd/ruleset.c
index 9722b320..23b224e0 100644
--- a/smtpd/ruleset.c
+++ b/smtpd/ruleset.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -121,7 +123,7 @@ ruleset_cmp_source(const char *s1, const char *s2)
if (n1.ss.ss_family != n2.ss.ss_family)
return 0;
- if (n1.ss.ss_len != n2.ss.ss_len)
+ if (SS_LEN(&n1.ss) != SS_LEN(&n2.ss))
return 0;
return ruleset_match_mask(&n1.ss, &n2);
diff --git a/smtpd/scheduler.c b/smtpd/scheduler.c
index 70f543f4..fb6d50f8 100644
--- a/smtpd/scheduler.c
+++ b/smtpd/scheduler.c
@@ -19,9 +19,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -31,6 +33,7 @@
#include <err.h>
#include <errno.h>
#include <event.h>
+#include <grp.h> /* needed for setgroups */
#include <imsg.h>
#include <inttypes.h>
#include <libgen.h>
diff --git a/smtpd/scheduler_backend.c b/smtpd/scheduler_backend.c
index 6fccd4da..53abe0fc 100644
--- a/smtpd/scheduler_backend.c
+++ b/smtpd/scheduler_backend.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/scheduler_ramqueue.c b/smtpd/scheduler_ramqueue.c
index 6b2514ff..95b5779f 100644
--- a/smtpd/scheduler_ramqueue.c
+++ b/smtpd/scheduler_ramqueue.c
@@ -17,9 +17,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/smtp.c b/smtpd/smtp.c
index 73067afc..a51e4b9d 100644
--- a/smtpd/smtp.c
+++ b/smtpd/smtp.c
@@ -18,16 +18,19 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <err.h>
#include <errno.h>
#include <event.h>
-#include <imsg.h>
+#include <grp.h> /* needed for setgroups */
+#include "imsg.h"
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
@@ -291,6 +294,13 @@ smtp_sig_handler(int sig, short event, void *p)
static void
smtp_shutdown(void)
{
+#ifdef VALGRIND
+// child_free();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_info("info: smtp server exiting");
_exit(0);
}
@@ -381,8 +391,10 @@ smtp_setup_events(void)
ssl_setup(l);
}
+ /* XXX chl */
log_debug("debug: smtp: will accept at most %d clients",
- (getdtablesize() - getdtablecount())/2 - SMTP_FD_RESERVE);
+ /* (getdtablesize() - getdtablecount())/2 - SMTP_FD_RESERVE); */
+ (getdtablesize() - 42)/2 - SMTP_FD_RESERVE);
}
static void
@@ -546,12 +558,7 @@ smtp_destroy(struct session *session)
static int
smtp_can_accept(void)
{
- uint32_t max;
-
- max = (getdtablesize() - getdtablecount())/2 - SMTP_FD_RESERVE;
- if (sessions < max)
- return 1;
- return 0;
+ return (!available_fds(SMTP_FD_RESERVE + 2));
}
/*
diff --git a/smtpd/smtp_session.c b/smtpd/smtp_session.c
index 39637ffc..0702a733 100644
--- a/smtpd/smtp_session.c
+++ b/smtpd/smtp_session.c
@@ -19,9 +19,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
@@ -445,6 +447,7 @@ session_rfc5321_mail_handler(struct session *s, char *args)
session_enter_state(s, S_MAIL_MFA);
session_imsg(s, PROC_MFA, IMSG_MFA_MAIL, 0, 0, -1, &s->s_msg,
sizeof(s->s_msg));
+
return 1;
}
@@ -1078,6 +1081,7 @@ session_destroy(struct session *s, const char * reason)
if (s->s_flags & F_ZOMBIE)
goto finalize;
+ log_debug("session_destroy: s->datafp = %p", s->datafp);
if (s->datafp != NULL)
fclose(s->datafp);
diff --git a/smtpd/smtpctl.c b/smtpd/smtpctl.c
index 9569fa0a..a2b72d91 100644
--- a/smtpd/smtpctl.c
+++ b/smtpd/smtpctl.c
@@ -19,13 +19,21 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/un.h>
#include <sys/param.h>
+#include <net/if.h>
+/* #include <net/if_media.h> */
+/* #include <net/if_types.h> */
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <err.h>
#include <errno.h>
#include <event.h>
diff --git a/smtpd/smtpctl/Makefile b/smtpd/smtpctl/Makefile
deleted file mode 100644
index 3c046ad1..00000000
--- a/smtpd/smtpctl/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-# $OpenBSD: Makefile,v 1.29 2012/10/07 15:46:38 chl Exp $
-
-.PATH: ${.CURDIR}/..
-
-PROG= smtpctl
-BINOWN= root
-
-BINMODE?=555
-
-BINDIR= /usr/sbin
-MAN= smtpctl.8
-
-CFLAGS+= -g3 -ggdb -I${.CURDIR}/..
-CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS+= -Wmissing-declarations
-CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
-CFLAGS+= -Wsign-compare -Wbounded
-CFLAGS+= -DNO_IO
-
-SRCS= enqueue.c parser.c log.c envelope.c
-SRCS+= queue_backend.c queue_fsqueue.c
-SRCS+= smtpctl.c util.c
-SRCS+= compress_backend.c compress_gzip.c
-
-LDADD+= -lutil -lz
-DPADD+= ${LIBUTIL} ${LIBZ}
-.include <bsd.prog.mk>
diff --git a/smtpd/smtpd.8 b/smtpd/smtpd.8
index 3edb2e09..09c280a9 100644
--- a/smtpd/smtpd.8
+++ b/smtpd/smtpd.8
@@ -88,17 +88,8 @@ Do not listen on SMTP sockets.
Produce more verbose output.
.El
.Pp
-.Nm
-is not enabled by default.
-In order to use it as the system mailer,
-ensure the mail queue is empty,
-then stop
-.Xr sendmail 8 :
-.Bd -literal -offset indent
-# /etc/rc.d/sendmail stop
-.Ed
-.Pp
-Modify the current
+If you are running a BSD Operating System,
+you should use and modify
.Xr mailwrapper 8
settings by editing
.Pa /etc/mailer.conf :
@@ -114,8 +105,6 @@ Rebuild the aliases database,
and enable the daemon:
.Bd -literal -offset indent
# newaliases
-# echo "sendmail_flags=NO" \*(Gt\*(Gt /etc/rc.conf.local
-# echo "smtpd_flags=" \*(Gt\*(Gt /etc/rc.conf.local
# /etc/rc.d/smtpd start
.Ed
.Sh FILES
diff --git a/smtpd/smtpd.c b/smtpd/smtpd.c
index b6aa4954..101cae3a 100644
--- a/smtpd/smtpd.c
+++ b/smtpd/smtpd.c
@@ -18,9 +18,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
+#include <sys/file.h> /* Needed for flock */
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/wait.h>
@@ -31,9 +34,13 @@
#include <dirent.h>
#include <err.h>
#include <errno.h>
-#include <fcntl.h>
#include <event.h>
-#include <imsg.h>
+#include <fcntl.h>
+#include <grp.h> /* needed for setgroups */
+#ifdef HAVE_LOGIN_CAP_H
+#include <login_cap.h>
+#endif
+#include "imsg.h"
#include <paths.h>
#include <pwd.h>
#include <signal.h>
@@ -114,6 +121,30 @@ static int profstat;
struct tree children;
+/* Saved arguments to main(). */
+char **saved_argv;
+int saved_argc;
+
+#ifdef VALGRIND
+void clean_setproctitle(void)
+{
+ int i;
+
+ log_debug("clean_setproctitle");
+
+ for (i = 0; i < saved_argc; i++)
+ free(saved_argv[i]);
+
+ free(saved_argv);
+
+#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
+ for (i = 0; environ[i] != NULL; i++)
+ free(environ[i]);
+ free(environ);
+#endif
+}
+#endif /* VALGRIND */
+
static void
parent_imsg(struct imsgev *iev, struct imsg *imsg)
{
@@ -247,6 +278,15 @@ parent_shutdown(void)
pid = waitpid(WAIT_MYPGRP, NULL, 0);
} while (pid != -1 || (pid == -1 && errno == EINTR));
+#ifdef VALGRIND
+ child_free();
+ purge_config(PURGE_EVERYTHING);
+ free_pipes();
+ free_peers();
+ clean_setproctitle();
+ event_base_free(NULL);
+#endif
+
log_warnx("warn: parent terminating");
exit(0);
}
@@ -296,9 +336,14 @@ parent_send_config_listeners(void)
if ((l->fd = socket(l->ss.ss_family, SOCK_STREAM, 0)) == -1)
fatal("smtpd: socket");
opt = 1;
+#ifdef SO_REUSEADDR
if (setsockopt(l->fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0)
fatal("smtpd: setsockopt");
- if (bind(l->fd, (struct sockaddr *)&l->ss, l->ss.ss_len) == -1)
+#else
+ if (setsockopt(l->fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0)
+ fatal("smtpd: setsockopt");
+#endif
+ if (bind(l->fd, (struct sockaddr *)&l->ss, SS_LEN(&l->ss)) == -1)
fatal("smtpd: bind");
imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_CONF_LISTENER,
0, 0, l->fd, l, sizeof(*l));
@@ -475,7 +520,7 @@ parent_sig_handler(int sig, short event, void *p)
int
main(int argc, char *argv[])
{
- int c;
+ int c, i;
int debug, verbose;
int opts, flags;
const char *conffile = CONF_FILE;
@@ -495,6 +540,19 @@ main(int argc, char *argv[])
{ PROC_QUEUE, imsg_dispatch }
};
+ /* Save argv. Duplicate so setproctitle emulation doesn't clobber it */
+ saved_argc = argc;
+ saved_argv = __xcalloc(argc + 1, sizeof(*saved_argv));
+ for (i = 0; i < argc; i++)
+ saved_argv[i] = __xstrdup(argv[i]);
+ saved_argv[i] = NULL;
+
+#ifndef HAVE_SETPROCTITLE
+ /* Prepare for later setproctitle emulation */
+ compat_init_setproctitle(argc, argv);
+ argv = saved_argv;
+#endif
+
env = &smtpd;
flags = 0;
@@ -590,6 +648,8 @@ main(int argc, char *argv[])
if (parse_config(&smtpd, conffile, opts))
exit(1);
+ seed_rng();
+
if (strlcpy(env->sc_conffile, conffile, MAXPATHLEN) >= MAXPATHLEN)
errx(1, "config file exceeds MAXPATHLEN");
@@ -693,6 +753,8 @@ main(int argc, char *argv[])
purge_timeout.tv_usec = 0;
evtimer_add(&purge_ev, &purge_timeout);
+ log_debug("libevent %s (%s)", event_get_version(), event_get_method());
+
if (event_dispatch() < 0)
fatal("smtpd: event_dispatch");
@@ -771,7 +833,10 @@ child_add(pid_t pid, int type, const char *title)
void
imsg_event_add(struct imsgev *iev)
{
+ int err;
+
if (iev->handler == NULL) {
+ log_debug("imsg_event_add: iev->handler=NULL");
imsg_flush(&iev->ibuf);
return;
}
@@ -780,9 +845,11 @@ imsg_event_add(struct imsgev *iev)
if (iev->ibuf.w.queued)
iev->events |= EV_WRITE;
- event_del(&iev->ev);
+ if ((err = event_del(&iev->ev)) != 0)
+ fatal("imsg_event_add: event_del");
event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data);
- event_add(&iev->ev, NULL);
+ if ((err = event_add(&iev->ev, NULL)) != 0)
+ fatal("imsg_event_add: event_add");
}
void
@@ -939,8 +1006,7 @@ forkmda(struct imsgev *iev, uint32_t id,
dup2(allout, STDOUT_FILENO) < 0 ||
dup2(allout, STDERR_FILENO) < 0)
error("forkmda: dup2");
- if (closefrom(STDERR_FILENO + 1) < 0)
- error("closefrom");
+ closefrom(STDERR_FILENO + 1);
if (setgroups(1, &u.gid) ||
setresgid(u.gid, u.gid, u.gid) ||
setresuid(u.uid, u.uid, u.uid))
@@ -1038,10 +1104,12 @@ offline_enqueue(char *name)
_exit(1);
}
+#ifdef HAVE_CHFLAGS
if (chflags(path, 0) == -1) {
log_warn("warn: smtpd: chflags: %s", path);
_exit(1);
}
+#endif
pw = getpwuid(sb.st_uid);
if (pw == NULL) {
@@ -1059,10 +1127,11 @@ offline_enqueue(char *name)
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) ||
- closefrom(STDERR_FILENO + 1) == -1)
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
_exit(1);
+ closefrom(STDERR_FILENO + 1);
+
if ((fp = fopen(path, "r")) == NULL)
_exit(1);
@@ -1190,7 +1259,6 @@ imsg_dispatch(int fd, short event, void *p)
return;
}
}
-
if (event & EV_WRITE) {
if (msgbuf_write(&iev->ibuf.w) == -1)
err(1, "%s: msgbuf_write", proc_to_str(smtpd_process));
diff --git a/smtpd/smtpd.conf b/smtpd/smtpd.conf
new file mode 100644
index 00000000..bc6aa32d
--- /dev/null
+++ b/smtpd/smtpd.conf
@@ -0,0 +1,18 @@
+# $OpenBSD: smtpd.conf,v 1.5 2012/10/11 21:16:28 gilles Exp $
+
+# This is the smtpd server system-wide configuration file.
+# See smtpd.conf(5) for more information.
+
+# To accept external mail, replace with: listen on all
+#
+# XXX try to find a portable way to get the IP interface
+#listen on lo0
+listen on 127.0.0.1
+
+map aliases source db "/etc/mail/aliases.db"
+
+# Uncomment the following to accept external mail for domain "example.org"
+#
+# accept from any for domain "example.org" alias aliases deliver to mbox
+accept for local alias aliases deliver to mbox
+accept for any relay
diff --git a/smtpd/smtpd.conf.5 b/smtpd/smtpd.conf.5
index d8710fc9..b229c15a 100644
--- a/smtpd/smtpd.conf.5
+++ b/smtpd/smtpd.conf.5
@@ -445,9 +445,7 @@ Spool directories for mail during processing.
.Sh EXAMPLES
The default
.Nm
-file which ships with
-.Ox
-listens on the loopback network interface (lo0),
+file listens on the loopback network interface (lo0),
and allows for mail from users and daemons on the local machine,
as well as permitting email to remote servers.
Some more complex configurations are given below.
diff --git a/smtpd/smtpd.h b/smtpd/smtpd.h
index 0c0d197e..d7a6dc29 100644
--- a/smtpd/smtpd.h
+++ b/smtpd/smtpd.h
@@ -18,6 +18,16 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#if LIBEVENT_MAJOR_VERSION < 2
+#include <event.h>
+#else
+#include <event2/event_struct.h>
+#endif
+
+#include "imsg.h"
+
+#include "openbsd-compat.h"
+
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
@@ -26,7 +36,11 @@
#include "ioev.h"
#include "iobuf.h"
-#define CONF_FILE "/etc/mail/smtpd.conf"
+
+#ifndef SMTPD_CONFDIR
+#define SMTPD_CONFDIR "/etc"
+#endif
+#define CONF_FILE SMTPD_CONFDIR "/smtpd.conf"
#define MAX_LISTEN 16
#define PROC_COUNT 9
#define MAX_NAME_SIZE 64
@@ -47,14 +61,21 @@
#define SMTPD_QUEUE_INTERVAL (15 * 60)
#define SMTPD_QUEUE_MAXINTERVAL (4 * 60 * 60)
#define SMTPD_QUEUE_EXPIRY (4 * 24 * 60 * 60)
+#ifndef SMTPD_USER
#define SMTPD_USER "_smtpd"
-#define SMTPD_FILTER_USER "_smtpmfa"
-#define SMTPD_SOCKET "/var/run/smtpd.sock"
-#define SMTPD_BANNER "220 %s ESMTP OpenSMTPD"
+#endif
+#define SMTPD_FILTER_USER SMTPD_USER "mfa"
+#ifndef SMTPD_SOCKDIR
+#define SMTPD_SOCKDIR "/var/run"
+#endif
+#define SMTPD_SOCKET SMTPD_SOCKDIR "/smtpd.sock"
+#define SMTPD_BANNER "220 %s ESMTP OpenSMTPD-portable"
#define SMTPD_SESSION_TIMEOUT 300
#define SMTPD_BACKLOG 5
+#ifndef PATH_SMTPCTL
#define PATH_SMTPCTL "/usr/sbin/smtpctl"
+#endif
#define PATH_SPOOL "/var/spool/smtpd"
#define PATH_OFFLINE "/offline"
@@ -961,6 +982,10 @@ void configure(void);
void init_pipes(void);
void config_pipes(struct peer *, uint);
void config_peers(struct peer *, uint);
+#ifdef VALGRIND
+void free_pipes(void);
+void free_peers(void);
+#endif
/* control.c */
@@ -1213,6 +1238,7 @@ int text_to_netaddr(struct netaddr *, const char *);
int text_to_relayhost(struct relayhost *, const char *);
void *xmalloc(size_t, const char *);
void *xcalloc(size_t, size_t, const char *);
+void *xrealloc(void *, size_t, const char *);
char *xstrdup(const char *, const char *);
void *xmemdup(const void *, size_t, const char *);
void iobuf_xinit(struct iobuf *, size_t, size_t, const char *);
diff --git a/smtpd/smtpd/Makefile b/smtpd/smtpd/Makefile
deleted file mode 100644
index 076b589e..00000000
--- a/smtpd/smtpd/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
-# $OpenBSD: Makefile,v 1.57 2012/10/14 11:58:23 gilles Exp $
-
-.PATH: ${.CURDIR}/.. /usr/src/lib/libc/asr
-
-PROG= smtpd
-
-SRCS= aliases.c auth.c bounce.c compress_backend.c config.c \
- control.c delivery.c dns.c envelope.c \
- expand.c forward.c iobuf.c ioev.c lka.c lka_session.c \
- log.c map.c mda.c mfa.c mfa_session.c mta.c \
- mta_session.c parse.y queue.c queue_backend.c ruleset.c \
- scheduler.c scheduler_backend.c smtp.c smtp_session.c \
- smtpd.c ssl.c ssl_privsep.c stat_backend.c tree.c \
- user.c util.c
-
-# backends
-SRCS+= auth_bsd.c
-SRCS+= auth_pwd.c
-SRCS+= compress_gzip.c
-SRCS+= delivery_filename.c
-SRCS+= delivery_maildir.c
-SRCS+= delivery_mbox.c
-SRCS+= delivery_mda.c
-SRCS+= map_db.c
-SRCS+= map_file.c
-SRCS+= map_static.c
-SRCS+= queue_fsqueue.c
-SRCS+= queue_ram.c
-SRCS+= scheduler_ramqueue.c
-SRCS+= stat_ramstat.c
-#SRCS+= stat_sqlite.c
-SRCS+= user_pwd.c
-
-# resolver
-SRCS+= asr.c asr_debug.c asr_utils.c gethostnamadr_async.c \
- res_send_async.c getaddrinfo_async.c getnameinfo_async.c
-
-MAN= smtpd.8 smtpd.conf.5
-BINDIR= /usr/sbin
-
-LDADD+= -levent -lutil -lssl -lcrypto -lm -lz
-DPADD+= ${LIBEVENT} ${LIBUTIL} ${LIBSSL} ${LIBCRYPTO} ${LIBM} ${LIBZ}
-CFLAGS+= -g3 -ggdb -I${.CURDIR}/.. -I/usr/src/lib/libc/asr
-CFLAGS+= -Wall -Wstrict-prototypes -Wmissing-prototypes
-CFLAGS+= -Wmissing-declarations
-CFLAGS+= -Wshadow -Wpointer-arith -Wcast-qual
-CFLAGS+= -Wsign-compare -Wbounded
-#CFLAGS+= -Werror # during development phase (breaks some archs)
-CFLAGS+= -DIO_SSL
-CFLAGS+= -DASR_OPT_THREADSAFE=0
-YFLAGS=
-
-.include <bsd.prog.mk>
diff --git a/smtpd/smtpfilter.c b/smtpd/smtpfilter.c
index 01c81a99..cb8cc00d 100644
--- a/smtpd/smtpfilter.c
+++ b/smtpd/smtpfilter.c
@@ -16,6 +16,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <stdlib.h>
diff --git a/smtpd/ssl.c b/smtpd/ssl.c
index 3ecf57b4..2a06992e 100644
--- a/smtpd/ssl.c
+++ b/smtpd/ssl.c
@@ -17,15 +17,22 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <ctype.h>
+#if LIBEVENT_MAJOR_VERSION < 2
#include <event.h>
+#else
+#include <event2/event.h>
+#include <event2/bufferevent_ssl.h>
+#endif
#include <fcntl.h>
#include <imsg.h>
#include <pwd.h>
@@ -159,7 +166,7 @@ ssl_load_certfile(const char *name, uint8_t flags)
(void)strlcpy(s->ssl_name, key.ssl_name, sizeof(s->ssl_name));
if (! bsnprintf(certfile, sizeof(certfile),
- "/etc/mail/certs/%s.crt", name))
+ SMTPD_CONFDIR "/certs/%s.crt", name))
goto err;
s->ssl_cert = ssl_load_file(certfile, &s->ssl_cert_len, 0755);
@@ -167,7 +174,7 @@ ssl_load_certfile(const char *name, uint8_t flags)
goto err;
if (! bsnprintf(certfile, sizeof(certfile),
- "/etc/mail/certs/%s.key", name))
+ SMTPD_CONFDIR "/certs/%s.key", name))
goto err;
s->ssl_key = ssl_load_file(certfile, &s->ssl_key_len, 0700);
@@ -175,7 +182,7 @@ ssl_load_certfile(const char *name, uint8_t flags)
goto err;
if (! bsnprintf(certfile, sizeof(certfile),
- "/etc/mail/certs/%s.ca", name))
+ SMTPD_CONFDIR "/certs/%s.ca", name))
goto err;
s->ssl_ca = ssl_load_file(certfile, &s->ssl_ca_len, 0755);
@@ -186,7 +193,7 @@ ssl_load_certfile(const char *name, uint8_t flags)
}
if (! bsnprintf(certfile, sizeof(certfile),
- "/etc/mail/certs/%s.dh", name))
+ SMTPD_CONFDIR "/certs/%s.dh", name))
goto err;
s->ssl_dhparams = ssl_load_file(certfile, &s->ssl_dhparams_len, 0755);
diff --git a/smtpd/ssl_privsep.c b/smtpd/ssl_privsep.c
index d7601054..3e45e7fd 100644
--- a/smtpd/ssl_privsep.c
+++ b/smtpd/ssl_privsep.c
@@ -62,6 +62,8 @@
* Adapted from openssl's ssl_rsa.c by Pierre-Yves Ritschard .
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/uio.h>
diff --git a/smtpd/stat_backend.c b/smtpd/stat_backend.c
index 4aaa5aff..b54cd0b5 100644
--- a/smtpd/stat_backend.c
+++ b/smtpd/stat_backend.c
@@ -14,10 +14,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <event.h>
diff --git a/smtpd/stat_ramstat.c b/smtpd/stat_ramstat.c
index 43165214..2f774c63 100644
--- a/smtpd/stat_ramstat.c
+++ b/smtpd/stat_ramstat.c
@@ -13,11 +13,12 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <event.h>
diff --git a/smtpd/tree.c b/smtpd/tree.c
index fe83d333..da41574f 100644
--- a/smtpd/tree.c
+++ b/smtpd/tree.c
@@ -16,8 +16,10 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/tree.h>
+#include "sys-tree.h"
#include <sys/socket.h> /* for smtpd.h */
#include <sys/queue.h> /* for smtpd.h */
diff --git a/smtpd/user.c b/smtpd/user.c
index 12aad9d6..749ab9b9 100644
--- a/smtpd/user.c
+++ b/smtpd/user.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
diff --git a/smtpd/user_pwd.c b/smtpd/user_pwd.c
index 341a897b..33dec408 100644
--- a/smtpd/user_pwd.c
+++ b/smtpd/user_pwd.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/smtpd/util.c b/smtpd/util.c
index a4670aac..d2a92cb1 100644
--- a/smtpd/util.c
+++ b/smtpd/util.c
@@ -19,10 +19,12 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/resource.h>
@@ -78,6 +80,17 @@ xcalloc(size_t nmemb, size_t size, const char *where)
return (r);
}
+void *
+xrealloc(void *p, size_t size, const char *where)
+{
+ void *r;
+
+ if ((r = realloc(p, size)) == NULL)
+ errx(1, "%s: realloc(%p, %zu)", where, p, size);
+
+ return (r);
+}
+
char *
xstrdup(const char *str, const char *where)
{
@@ -636,7 +649,9 @@ text_to_netaddr(struct netaddr *netaddr, const char *s)
if (bits != -1) {
ssin.sin_family = AF_INET;
memcpy(&ss, &ssin, sizeof(ssin));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss.ss_len = sizeof(struct sockaddr_in);
+#endif
}
else {
bzero(&ssin6, sizeof(struct sockaddr_in6));
@@ -659,7 +674,9 @@ text_to_netaddr(struct netaddr *netaddr, const char *s)
}
ssin6.sin6_family = AF_INET6;
memcpy(&ss, &ssin6, sizeof(ssin6));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss.ss_len = sizeof(struct sockaddr_in6);
+#endif
}
}
else {
@@ -668,13 +685,17 @@ text_to_netaddr(struct netaddr *netaddr, const char *s)
ssin.sin_family = AF_INET;
bits = 32;
memcpy(&ss, &ssin, sizeof(ssin));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss.ss_len = sizeof(struct sockaddr_in);
+#endif
}
else if (inet_pton(AF_INET6, s, &ssin6.sin6_addr) == 1) {
ssin6.sin6_family = AF_INET6;
bits = 128;
memcpy(&ss, &ssin6, sizeof(ssin6));
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
ss.ss_len = sizeof(struct sockaddr_in6);
+#endif
}
else return 0;
}
@@ -856,7 +877,7 @@ sa_set_port(struct sockaddr *sa, int port)
struct addrinfo hints, *res;
int error;
- error = getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
+ error = getnameinfo(sa, SA_LEN(sa), hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);
if (error)
fatalx("sa_set_port: getnameinfo failed");
@@ -896,6 +917,8 @@ fdlimit(double percent)
fatalx("fdlimit: parameter out of range");
if (getrlimit(RLIMIT_NOFILE, &rl) == -1)
fatal("fdlimit: getrlimit");
+ if (rl.rlim_max == RLIM_INFINITY)
+ rl.rlim_max = OPEN_MAX;
rl.rlim_cur = percent * rl.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
fatal("fdlimit: setrlimit");
@@ -948,7 +971,9 @@ log_in6addr(const struct in6_addr *addr)
uint16_t tmp16;
bzero(&sa_in6, sizeof(sa_in6));
+#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
sa_in6.sin6_len = sizeof(sa_in6);
+#endif
sa_in6.sin6_family = AF_INET6;
memcpy(&sa_in6.sin6_addr, addr, sizeof(sa_in6.sin6_addr));
@@ -969,7 +994,7 @@ log_sockaddr(struct sockaddr *sa)
{
static char buf[NI_MAXHOST];
- if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0,
+ if (getnameinfo(sa, SA_LEN(sa), buf, sizeof(buf), NULL, 0,
NI_NUMERICHOST))
return ("(unknown)");
else
diff --git a/smtpd/waitq.c b/smtpd/waitq.c
index da6519a6..ff34e024 100644
--- a/smtpd/waitq.c
+++ b/smtpd/waitq.c
@@ -16,9 +16,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "includes.h"
+
#include <sys/types.h>
-#include <sys/tree.h>
-#include <sys/queue.h>
+#include "sys-queue.h"
+#include "sys-tree.h"
#include <sys/uio.h>
#include <imsg.h>