diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-21 16:40:21 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-21 16:40:21 +0000 |
commit | 798a848ddabe2ad7406d31f9a6b37f54a0405cbd (patch) | |
tree | ccbe2f58dc20b9437f5bef5c157bfa36c7f1062c /usr.sbin | |
parent | 435dd7662458f4444988e5c2144782dff64f14bf (diff) |
wrap expandtree into a "struct expand".
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 32 | ||||
-rw-r--r-- | usr.sbin/smtpd/expand.c | 18 | ||||
-rw-r--r-- | usr.sbin/smtpd/forward.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 18 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_db.c | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_static.c | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/map_stdio.c | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 22 |
8 files changed, 64 insertions, 68 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index 43c4073102b..9a9aa9b6080 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.54 2012/09/20 14:28:57 eric Exp $ */ +/* $OpenBSD: aliases.c,v 1.55 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -33,7 +33,7 @@ #include "smtpd.h" #include "log.h" -static int aliases_expand_include(struct expandtree *, const char *); +static int aliases_expand_include(struct expand *, const char *); static int alias_is_filter(struct expandnode *, const char *, size_t); static int alias_is_username(struct expandnode *, const char *, size_t); static int alias_is_address(struct expandnode *, const char *, size_t); @@ -41,7 +41,7 @@ static int alias_is_filename(struct expandnode *, const char *, size_t); static int alias_is_include(struct expandnode *, const char *, size_t); int -aliases_get(objid_t mapid, struct expandtree *expandtree, const char *username) +aliases_get(objid_t mapid, struct expand *expand, const char *username) { struct map_alias *map_alias; struct expandnode *xn; @@ -55,17 +55,17 @@ aliases_get(objid_t mapid, struct expandtree *expandtree, const char *username) /* foreach node in map_alias expandtree, we merge */ nbaliases = 0; - RB_FOREACH(xn, expandtree, &map_alias->expandtree) { + RB_FOREACH(xn, expandtree, &map_alias->expand.tree) { strlcpy(xn->as_user, SMTPD_USER, sizeof (xn->as_user)); if (xn->type == EXPAND_INCLUDE) - nbaliases += aliases_expand_include(expandtree, xn->u.buffer); + nbaliases += aliases_expand_include(expand, xn->u.buffer); else { - expand_insert(expandtree, xn); + expand_insert(expand, xn); nbaliases++; } } - expand_free(&map_alias->expandtree); + expand_free(&map_alias->expand); free(map_alias); log_debug("aliases_get: returned %zd aliases", nbaliases); @@ -73,7 +73,7 @@ aliases_get(objid_t mapid, struct expandtree *expandtree, const char *username) } int -aliases_virtual_get(objid_t mapid, struct expandtree *expandtree, +aliases_virtual_get(objid_t mapid, struct expand *expand, const struct mailaddr *maddr) { struct map_virtual *map_virtual; @@ -95,19 +95,19 @@ aliases_virtual_get(objid_t mapid, struct expandtree *expandtree, if (map_virtual == NULL) return 0; - /* foreach node in map_virtual expandtree, we merge */ + /* foreach node in map_virtual expand, we merge */ nbaliases = 0; - RB_FOREACH(xn, expandtree, &map_virtual->expandtree) { + RB_FOREACH(xn, expandtree, &map_virtual->expand.tree) { strlcpy(xn->as_user, SMTPD_USER, sizeof (xn->as_user)); if (xn->type == EXPAND_INCLUDE) - nbaliases += aliases_expand_include(expandtree, xn->u.buffer); + nbaliases += aliases_expand_include(expand, xn->u.buffer); else { - expand_insert(expandtree, xn); + expand_insert(expand, xn); nbaliases++; } } - expand_free(&map_virtual->expandtree); + expand_free(&map_virtual->expand); free(map_virtual); log_debug("aliases_virtual_get: '%s' resolved to %d nodes", pbuf, nbaliases); @@ -127,14 +127,14 @@ aliases_vdomain_exists(objid_t mapid, const char *hostname) /* XXX - for now the map API always allocate */ log_debug("aliases_vdomain_exist: '%s' exists", hostname); - expand_free(&map_virtual->expandtree); + expand_free(&map_virtual->expand); free(map_virtual); return 1; } static int -aliases_expand_include(struct expandtree *expandtree, const char *filename) +aliases_expand_include(struct expand *expand, const char *filename) { FILE *fp; char *line; @@ -162,7 +162,7 @@ aliases_expand_include(struct expandtree *expandtree, const char *filename) if (xn.type == EXPAND_INCLUDE) log_warnx("nested inclusion is not supported."); else - expand_insert(expandtree, &xn); + expand_insert(expand, &xn); free(line); } diff --git a/usr.sbin/smtpd/expand.c b/usr.sbin/smtpd/expand.c index 4d4fa5009e2..a3c9b9733eb 100644 --- a/usr.sbin/smtpd/expand.c +++ b/usr.sbin/smtpd/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.14 2012/09/19 12:45:04 eric Exp $ */ +/* $OpenBSD: expand.c,v 1.15 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org> @@ -32,30 +32,30 @@ #include "log.h" struct expandnode * -expand_lookup(struct expandtree *expandtree, struct expandnode *key) +expand_lookup(struct expand *expand, struct expandnode *key) { - return RB_FIND(expandtree, expandtree, key); + return RB_FIND(expandtree, &expand->tree, key); } void -expand_insert(struct expandtree *expandtree, struct expandnode *node) +expand_insert(struct expand *expand, struct expandnode *node) { struct expandnode *xn; - if (expand_lookup(expandtree, node)) + if (expand_lookup(expand, node)) return; xn = xmemdup(node, sizeof *xn, "expand_insert"); - RB_INSERT(expandtree, expandtree, xn); + RB_INSERT(expandtree, &expand->tree, xn); } void -expand_free(struct expandtree *expandtree) +expand_free(struct expand *expand) { struct expandnode *xn; - while ((xn = RB_ROOT(expandtree)) != NULL) { - RB_REMOVE(expandtree, expandtree, xn); + while ((xn = RB_ROOT(&expand->tree)) != NULL) { + RB_REMOVE(expandtree, &expand->tree, xn); free(xn); } } diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c index a4714fb2172..ce8938f3e95 100644 --- a/usr.sbin/smtpd/forward.c +++ b/usr.sbin/smtpd/forward.c @@ -1,4 +1,4 @@ -/* $OpenBSD: forward.c,v 1.28 2012/09/20 14:28:57 eric Exp $ */ +/* $OpenBSD: forward.c,v 1.29 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -34,7 +34,7 @@ #include "log.h" int -forwards_get(int fd, struct expandtree *expandtree, const char *as_user) +forwards_get(int fd, struct expand *expand, const char *as_user) { FILE *fp; char *buf, *lbuf, *p, *cp; @@ -95,7 +95,7 @@ forwards_get(int fd, struct expandtree *expandtree, const char *as_user) (void)strlcpy(xn.as_user, as_user, sizeof(xn.as_user)); - expand_insert(expandtree, &xn); + expand_insert(expand, &xn); nbaliases++; } while (*cp != '\0'); } diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index 5cfdbc2c1e6..ee77d3a3498 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.31 2012/09/21 13:23:07 eric Exp $ */ +/* $OpenBSD: lka_session.c,v 1.32 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -48,7 +48,7 @@ struct lka_session { uint64_t id; TAILQ_HEAD(, envelope) deliverylist; - struct expandtree expandtree; + struct expand expand; uint8_t iterations; uint32_t pending; @@ -80,7 +80,7 @@ lka_session(struct submit_status *ss) lks->id = generate_uid(); lks->ss = *ss; lks->ss.code = 250; - RB_INIT(&lks->expandtree); + RB_INIT(&lks->expand.tree); TAILQ_INIT(&lks->deliverylist); tree_xset(&sessions, lks->id, lks); @@ -123,7 +123,7 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) tag++; } - if (aliases_get(ep->rule.r_amap, &lks->expandtree, username)) + if (aliases_get(ep->rule.r_amap, &lks->expand, username)) return 1; bzero(&u, sizeof (u)); @@ -167,7 +167,7 @@ lka_session_envelope_expand(struct lka_session *lks, struct envelope *ep) case C_VDOM: if (aliases_virtual_get(ep->rule.r_condition.c_map, - &lks->expandtree, &ep->dest)) + &lks->expand, &ep->dest)) return 1; return 0; @@ -193,7 +193,7 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd) if (fd != -1) { /* opened .forward okay */ - if (! forwards_get(fd, &lks->expandtree, fwreq->as_user)) { + if (! forwards_get(fd, &lks->expand, fwreq->as_user)) { lks->ss.code = 530; lks->flags |= F_ERROR; } @@ -249,7 +249,7 @@ lka_session_resume(struct lka_session *lks, struct envelope *ep) struct expandnode *xn; uint8_t done = 1; - RB_FOREACH(xn, expandtree, &lks->expandtree) { + RB_FOREACH(xn, expandtree, &lks->expand.tree) { /* this node has already been expanded, skip */ if (xn->done) @@ -276,7 +276,7 @@ lka_session_resume(struct lka_session *lks, struct envelope *ep) return -1; /* we're done expanding, no need for another iteration */ - if (RB_ROOT(&lks->expandtree) == NULL || done) + if (RB_ROOT(&lks->expand.tree) == NULL || done) return 0; return 1; @@ -334,7 +334,7 @@ lka_session_destroy(struct lka_session *lks) free(ep); } - expand_free(&lks->expandtree); + expand_free(&lks->expand); tree_xpop(&sessions, lks->id); free(lks); } diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c index 077f4c6c264..3f77c277e9e 100644 --- a/usr.sbin/smtpd/map_db.c +++ b/usr.sbin/smtpd/map_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_db.c,v 1.8 2012/09/21 10:22:29 eric Exp $ */ +/* $OpenBSD: map_db.c,v 1.9 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -236,15 +236,14 @@ map_db_alias(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_alias->expandtree, &xn); + expand_insert(&map_alias->expand, &xn); map_alias->nbnodes++; } return map_alias; error: - /* free elements in map_alias->expandtree */ - expand_free(&map_alias->expandtree); + expand_free(&map_alias->expand); free(map_alias); return NULL; } @@ -280,15 +279,14 @@ map_db_virtual(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_virtual->expandtree, &xn); + expand_insert(&map_virtual->expand, &xn); map_virtual->nbnodes++; } return map_virtual; error: - /* free elements in map_virtual->expandtree */ - expand_free(&map_virtual->expandtree); + expand_free(&map_virtual->expand); free(map_virtual); return NULL; } diff --git a/usr.sbin/smtpd/map_static.c b/usr.sbin/smtpd/map_static.c index f5178fc240c..646b1eb5d74 100644 --- a/usr.sbin/smtpd/map_static.c +++ b/usr.sbin/smtpd/map_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_static.c,v 1.5 2012/09/21 10:22:29 eric Exp $ */ +/* $OpenBSD: map_static.c,v 1.6 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org> @@ -204,15 +204,14 @@ map_static_alias(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_alias->expandtree, &xn); + expand_insert(&map_alias->expand, &xn); map_alias->nbnodes++; } return map_alias; error: - /* free elements in map_alias->expandtree */ - expand_free(&map_alias->expandtree); + expand_free(&map_alias->expand); free(map_alias); return NULL; } @@ -248,15 +247,14 @@ map_static_virtual(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_virtual->expandtree, &xn); + expand_insert(&map_virtual->expand, &xn); map_virtual->nbnodes++; } return map_virtual; error: - /* free elements in map_virtual->expandtree */ - expand_free(&map_virtual->expandtree); + expand_free(&map_virtual->expand); free(map_virtual); return NULL; } diff --git a/usr.sbin/smtpd/map_stdio.c b/usr.sbin/smtpd/map_stdio.c index ef6f37ee3f2..faf84ce4e48 100644 --- a/usr.sbin/smtpd/map_stdio.c +++ b/usr.sbin/smtpd/map_stdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map_stdio.c,v 1.8 2012/09/21 10:22:29 eric Exp $ */ +/* $OpenBSD: map_stdio.c,v 1.9 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -267,15 +267,14 @@ map_stdio_alias(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_alias->expandtree, &xn); + expand_insert(&map_alias->expand, &xn); map_alias->nbnodes++; } return map_alias; error: - /* free elements in map_alias->expandtree */ - expand_free(&map_alias->expandtree); + expand_free(&map_alias->expand); free(map_alias); return NULL; } @@ -311,15 +310,14 @@ map_stdio_virtual(const char *key, char *line, size_t len) if (! alias_parse(&xn, subrcpt)) goto error; - expand_insert(&map_virtual->expandtree, &xn); + expand_insert(&map_virtual->expand, &xn); map_virtual->nbnodes++; } return map_virtual; error: - /* free elements in map_virtual->expandtree */ - expand_free(&map_virtual->expandtree); + expand_free(&map_virtual->expand); free(map_virtual); return NULL; } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 1e6ae321f26..28cd955fb0e 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.364 2012/09/21 13:23:07 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.365 2012/09/21 16:40:20 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -376,7 +376,9 @@ struct expandnode { union delivery_data u; }; -RB_HEAD(expandtree, expandnode); +struct expand { + RB_HEAD(expandtree, expandnode) tree; +}; #define SMTPD_ENVELOPE_VERSION 1 struct envelope { @@ -752,12 +754,12 @@ struct map_credentials { struct map_alias { size_t nbnodes; - struct expandtree expandtree; + struct expand expand; }; struct map_virtual { size_t nbnodes; - struct expandtree expandtree; + struct expand expand; }; struct map_netaddr { @@ -911,8 +913,8 @@ extern void (*imsg_callback)(struct imsgev *, struct imsg *); /* aliases.c */ -int aliases_get(objid_t, struct expandtree *, const char *); -int aliases_virtual_get(objid_t, struct expandtree *, const struct mailaddr *); +int aliases_get(objid_t, struct expand *, const char *); +int aliases_virtual_get(objid_t, struct expand *, const struct mailaddr *); int aliases_vdomain_exists(objid_t, const char *); int alias_parse(struct expandnode *, char *); @@ -973,13 +975,13 @@ int envelope_dump_buffer(struct envelope *, char *, size_t); /* expand.c */ int expand_cmp(struct expandnode *, struct expandnode *); -void expand_insert(struct expandtree *, struct expandnode *); -struct expandnode *expand_lookup(struct expandtree *, struct expandnode *); -void expand_free(struct expandtree *); +void expand_insert(struct expand *, struct expandnode *); +struct expandnode *expand_lookup(struct expand *, struct expandnode *); +void expand_free(struct expand *); RB_PROTOTYPE(expandtree, expandnode, nodes, expand_cmp); /* forward.c */ -int forwards_get(int, struct expandtree *, const char *); +int forwards_get(int, struct expand *, const char *); /* lka.c */ |