summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2008-11-25 20:26:40 +0000
committergilles <gilles@openbsd.org>2008-11-25 20:26:40 +0000
commit93de19f82ed160aa519a0f441411f6c075d12d65 (patch)
tree87038f08c4bc76563839f22adf0d2f578bc3fcae
parentm_defrag() a mbuf chain defragmenter. It will collaps a mbuf chain into a (diff)
downloadwireguard-openbsd-93de19f82ed160aa519a0f441411f6c075d12d65.tar.xz
wireguard-openbsd-93de19f82ed160aa519a0f441411f6c075d12d65.zip
- recent change in parse.y caused htons() to be called twice on the port
provided to "relay via" rules, once in parse.y once in lka.c, fix. - rename struct address to struct relayhost, introduce struct mxhost which not only holds the sockaddr_storage, but also additionnal flags we want forwarded to the mta process. - propagate the change
-rw-r--r--usr.sbin/smtpd/lka.c26
-rw-r--r--usr.sbin/smtpd/mta.c22
-rw-r--r--usr.sbin/smtpd/parse.y16
-rw-r--r--usr.sbin/smtpd/queue.c8
-rw-r--r--usr.sbin/smtpd/smtpd.h31
5 files changed, 59 insertions, 44 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index d806b513801..43b4daa2ce4 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.3 2008/11/10 21:29:18 chl Exp $ */
+/* $OpenBSD: lka.c,v 1.4 2008/11/25 20:26:40 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -477,7 +477,7 @@ lka_dispatch_queue(int sig, short event, void *p)
char *lmx[1];
size_t len, i, j;
int error;
- u_int16_t port = 25;
+ u_int16_t port = htons(25);
batchp = imsg.data;
@@ -494,11 +494,13 @@ lka_dispatch_queue(int sig, short event, void *p)
}
}
else if (batchp->rule.r_action == A_RELAYVIA) {
- lmx[0] = batchp->rule.r_value.host.hostname;
- port = batchp->rule.r_value.host.port;
- log_debug("attempting to resolve %s:%d (forced)", lmx[0], port);
+
+ lmx[0] = batchp->rule.r_value.relayhost.hostname;
+ port = batchp->rule.r_value.relayhost.port;
+ log_debug("attempting to resolve %s:%d (forced)", lmx[0], ntohs(port));
mx = lmx;
len = 1;
+
}
memset(&hints, 0, sizeof(hints));
@@ -515,16 +517,16 @@ lka_dispatch_queue(int sig, short event, void *p)
if (resp->ai_family == PF_INET) {
struct sockaddr_in *ssin;
- batchp->ss[j] = *(struct sockaddr_storage *)resp->ai_addr;
- ssin = (struct sockaddr_in *)&batchp->ss[j];
- ssin->sin_port = htons(port);
+ batchp->mxarray[j].ss = *(struct sockaddr_storage *)resp->ai_addr;
+ ssin = (struct sockaddr_in *)&batchp->mxarray[j].ss;
+ ssin->sin_port = port;
++j;
}
if (resp->ai_family == PF_INET6) {
struct sockaddr_in6 *ssin6;
- batchp->ss[j] = *(struct sockaddr_storage *)resp->ai_addr;
- ssin6 = (struct sockaddr_in6 *)&batchp->ss[j];
- ssin6->sin6_port = htons(port);
+ batchp->mxarray[j].ss = *(struct sockaddr_storage *)resp->ai_addr;
+ ssin6 = (struct sockaddr_in6 *)&batchp->mxarray[j].ss;
+ ssin6->sin6_port = port;
++j;
}
}
@@ -532,7 +534,7 @@ lka_dispatch_queue(int sig, short event, void *p)
freeaddrinfo(res);
}
- batchp->ss_cnt = j;
+ batchp->mx_cnt = j;
batchp->getaddrinfo_error = 0;
if (j == 0)
batchp->getaddrinfo_error = error;
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index 382a356bf3f..a16a5b011a9 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.6 2008/11/24 22:30:19 gilles Exp $ */
+/* $OpenBSD: mta.c,v 1.7 2008/11/25 20:26:40 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -158,7 +158,7 @@ mta_dispatch_queue(int sig, short event, void *p)
err(1, "calloc");
*batchp = *(struct batch *)imsg.data;
- batchp->ss_off = 0;
+ batchp->mx_off = 0;
batchp->env = env;
batchp->flags = 0;
@@ -196,7 +196,7 @@ mta_dispatch_queue(int sig, short event, void *p)
batchp->flags |= F_BATCH_COMPLETE;
while (! mta_connect(batchp)) {
- if (batchp->ss_off == batchp->ss_cnt) {
+ if (batchp->mx_off == batchp->mx_cnt) {
break;
}
}
@@ -341,7 +341,7 @@ mta_connect(struct batch *batchp)
struct sockaddr_in ssin;
struct sockaddr_in6 ssin6;
- if ((s = socket(batchp->ss[batchp->ss_off].ss_family, SOCK_STREAM, 0)) == -1) {
+ if ((s = socket(batchp->mxarray[batchp->mx_off].ss.ss_family, SOCK_STREAM, 0)) == -1) {
goto bad;
}
@@ -357,8 +357,8 @@ mta_connect(struct batch *batchp)
session_socket_blockmode(s, BM_NONBLOCK);
- if (batchp->ss[batchp->ss_off].ss_family == PF_INET) {
- ssin = *(struct sockaddr_in *)&batchp->ss[batchp->ss_off];
+ if (batchp->mxarray[batchp->mx_off].ss.ss_family == PF_INET) {
+ ssin = *(struct sockaddr_in *)&batchp->mxarray[batchp->mx_off].ss;
if (connect(s, (struct sockaddr *)&ssin, sizeof(struct sockaddr_in)) == -1) {
if (errno != EINPROGRESS) {
goto bad;
@@ -366,8 +366,8 @@ mta_connect(struct batch *batchp)
}
}
- if (batchp->ss[batchp->ss_off].ss_family == PF_INET6) {
- ssin6 = *(struct sockaddr_in6 *)&batchp->ss[batchp->ss_off];
+ if (batchp->mxarray[batchp->mx_off].ss.ss_family == PF_INET6) {
+ ssin6 = *(struct sockaddr_in6 *)&batchp->mxarray[batchp->mx_off].ss;
if (connect(s, (struct sockaddr *)&ssin6, sizeof(struct sockaddr_in6)) == -1) {
if (errno != EINPROGRESS) {
goto bad;
@@ -384,7 +384,7 @@ mta_connect(struct batch *batchp)
return 1;
bad:
- batchp->ss_off++;
+ batchp->mx_off++;
close(s);
return 0;
}
@@ -396,7 +396,7 @@ mta_write(int s, short event, void *arg)
int ret;
if (event == EV_TIMEOUT) {
- batchp->ss_off++;
+ batchp->mx_off++;
close(s);
if (batchp->bev) {
bufferevent_free(batchp->bev);
@@ -405,7 +405,7 @@ mta_write(int s, short event, void *arg)
strlcpy(batchp->errorline, "connection timed-out.", MAX_LINE_SIZE);
ret = 0;
- while (batchp->ss_off < batchp->ss_cnt &&
+ while (batchp->mx_off < batchp->mx_cnt &&
(ret = mta_connect(batchp)) == 0) {
continue;
}
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index 9052083e7c9..757fe84e03d 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.10 2008/11/22 20:26:08 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.11 2008/11/25 20:26:40 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -230,9 +230,9 @@ main : QUEUE INTERVAL interval {
if ($5 == 0) {
if ($1)
- $5 = htons(487);
+ $5 = 487;
else
- $5 = htons(25);
+ $5 = 25;
}
cert = ($6 != NULL) ? $6 : $4;
@@ -653,14 +653,18 @@ action : DELIVER TO MAILDIR STRING {
}
| RELAY VIA ssmtp STRING port {
rule->r_action = A_RELAYVIA;
- if (strlcpy(rule->r_value.host.hostname, $4, MAXHOSTNAMELEN)
+
+ if ($3)
+ rule->r_value.relayhost.flags = F_SSMTP;
+
+ if (strlcpy(rule->r_value.relayhost.hostname, $4, MAXHOSTNAMELEN)
>= MAXHOSTNAMELEN)
fatal("hostname too long");
if ($5 == 0)
- rule->r_value.host.port = htons(25);
+ rule->r_value.relayhost.port = 25;
else
- rule->r_value.host.port = htons($5);
+ rule->r_value.relayhost.port = $5;
free($4);
}
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index bbff1a36d8c..aa952c596ee 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.15 2008/11/24 23:55:25 gilles Exp $ */
+/* $OpenBSD: queue.c,v 1.16 2008/11/25 20:26:40 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1030,7 +1030,7 @@ queue_batch_resolved(struct smtpd *env, struct batch *lookup)
batchp = batch_by_id(env, lookup->id);
batchp->getaddrinfo_error = lookup->getaddrinfo_error;
- batchp->ss_cnt = lookup->ss_cnt;
+ batchp->mx_cnt = lookup->mx_cnt;
/*
EAI_NODATA no address associated with hostname
@@ -1076,8 +1076,8 @@ queue_batch_resolved(struct smtpd *env, struct batch *lookup)
default:
batchp->flags |= F_BATCH_RESOLVED;
- for (i = 0; i < batchp->ss_cnt; ++i)
- batchp->ss[i] = lookup->ss[i];
+ for (i = 0; i < batchp->mx_cnt; ++i)
+ batchp->mxarray[i].ss = lookup->mxarray[i].ss;
}
return 1;
}
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 6ed1410d6a8..c68d968f76b 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.12 2008/11/25 15:55:13 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.13 2008/11/25 20:26:40 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -58,14 +58,26 @@
/* number of MX records to lookup */
#define MXARRAYSIZE 5
-struct address {
+
+#define F_STARTTLS 0x01
+#define F_SSMTP 0x02
+#define F_SSL (F_SSMTP|F_STARTTLS)
+
+
+struct netaddr {
+ struct sockaddr_storage ss;
+ int masked;
+};
+
+struct relayhost {
+ u_int8_t flags;
char hostname[MAXHOSTNAMELEN];
u_int16_t port;
};
-struct netaddr {
+struct mxhost {
+ u_int8_t flags;
struct sockaddr_storage ss;
- int masked;
};
/* buffer specific headers */
@@ -319,7 +331,7 @@ struct rule {
enum action_type r_action;
union {
char path[MAXPATHLEN];
- struct address host;
+ struct relayhost relayhost;
#define MAXCOMMANDLEN 256
char command[MAXCOMMANDLEN];
} r_value;
@@ -493,9 +505,9 @@ struct batch {
char errorline[MAX_LINE_SIZE];
u_int8_t getaddrinfo_error;
- struct sockaddr_storage ss[MXARRAYSIZE*2];
- u_int8_t ss_cnt;
- u_int8_t ss_off;
+ struct mxhost mxarray[MXARRAYSIZE*2];
+ u_int8_t mx_cnt;
+ u_int8_t mx_off;
time_t creation;
time_t lasttry;
@@ -535,9 +547,6 @@ struct ssl {
};
struct listener {
-#define F_STARTTLS 0x01
-#define F_SSMTP 0x02
-#define F_SSL (F_SSMTP|F_STARTTLS)
u_int8_t flags;
int fd;
struct sockaddr_storage ss;