#include #include "hostlist.h" #include "gzip.h" #include "params.h" #include "helpers.h" // inplace tolower() and add to pool static bool addpool(strpool **hostlist, char **s, const char *end) { char *p; // advance until eol lowering all chars for (p = *s; pstr)) return false; } return true; } bool NonEmptyHostlist(strpool **hostlist) { // add impossible hostname if the list is empty return *hostlist ? true : StrPoolAddStrLen(hostlist, "@&()", 4); } bool SearchHostList(strpool *hostlist, const char *host) { if (hostlist) { const char *p = host; bool bInHostList; while (p) { bInHostList = StrPoolCheckStr(hostlist, p); if (params.debug) printf("Hostlist check for %s : %s\n", p, bInHostList ? "positive" : "negative"); if (bInHostList) return true; p = strchr(p, '.'); if (p) p++; } } return false; } // return : true = apply fooling, false = do not apply static bool HostlistCheck_(strpool *hostlist, strpool *hostlist_exclude, const char *host, bool *excluded) { if (excluded) *excluded = false; if (hostlist_exclude) { if (params.debug) printf("Checking exclude hostlist\n"); if (SearchHostList(hostlist_exclude, host)) { if (excluded) *excluded = true; return false; } } if (hostlist) { if (params.debug) printf("Checking include hostlist\n"); return SearchHostList(hostlist, host); } return true; } // return : true = apply fooling, false = do not apply bool HostlistCheck(const char *host, bool *excluded) { if (*params.hostlist_auto_filename) { time_t t = file_mod_time(params.hostlist_auto_filename); if (t!=params.hostlist_auto_mod_time) { printf("Autohostlist was modified by another process. Reloading include hostslist.\n"); if (!LoadIncludeHostLists()) { // what will we do without hostlist ?? sure, gonna die exit(1); } params.hostlist_auto_mod_time = t; } } return HostlistCheck_(params.hostlist, params.hostlist_exclude, host, excluded); } bool LoadIncludeHostLists() { if (!LoadHostLists(¶ms.hostlist, ¶ms.hostlist_files)) return false; if (*params.hostlist_auto_filename) params.hostlist_auto_mod_time = file_mod_time(params.hostlist_auto_filename); return true; } bool LoadExcludeHostLists() { return LoadHostLists(¶ms.hostlist_exclude, ¶ms.hostlist_exclude_files); }