diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-10-23 09:30:08 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-10-23 09:30:08 +0000 |
commit | e3cfbeb71221f3f3bee3fcbfef00515742b2db32 (patch) | |
tree | b6982699bd3a5aa673680f516988242d259225b7 /usr.sbin/smtpd/lka_session.c | |
parent | 436e188d636566b43d727d0356572ecdff1c87d9 (diff) |
fsqueue no longer stores envelopes by dumping the structure, instead use a
couple of load/dump functions to convert to and from a human readable fmt.
while at it kill struct delivery and merge back its fields to the envelope.
this basically means we shouldn't require users to flush their queues every
time we make a change to struct envelope.
work is not done, but we're at a better state than the binary fsqueue so
we'll improve it in-tree.
has been running on my own box for the last 12 hours or so
ok eric@, chl@
Diffstat (limited to 'usr.sbin/smtpd/lka_session.c')
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 111 |
1 files changed, 56 insertions, 55 deletions
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index df60ebf1dd3..6c0ddcb82a3 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.10 2011/10/22 18:03:27 eric Exp $ */ +/* $OpenBSD: lka_session.c,v 1.11 2011/10/23 09:30:07 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -81,7 +81,7 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) char username[MAX_LOCALPART_SIZE]; /* remote delivery, no need to process further */ - if (ep->delivery.type == D_MTA) { + if (ep->type == D_MTA) { lka_session_deliver(lks, ep); return 1; } @@ -90,10 +90,10 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) case C_ALL: case C_NET: case C_DOM: { - if (ep->delivery.agent.mda.to.user[0] == '\0') - user = ep->delivery.rcpt.user; + if (ep->agent.mda.to.user[0] == '\0') + user = ep->dest.user; else - user = ep->delivery.agent.mda.to.user; + user = ep->agent.mda.to.user; lowercase(username, user, sizeof(username)); /* gilles+hackers@ -> gilles@ */ @@ -113,24 +113,24 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) if (! ub->getbyname(&u, username)) return 0; - (void)strlcpy(ep->delivery.agent.mda.as_user, u.username, - sizeof (ep->delivery.agent.mda.as_user)); + (void)strlcpy(ep->agent.mda.as_user, u.username, + sizeof (ep->agent.mda.as_user)); - ep->delivery.type = D_MDA; + ep->type = D_MDA; switch (ep->rule.r_action) { case A_MBOX: - ep->delivery.agent.mda.method = A_MBOX; - (void)strlcpy(ep->delivery.agent.mda.to.user, + ep->agent.mda.method = A_MBOX; + (void)strlcpy(ep->agent.mda.to.user, u.username, - sizeof (ep->delivery.agent.mda.to.user)); + sizeof (ep->agent.mda.to.user)); break; case A_MAILDIR: case A_FILENAME: case A_EXT: - ep->delivery.agent.mda.method = ep->rule.r_action; - (void)strlcpy(ep->delivery.agent.mda.to.buffer, + ep->agent.mda.method = ep->rule.r_action; + (void)strlcpy(ep->agent.mda.to.buffer, ep->rule.r_value.buffer, - sizeof (ep->delivery.agent.mda.to.buffer)); + sizeof (ep->agent.mda.to.buffer)); break; default: fatalx("lka_session_envelope_expand: unexpected rule action"); @@ -142,9 +142,9 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) } case C_VDOM: { - if (aliases_virtual_exist(ep->rule.r_condition.c_map, &ep->delivery.rcpt)) { + if (aliases_virtual_exist(ep->rule.r_condition.c_map, &ep->dest)) { if (! aliases_virtual_get(ep->rule.r_condition.c_map, - &lks->expandtree, &ep->delivery.rcpt)) + &lks->expandtree, &ep->dest)) return 0; return 1; } @@ -373,8 +373,8 @@ lka_session_deliver(struct lka_session *lks, struct envelope *ep) if (new_ep == NULL) fatal("lka_session_deliver: calloc"); *new_ep = *ep; - if (new_ep->delivery.type == D_MDA) { - d_mda = &new_ep->delivery.agent.mda; + if (new_ep->type == D_MDA) { + d_mda = &new_ep->agent.mda; if (d_mda->method == A_INVALID) fatalx("lka_session_deliver: mda method == A_INVALID"); @@ -391,11 +391,12 @@ lka_session_deliver(struct lka_session *lks, struct envelope *ep) default: break; } - } else if (new_ep->delivery.type == D_MTA) { + } + else if (new_ep->type == D_MTA) { if (ep->rule.r_action == A_RELAYVIA) - new_ep->delivery.agent.mta.relay = ep->rule.r_value.relayhost; + new_ep->agent.mta.relay = ep->rule.r_value.relayhost; if (ep->rule.r_as) - new_ep->delivery.from = *ep->rule.r_as; + new_ep->sender = *ep->rule.r_as; } TAILQ_INSERT_TAIL(&lks->deliverylist, new_ep, entry); } @@ -403,12 +404,12 @@ lka_session_deliver(struct lka_session *lks, struct envelope *ep) int lka_session_resolve_node(struct envelope *ep, struct expandnode *xn) { - struct delivery *dlv; - struct delivery olddlv; +// struct delivery *dlv; +// struct delivery olddlv; + struct envelope oldep; - dlv = &ep->delivery; - memcpy(&olddlv, dlv, sizeof (*dlv)); - bzero(&dlv->agent, sizeof (dlv->agent)); + memcpy(&oldep, ep, sizeof (*ep)); + bzero(&ep->agent, sizeof (ep->agent)); switch (xn->type) { case EXPAND_INVALID: @@ -419,13 +420,13 @@ lka_session_resolve_node(struct envelope *ep, struct expandnode *xn) case EXPAND_ADDRESS: log_debug("lka_resolve_node: node is address: %s@%s", xn->u.mailaddr.user, xn->u.mailaddr.domain); - dlv->rcpt = xn->u.mailaddr; + ep->dest = xn->u.mailaddr; /* evaluation of ruleset assumes local source * since we're expanding on already accepted * source. */ - dlv->flags |= DF_INTERNAL; + ep->flags |= DF_INTERNAL; if (! lka_session_rcpt_action(ep)) return -1; return 0; @@ -433,8 +434,8 @@ lka_session_resolve_node(struct envelope *ep, struct expandnode *xn) case EXPAND_USERNAME: log_debug("lka_resolve_node: node is local username: %s", xn->u.user); - dlv->type = D_MDA; - dlv->agent.mda.to = xn->u; + ep->type = D_MDA; + ep->agent.mda.to = xn->u; /* overwrite the initial condition before we expand the * envelope again. if we came from a C_VDOM, not doing @@ -448,35 +449,35 @@ lka_session_resolve_node(struct envelope *ep, struct expandnode *xn) /* if expansion of a user results in same user ... deliver */ if (strcmp(xn->u.user, xn->as_user) == 0) { - ep->delivery.agent.mda.method = olddlv.agent.mda.method; + ep->agent.mda.method = oldep.agent.mda.method; break; } /* otherwise rewrite delivery user with expansion result */ - (void)strlcpy(dlv->agent.mda.to.user, xn->u.user, - sizeof (dlv->agent.mda.to.user)); - (void)strlcpy(dlv->agent.mda.as_user, xn->u.user, - sizeof (dlv->agent.mda.as_user)); + (void)strlcpy(ep->agent.mda.to.user, xn->u.user, + sizeof (ep->agent.mda.to.user)); + (void)strlcpy(ep->agent.mda.as_user, xn->u.user, + sizeof (ep->agent.mda.as_user)); return 0; case EXPAND_FILENAME: log_debug("lka_resolve_node: node is filename: %s", xn->u.buffer); - dlv->type = D_MDA; - dlv->agent.mda.to = xn->u; - dlv->agent.mda.method = A_FILENAME; - (void)strlcpy(dlv->agent.mda.as_user, xn->as_user, - sizeof (dlv->agent.mda.as_user)); + ep->type = D_MDA; + ep->agent.mda.to = xn->u; + ep->agent.mda.method = A_FILENAME; + (void)strlcpy(ep->agent.mda.as_user, xn->as_user, + sizeof (ep->agent.mda.as_user)); break; case EXPAND_FILTER: log_debug("lka_resolve_node: node is filter: %s", xn->u.buffer); - dlv->type = D_MDA; - dlv->agent.mda.to = xn->u; - dlv->agent.mda.method = A_EXT; - (void)strlcpy(dlv->agent.mda.as_user, xn->as_user, - sizeof (dlv->agent.mda.as_user)); + ep->type = D_MDA; + ep->agent.mda.to = xn->u; + ep->agent.mda.method = A_EXT; + (void)strlcpy(ep->agent.mda.as_user, xn->as_user, + sizeof (ep->agent.mda.as_user)); break; } @@ -491,7 +492,7 @@ lka_session_expand_format(char *buf, size_t len, struct envelope *ep) struct user_backend *ub; struct user u; char lbuffer[MAX_RULEBUFFER_LEN]; - struct delivery *dlv = &ep->delivery; +// struct delivery *dlv = &ep->delivery; bzero(lbuffer, sizeof (lbuffer)); pbuf = lbuffer; @@ -504,7 +505,7 @@ lka_session_expand_format(char *buf, size_t len, struct envelope *ep) bzero(&u, sizeof (u)); ub = user_backend_lookup(USER_GETPWNAM); - if (! ub->getbyname(&u, dlv->agent.mda.as_user)) + if (! ub->getbyname(&u, ep->agent.mda.as_user)) return 0; lret = strlcat(pbuf, u.directory, len); @@ -549,19 +550,19 @@ lka_session_expand_format(char *buf, size_t len, struct envelope *ep) } switch (*tmp) { case 'U': - string = dlv->from.user; + string = ep->sender.user; break; case 'D': - string = dlv->from.domain; + string = ep->sender.domain; break; case 'a': - string = dlv->agent.mda.as_user; + string = ep->agent.mda.as_user; break; case 'u': - string = dlv->rcpt.user; + string = ep->dest.user; break; case 'd': - string = dlv->rcpt.domain; + string = ep->dest.domain; break; default: goto copy; @@ -604,7 +605,7 @@ lka_session_rcpt_action(struct envelope *ep) r = ruleset_match(ep); if (r == NULL) { - ep->delivery.type = D_MTA; + ep->type = D_MTA; return 0; } @@ -614,10 +615,10 @@ lka_session_rcpt_action(struct envelope *ep) case A_MAILDIR: case A_FILENAME: case A_EXT: - ep->delivery.type = D_MDA; + ep->type = D_MDA; break; default: - ep->delivery.type = D_MTA; + ep->type = D_MTA; } return 1; |