X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=postlicyd%2Fstrlist.c;h=72a6c66981f51727c3a3f0f7f0e712e5a487be6a;hb=8ca147e634f83b185dd4cddebde78878a69f315f;hp=29fe79e01a06c712ec145ecbd8239725215d2501;hpb=56eeb7d73ed0c82f2a8165b6aba525af73c58f73;p=apps%2Fpfixtools.git diff --git a/postlicyd/strlist.c b/postlicyd/strlist.c index 29fe79e..72a6c66 100644 --- a/postlicyd/strlist.c +++ b/postlicyd/strlist.c @@ -16,17 +16,20 @@ /* products derived from this software without specific prior written */ /* permission. */ /* */ -/* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND */ -/* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE */ -/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ -/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS */ -/* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR */ -/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF */ -/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */ -/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */ -/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) */ -/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF */ -/* THE POSSIBILITY OF SUCH DAMAGE. */ +/* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS */ +/* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ +/* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY */ +/* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */ +/* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS */ +/* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */ +/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, */ +/* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN */ +/* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/* POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/* Copyright (c) 2006-2008 the Authors */ +/* see AUTHORS and source files for details */ /******************************************************************************/ /* @@ -147,6 +150,7 @@ static bool strlist_create(strlist_local_t *local, const char *p, *end; char line[BUFSIZ]; uint32_t count = 0; + time_t now = time(0); if (!file_map_open(&map, file, false)) { return false; @@ -157,8 +161,7 @@ static bool strlist_create(strlist_local_t *local, --end; } if (end != map.end) { - warn("file %s miss a final \\n, ignoring last line", - file); + warn("%s: final \\n missing, ignoring last line", file); } strlist_resource_t *res = resource_get("strlist", file); @@ -166,8 +169,7 @@ static bool strlist_create(strlist_local_t *local, res = p_new(strlist_resource_t, 1); resource_set("strlist", file, res, (resource_destructor_t)strlist_resource_wipe); } else if (res->trie2 != NULL) { - err("A file (%s) cannot be used as a rbldns zone file and a strlist file at the same time", - file); + err("%s not loaded: the file is already used as a rbldns zone file", file); resource_release("strlist", file); file_map_close(&map); return false; @@ -180,7 +182,7 @@ static bool strlist_create(strlist_local_t *local, local->reverse = reverse; local->partial = partial; if (res->size == map.st.st_size && res->mtime == map.st.st_mtime) { - info("strlist %s up to date", file); + info("%s loaded: already up-to-date", file); file_map_close(&map); return true; } @@ -195,7 +197,7 @@ static bool strlist_create(strlist_local_t *local, eol = end; } if (eol - p >= BUFSIZ) { - err("unreasonnable long line"); + err("%s not loaded: unreasonnable long line", file); file_map_close(&map); trie_delete(&res->trie1); strlist_local_wipe(local); @@ -219,7 +221,7 @@ static bool strlist_create(strlist_local_t *local, } file_map_close(&map); trie_compile(res->trie1, lock); - info("%s loaded, %u entries", file, count); + info("%s loaded: done in %us, %u entries", file, (uint32_t)(time(0) - now), count); return true; } @@ -230,6 +232,7 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do file_map_t map; const char *p, *end; char line[BUFSIZ]; + time_t now = time(0); if (!file_map_open(&map, file, false)) { return false; @@ -240,8 +243,7 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do --end; } if (end != map.end) { - warn("file %s miss a final \\n, ignoring last line", - file); + warn("%s: final \\n missing, ignoring last line", file); } @@ -250,8 +252,7 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do res = p_new(strlist_resource_t, 1); resource_set("strlist", file, res, (resource_destructor_t)strlist_resource_wipe); } else if (res->trie2 == NULL) { - err("A file (%s) cannot be used as a rbldns zone file and a strlist file at the same time", - file); + err("%s not loaded: the file is already used as a strlist-file parameter", file); resource_release("strlist", file); file_map_close(&map); return false; @@ -273,7 +274,7 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do domain_count = 0; if (map.st.st_size == res->size && map.st.st_mtime == res->mtime) { - info("rbldns %s up to date", file); + info("%s loaded: already up-to-date", file); file_map_close(&map); return true; } @@ -291,7 +292,7 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do eol = end; } if (eol - p >= BUFSIZ) { - err("unreasonnable long line"); + err("%s not loaded: unreasonnable long line", file); file_map_close(&map); trie_delete(&res->trie1); trie_delete(&res->trie2); @@ -332,11 +333,13 @@ static bool strlist_create_from_rhbl(strlist_local_t *hosts, strlist_local_t *do } else { trie_delete(&res->trie2); } - info("rhbl %s loaded, %u hosts, %u domains", file, host_count, domain_count); if (res->trie1 == NULL && res->trie2 == NULL) { + err("%s not loaded: no data found", file); strlist_local_wipe(hosts); return false; } + info("%s loaded: done in %us, %u hosts, %u domains", file, + (uint32_t)(time(0) - now), host_count, domain_count); return true; } @@ -681,9 +684,9 @@ static filter_result_t strlist_filter(const filter_t *filter, const query_t *que } #define LOOKUP(Flag, Field) \ if (config->match_ ## Flag) { \ - const int len = m_strlen(query->Field); \ - strlist_copy(normal, query->Field, len, false); \ - strlist_copy(reverse, query->Field, len, true); \ + const int len = query->Field.len; \ + strlist_copy(normal, query->Field.str, len, false); \ + strlist_copy(reverse, query->Field.str, len, true); \ foreach (strlist_local_t *entry, config->locals) { \ if ((!entry->partial && trie_lookup(*(entry->db), \ entry->reverse ? reverse : normal)) \ @@ -699,8 +702,8 @@ static filter_result_t strlist_filter(const filter_t *filter, const query_t *que } #define DNS(Flag, Field) \ if (config->match_ ## Flag) { \ - const int len = m_strlen(query->Field); \ - strlist_copy(normal, query->Field, len, false); \ + const int len = query->Field.len; \ + strlist_copy(normal, query->Field.str, len, false); \ for (uint32_t i = 0 ; len > 0 && i < config->host_offsets.len ; ++i) { \ const char *rbl = array_ptr(config->hosts, \ array_elt(config->host_offsets, i)); \