#include #include "hostlist.h" #include "gzip.h" #include "helpers.h" // inplace tolower() and add to pool static bool addpool(strpool **hostlist, char **s, const char *end, int *ct) { char *p=*s; // comment line if ( *p == '#' || *p == ';' || *p == '/' || *p == '\r' || *p == '\n') { // advance until eol for (; 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); DLOG("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) { DLOG("Checking exclude hostlist\n"); if (SearchHostList(hostlist_exclude, host)) { if (excluded) *excluded = true; return false; } } if (hostlist) { DLOG("Checking include hostlist\n"); return SearchHostList(hostlist, host); } return true; } static bool LoadIncludeHostListsForProfile(struct desync_profile *dp) { if (!LoadHostLists(&dp->hostlist, &dp->hostlist_files)) return false; if (*dp->hostlist_auto_filename) { dp->hostlist_auto_mod_time = file_mod_time(dp->hostlist_auto_filename); NonEmptyHostlist(&dp->hostlist); } return true; } // return : true = apply fooling, false = do not apply bool HostlistCheck(struct desync_profile *dp, const char *host, bool *excluded) { DLOG("* Hostlist check for profile %d\n",dp->n); if (*dp->hostlist_auto_filename) { time_t t = file_mod_time(dp->hostlist_auto_filename); if (t!=dp->hostlist_auto_mod_time) { DLOG_CONDUP("Autohostlist '%s' from profile %d was modified. Reloading include hostlists for this profile.\n",dp->hostlist_auto_filename, dp->n); if (!LoadIncludeHostListsForProfile(dp)) { // what will we do without hostlist ?? sure, gonna die exit(1); } dp->hostlist_auto_mod_time = t; NonEmptyHostlist(&dp->hostlist); } } return HostlistCheck_(dp->hostlist, dp->hostlist_exclude, host, excluded); } bool LoadIncludeHostLists() { struct desync_profile_list *dpl; LIST_FOREACH(dpl, ¶ms.desync_profiles, next) if (!LoadIncludeHostListsForProfile(&dpl->dp)) return false; return true; } bool LoadExcludeHostLists() { struct desync_profile_list *dpl; LIST_FOREACH(dpl, ¶ms.desync_profiles, next) if (!LoadHostLists(&dpl->dp.hostlist_exclude, &dpl->dp.hostlist_exclude_files)) return false; return true; }