mirror of
https://github.com/pi-hole/FTL.git
synced 2025-12-20 08:48:24 +00:00
Remove Pi-hole specific domain files. Gravity, white-, blacklist and regex domains will all be sourced from the database. There is no need for the old files to exist.
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
4
FTL.h
4
FTL.h
@@ -141,10 +141,6 @@ typedef struct {
|
|||||||
} FTLFileNamesStruct;
|
} FTLFileNamesStruct;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* whitelist;
|
|
||||||
char* blacklist;
|
|
||||||
char* gravity;
|
|
||||||
char* regexlist;
|
|
||||||
char* setupVars;
|
char* setupVars;
|
||||||
char* auditlist;
|
char* auditlist;
|
||||||
} logFileNamesStruct;
|
} logFileNamesStruct;
|
||||||
|
|||||||
12
config.c
12
config.c
@@ -288,18 +288,6 @@ void read_FTLconf(void)
|
|||||||
// SOCKETFILE
|
// SOCKETFILE
|
||||||
getpath(fp, "SOCKETFILE", "/var/run/pihole/FTL.sock", &FTLfiles.socketfile);
|
getpath(fp, "SOCKETFILE", "/var/run/pihole/FTL.sock", &FTLfiles.socketfile);
|
||||||
|
|
||||||
// WHITELISTFILE
|
|
||||||
getpath(fp, "WHITELISTFILE", "/etc/pihole/whitelist.txt", &files.whitelist);
|
|
||||||
|
|
||||||
// BLACKLISTFILE
|
|
||||||
getpath(fp, "BLACKLISTFILE", "/etc/pihole/black.list", &files.blacklist);
|
|
||||||
|
|
||||||
// GRAVITYFILE
|
|
||||||
getpath(fp, "GRAVITYFILE", "/etc/pihole/gravity.list", &files.gravity);
|
|
||||||
|
|
||||||
// REGEXLISTFILE
|
|
||||||
getpath(fp, "REGEXLISTFILE", "/etc/pihole/regex.list", &files.regexlist);
|
|
||||||
|
|
||||||
// SETUPVARSFILE
|
// SETUPVARSFILE
|
||||||
getpath(fp, "SETUPVARSFILE", "/etc/pihole/setupVars.conf", &files.setupVars);
|
getpath(fp, "SETUPVARSFILE", "/etc/pihole/setupVars.conf", &files.setupVars);
|
||||||
|
|
||||||
|
|||||||
@@ -981,9 +981,6 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
|
|||||||
|
|
||||||
eatspace(f);
|
eatspace(f);
|
||||||
|
|
||||||
name_count = FTL_listsfile(filename, index, f, cache_size, rhash, hashsz);
|
|
||||||
addr_count = name_count - cache_size;
|
|
||||||
|
|
||||||
while ((atnl = gettok(f, token)) != EOF)
|
while ((atnl = gettok(f, token)) != EOF)
|
||||||
{
|
{
|
||||||
lineno++;
|
lineno++;
|
||||||
@@ -1185,6 +1182,10 @@ void cache_reload(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*------------------------------- Pi-hole modification -------------------------------*/
|
||||||
|
total_size = FTL_database_import(total_size, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
/*------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
if (!option_bool(OPT_NO_HOSTS))
|
if (!option_bool(OPT_NO_HOSTS))
|
||||||
total_size = read_hostsfile(HOSTSFILE, SRC_HOSTS, total_size, (struct crec **)daemon->packet, revhashsz);
|
total_size = read_hostsfile(HOSTSFILE, SRC_HOSTS, total_size, (struct crec **)daemon->packet, revhashsz);
|
||||||
|
|
||||||
@@ -1688,7 +1689,11 @@ char *record_source(unsigned int index)
|
|||||||
return HOSTSFILE;
|
return HOSTSFILE;
|
||||||
/*----- Pi-hole modification -----*/
|
/*----- Pi-hole modification -----*/
|
||||||
else if (index == SRC_REGEX)
|
else if (index == SRC_REGEX)
|
||||||
return (char*)regexlistname;
|
return "regex";
|
||||||
|
else if (index == SRC_GRAVITY)
|
||||||
|
return "gravity";
|
||||||
|
else if (index == SRC_BLACK)
|
||||||
|
return "blacklist";
|
||||||
/*--------------------------------*/
|
/*--------------------------------*/
|
||||||
|
|
||||||
for (ah = daemon->addn_hosts; ah; ah = ah->next)
|
for (ah = daemon->addn_hosts; ah; ah = ah->next)
|
||||||
|
|||||||
@@ -490,13 +490,16 @@ struct crec {
|
|||||||
#define SRC_INTERFACE UID_NONE
|
#define SRC_INTERFACE UID_NONE
|
||||||
#define SRC_CONFIG 1
|
#define SRC_CONFIG 1
|
||||||
#define SRC_HOSTS 2
|
#define SRC_HOSTS 2
|
||||||
/*----- Pi-hole modification -----*/
|
/*------------------------- Pi-hole modification -------------------------*/
|
||||||
// ID 3 will be used for the regex list file name
|
// ID 3 will be used for the regex table
|
||||||
// ID 4 will be used as starting index for any Additional Hosts (AH) files
|
// ID 3 will be used for the gravity table
|
||||||
|
// ID 3 will be used for the blacklist table
|
||||||
|
// ID 6 will be used as starting index for any Additional Hosts (AH) files
|
||||||
#define SRC_REGEX 3
|
#define SRC_REGEX 3
|
||||||
#define SRC_AH 4
|
#define SRC_GRAVITY 4
|
||||||
const char *regexlistname;
|
#define SRC_BLACK 5
|
||||||
/*--------------------------------*/
|
#define SRC_AH 6
|
||||||
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/* struct sockaddr is not large enough to hold any address,
|
/* struct sockaddr is not large enough to hold any address,
|
||||||
and specifically not big enough to hold an IPv6 address.
|
and specifically not big enough to hold an IPv6 address.
|
||||||
|
|||||||
@@ -1323,75 +1323,28 @@ static void block_single_domain_regex(const char *domain)
|
|||||||
|
|
||||||
// Get IPv4/v6 addresses for blocking depending on user configures blocking mode
|
// Get IPv4/v6 addresses for blocking depending on user configures blocking mode
|
||||||
prepare_blocking_mode(&addr4, &addr6, &has_IPv4, &has_IPv6);
|
prepare_blocking_mode(&addr4, &addr6, &has_IPv4, &has_IPv6);
|
||||||
regexlistname = files.regexlist;
|
|
||||||
add_blocked_domain(&addr4, &addr6, has_IPv4, has_IPv6, domain, strlen(domain), NULL, 0, SRC_REGEX);
|
add_blocked_domain(&addr4, &addr6, has_IPv4, has_IPv6, domain, strlen(domain), NULL, 0, SRC_REGEX);
|
||||||
|
|
||||||
if(config.debug & DEBUG_QUERIES) logg("Added %s to cache", domain);
|
if(config.debug & DEBUG_QUERIES) logg("Added %s to cache", domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FTL_listsfile(const char* filename, unsigned int index, FILE *f, int cache_size, struct crec **rhash, int hashsz)
|
static int FTL_table_import(const char *tablename, const unsigned char list, const unsigned int index,
|
||||||
|
struct all_addr addr4, struct all_addr addr6, bool has_IPv4, bool has_IPv6,
|
||||||
|
int cache_size, struct crec **rhash, int hashsz)
|
||||||
{
|
{
|
||||||
int name_count = cache_size;
|
// Variables
|
||||||
int added = 0;
|
int name_count = cache_size, added = 0;
|
||||||
struct all_addr addr4 = {{{ 0 }}}, addr6 = {{{ 0 }}};
|
|
||||||
bool has_IPv4 = false, has_IPv6 = false;
|
|
||||||
unsigned char list = UNKNOWN_LIST;
|
|
||||||
|
|
||||||
// Handle only gravity.list and black.list
|
|
||||||
// Skip all other files (they are interpreted in the usual format)
|
|
||||||
const char* tablename = NULL;
|
|
||||||
if(strcmp(filename, files.gravity) == 0)
|
|
||||||
{
|
|
||||||
list = GRAVITY_LIST;
|
|
||||||
tablename = "gravity";
|
|
||||||
}
|
|
||||||
else if(strcmp(filename, files.blacklist) == 0)
|
|
||||||
{
|
|
||||||
list = BLACK_LIST;
|
|
||||||
tablename = "blacklist";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return cache_size;
|
|
||||||
|
|
||||||
// Jump to end of file to ensure dnsmasq does not
|
|
||||||
// try to read whatever might be in the file on
|
|
||||||
// disk when we return
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
|
|
||||||
if(blockingstatus == BLOCKING_DISABLED)
|
|
||||||
{
|
|
||||||
logg("Skipping import of %s because blocking is disabled", tablename);
|
|
||||||
return cache_size;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logg("Importing %s...", tablename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start timer for list analysis
|
// Start timer for list analysis
|
||||||
timer_start(LISTS_TIMER);
|
timer_start(LISTS_TIMER);
|
||||||
|
|
||||||
// Start database interaction
|
// Get database table handle
|
||||||
if(!gravityDB_getTable(list))
|
if(!gravityDB_getTable(list))
|
||||||
{
|
{
|
||||||
logg("FTL_listsfile(): Error getting %s table from database", tablename);
|
logg("FTL_listsfile(): Error getting %s table from database", tablename);
|
||||||
return name_count;
|
return name_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get IPv4/v6 addresses for blocking depending on user configured blocking mode
|
|
||||||
prepare_blocking_mode(&addr4, &addr6, &has_IPv4, &has_IPv6);
|
|
||||||
|
|
||||||
// If we have neither a valid IPv4 nor a valid IPv6 but the user asked for
|
|
||||||
// blocking modes MODE_IP or MODE_IP_NODATA_AAAA then we cannot add any entries here
|
|
||||||
if(!has_IPv4 && !has_IPv6)
|
|
||||||
{
|
|
||||||
logg("ERROR: Cannot add domains from gravity because pihole-FTL found\n" \
|
|
||||||
" neither a valid IPV4_ADDRESS nor IPV6_ADDRESS in setupVars.conf" \
|
|
||||||
" This is an impossible configuration. Please contact the Pi-hole" \
|
|
||||||
" support if you need assistance.");
|
|
||||||
return cache_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk database table
|
// Walk database table
|
||||||
const char *domain = NULL;
|
const char *domain = NULL;
|
||||||
while((domain = gravityDB_getDomain()) != NULL)
|
while((domain = gravityDB_getDomain()) != NULL)
|
||||||
@@ -1425,6 +1378,43 @@ int FTL_listsfile(const char* filename, unsigned int index, FILE *f, int cache_s
|
|||||||
|
|
||||||
// Final logging
|
// Final logging
|
||||||
logg("Database (%s): imported %i domains (took %.1f ms)", tablename, added, timer_elapsed_msec(LISTS_TIMER));
|
logg("Database (%s): imported %i domains (took %.1f ms)", tablename, added, timer_elapsed_msec(LISTS_TIMER));
|
||||||
counters->gravity += added;
|
|
||||||
return name_count;
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FTL_database_import(int cache_size, struct crec **rhash, int hashsz)
|
||||||
|
{
|
||||||
|
struct all_addr addr4 = {{{ 0 }}}, addr6 = {{{ 0 }}};
|
||||||
|
bool has_IPv4 = false, has_IPv6 = false;
|
||||||
|
|
||||||
|
if(blockingstatus == BLOCKING_DISABLED)
|
||||||
|
{
|
||||||
|
logg("Skipping import of database tables because blocking is disabled");
|
||||||
|
return cache_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get IPv4/v6 addresses for blocking depending on user configured blocking mode
|
||||||
|
prepare_blocking_mode(&addr4, &addr6, &has_IPv4, &has_IPv6);
|
||||||
|
|
||||||
|
// If we have neither a valid IPv4 nor a valid IPv6 but the user asked for
|
||||||
|
// blocking modes MODE_IP or MODE_IP_NODATA_AAAA then we cannot add any entries here
|
||||||
|
if(!has_IPv4 && !has_IPv6)
|
||||||
|
{
|
||||||
|
logg("ERROR: Cannot add domains from gravity because pihole-FTL found\n" \
|
||||||
|
" neither a valid IPV4_ADDRESS nor IPV6_ADDRESS in setupVars.conf" \
|
||||||
|
" This is an impossible configuration. Please contact the Pi-hole" \
|
||||||
|
" support if you need assistance.");
|
||||||
|
return cache_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import gravity and blacklist domains
|
||||||
|
int added;
|
||||||
|
added = FTL_table_import("gravity", GRAVITY_LIST, SRC_GRAVITY, addr4, addr6, has_IPv4, has_IPv6, cache_size, rhash, hashsz);
|
||||||
|
added += FTL_table_import("blacklist", BLACK_LIST, SRC_BLACK, addr4, addr6, has_IPv4, has_IPv6, cache_size, rhash, hashsz);
|
||||||
|
|
||||||
|
// Update counter of blocked domains
|
||||||
|
counters->gravity += added;
|
||||||
|
|
||||||
|
// Return new cache size which now includes more domains than before
|
||||||
|
return cache_size + added;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,6 @@ void _FTL_upstream_error(const unsigned int rcode, const int id, const char* fil
|
|||||||
|
|
||||||
void FTL_dnsmasq_reload(void);
|
void FTL_dnsmasq_reload(void);
|
||||||
void FTL_fork_and_bind_sockets(struct passwd *ent_pw);
|
void FTL_fork_and_bind_sockets(struct passwd *ent_pw);
|
||||||
int FTL_listsfile(const char* filename, unsigned int index, FILE *f, int cache_size, struct crec **rhash, int hashsz);
|
int FTL_database_import(int cache_size, struct crec **rhash, int hashsz);
|
||||||
|
|
||||||
#endif // DNSMASQ_INTERFACE_H
|
#endif // DNSMASQ_INTERFACE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user