diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2008-12-06 02:04:57 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2008-12-06 02:04:57 +0000 |
commit | 2404c313585ee5ac34f440f9fea648e313a08d2f (patch) | |
tree | e803a071e1efca6900d18eed5042c4959106f246 /usr.sbin/smtpd | |
parent | 9ca0f96bfd16e833750204dcdbbc5982f3c2f114 (diff) |
- it is now possible to specify an interface instead of an address or a
hostname in a listen statement (ie: listen on lo0)
request by deraadt@ a while ago, ok jacekm@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/parse.y | 79 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.conf | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.conf.5 | 5 |
3 files changed, 77 insertions, 11 deletions
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 9767263804d..2e2ce634d79 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.13 2008/12/04 17:24:13 cloder Exp $ */ +/* $OpenBSD: parse.y,v 1.14 2008/12/06 02:04:56 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -37,6 +37,7 @@ #include <err.h> #include <errno.h> #include <event.h> +#include <ifaddrs.h> #include <limits.h> #include <pwd.h> #include <netdb.h> @@ -256,12 +257,15 @@ main : QUEUE INTERVAL interval { flags = F_STARTTLS; } - if (host($4, &conf->sc_listeners, - MAX_LISTEN, $5, flags) <= 0) { - yyerror("invalid virtual ip: %s", $4); - free($6); - free($4); - YYERROR; + if (! interface($4, &conf->sc_listeners, + MAX_LISTEN, $5, flags)) { + if (host($4, &conf->sc_listeners, + MAX_LISTEN, $5, flags) <= 0) { + yyerror("invalid virtual ip or interface: %s", $4); + free($6); + free($4); + YYERROR; + } } free($6); free($4); @@ -1408,3 +1412,64 @@ host(const char *s, struct listenerlist *al, int max, in_port_t port, return (host_dns(s, al, max, port, flags)); } + +int +interface(const char *s, struct listenerlist *al, int max, in_port_t port, + u_int8_t flags) +{ + struct ifaddrs *ifap, *p; + struct sockaddr_in *sain; + struct sockaddr_in6 *sin6; + struct listener *h; + int ret = 0; + + if (getifaddrs(&ifap) == -1) + fatal("getifaddrs"); + + for (p = ifap; p != NULL; p = p->ifa_next) { + if (strcmp(s, p->ifa_name) != 0) + continue; + + switch (p->ifa_addr->sa_family) { + case AF_INET: + if ((h = calloc(1, sizeof(*h))) == NULL) + fatal(NULL); + sain = (struct sockaddr_in *)&h->ss; + *sain = *(struct sockaddr_in *)p->ifa_addr; + sain->sin_len = sizeof(struct sockaddr_in); + sain->sin_port = port; + + h->port = port; + h->flags = flags; + h->ssl = NULL; + (void)strlcpy(h->ssl_cert_name, s, sizeof(h->ssl_cert_name)); + + ret = 1; + TAILQ_INSERT_HEAD(al, h, entry); + + break; + + case AF_INET6: + if ((h = calloc(1, sizeof(*h))) == NULL) + fatal(NULL); + sin6 = (struct sockaddr_in6 *)&h->ss; + *sin6 = *(struct sockaddr_in6 *)p->ifa_addr; + sin6->sin6_len = sizeof(struct sockaddr_in6); + sin6->sin6_port = port; + + h->port = port; + h->flags = flags; + h->ssl = NULL; + (void)strlcpy(h->ssl_cert_name, s, sizeof(h->ssl_cert_name)); + + ret = 1; + TAILQ_INSERT_HEAD(al, h, entry); + + break; + } + } + + freeifaddrs(ifap); + + return ret; +} diff --git a/usr.sbin/smtpd/smtpd.conf b/usr.sbin/smtpd/smtpd.conf index 25ee9dd8dd7..c0f920afb73 100644 --- a/usr.sbin/smtpd/smtpd.conf +++ b/usr.sbin/smtpd/smtpd.conf @@ -1,6 +1,6 @@ -# $OpenBSD: smtpd.conf,v 1.2 2008/11/05 12:14:45 sobrado Exp $ +# $OpenBSD: smtpd.conf,v 1.3 2008/12/06 02:04:56 gilles Exp $ -listen on localhost port 25 +listen on lo0 port 25 #ssmtp listen on localhost port 465 hostname localhost diff --git a/usr.sbin/smtpd/smtpd.conf.5 b/usr.sbin/smtpd/smtpd.conf.5 index 2f0f69cbf49..97bf57f2ebc 100644 --- a/usr.sbin/smtpd/smtpd.conf.5 +++ b/usr.sbin/smtpd/smtpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpd.conf.5,v 1.3 2008/11/02 08:19:13 jmc Exp $ +.\" $OpenBSD: smtpd.conf.5,v 1.4 2008/12/06 02:04:56 gilles Exp $ .\" .\" Copyright (c) 2008 Janne Johansson <jj@openbsd.org> .\" @@ -15,7 +15,7 @@ .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .\" -.Dd $Mdocdate: November 2 2008 $ +.Dd $Mdocdate: December 6 2008 $ .Dt SMTPD.CONF 5 .Os .Sh NAME @@ -55,6 +55,7 @@ For example, .Bd -literal -offset indent smtp_port = 25 listen on 127.0.0.1 port $smtp_port +listen on fxp0 port $smtp_port .Ed .Sh EXPANSION Some configuration directives expect expansion of their parameter at |