diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-05-13 21:20:56 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-05-13 21:20:56 +0000 |
commit | e9d3913b8e8939eb82d3476ea06ef58adea70da5 (patch) | |
tree | 6b5658c977aa7811d42bca65c85aeca35baaeabc | |
parent | 87b7d7c228a4305751170cba8b48bb727e7332c9 (diff) |
log dbopen and db->get errors; based on diff from Daniel Ouellet.
looks ok to gilles@
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 46 | ||||
-rw-r--r-- | usr.sbin/smtpd/map.c | 7 |
2 files changed, 35 insertions, 18 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index cb4ee6dc0ae..8208af69d40 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.17 2009/04/24 10:02:35 jacekm Exp $ */ +/* $OpenBSD: aliases.c,v 1.18 2009/05/13 21:20:55 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -56,21 +56,22 @@ aliases_exist(struct smtpd *env, char *username) return 0; aliasesdb = dbopen(map->m_config, O_RDONLY, 0600, DB_HASH, NULL); - if (aliasesdb == NULL) + if (aliasesdb == NULL) { + log_warn("aliases_exist: dbopen"); return 0; + } lowercase(buf, username, sizeof(buf)); key.data = buf; key.size = strlen(key.data) + 1; - if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) == -1) { - aliasesdb->close(aliasesdb); - return 0; - } + ret = aliasesdb->get(aliasesdb, &key, &val, 0); + if (ret == -1) + log_warn("aliases_exist"); aliasesdb->close(aliasesdb); - return ret == 0 ? 1 : 0; + return (ret == 0); } int @@ -92,8 +93,10 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username) return 0; aliasesdb = dbopen(map->m_config, O_RDONLY, 0600, DB_HASH, NULL); - if (aliasesdb == NULL) + if (aliasesdb == NULL) { + log_warn("aliases_get: dbopen"); return 0; + } lowercase(buf, username, sizeof(buf)); @@ -101,6 +104,8 @@ aliases_get(struct smtpd *env, struct aliaseslist *aliases, char *username) key.size = strlen(key.data) + 1; if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) != 0) { + if (ret == -1) + log_warn("aliases_get"); aliasesdb->close(aliasesdb); return 0; } @@ -145,8 +150,10 @@ aliases_virtual_exist(struct smtpd *env, struct path *path) return 0; aliasesdb = dbopen(map->m_config, O_RDONLY, 0600, DB_HASH, NULL); - if (aliasesdb == NULL) + if (aliasesdb == NULL) { + log_warn("aliases_virtual_exist: dbopen"); return 0; + } if (! bsnprintf(strkey, sizeof(strkey), "%s@%s", path->user, path->domain)) { @@ -160,6 +167,8 @@ aliases_virtual_exist(struct smtpd *env, struct path *path) key.size = strlen(key.data) + 1; if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) != 0) { + if (ret == -1) + log_warn("aliases_virtual_exist"); if (! bsnprintf(strkey, sizeof(strkey), "@%s", path->domain)) { aliasesdb->close(aliasesdb); @@ -171,14 +180,13 @@ aliases_virtual_exist(struct smtpd *env, struct path *path) key.data = strkey; key.size = strlen(key.data) + 1; - if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) != 0) { - aliasesdb->close(aliasesdb); - return 0; - } + ret = aliasesdb->get(aliasesdb, &key, &val, 0); } + if (ret == -1) + log_warn("aliases_virtual_exist"); aliasesdb->close(aliasesdb); - return ret == 0 ? 1 : 0; + return (ret == 0); } int @@ -201,8 +209,10 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, return 0; aliasesdb = dbopen(map->m_config, O_RDONLY, 0600, DB_HASH, NULL); - if (aliasesdb == NULL) + if (aliasesdb == NULL) { + log_warn("aliases_virtual_get: dbopen"); return 0; + } if (! bsnprintf(strkey, sizeof(strkey), "%s@%s", path->user, path->domain)) { @@ -216,6 +226,8 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, key.size = strlen(key.data) + 1; if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) != 0) { + if (ret == -1) + log_warn("aliases_virtual_get"); if (! bsnprintf(strkey, sizeof(strkey), "@%s", path->domain)) { aliasesdb->close(aliasesdb); @@ -228,6 +240,8 @@ aliases_virtual_get(struct smtpd *env, struct aliaseslist *aliases, key.size = strlen(key.data) + 1; if ((ret = aliasesdb->get(aliasesdb, &key, &val, 0)) != 0) { + if (ret == -1) + log_warn("aliases_virtual_get"); aliasesdb->close(aliasesdb); return 0; } @@ -271,7 +285,7 @@ aliases_expand_include(struct aliaseslist *aliases, char *filename) fp = fopen(filename, "r"); if (fp == NULL) { - log_warnx("failed to open include file \"%s\".", filename); + log_warn("failed to open include file \"%s\".", filename); return 0; } diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c index f9db97397d5..28466c02462 100644 --- a/usr.sbin/smtpd/map.c +++ b/usr.sbin/smtpd/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.5 2009/03/06 23:38:18 gilles Exp $ */ +/* $OpenBSD: map.c,v 1.6 2009/05/13 21:20:55 jacekm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -76,13 +76,16 @@ map_dblookup(struct smtpd *env, char *mapname, char *keyname) } db = dbopen(map->m_config, O_RDONLY, 0600, DB_HASH, NULL); - if (db == NULL) + if (db == NULL) { + log_warn("map_dblookup: can't open %s", map->m_config); return NULL; + } key.data = keyname; key.size = strlen(key.data) + 1; if ((ret = db->get(db, &key, &val, 0)) == -1) { + log_warn("map_dblookup: map '%s'", mapname); db->close(db); return NULL; } |