uint32_t old_count = 0;
uint32_t new_count = 0;
bool replace = false;
+ bool trashable = false;
char tmppath[PATH_MAX];
snprintf(tmppath, PATH_MAX, "%s.tmp", path);
awl_db = tcbdbnew();
if (tcbdbopen(awl_db, path, BDBOREADER)) {
tmp_db = tcbdbnew();
- if (tcbdbopen(tmp_db, tmppath, BDBOWRITER | BDBOTRUNC)) {
+ if (tcbdbopen(tmp_db, tmppath, BDBOWRITER | BDBOCREAT | BDBOTRUNC)) {
BDBCUR *cur = tcbdbcurnew(awl_db);
TCXSTR *key, *value;
+
key = tcxstrnew();
value = tcxstrnew();
if (tcbdbcurfirst(cur)) {
tcxstrdel(value);
tcbdbcurdel(cur);
tcbdbsync(tmp_db);
+ } else {
+ syslog(LOG_ERR, "cannot run database cleanup: can't open destination database: %s",
+ tcbdberrmsg(tcbdbecode(awl_db)));
}
tcbdbdel(tmp_db);
+ } else {
+ int ecode = tcbdbecode(awl_db);
+ syslog(LOG_ERR, "can not open database: %s", tcbdberrmsg(ecode));
+ trashable = ecode != TCENOPERM && ecode != TCEOPEN && ecode != TCENOFILE && ecode != TCESUCCESS;
}
tcbdbdel(awl_db);
/** Cleanup successful, replace the old database with the new one.
*/
- if (replace) {
+ if (trashable) {
+ syslog(LOG_INFO, "database cleanup finished: database was corrupted, create a new one");
+ unlink(path);
+ } else if (replace) {
+ syslog(LOG_INFO, "database cleanup finished: before %u entries, after %d entries",
+ old_count, new_count);
unlink(path);
if (rename(tmppath, path) != 0) {
UNIXERR("rename");
return NULL;
}
- syslog(LOG_INFO, "database cleanup stat: before %u entries, after %d entries",
- old_count, new_count);
+ } else {
+ syslog(LOG_INFO, "database cleanup finished: nothing to do, %u entries", new_count);
}
- syslog(LOG_INFO, "database cleanup finished");
}
/* Effectively open the database.
*/
awl_db = tcbdbnew();
if (!tcbdbopen(awl_db, path, BDBOWRITER | BDBOCREAT)) {
+ syslog(LOG_ERR, "can not open database: %s", tcbdberrmsg(tcbdbecode(awl_db)));
tcbdbdel(awl_db);
return NULL;
}
if (config->client_awl) {
snprintf(path, sizeof(path), "%s/%swhitelist.db", directory, prefix);
+ syslog(LOG_INFO, "loading auto-whitelist database");
config->awl_db = greylist_db_get(config, path, true,
sizeof(struct awl_entry),
(db_entry_checker_t)(greylist_check_awlentry));
}
snprintf(path, sizeof(path), "%s/%sgreylist.db", directory, prefix);
+ syslog(LOG_INFO, "loading greylist database");
config->obj_db = greylist_db_get(config, path, true,
sizeof(struct obj_entry),
(db_entry_checker_t)(greylist_check_object));