From 921e9a76f1ca47d30d765f2f2bf61954e8ac9c9c Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Tue, 21 Jan 2025 16:11:42 -0500 Subject: Avoid requiring root access Make temporary folder generation lazy to postpone requiring root access until needed. --- SBO-Lib/lib/SBO/App/Remove.pm | 7 ++++++- SBO-Lib/lib/SBO/App/Snap.pm | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'SBO-Lib/lib/SBO/App') diff --git a/SBO-Lib/lib/SBO/App/Remove.pm b/SBO-Lib/lib/SBO/App/Remove.pm index 4c7dd31..b97cdf8 100644 --- a/SBO-Lib/lib/SBO/App/Remove.pm +++ b/SBO-Lib/lib/SBO/App/Remove.pm @@ -10,7 +10,7 @@ package SBO::App::Remove; use 5.16.0; use strict; use warnings FATAL => 'all'; -use SBO::Lib qw/ get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents prompt show_version in /; +use SBO::Lib qw/ _ERR_USAGE get_inst_names get_installed_packages get_sbo_location get_build_queue merge_queues get_requires get_readme_contents prompt show_version in /; use Getopt::Long qw(GetOptionsFromArray :config bundling); use parent 'SBO::App'; @@ -41,6 +41,11 @@ sub run { if ($self->{vers}) { $self->show_version(); return 0; } if (!@{ $self->{args} }) { $self->show_usage(); return 1; } + unless ($< == 0) { + warn "This script requires root privileges.\n"; + exit _ERR_USAGE; + } + # current workflow: # * get names of all installed SBo packages # * compare commandline args to SBo packages as well as installed SBo packages diff --git a/SBO-Lib/lib/SBO/App/Snap.pm b/SBO-Lib/lib/SBO/App/Snap.pm index d2b0f57..f9e44a6 100644 --- a/SBO-Lib/lib/SBO/App/Snap.pm +++ b/SBO-Lib/lib/SBO/App/Snap.pm @@ -13,7 +13,7 @@ package SBO::App::Snap; use 5.16.0; use strict; use warnings FATAL => 'all'; -use SBO::Lib qw/ fetch_tree import_gpg_key update_tree %config show_version /; +use SBO::Lib qw/ _ERR_USAGE fetch_tree import_gpg_key update_tree %config show_version /; use Getopt::Long qw/ GetOptionsFromArray /; use parent 'SBO::App'; @@ -64,6 +64,11 @@ sub run { if ($self->{help}) { $self->show_usage(); return 0 } if ($self->{vers}) { $self->show_version(); return 0 } + unless ($< == 0) { + warn "This script requires root privileges.\n"; + exit _ERR_USAGE; + } + # check for a command and, if found, execute it $args[0] //= ''; -- cgit v1.2.3