From 939936b9bdf670b8b77f4c1bb17a28c64963e5c3 Mon Sep 17 00:00:00 2001 From: Barry Cannon Date: Mon, 10 Sep 2012 15:23:29 +0100 Subject: [PATCH] Bug 8745 - Disallow rebuild_zebra.pl from executing, when run by root user. Content-Type: text/plain; charset="utf-8" http://koha-community.org Added a check to warn users of execution as root user. Added a 'runas-root' switch to allow users to force execution as root user. Signed-off-by: Mason James --- misc/migration_tools/rebuild_zebra.pl | 27 +++++++++++++++++++++++++-- 1 files changed, 25 insertions(+), 2 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index e11817d..5df377d 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -12,6 +12,9 @@ use C4::AuthoritiesMarc; use C4::Items; use Koha::RecordProcessor; + + +use Smart::Comments; # # script that checks zebradir structure & create directories & mandatory files if needed # @@ -39,6 +42,12 @@ my $do_not_clear_zebraqueue; my $length; my $where; my $offset; +my $run_as_root; +my $run_user = (getpwuid($<))[0]; +### $run_user +### $run_as_root + + my $verbose_logging = 0; my $zebraidx_log_opt = " -v none,fatal,warn "; my $result = GetOptions( @@ -46,7 +55,7 @@ my $result = GetOptions( 'r|reset' => \$reset, 's' => \$skip_export, 'k' => \$keep_export, - 'I|skip-index' => \$skip_index, + 'I|skip-index' => \$skip_index, 'nosanitize' => \$nosanitize, 'b' => \$biblios, 'noxml' => \$noxml, @@ -61,13 +70,23 @@ my $result = GetOptions( 'length:i' => \$length, 'offset:i' => \$offset, 'v+' => \$verbose_logging, + 'run-as-root' => \$run_as_root, ); - if (not $result or $want_help) { print_usage(); exit 0; } +### $run_user +### $run_as_root + + +if( undef $run_as_root and $run_user eq 'root') { + my $msg = "Warning: You are running this script as the user 'root'.\n"; + $msg .= "If this is intentional you must explicitly specify this using the -run-as-root switch\n"; + $msg .= "Please do '$0 --help' to see usage.\n"; + die $msg; +} if (not $biblios and not $authorities) { my $msg = "Must specify -b or -a to reindex bibs or authorities\n"; @@ -657,6 +676,7 @@ only if you are using Zebra; if you are using the 'NoZebra' mode, this job should not be used. Parameters: + -b index bibliographic records -a index authority records @@ -716,6 +736,9 @@ Parameters: --munge-config Deprecated option to try to fix Zebra config files. + + --run-as-root explicitily allow script to run as 'root' user + --help or -h show this message. _USAGE_ } -- 1.7.2.5