diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2008-12-13 19:05:27 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2008-12-13 19:05:27 +0000 |
commit | 148c4ae7ddfc47310109627eba86faebdc0f2893 (patch) | |
tree | a75a0c67847561f751d74ec3447886a07280a0ca /usr.sbin | |
parent | cb5d68f0b67082e9df46e63e2f1c4a70e25687b8 (diff) |
If parse_aliases fails, don't warn about syntax errors; it may fail
for other reasons.
Never exit outside main; we need to return to main to clean the
temp file.
Check parse_entry return code; otherwise $? == 0 even when invalid
entries were found.
ok gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/newaliases.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/usr.sbin/smtpd/newaliases.c b/usr.sbin/smtpd/newaliases.c index dacc33f7eca..60af25fa0d1 100644 --- a/usr.sbin/smtpd/newaliases.c +++ b/usr.sbin/smtpd/newaliases.c @@ -66,10 +66,8 @@ main(int argc, char *argv[]) goto bad; } - if (! parse_aliases(PATH_ALIASES)) { - warnx("syntax error in aliases file"); + if (! parse_aliases(PATH_ALIASES)) goto bad; - } if (db->close(db) == -1) { warn("dbclose: %s", dbname); @@ -102,14 +100,19 @@ parse_aliases(const char *filename) char delim[] = { '\\', '\\', '#' }; fp = fopen(filename, "r"); - if (fp == NULL) - errx(1, "failed to open aliases file"); - + if (fp == NULL) { + warn("%s", filename); + return 0; + } while ((line = fparseln(fp, &len, &lineno, delim, 0)) != NULL) { if (len == 0) continue; - parse_entry(line, len, lineno); + if (! parse_entry(line, len, lineno)) { + free(line); + fclose(fp); + return 0; + } free(line); } @@ -160,8 +163,10 @@ parse_entry(char *line, size_t len, size_t lineno) key.data = name; key.size = strlen(name) + 1; - if ((ret = db->get(db, &key, &val, 0)) == -1) - errx(1, "db->get()"); + if ((ret = db->get(db, &key, &val, 0)) == -1) { + warn("dbget"); + return 0; + } if (ret == 1) { val.data = NULL; @@ -175,23 +180,29 @@ parse_entry(char *line, size_t len, size_t lineno) val.size = sizeof(struct alias); val.data = &alias; - if ((ret = db->put(db, &key, &val, 0)) == -1) - errx(1, "db->get()"); + if ((ret = db->put(db, &key, &val, 0)) == -1) { + warn("dbput"); + return 0; + } } else { void *p; p = calloc(val.size + sizeof(alias), 1); - if (p == NULL) - errx(1, "calloc: memory exhausted"); + 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) - errx(1, "db->get()"); + if ((ret = db->put(db, &key, &val, 0)) == -1) { + warn("dbput"); + return 0; + } free(p); } |