summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-13 19:11:34 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2008-12-13 19:11:34 +0000
commit42ffb458c2ea7e8a1fc3d226bb765024fe83420d (patch)
tree5f9df71fbe7db7b084fc776a82c834c5ca1a7883 /usr.sbin
parent148c4ae7ddfc47310109627eba86faebdc0f2893 (diff)
Simplify parse_entry; streamline the code to call db->put in one
place, regardless of number of preexisting aliases. Don't call db->sync; it's covered by db->close shortly before rename. ok chl@ gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/newaliases.c62
1 files changed, 22 insertions, 40 deletions
diff --git a/usr.sbin/smtpd/newaliases.c b/usr.sbin/smtpd/newaliases.c
index 60af25fa0d1..27e7cb23c98 100644
--- a/usr.sbin/smtpd/newaliases.c
+++ b/usr.sbin/smtpd/newaliases.c
@@ -127,8 +127,6 @@ parse_entry(char *line, size_t len, size_t lineno)
char *delim;
char *rcpt;
char *subrcpt;
- struct alias alias;
- int ret;
DBT key;
DBT val;
@@ -150,7 +148,10 @@ parse_entry(char *line, size_t len, size_t lineno)
goto bad;
/* At this point, name points to nul-terminate name */
- for (; (subrcpt = strsep(&rcpt, ",")) != NULL;) {
+ while ((subrcpt = strsep(&rcpt, ",")) != NULL) {
+ struct alias alias;
+ void *p;
+
while (*subrcpt && isspace(*subrcpt))
++subrcpt;
if (*subrcpt == '\0')
@@ -160,54 +161,35 @@ parse_entry(char *line, size_t len, size_t lineno)
while (isspace(*delim))
*delim-- = '\0';
+ if (! alias_parse(&alias, subrcpt))
+ goto bad;
+
key.data = name;
key.size = strlen(name) + 1;
-
- if ((ret = db->get(db, &key, &val, 0)) == -1) {
+ val.data = NULL;
+ val.size = 0;
+ if (db->get(db, &key, &val, 0) == -1) {
warn("dbget");
return 0;
}
- if (ret == 1) {
- val.data = NULL;
- val.size = 0;
- }
-
- if (! alias_parse(&alias, subrcpt))
- goto bad;
-
- if (val.size == 0) {
- val.size = sizeof(struct alias);
- val.data = &alias;
-
- if ((ret = db->put(db, &key, &val, 0)) == -1) {
- warn("dbput");
- return 0;
- }
+ p = calloc(1, val.size + sizeof(struct alias));
+ if (p == NULL) {
+ warn("calloc");
+ return 0;
}
- else {
- void *p;
-
- p = calloc(val.size + sizeof(alias), 1);
- if (p == NULL) {
- warn("calloc");
- return 0;
- }
- memcpy(p, val.data, val.size);
- memcpy((u_int8_t *)p + val.size, &alias, sizeof(alias));
-
- val.data = p;
- val.size += sizeof(alias);
-
- if ((ret = db->put(db, &key, &val, 0)) == -1) {
- warn("dbput");
- return 0;
- }
+ memcpy(p, val.data, val.size);
+ memcpy((u_int8_t *)p + val.size, &alias, sizeof(struct alias));
+ val.data = p;
+ val.size += sizeof(struct alias);
+ if (db->put(db, &key, &val, 0) == -1) {
+ warn("dbput");
free(p);
+ return 0;
}
- db->sync(db, 0);
+ free(p);
}
return 1;