X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Frbl.c;h=b3d7d455e9b9dbea4f9f8a700c22aa5de10c9943;hb=520b2f3bb198bfbb88b90b058ef610f0a9b980c6;hp=9c76ed6a89b22ada956090edb4b43bf381da1039;hpb=d0eb62ddac601110ebbcc73bb17c8b90407c9874;p=apps%2Fpfixtools.git diff --git a/postlicyd/rbl.c b/postlicyd/rbl.c index 9c76ed6..b3d7d45 100644 --- a/postlicyd/rbl.c +++ b/postlicyd/rbl.c @@ -62,7 +62,6 @@ enum { struct rbldb_t { A(uint32_t) ips; - bool locked; }; ARRAY(rbldb_t) @@ -134,8 +133,8 @@ rbldb_t *rbldb_create(const char *file, bool lock) --end; } if (end != map.end) { - syslog(LOG_WARNING, "file %s miss a final \\n, ignoring last line", - file); + warn("file %s miss a final \\n, ignoring last line", + file); } db = p_new(rbldb_t, 1); @@ -156,8 +155,7 @@ rbldb_t *rbldb_create(const char *file, bool lock) /* Lookup may perform serveral I/O, so avoid swap. */ array_adjust(db->ips); - db->locked = lock && array_lock(db->ips); - if (lock && !db->locked) { + if (lock && !array_lock(db->ips)) { UNIXERR("mlock"); } @@ -169,15 +167,12 @@ rbldb_t *rbldb_create(const char *file, bool lock) # include "qsort.c" } - syslog(LOG_INFO, "rbl %s loaded, %d IPs", file, db->ips.len); + info("rbl %s loaded, %d IPs", file, db->ips.len); return db; } static void rbldb_wipe(rbldb_t *db) { - if (db->locked) { - array_unlock(db->ips); - } array_wipe(db->ips); } @@ -247,7 +242,7 @@ static bool rbl_filter_constructor(filter_t *filter) #define PARSE_CHECK(Expr, Str, ...) \ if (!(Expr)) { \ - syslog(LOG_ERR, Str, ##__VA_ARGS__); \ + err(Str, ##__VA_ARGS__); \ rbl_filter_delete(&data); \ return false; \ } @@ -305,8 +300,10 @@ static bool rbl_filter_constructor(filter_t *filter) array_add(data->weights, weight); break; } - current = p + 1; - p = m_strchrnul(current, ':'); + if (i != 2) { + current = p + 1; + p = m_strchrnul(current, ':'); + } } } break; @@ -351,11 +348,11 @@ static filter_result_t rbl_filter(const filter_t *filter, const query_t *query) const rbl_filter_t *data = filter->data; if (parse_ipv4(query->client_address, &end, &ip) != 0) { - syslog(LOG_WARNING, "invalid client address: %s, expected ipv4", - query->client_address); + warn("invalid client address: %s, expected ipv4", + query->client_address); return HTK_ERROR; } - for (int i = 0 ; i < data->rbls.len ; ++i) { + for (uint32_t i = 0 ; i < data->rbls.len ; ++i) { const rbldb_t *rbl = array_elt(data->rbls, i); int weight = array_elt(data->weights, i); if (rbldb_ipv4_lookup(rbl, ip)) { @@ -373,7 +370,7 @@ static filter_result_t rbl_filter(const filter_t *filter, const query_t *query) static int rbl_init(void) { - filter_type_t type = filter_register("rbl", rbl_filter_constructor, + filter_type_t type = filter_register("iplist", rbl_filter_constructor, rbl_filter_destructor, rbl_filter); /* Hooks. */