Skip to content
API Documentation
BastionGuard™
BastionGuard-secure-cli.cpp
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#include "../SafeProcess.hpp"
23#include "SecureBrowser.hpp"
24#include "dns_secure.hpp"
25#include "Resource.hpp"
26#include <include/cef_app.h>
27#include <glib/gi18n.h>
28#include <unistd.h>
29#include <sys/stat.h>
30#include <fcntl.h>
31#include <cerrno>
32
33#include <iostream>
34#include <fstream>
35#include <vector>
36#include <cstdlib>
37#include <cstring>
38#include <string>
39
40
42 const char* wayland = std::getenv("WAYLAND_DISPLAY");
43 const char* x11 = std::getenv("DISPLAY");
44
45 if (wayland && *wayland) {
46 std::cout << _("[BastionGuard-secure] Sessione Wayland rilevata → backend Wayland.\n");
47 setenv("GDK_BACKEND", "wayland", 1);
48 setenv("OZONE_PLATFORM", "wayland", 1);
49 } else if (x11 && *x11) {
50 std::cout << _("[BastionGuard-secure] Sessione X11 rilevata → backend X11.\n");
51 setenv("GDK_BACKEND", "x11", 1);
52 setenv("OZONE_PLATFORM", "x11", 1);
53 } else {
54 std::cout << _("[BastionGuard-secure] Nessuna sessione grafica rilevata → fallback X11.\n");
55 setenv("GDK_BACKEND", "x11", 1);
56 setenv("OZONE_PLATFORM", "x11", 1);
57 }
58
59 const char* force_sw = std::getenv("BASTIONGUARD_FORCE_SOFTWARE_GL");
60 if (force_sw && std::strcmp(force_sw, "1") == 0) {
61 std::cout << _("[BastionGuard-secure] Forzo rendering software (LIBGL_ALWAYS_SOFTWARE=1)\n");
62 setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1);
63 }
64}
65
66
67static bool has_in_path(const char* exe) {
68 return exe && bg_process::exists_on_path(exe);
69}
70
71
72
73
74int main(int argc, char** argv) {
75 setlocale(LC_ALL, "");
76 bindtextdomain("BastionGuard", LOCALEDIR);
77 bind_textdomain_codeset("BastionGuard", "UTF-8");
78 textdomain("BastionGuard");
79
80 CefMainArgs cef_args(argc, argv);
81 int rc = CefExecuteProcess(cef_args, nullptr, nullptr);
82 if (rc >= 0)
83 return rc;
84
85 const char* no_bwrap = std::getenv("BASTIONGUARD_NO_BWRAP");
86 if (!(no_bwrap && std::strcmp(no_bwrap, "1") == 0)) {
88 } else {
89 std::cerr << _("[BastionGuard-secure] Bypass dnsmasq disabilitato (BASTIONGUARD_NO_BWRAP=1)\n");
90 }
91
92 if (argc < 2) {
93 std::cerr << _("Usage: BastionGuard-secure <url>\n");
94 return 2;
95 }
96
97 const std::string url = argv[1];
98 std::cout << _("[BastionGuard-secure] URL richiesto: ") << url << "\n";
99
100
102
103 SecureList::open_if_allowed(url, argc, argv);
104
105 return 0;
106}
#define _(s)
int main(int argc, char *argv[])
static void configure_graphics_backend()
static bool has_in_path(const char *exe)
#define LOCALEDIR
static bool open_if_allowed(const std::string &url, int argc, char **argv)
void reexec_inside_bwrap_with_custom_dns(int argc, char **argv)
bool exists_on_path(const std::string &name)