Skip to content
API Documentation
BastionGuard™
bastionguard_privhelper.cpp File Reference

Go to the source code of this file.

Classes

struct  anonymous_namespace{bastionguard_privhelper.cpp}::CallerIdentity

Namespaces

namespace  anonymous_namespace{bastionguard_privhelper.cpp}

Functions

bool anonymous_namespace{bastionguard_privhelper.cpp}::parse_uid (const char *value, uid_t &out)
CallerIdentity anonymous_namespace{bastionguard_privhelper.cpp}::resolve_caller_identity ()
bool anonymous_namespace{bastionguard_privhelper.cpp}::runtime_dir_is_safe (uid_t uid, const std::string &path)
bool anonymous_namespace{bastionguard_privhelper.cpp}::drop_to_caller (const CallerIdentity &caller)
std::vector< char * > anonymous_namespace{bastionguard_privhelper.cpp}::make_exec_argv (const std::vector< std::string > &args)
bool anonymous_namespace{bastionguard_privhelper.cpp}::run_as_caller (const CallerIdentity &caller, const std::vector< std::string > &args, std::string *output=nullptr)
std::string anonymous_namespace{bastionguard_privhelper.cpp}::find_pw_cli ()
bool anonymous_namespace{bastionguard_privhelper.cpp}::is_decimal_id (const std::string &value)
std::vector< std::string > anonymous_namespace{bastionguard_privhelper.cpp}::parse_video_node_ids (const std::string &listing)
bool anonymous_namespace{bastionguard_privhelper.cpp}::set_pipewire_camera_state (const CallerIdentity &caller, bool disabled)
bool anonymous_namespace{bastionguard_privhelper.cpp}::is_video_device_name (const std::string &name)
bool anonymous_namespace{bastionguard_privhelper.cpp}::ensure_state_directory ()
int anonymous_namespace{bastionguard_privhelper.cpp}::open_video_device (int dev_dir_fd, const std::string &name, struct stat &st)
bool anonymous_namespace{bastionguard_privhelper.cpp}::block_v4l2_devices ()
bool anonymous_namespace{bastionguard_privhelper.cpp}::restore_legacy_v4l2_modes ()
bool anonymous_namespace{bastionguard_privhelper.cpp}::restore_v4l2_devices ()
int main (int argc, char *argv[])

Variables

constexpr const char * anonymous_namespace{bastionguard_privhelper.cpp}::kStateDir = "/run/bastionguard"
constexpr const char * anonymous_namespace{bastionguard_privhelper.cpp}::kStateFile = "/run/bastionguard/camera-device-modes"
constexpr std::size_t anonymous_namespace{bastionguard_privhelper.cpp}::kMaxPipewireOutput = 1024U * 1024U

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 537 of file bastionguard_privhelper.cpp.

538{
539 const uid_t real_uid = getuid();
540 const uid_t effective_uid = geteuid();
541 const CallerIdentity caller = resolve_caller_identity();
542
543 // A setuid installation is explicitly unsupported. Privilege must be
544 // granted by pkexec/sudo so the authorization step remains visible.
545 if (effective_uid == 0 && real_uid != 0) {
546 std::cerr << "[Privacy] Refusing setuid execution; use pkexec or sudo\n";
547 return 11;
548 }
549
550 clearenv();
551 setenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
552
553 if (effective_uid != 0) {
554 std::cerr << "[Privacy] This helper must be executed as root via pkexec or sudo\n";
555 return 10;
556 }
557
558 if (argc != 2) {
559 std::cerr << "Usage: " << argv[0] << " block|unblock\n";
560 return 1;
561 }
562
563 const std::string action(argv[1]);
564
565 if (action == "block") {
566 if (set_pipewire_camera_state(caller, true))
567 return 0;
568 return block_v4l2_devices() ? 0 : 5;
569 }
570
571 if (action == "unblock") {
572 const bool pipewire_ok = set_pipewire_camera_state(caller, false);
573 const bool v4l2_ok = restore_v4l2_devices();
574 return (pipewire_ok || v4l2_ok) ? 0 : 5;
575 }
576
577 std::cerr << "[Privacy] Invalid command: " << action << "\n";
578 return 2;
579}
bool set_pipewire_camera_state(const CallerIdentity &caller, bool disabled)

References anonymous_namespace{bastionguard_privhelper.cpp}::block_v4l2_devices(), main(), anonymous_namespace{bastionguard_privhelper.cpp}::resolve_caller_identity(), anonymous_namespace{bastionguard_privhelper.cpp}::restore_v4l2_devices(), and anonymous_namespace{bastionguard_privhelper.cpp}::set_pipewire_camera_state().