1. Overview
The FirewallInstaller.hpp header defines the FirewallInstaller utility class, a platform-aware helper responsible for generating appropriate installation commands for supported firewall backends based on the detected Linux distribution.
This component enables BastionGuard to guide users through firewall installation in a safe and distribution-specific manner, without hardcoding package manager logic throughout the codebase.
Functionally, FirewallInstaller provides:
- Distribution-aware package installation command generation
- Support for firewalld and UFW backends
- Automatic selection of package managers (apt, dnf, pacman, etc.)
- User-friendly onboarding for missing firewall components
- Centralized abstraction of install procedures
2. Dependencies and Includes
#include <string>
- <string> – shell command generation and distribution identifiers
3. Class Declaration and Scope
class FirewallInstaller
The class is implemented as a static utility container. All methods are static, and no instances are intended to be created.
This design allows easy integration with setup dialogs and service configuration workflows.
4. Public Interface
4.1 Installation Command Generator
static std::string getInstallCommand(
const std::string& distro,
bool preferFirewalld = true
);
Returns a shell command suitable for installing a supported firewall backend on the specified distribution.
- distro – normalized distribution identifier (e.g.,
ubuntu,fedora,arch) - preferFirewalld – indicates whether firewalld should be preferred when multiple options are available
- Return value – executable shell command string
The returned command is intended to be executed with elevated privileges by a dedicated installer or authorization helper.
5. UI Components
This module does not define graphical interface elements. It operates exclusively as a backend helper.
6. Internal State and Data Model
No runtime state is stored in this class. All logic is computed dynamically from the input parameters.
7. Internal Logic
Although implementation details are not shown, a typical command generation workflow includes:
- Mapping
distroto the correct package manager - Selecting firewalld or UFW based on preferences and availability
- Constructing safe, minimal install commands
- Including non-interactive flags when appropriate
- Normalizing output for display and execution
8. Integration with Firewall Setup Workflow
FirewallInstaller is typically used in:
FirewallChoiceDialog– user-driven firewall installation- First-run setup wizards
- Security hardening workflows
- Automated deployment scripts
9. Auto-Update (Scheduled Refresh)
This module does not implement scheduling. Installation commands are generated on demand.
10. Settings Storage
No persistent configuration is stored. Preferences such as backend choice should be managed by higher-level components.
11. Helper Functions and Platform Integration
Generated commands typically integrate with standard Linux package managers:
apt/apt-get(Debian/Ubuntu)dnf/yum(Fedora/RHEL)pacman(Arch Linux)zypper(openSUSE)
Commands may also include service enablement steps (e.g., systemctl enable --now).
12. Runtime and Security Considerations
- Command injection: distribution identifiers must be sanitized before command construction.
- Privilege escalation: commands should be executed only through controlled authorization mechanisms (pkexec, sudo wrappers).
- User consent: installation must be performed only after explicit user approval.
- Error handling: failures during installation should be detected and clearly reported.
- Maintainability: package mappings must be kept up to date with evolving distributions.