From 6686c4a1904fdfa20ed81d2d7e17e00c8aaf2e3d Mon Sep 17 00:00:00 2001 From: bol-van Date: Tue, 29 Oct 2024 13:41:29 +0300 Subject: [PATCH] nfqws: fail if hostlist/ipset does not exist at startup --- nfq/hostlist.c | 5 +++++ nfq/ipset.c | 8 +++++++- nfq/nfqws.c | 10 +++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/nfq/hostlist.c b/nfq/hostlist.c index 46b5e6c..ade317a 100644 --- a/nfq/hostlist.c +++ b/nfq/hostlist.c @@ -245,6 +245,11 @@ static struct hostlist_file *RegisterHostlist_(struct hostlist_files_head *hostl } struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename) { + if (!file_mod_time(filename)) + { + DLOG_ERR("cannot access hostlist file '%s'\n",filename); + return NULL; + } return RegisterHostlist_( ¶ms.hostlists, bExclude ? &dp->hl_collection_exclude : &dp->hl_collection, diff --git a/nfq/ipset.c b/nfq/ipset.c index b7ce05f..7c7a4be 100644 --- a/nfq/ipset.c +++ b/nfq/ipset.c @@ -225,7 +225,8 @@ static bool IpsetCheck_(const struct ipset_collection_head *ips, const struct ip bool IpsetCheck(const struct desync_profile *dp, const struct in_addr *ipv4, const struct in6_addr *ipv6) { - if (!PROFILE_IPSETS_EMPTY(dp)) DLOG("* ipset check for profile %d\n",dp->n); + if (PROFILE_IPSETS_EMPTY(dp)) return true; + DLOG("* ipset check for profile %d\n",dp->n); return IpsetCheck_(&dp->ips_collection,&dp->ips_collection_exclude,ipv4,ipv6); } @@ -243,6 +244,11 @@ static struct ipset_file *RegisterIpset_(struct ipset_files_head *ipsets, struct } struct ipset_file *RegisterIpset(struct desync_profile *dp, bool bExclude, const char *filename) { + if (!file_mod_time(filename)) + { + DLOG_ERR("cannot access ipset file '%s'\n",filename); + return NULL; + } return RegisterIpset_( ¶ms.ipsets, bExclude ? &dp->ips_collection_exclude : &dp->ips_collection, diff --git a/nfq/nfqws.c b/nfq/nfqws.c index 149b751..9320cec 100644 --- a/nfq/nfqws.c +++ b/nfq/nfqws.c @@ -1511,14 +1511,14 @@ int main(int argc, char **argv) case 45: /* hostlist */ if (!RegisterHostlist(dp, false, optarg)) { - DLOG_ERR("failed to register hostlist %s\n", optarg); + DLOG_ERR("failed to register hostlist '%s'\n", optarg); exit_clean(1); } break; case 46: /* hostlist-exclude */ if (!RegisterHostlist(dp, true, optarg)) { - DLOG_ERR("failed to register hostlist %s\n", optarg); + DLOG_ERR("failed to register hostlist '%s'\n", optarg); exit_clean(1); } break; @@ -1549,7 +1549,7 @@ int main(int argc, char **argv) } if (!(dp->hostlist_auto=RegisterHostlist(dp, false, optarg))) { - DLOG_ERR("failed to register hostlist %s\n", optarg); + DLOG_ERR("failed to register hostlist '%s'\n", optarg); exit_clean(1); } break; @@ -1639,14 +1639,14 @@ int main(int argc, char **argv) case 57: /* ipset */ if (!RegisterIpset(dp, false, optarg)) { - DLOG_ERR("failed to register ipset %s\n", optarg); + DLOG_ERR("failed to register ipset '%s'\n", optarg); exit_clean(1); } break; case 58: /* ipset-exclude */ if (!RegisterIpset(dp, true, optarg)) { - DLOG_ERR("failed to register ipset %s\n", optarg); + DLOG_ERR("failed to register ipset '%s'\n", optarg); exit_clean(1); } break;