Bug 8745 - Disallow rebuild_zebra.pl from executing, when run by root user.
authorBarry Cannon <barry@oslo.ie>
Mon, 10 Sep 2012 14:23:29 +0000 (15:23 +0100)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Sun, 21 Apr 2013 13:41:34 +0000 (09:41 -0400)
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 <mtj@kohaaloha.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
misc/migration_tools/rebuild_zebra.pl

index c29ef76..14fea3c 100755 (executable)
@@ -13,7 +13,6 @@ use C4::Items;
 use Koha::RecordProcessor;
 use XML::LibXML;
 
-# 
 # script that checks zebradir structure & create directories & mandatory files if needed
 #
 #
@@ -40,6 +39,9 @@ my $do_not_clear_zebraqueue;
 my $length;
 my $where;
 my $offset;
+my $run_as_root;
+my $run_user = (getpwuid($<))[0];
+
 my $verbose_logging = 0;
 my $zebraidx_log_opt = " -v none,fatal,warn ";
 my $result = GetOptions(
@@ -47,7 +49,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,
@@ -62,14 +64,21 @@ 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;
 }
 
+if( not defined $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";
     $msg   .= "Please do '$0 --help' to see usage.\n";
@@ -678,6 +687,7 @@ Use this batch job to reindex all biblio or authority
 records in your Koha database.
 
 Parameters:
+
     -b                      index bibliographic records
 
     -a                      index authority records
@@ -737,6 +747,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_
 }