diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-06-03 19:52:57 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-06-03 19:52:57 +0000 |
commit | 42c41c62100cdf01bb0d559330453b039a73d075 (patch) | |
tree | b5bb4dc120a6224d1c0472817895f4a85058182c /usr.sbin/smtpd | |
parent | 9348823983c1093c5fae4fe0a8d18ecf1754d41d (diff) |
Do not store the envelope id within the envelope, only the message id.
Make sure existing envelopes can be properly loaded.
ok chl@ gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/envelope.c | 37 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_backend.c | 17 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 3 |
3 files changed, 45 insertions, 12 deletions
diff --git a/usr.sbin/smtpd/envelope.c b/usr.sbin/smtpd/envelope.c index 5a2014b3f13..6cbb2c8e923 100644 --- a/usr.sbin/smtpd/envelope.c +++ b/usr.sbin/smtpd/envelope.c @@ -1,4 +1,4 @@ -/* $OpenBSD: envelope.c,v 1.5 2012/06/01 09:24:58 eric Exp $ */ +/* $OpenBSD: envelope.c,v 1.6 2012/06/03 19:52:56 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -48,6 +48,7 @@ static int ascii_load_uint8(u_int8_t *, char *); static int ascii_load_uint16(u_int16_t *, char *); static int ascii_load_uint32(u_int32_t *, char *); static int ascii_load_time(time_t *, char *); +static int ascii_load_uint32_hex(u_int32_t *, char *); static int ascii_load_uint64_hex(u_int64_t *, char *); static int ascii_load_type(enum delivery_type *, char *); static int ascii_load_string(char *, char *, size_t); @@ -60,6 +61,7 @@ static int ascii_load_mta_relay_flags(u_int8_t *, char *); static int ascii_dump_uint8(u_int8_t, char *, size_t); static int ascii_dump_uint32(u_int32_t, char *, size_t); static int ascii_dump_time(time_t, char *, size_t); +static int ascii_dump_uint32_hex(u_int32_t, char *, size_t); static int ascii_dump_uint64_hex(u_int64_t, char *, size_t); static int ascii_dump_string(char *, char *, size_t); static int ascii_dump_type(enum delivery_type, char *, size_t); @@ -96,6 +98,7 @@ envelope_load_file(struct envelope *ep, FILE *fp) enum envelope_field fields[] = { EVP_VERSION, EVP_ID, + EVP_MSGID, EVP_HOSTNAME, EVP_SOCKADDR, EVP_HELO, @@ -180,7 +183,7 @@ envelope_dump_file(struct envelope *ep, FILE *fp) enum envelope_field fields[] = { EVP_VERSION, - EVP_ID, + EVP_MSGID, EVP_TYPE, EVP_HELO, EVP_HOSTNAME, @@ -268,6 +271,8 @@ envelope_ascii_field_name(enum envelope_field field) return "version"; case EVP_ID: return "id"; + case EVP_MSGID: + return "msgid"; case EVP_TYPE: return "type"; case EVP_HELO: @@ -318,11 +323,18 @@ envelope_ascii_field_name(enum envelope_field field) int envelope_ascii_load(enum envelope_field field, struct envelope *ep, char *buf) { + uint32_t msgid; + int r; + switch (field) { case EVP_VERSION: return ascii_load_uint32(&ep->version, buf); case EVP_ID: return ascii_load_uint64_hex(&ep->id, buf); + case EVP_MSGID: + if ((r = ascii_load_uint32_hex(&msgid, buf))) + ep->id = msgid_to_evpid(msgid); + return (r); case EVP_TYPE: return ascii_load_type(&ep->type, buf); case EVP_HELO: @@ -392,6 +404,8 @@ envelope_ascii_dump(enum envelope_field field, struct envelope *ep, return ascii_dump_uint32(SMTPD_ENVELOPE_VERSION, buf, len); case EVP_ID: return ascii_dump_uint64_hex(ep->id, buf, len); + case EVP_MSGID: + return ascii_dump_uint32_hex(evpid_to_msgid(ep->id), buf, len); case EVP_TYPE: return ascii_dump_type(ep->type, buf, len); case EVP_HELO: @@ -488,6 +502,19 @@ ascii_load_time(time_t *dest, char *buf) } static int +ascii_load_uint32_hex(u_int32_t *dest, char *buf) +{ + uint64_t u; + + if (ascii_load_uint64_hex(&u, buf) == 0) + return (0); + if (u > (uint64_t)0xffffffff) + return (0); + *dest = (uint32_t)u; + return (1); +} + +static int ascii_load_uint64_hex(u_int64_t *dest, char *buf) { char *endptr; @@ -626,6 +653,12 @@ ascii_dump_time(time_t src, char *dest, size_t len) } static int +ascii_dump_uint32_hex(u_int32_t src, char *dest, size_t len) +{ + return bsnprintf(dest, len, "%08" PRIx32, src); +} + +static int ascii_dump_uint64_hex(u_int64_t src, char *dest, size_t len) { return bsnprintf(dest, len, "%016" PRIx64, src); diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c index e6ec91bc385..c78a0b3990e 100644 --- a/usr.sbin/smtpd/queue_backend.c +++ b/usr.sbin/smtpd/queue_backend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_backend.c,v 1.21 2012/06/01 11:42:34 eric Exp $ */ +/* $OpenBSD: queue_backend.c,v 1.22 2012/06/03 19:52:56 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -120,11 +120,13 @@ queue_envelope_load(enum queue_kind qkind, u_int64_t evpid, struct envelope *ep) ep->id = evpid; if (env->sc_queue->envelope(qkind, QOP_LOAD, ep)) { - if ((e = envelope_validate(ep, evpid)) == NULL) - return 1; + if ((e = envelope_validate(ep, evpid)) == NULL) { + ep->id = evpid; + return (1); + } log_debug("invalid envelope %016" PRIx64 ": %s", ep->id, e); } - return 0; + return (0); } int @@ -186,11 +188,8 @@ envelope_validate(struct envelope *ep, uint64_t id) if (ep->version != SMTPD_ENVELOPE_VERSION) return "version mismatch"; - if ((ep->id & 0xffffffff) == 0 || ((ep->id >> 32) & 0xffffffff) == 0) - return "invalid id"; - - if (ep->id != id) - return "id mismatch"; + if (evpid_to_msgid(ep->id) != (evpid_to_msgid(id))) + return "msgid mismatch"; if (memchr(ep->helo, '\0', sizeof(ep->helo)) == NULL) return "invalid helo"; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 31eb62004bc..a41270590df 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.297 2012/06/01 10:40:14 chl Exp $ */ +/* $OpenBSD: smtpd.h,v 1.298 2012/06/03 19:52:56 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -427,6 +427,7 @@ TAILQ_HEAD(deliverylist, envelope); enum envelope_field { EVP_VERSION, EVP_ID, + EVP_MSGID, EVP_TYPE, EVP_HELO, EVP_HOSTNAME, |