FirewallDetector.hpp

1. Overview

The FirewallDetector.hpp header defines the FirewallDetector utility class, a platform inspection component responsible for identifying the firewall technologies and Linux distribution present on the host system.

This module provides foundational environment-detection logic used by BastionGuard to adapt firewall configuration, installation, and management workflows to the user’s system.

Functionally, FirewallDetector provides:

  • Detection of installed firewall frameworks (firewalld, UFW)
  • Identification of the underlying Linux distribution
  • Automatic selection of the most appropriate firewall backend
  • Support for distribution-aware configuration logic
  • Integration with firewall setup and onboarding workflows

2. Dependencies and Includes

#include <string>
#include "FirewallEnums.hpp"
  • <string> – distribution identifiers and textual metadata
  • FirewallEnums.hpp – centralized firewall type enumeration (FirewallType)

3. Class Declaration and Scope

class FirewallDetector

The class is implemented as a static utility container. All methods are static, and no instances are intended to be created.

This design enables easy invocation from setup dialogs, settings pages, and backend services.


4. Public Interface

4.1 Firewall Presence Detection

static bool isFirewalldPresent();
static bool isUfwPresent();

Checks whether the corresponding firewall backend is installed and accessible on the system.

  • isFirewalldPresent() – verifies availability of firewalld
  • isUfwPresent() – verifies availability of UFW

Detection is typically performed by probing executable paths, system services, or package metadata.


4.2 Distribution Detection

static std::string detectDistro();

Identifies the current Linux distribution and returns a normalized identifier (e.g., ubuntu, fedora, arch).

This information is used to tailor installation and configuration procedures.


4.3 Automatic Firewall Selection

static FirewallType detectFirewall();

Determines the most appropriate firewall backend based on availability, system configuration, and distribution-specific conventions.

The method returns a value from the FirewallType enumeration.


5. UI Components

This module does not define graphical user interface elements. It operates exclusively as a backend detection service.


6. Internal State and Data Model

No persistent or shared state is stored in this class. All detection logic is executed on demand.


7. Internal Logic

Although implementation details are not shown, a typical detection workflow includes:

  • Inspecting standard binary locations (/usr/bin, /usr/sbin)
  • Querying systemd service units
  • Parsing /etc/os-release or similar files
  • Checking package manager metadata
  • Applying precedence rules between firewalld and UFW

8. Integration with Firewall Management

FirewallDetector is used by several components, including:

  • FirewallChoiceDialog – initial firewall selection
  • FirewallInstaller – backend installation logic
  • SettingsPage – firewall-related configuration panels
  • Network protection subsystems

9. Auto-Update (Scheduled Refresh)

This module does not implement periodic refresh. Detection is performed synchronously when requested.


10. Settings Storage

No configuration data is persisted by this class. Detection results are transient and recomputed as needed.


11. Helper Functions and Platform Integration

The implementation is expected to integrate with standard Linux system facilities, including:

  • systemctl and service unit inspection
  • Package managers (apt, dnf, pacman)
  • Filesystem probes for firewall binaries
  • Distribution metadata files

12. Runtime and Security Considerations

  • Privilege separation: detection should avoid requiring root privileges whenever possible.
  • False negatives: misconfigured systems may hide firewall services; detection logic should include fallback heuristics.
  • Consistency: detection results should be cached at higher layers if used repeatedly in short intervals.
  • Robustness: failures in detection must not block application startup.
  • Extensibility: support for additional firewall backends should be achievable without redesigning this interface.