summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2012-09-19 09:06:35 +0000
committereric <eric@openbsd.org>2012-09-19 09:06:35 +0000
commitfaa7039fb7e8c424415755cf701e017014ffd607 (patch)
treef5705795ab2b0963f7887bce7a617a83f7fc6f7e
parentremove files that became unused by new configuration syntax. (diff)
downloadwireguard-openbsd-faa7039fb7e8c424415755cf701e017014ffd607.tar.xz
wireguard-openbsd-faa7039fb7e8c424415755cf701e017014ffd607.zip
start cleaning the expansion code:
- change expandtree_* prefix to expand_ for better readability and because the structure might change at some point - rename <>_free_nodes() to <>_free() - remove unused <>_remove_node() - refcounting has no purpose at all; just remove it as well as the decrement/increment functions, and replace the latter with <>_insert - expandnode flags is only used to know if it's been processed or not, don't make it a flag but a simple field with clear name. ok gilles@ chl@
-rw-r--r--usr.sbin/smtpd/aliases.c18
-rw-r--r--usr.sbin/smtpd/expand.c50
-rw-r--r--usr.sbin/smtpd/forward.c4
-rw-r--r--usr.sbin/smtpd/lka_session.c10
-rw-r--r--usr.sbin/smtpd/map_db.c10
-rw-r--r--usr.sbin/smtpd/map_static.c10
-rw-r--r--usr.sbin/smtpd/map_stdio.c10
-rw-r--r--usr.sbin/smtpd/smtpd.h19
8 files changed, 44 insertions, 87 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c
index 33ac248730a..2d358e59947 100644
--- a/usr.sbin/smtpd/aliases.c
+++ b/usr.sbin/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.49 2012/09/18 12:54:56 eric Exp $ */
+/* $OpenBSD: aliases.c,v 1.50 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -55,7 +55,7 @@ aliases_exist(objid_t mapid, char *username)
log_debug("aliases_exist: '%s' exists with %zd expansion nodes",
username, map_alias->nbnodes);
- expandtree_free_nodes(&map_alias->expandtree);
+ expand_free(&map_alias->expandtree);
free(map_alias);
return 1;
@@ -81,12 +81,12 @@ aliases_get(objid_t mapid, struct expandtree *expandtree, char *username)
if (expnode->type == EXPAND_INCLUDE)
nbaliases += aliases_expand_include(expandtree, expnode->u.buffer);
else {
- expandtree_increment_node(expandtree, expnode);
+ expand_insert(expandtree, expnode);
nbaliases++;
}
}
- expandtree_free_nodes(&map_alias->expandtree);
+ expand_free(&map_alias->expandtree);
free(map_alias);
log_debug("aliases_get: returned %zd aliases", nbaliases);
@@ -106,7 +106,7 @@ aliases_vdomain_exists(objid_t mapid, char *hostname)
/* XXX - for now the map API always allocate */
log_debug("aliases_vdomain_exist: '%s' exists", hostname);
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
return 1;
@@ -133,7 +133,7 @@ aliases_virtual_exist(objid_t mapid, struct mailaddr *maddr)
return 0;
log_debug("aliases_virtual_exist: '%s' exists", pbuf);
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
return 1;
@@ -169,12 +169,12 @@ aliases_virtual_get(objid_t mapid, struct expandtree *expandtree,
if (expnode->type == EXPAND_INCLUDE)
nbaliases += aliases_expand_include(expandtree, expnode->u.buffer);
else {
- expandtree_increment_node(expandtree, expnode);
+ expand_insert(expandtree, expnode);
nbaliases++;
}
}
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
log_debug("aliases_virtual_get: '%s' resolved to %d nodes", pbuf, nbaliases);
@@ -211,7 +211,7 @@ aliases_expand_include(struct expandtree *expandtree, const char *filename)
if (expnode.type == EXPAND_INCLUDE)
log_warnx("nested inclusion is not supported.");
else
- expandtree_increment_node(expandtree, &expnode);
+ expand_insert(expandtree, &expnode);
free(line);
}
diff --git a/usr.sbin/smtpd/expand.c b/usr.sbin/smtpd/expand.c
index 5f6fd8754bd..8f265a1c17b 100644
--- a/usr.sbin/smtpd/expand.c
+++ b/usr.sbin/smtpd/expand.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: expand.c,v 1.12 2012/09/18 15:35:13 eric Exp $ */
+/* $OpenBSD: expand.c,v 1.13 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -32,57 +32,25 @@
#include "log.h"
struct expandnode *
-expandtree_lookup(struct expandtree *expandtree, struct expandnode *node)
+expand_lookup(struct expandtree *expandtree, struct expandnode *key)
{
- struct expandnode key;
-
- key = *node;
- return RB_FIND(expandtree, expandtree, &key);
-}
-
-void
-expandtree_increment_node(struct expandtree *expandtree, struct expandnode *node)
-{
- struct expandnode *p;
-
- p = expandtree_lookup(expandtree, node);
- if (p == NULL) {
- p = calloc(1, sizeof(struct expandnode));
- if (p == NULL)
- fatal("calloc");
- *p = *node;
- if (RB_INSERT(expandtree, expandtree, p))
- fatalx("expandtree_increment_node: node already exists");
- }
- p->refcnt++;
-}
-
-void
-expandtree_decrement_node(struct expandtree *expandtree, struct expandnode *node)
-{
- struct expandnode *p;
-
- p = expandtree_lookup(expandtree, node);
- if (p == NULL)
- fatalx("expandtree_decrement_node: node doesn't exist.");
-
- p->refcnt--;
+ return RB_FIND(expandtree, expandtree, key);
}
void
-expandtree_remove_node(struct expandtree *expandtree, struct expandnode *node)
+expand_insert(struct expandtree *expandtree, struct expandnode *node)
{
struct expandnode *p;
- p = expandtree_lookup(expandtree, node);
- if (p == NULL)
- fatalx("expandtree_remove: node doesn't exist.");
+ if (expand_lookup(expandtree, node))
+ return;
- RB_REMOVE(expandtree, expandtree, p);
+ p = xmemdup(node, sizeof *p, "expand_insert");
+ RB_INSERT(expandtree, expandtree, p);
}
void
-expandtree_free_nodes(struct expandtree *expandtree)
+expand_free(struct expandtree *expandtree)
{
struct expandnode *xn;
diff --git a/usr.sbin/smtpd/forward.c b/usr.sbin/smtpd/forward.c
index a8046cfad8b..a23c6d215da 100644
--- a/usr.sbin/smtpd/forward.c
+++ b/usr.sbin/smtpd/forward.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: forward.c,v 1.24 2011/05/16 21:05:51 gilles Exp $ */
+/* $OpenBSD: forward.c,v 1.25 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -96,7 +96,7 @@ forwards_get(int fd, struct expandtree *expandtree, char *as_user)
(void)strlcpy(expnode.as_user, as_user, sizeof(expnode.as_user));
- expandtree_increment_node(expandtree, &expnode);
+ expand_insert(expandtree, &expnode);
nbaliases++;
} while (*cp != '\0');
}
diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c
index eebee6052e1..4c31b28a0e9 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.27 2012/09/18 15:35:13 eric Exp $ */
+/* $OpenBSD: lka_session.c,v 1.28 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -243,7 +243,7 @@ lka_session_resume(struct lka_session *lks, struct envelope *ep)
RB_FOREACH(xn, expandtree, &lks->expandtree) {
/* this node has already been expanded, skip */
- if (xn->flags & F_EXPAND_DONE)
+ if (xn->done)
continue;
done = 0;
@@ -259,9 +259,7 @@ lka_session_resume(struct lka_session *lks, struct envelope *ep)
return -1;
}
- /* decrement refcount on this node and flag it as processed */
- expandtree_decrement_node(&lks->expandtree, xn);
- xn->flags |= F_EXPAND_DONE;
+ xn->done = 1;
}
/* still not done after 5 iterations ? loop detected ... reject */
@@ -327,7 +325,7 @@ lka_session_destroy(struct lka_session *lks)
free(ep);
}
- expandtree_free_nodes(&lks->expandtree);
+ expand_free(&lks->expandtree);
tree_xpop(&sessions, lks->id);
free(lks);
}
diff --git a/usr.sbin/smtpd/map_db.c b/usr.sbin/smtpd/map_db.c
index b014fd929f3..539a5ecb6d9 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.4 2012/05/29 19:53:10 gilles Exp $ */
+/* $OpenBSD: map_db.c,v 1.5 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -233,7 +233,7 @@ map_db_alias(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_alias->expandtree, &expnode);
+ expand_insert(&map_alias->expandtree, &expnode);
map_alias->nbnodes++;
}
@@ -241,7 +241,7 @@ map_db_alias(char *key, char *line, size_t len)
error:
/* free elements in map_alias->expandtree */
- expandtree_free_nodes(&map_alias->expandtree);
+ expand_free(&map_alias->expandtree);
free(map_alias);
return NULL;
}
@@ -278,7 +278,7 @@ map_db_virtual(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_virtual->expandtree, &expnode);
+ expand_insert(&map_virtual->expandtree, &expnode);
map_virtual->nbnodes++;
}
@@ -286,7 +286,7 @@ map_db_virtual(char *key, char *line, size_t len)
error:
/* free elements in map_virtual->expandtree */
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
return NULL;
}
diff --git a/usr.sbin/smtpd/map_static.c b/usr.sbin/smtpd/map_static.c
index 86488338ba9..c3088a3cd70 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.1 2012/05/29 19:53:10 gilles Exp $ */
+/* $OpenBSD: map_static.c,v 1.2 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@openbsd.org>
@@ -205,7 +205,7 @@ map_static_alias(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_alias->expandtree, &expnode);
+ expand_insert(&map_alias->expandtree, &expnode);
map_alias->nbnodes++;
}
@@ -213,7 +213,7 @@ map_static_alias(char *key, char *line, size_t len)
error:
/* free elements in map_alias->expandtree */
- expandtree_free_nodes(&map_alias->expandtree);
+ expand_free(&map_alias->expandtree);
free(map_alias);
return NULL;
}
@@ -250,7 +250,7 @@ map_static_virtual(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_virtual->expandtree, &expnode);
+ expand_insert(&map_virtual->expandtree, &expnode);
map_virtual->nbnodes++;
}
@@ -258,7 +258,7 @@ map_static_virtual(char *key, char *line, size_t len)
error:
/* free elements in map_virtual->expandtree */
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
return NULL;
}
diff --git a/usr.sbin/smtpd/map_stdio.c b/usr.sbin/smtpd/map_stdio.c
index 163e7e314d2..e10027a031a 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.4 2012/05/29 19:53:10 gilles Exp $ */
+/* $OpenBSD: map_stdio.c,v 1.5 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -268,7 +268,7 @@ map_stdio_alias(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_alias->expandtree, &expnode);
+ expand_insert(&map_alias->expandtree, &expnode);
map_alias->nbnodes++;
}
@@ -276,7 +276,7 @@ map_stdio_alias(char *key, char *line, size_t len)
error:
/* free elements in map_alias->expandtree */
- expandtree_free_nodes(&map_alias->expandtree);
+ expand_free(&map_alias->expandtree);
free(map_alias);
return NULL;
}
@@ -313,7 +313,7 @@ map_stdio_virtual(char *key, char *line, size_t len)
if (! alias_parse(&expnode, subrcpt))
goto error;
- expandtree_increment_node(&map_virtual->expandtree, &expnode);
+ expand_insert(&map_virtual->expandtree, &expnode);
map_virtual->nbnodes++;
}
@@ -321,7 +321,7 @@ map_stdio_virtual(char *key, char *line, size_t len)
error:
/* free elements in map_virtual->expandtree */
- expandtree_free_nodes(&map_virtual->expandtree);
+ expand_free(&map_virtual->expandtree);
free(map_virtual);
return NULL;
}
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index b74e445d6be..a19ea91328c 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.356 2012/09/18 14:23:01 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.357 2012/09/19 09:06:35 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -371,15 +371,9 @@ enum expand_type {
EXPAND_ADDRESS
};
-enum expand_flags {
- F_EXPAND_NONE,
- F_EXPAND_DONE
-};
-
struct expandnode {
RB_ENTRY(expandnode) entry;
- size_t refcnt;
- enum expand_flags flags;
+ int done;
enum expand_type type;
char as_user[MAXLOGNAME];
union delivery_data u;
@@ -1001,14 +995,11 @@ int envelope_dump_buffer(struct envelope *, char *, size_t);
/* expand.c */
int expand_cmp(struct expandnode *, struct expandnode *);
-void expandtree_increment_node(struct expandtree *, struct expandnode *);
-void expandtree_decrement_node(struct expandtree *, struct expandnode *);
-void expandtree_remove_node(struct expandtree *, struct expandnode *);
-struct expandnode *expandtree_lookup(struct expandtree *, struct expandnode *);
-void expandtree_free_nodes(struct expandtree *);
+void expand_insert(struct expandtree *, struct expandnode *);
+struct expandnode *expand_lookup(struct expandtree *, struct expandnode *);
+void expand_free(struct expandtree *);
RB_PROTOTYPE(expandtree, expandnode, nodes, expand_cmp);
-
/* forward.c */
int forwards_get(int, struct expandtree *, char *);