summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-09-15 15:12:12 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-09-15 15:12:12 +0000
commit59d5b3b2e128a0412b4c399b4f4c9931fc66e35c (patch)
tree3ec1a3d418c08cb79704b05cc6c13ff98f173ffc
parent4cb5807cfbcc620e6ad7fa553c06e86570ddeca0 (diff)
When enqueueing from the local socket, the input address is faked as "::1".
This is confusing and even broken, as systems running with ipv6 disabled on lo0 will not be able to enqueue mails using the local socket. So instead, use AF_LOCAL and print it as "local" in envelopes/maps. Add it to the "localhost" and "all" maps accordingly, and fix the ruleset matching. ok gilles@ chl@
-rw-r--r--usr.sbin/smtpd/envelope.c7
-rw-r--r--usr.sbin/smtpd/parse.y12
-rw-r--r--usr.sbin/smtpd/ruleset.c7
-rw-r--r--usr.sbin/smtpd/smtp.c21
-rw-r--r--usr.sbin/smtpd/util.c10
5 files changed, 34 insertions, 23 deletions
diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c
index 684fe2cea27..e295b47607f 100644
--- a/usr.sbin/smtpd/envelope.c
+++ b/usr.sbin/smtpd/envelope.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: envelope.c,v 1.11 2012/09/02 12:21:22 chl Exp $ */
+/* $OpenBSD: envelope.c,v 1.12 2012/09/15 15:12:11 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -512,7 +512,10 @@ ascii_load_sockaddr(struct sockaddr_storage *ss, char *buf)
struct sockaddr_in6 ssin6;
struct sockaddr_in ssin;
- if (strncasecmp("IPv6:", buf, 5) == 0) {
+ if (!strcmp("local", buf)) {
+ ss->ss_family = AF_LOCAL;
+ }
+ else if (strncasecmp("IPv6:", buf, 5) == 0) {
if (inet_pton(AF_INET6, buf + 5, &ssin6.sin6_addr) != 1)
return 0;
ssin6.sin6_family = AF_INET6;
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 51649d290ec..06678a461ae 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.98 2012/09/08 13:58:29 chl Exp $ */
+/* $OpenBSD: parse.y,v 1.99 2012/09/15 15:12:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -995,6 +995,12 @@ from : FROM mapref {
if ((me = calloc(1, sizeof(*me))) == NULL)
fatal("out of memory");
+ (void)strlcpy(me->me_key.med_string, "local",
+ sizeof(me->me_key.med_string));
+ TAILQ_INSERT_TAIL(&m->m_contents, me, me_entry);
+
+ if ((me = calloc(1, sizeof(*me))) == NULL)
+ fatal("out of memory");
(void)strlcpy(me->me_key.med_string, "0.0.0.0/0",
sizeof(me->me_key.med_string));
TAILQ_INSERT_TAIL(&m->m_contents, me, me_entry);
@@ -1898,6 +1904,10 @@ set_localaddrs(void)
m = map_findbyname("localhost");
+ me = xcalloc(1, sizeof *me, "set_localaddrs");
+ strlcpy(me->me_key.med_string, "local", sizeof(me->me_key.med_string));
+ TAILQ_INSERT_TAIL(&m->m_contents, me, me_entry);
+
for (p = ifap; p != NULL; p = p->ifa_next) {
if (p->ifa_addr == NULL)
continue;
diff --git a/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c
index 1923e0766d9..051151a7bea 100644
--- a/usr.sbin/smtpd/ruleset.c
+++ b/usr.sbin/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.21 2012/05/13 00:10:49 gilles Exp $ */
+/* $OpenBSD: ruleset.c,v 1.22 2012/09/15 15:12:11 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -128,6 +128,11 @@ ruleset_check_source(struct map *map, struct sockaddr_storage *ss)
if (map->m_src == S_NONE) {
TAILQ_FOREACH(me, &map->m_contents, me_entry) {
+ if (ss->ss_family == AF_LOCAL) {
+ if (!strcmp(me->me_key.med_string, "local"))
+ return 1;
+ continue;
+ }
if (ruleset_cmp_source(ss_to_text(ss),
me->me_key.med_string))
return 1;
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index 0b03b7098ea..e789f93783e 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.110 2012/09/14 16:38:53 eric Exp $ */
+/* $OpenBSD: smtp.c,v 1.111 2012/09/15 15:12:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -419,25 +419,14 @@ smtp_resume(void)
static int
smtp_enqueue(uid_t *euid)
{
- static struct listener local, *l;
- static struct sockaddr_storage sa;
+ static struct listener local, *l = NULL;
struct session *s;
int fd[2];
if (l == NULL) {
- struct addrinfo hints, *res;
-
l = &local;
strlcpy(l->tag, "local", sizeof(l->tag));
-
- bzero(&hints, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_flags = AI_NUMERICHOST;
-
- if (getaddrinfo("::1", NULL, &hints, &res))
- fatal("getaddrinfo");
- memcpy(&sa, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
+ l->ss.ss_family = AF_LOCAL;
}
/*
@@ -455,7 +444,7 @@ smtp_enqueue(uid_t *euid)
fatal("socketpair");
s->s_io.sock = fd[0];
- s->s_ss = sa;
+ s->s_ss = l->ss;
s->s_msg.flags |= DF_ENQUEUED;
if (euid)
@@ -530,6 +519,8 @@ smtp_new(struct listener *l)
stat_increment("smtp.session", 1);
+ if (s->s_l->ss.ss_family == AF_LOCAL)
+ stat_increment("smtp.session.local", 1);
if (s->s_l->ss.ss_family == AF_INET)
stat_increment("smtp.session.inet4", 1);
if (s->s_l->ss.ss_family == AF_INET6)
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 07979644c4d..4da4dcba48e 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.75 2012/08/27 11:59:38 chl Exp $ */
+/* $OpenBSD: util.c,v 1.76 2012/09/15 15:12:11 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -502,7 +502,10 @@ ss_to_text(struct sockaddr_storage *ss)
buf[0] = '\0';
p = buf;
- if (ss->ss_family == PF_INET) {
+ if (ss->ss_family == AF_LOCAL) {
+ strlcpy(buf, "local", sizeof buf);
+ }
+ else if (ss->ss_family == AF_INET) {
in_addr_t addr;
addr = ((struct sockaddr_in *)ss)->sin_addr.s_addr;
@@ -514,8 +517,7 @@ ss_to_text(struct sockaddr_storage *ss)
(addr >> 8) & 0xff,
addr & 0xff);
}
-
- if (ss->ss_family == PF_INET6) {
+ else if (ss->ss_family == AF_INET6) {
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)ss;
struct in6_addr *in6_addr;