Skip to content
API Documentation
BastionGuard™
dnsmasq_backend.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21#pragma once
22#include <string>
23#include <vector>
24
25namespace BastionGuard {
27public:
28 DnsmasqBackend(const std::string& blacklist_path="/etc/dnsmasq.d/BastionGuard-blacklist.conf",
29 const std::string& whitelist_path="/etc/dnsmasq.d/BastionGuard-whitelist.conf",
30 const std::string& dnsmasq_user="dnsmasq");
31
32 // Add/Remove domains (not full URLs). Domains should be sanitized.
33 bool add_to_blacklist(const std::string& domain);
34 bool remove_from_blacklist(const std::string& domain);
35 bool add_to_whitelist(const std::string& domain);
36 bool remove_from_whitelist(const std::string& domain);
37
38 // Replace entire list (atomic)
39 bool write_blacklist(const std::vector<std::string>& domains);
40 bool write_whitelist(const std::vector<std::string>& domains);
41
42 bool reload_dnsmasq();
43
44private:
45 std::string blacklist_path_;
46 std::string whitelist_path_;
47 std::string dnsmasq_user_;
48
49 bool atomic_write(const std::string& path, const std::string& content);
50 std::string make_dnsmasq_entries(const std::vector<std::string>& domains);
51};
52}
bool add_to_blacklist(const std::string &domain)
bool remove_from_blacklist(const std::string &domain)
std::string make_dnsmasq_entries(const std::vector< std::string > &domains)
bool remove_from_whitelist(const std::string &domain)
DnsmasqBackend(const std::string &blacklist_path="/etc/dnsmasq.d/BastionGuard-blacklist.conf", const std::string &whitelist_path="/etc/dnsmasq.d/BastionGuard-whitelist.conf", const std::string &dnsmasq_user="dnsmasq")
bool atomic_write(const std::string &path, const std::string &content)
bool write_blacklist(const std::vector< std::string > &domains)
bool write_whitelist(const std::vector< std::string > &domains)
bool add_to_whitelist(const std::string &domain)