#include "str.h"
#include "resources.h"
+static const static_str_t static_cleanup = { "@@cleanup@@", 11 };
typedef struct greylist_config_t {
unsigned lookup_by_host : 1;
{
int len = 0;
time_t now = time(NULL);
- const time_t *last_cleanup = tcbdbget3(db, "@@cleanup@@", strlen("@@cleanup@@"), &len);
+ const time_t *last_cleanup = tcbdbget3(db, static_cleanup.str, static_cleanup.len, &len);
if (last_cleanup == NULL) {
debug("No last cleanup time");
} else {
}
}
if (!greylist_db_need_cleanup(config, awl_db) || config->max_age <= 0) {
- info("no cleanup needed");
+ info("%s loaded: no cleanup needed", path);
res->db = awl_db;
return &res->db;
} else {
}
++old_count;
} while (tcbdbcurnext(cur));
- now = time(0);
- tcbdbput(tmp_db, "@@cleanup@@", strlen("@@cleanup@@"), &now, sizeof(now));
+ tcbdbput(tmp_db, static_cleanup.str, static_cleanup.len, &now, sizeof(now));
}
tcxstrdel(key);
tcxstrdel(value);
/** Cleanup successful, replace the old database with the new one.
*/
if (trashable) {
- info("database cleanup finished: database was corrupted, create a new one");
+ info("%s cleanup: database was corrupted, create a new one", path);
unlink(path);
} else if (replace) {
- info("database cleanup finished: before %u entries, after %d entries",
- old_count, new_count);
+ info("%s cleanup: done in %us, before %u, after %u entries",
+ path, (uint32_t)(time(0) - now), old_count, new_count);
unlink(path);
if (rename(tmppath, path) != 0) {
UNIXERR("rename");
}
} else {
unlink(tmppath);
- info("database cleanup finished: nothing to do, %u entries", new_count);
+ info("%s cleanup: done in %us, nothing to do, %u entries",
+ path, (uint32_t)(time(0) - now), old_count);
}
}
return NULL;
}
+ info("%s loaded", path);
res->db = awl_db;
return &res->db;
}
if (config->client_awl) {
snprintf(path, sizeof(path), "%s/%swhitelist.db", directory, prefix);
- info("loading auto-whitelist database");
config->awl_db = greylist_db_get(config, path,
sizeof(struct awl_entry),
(db_entry_checker_t)(greylist_check_awlentry));
}
snprintf(path, sizeof(path), "%s/%sgreylist.db", directory, prefix);
- info("loading greylist database");
config->obj_db = greylist_db_get(config, path,
sizeof(struct obj_entry),
(db_entry_checker_t)(greylist_check_object));
static bool try_greylist(const greylist_config_t *config,
- const char *sender, const char *c_addr,
- const char *c_name, const char *rcpt)
+ const static_str_t *sender, const static_str_t *c_addr,
+ const static_str_t *c_name, const static_str_t *rcpt)
{
#define INCR_AWL \
aent.count++; \
aent.last = now; \
debug("whitelist entry for %.*s updated, count %d", \
- c_addrlen, c_addr, aent.count); \
- tcbdbput(awl_db, c_addr, c_addrlen, &aent, sizeof(aent));
+ (int)c_addr->len, c_addr->str, aent.count); \
+ tcbdbput(awl_db, c_addr->str, c_addr->len, &aent, sizeof(aent));
char sbuf[BUFSIZ], cnet[64], key[BUFSIZ];
const void *res;
struct obj_entry oent = { now, now };
struct awl_entry aent = { 0, 0 };
- int len, klen, c_addrlen = strlen(c_addr);
+ int len, klen;
TCBDB * const awl_db = config->awl_db ? *(config->awl_db) : NULL;
TCBDB * const obj_db = config->obj_db ? *(config->obj_db) : NULL;
/* Auto whitelist clients.
*/
if (config->client_awl) {
- res = tcbdbget3(awl_db, c_addr, c_addrlen, &len);
+ res = tcbdbget3(awl_db, c_addr->str, c_addr->len, &len);
if (res && len == sizeof(aent)) {
memcpy(&aent, res, len);
debug("client %.*s has a whitelist entry, count is %d",
- c_addrlen, c_addr, aent.count);
+ (int)c_addr->len, c_addr->str, aent.count);
}
if (!greylist_check_awlentry(config, &aent, now)) {
aent.count = 0;
aent.last = 0;
debug("client %.*s whitelist entry too old",
- c_addrlen, c_addr);
+ (int)c_addr->len, c_addr->str);
}
/* Whitelist if count is enough.
*/
if (aent.count >= config->client_awl) {
- debug("client %.*s whitelisted", c_addrlen, c_addr);
+ debug("client %.*s whitelisted", (int)c_addr->len, c_addr->str);
if (now < aent.last + 3600) {
INCR_AWL
}
/* Lookup.
*/
klen = snprintf(key, sizeof(key), "%s/%s/%s",
- c_net(config, c_addr, c_name, cnet, sizeof(cnet)),
- config->no_sender ? "" : sender_normalize(sender, sbuf, sizeof(sbuf)),
- config->no_recipient ? "" : rcpt);
+ c_net(config, c_addr->str, c_name->str, cnet, sizeof(cnet)),
+ config->no_sender ? "" : sender_normalize(sender->str, sbuf, sizeof(sbuf)),
+ config->no_recipient ? "" : rcpt->str);
klen = MIN(klen, ssizeof(key) - 1);
res = tcbdbget3(obj_db, key, klen, &len);
foreach (filter_param_t *param, filter->params) {
switch (param->type) {
- FILTER_PARAM_PARSE_STRING(PATH, path);
- FILTER_PARAM_PARSE_STRING(PREFIX, prefix);
+ FILTER_PARAM_PARSE_STRING(PATH, path, false);
+ FILTER_PARAM_PARSE_STRING(PREFIX, prefix, false);
FILTER_PARAM_PARSE_BOOLEAN(LOOKUP_BY_HOST, config->lookup_by_host);
FILTER_PARAM_PARSE_BOOLEAN(NO_SENDER, config->no_sender);
FILTER_PARAM_PARSE_BOOLEAN(NO_RECIPIENT, config->no_recipient);
return HTK_ABORT;
}
- return try_greylist(config, query->sender, query->client_address,
- query->client_name, query->recipient) ?
+ return try_greylist(config, &query->sender, &query->client_address,
+ &query->client_name, &query->recipient) ?
HTK_WHITELIST : HTK_GREYLIST;
}