413 {
414
415 std::string lang_conf = Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
417
418 std::ifstream f(lang_conf);
419 if (f.is_open()) {
421 while (std::getline(f, line)) {
422 auto pos =
line.find(
'=');
423 if (pos != std::string::npos) {
424 std::string key =
line.substr(0, pos);
425 std::string val =
line.substr(pos + 1);
426 if (!key.empty() && !val.empty()) {
427 setenv(key.c_str(), val.c_str(), 1);
428 }
429 }
430 }
431 f.close();
432 std::cout << "[Lang] Config caricata da " << lang_conf << std::endl;
433 } else {
434 std::cerr << "[Lang] ⚠️ Impossibile aprire lang.conf, forzo inglese di default" << std::endl;
435 }
436
437
438 const char* lang_env = std::getenv("LANG");
439 if (!lang_env || std::string(lang_env).empty()) {
440 setenv("LANG", "en_US.UTF-8", 1);
441 }
442
443 const char* lc_all_env = std::getenv("LC_ALL");
444 if (!lc_all_env || std::string(lc_all_env).empty()) {
445 setenv("LC_ALL", "en_US.UTF-8", 1);
446 }
447
448 const char* language_env = std::getenv("LANGUAGE");
449 if (!language_env || std::string(language_env).empty()) {
450 setenv("LANGUAGE", "en_US", 1);
451 }
452
453 const char* applied = setlocale(LC_ALL, "");
454 if (!applied) {
455 applied = setlocale(LC_ALL, "en_US.UTF-8");
456 }
457 if (!applied) {
458 applied = setlocale(LC_ALL, "en_US");
459 }
460 if (!applied) {
461 applied = setlocale(LC_ALL, "C.UTF-8");
462 }
463 if (!applied) {
464 applied = setlocale(LC_ALL, "C");
465 }
466
467 bindtextdomain(
"BastionGuard",
LOCALEDIR);
468 bind_textdomain_codeset("BastionGuard", "UTF-8");
469 textdomain("BastionGuard");
470
471 bool do_update_phish = false;
472 bool do_update_sanesecurity = false;
473 bool start_minimized = false;
474
475 std::vector<char*> gtk_argv;
476 gtk_argv.push_back(argv[0]);
477
478 for (int i = 1; i < argc; ++i) {
479 std::string arg = argv[i];
480 if (arg == "--update-phish") {
481 do_update_phish = true;
482 } else if (arg == "--update-sanesecurity") {
483 do_update_sanesecurity = true;
484 } else if (arg == "--minimized") {
485 start_minimized = true;
486 } else {
487 gtk_argv.push_back(argv[i]);
488 }
489 }
490
492
493 if (do_update_phish) {
494 std::cout <<
"[BastionGuard] " <<
_(
"Avvio aggiornamento blacklist (modalità headless)...") << std::endl;
495 try {
497 if (ok) {
498 std::cout <<
"[BastionGuard] " <<
_(
"✔ Blacklist aggiornata con successo.") << std::endl;
499 return 0;
500 } else {
501 std::cerr <<
"[BastionGuard] " <<
_(
"❌ Errore durante l'aggiornamento blacklist.") << std::endl;
502 return 2;
503 }
504 } catch (const std::exception& ex) {
505 std::cerr <<
"[BastionGuard] " <<
_(
"Eccezione durante updatePhishLists(): ") << ex.what() << std::endl;
506 return 3;
507 }
508 }
509
510 if (do_update_sanesecurity) {
511 std::cout <<
_(
"[BastionGuard] Avvio aggiornamento SaneSecurity (modalità headless)...") << std::endl;
512 try {
514 if (ok) {
515 std::cout <<
_(
"[BastionGuard] ✔ Aggiornamento SaneSecurity completato.") << std::endl;
516 return 0;
517 } else {
518 std::cerr <<
_(
"[BastionGuard] ❌ Errore durante l'aggiornamento SaneSecurity.") << std::endl;
519 return 5;
520 }
521 } catch (const std::exception& ex) {
522 std::cerr <<
_(
"[BastionGuard] ❌ Eccezione durante updateSaneSecurity(): ")
523 << ex.what() << std::endl;
524 return 6;
525 }
526 }
527
528 {
529 struct passwd* pw = getpwnam("clamav");
530 if (!pw) {
531 std::cerr <<
_(
"[Main] ❌ Utente 'clamav' non trovato. Lo scanner userà l'utente normale.") << std::endl;
532 } else {
533 uid_t original_euid = geteuid();
534 gid_t original_egid = getegid();
535
536 setenv("BastionGuard_ORIG_EUID", std::to_string(original_euid).c_str(), 1);
537 setenv("BastionGuard_ORIG_EGID", std::to_string(original_egid).c_str(), 1);
538
539 initgroups("clamav", pw->pw_gid);
540
541 if (setegid(pw->pw_gid) != 0)
542 perror("[Main] setegid clamav");
543
544 if (seteuid(pw->pw_uid) != 0)
545 perror("[Main] seteuid clamav");
546
547 std::cout <<
_(
"[Main] 🔐 Processo configurato per lanciare i sottoprocessi come 'clamav'") << std::endl;
548
549 setegid(original_egid);
550 seteuid(original_euid);
551 }
552 }
553
554 int gtk_argc = static_cast<int>(gtk_argv.size());
555 char** gtk_argv_data = gtk_argv.data();
556
557 auto app = Glib::make_refptr_for_instance<ClamApp>(
new ClamApp(start_minimized));
558 return app->run(gtk_argc, gtk_argv_data);
559}
static Backend & instance()
ClamApp(bool start_minimized)
static bool runHeadless()
static void ensure_lang_conf_exists(const std::string &lang_conf_path)
static void ensureUserWrapperInstalled()