X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_archiveHost;h=e66c241f80d10651e73de77bdddefce4b3cb4fc3;hp=3b68aa95961f5d5da1284bd7c199e00d92aa4b7d;hb=c615e1bfc6f2b0604a2658996f5dd6b6cfa9469c;hpb=2c14784ad71874ec850d189060fe63d6eb9eba95 diff --git a/bin/BackupPC_archiveHost b/bin/BackupPC_archiveHost index 3b68aa9..e66c241 100755 --- a/bin/BackupPC_archiveHost +++ b/bin/BackupPC_archiveHost @@ -1,4 +1,4 @@ -#!/bin/perl +#!/usr/bin/perl #============================================================= # # BackupPC_archiveHost: Archive files for a single host @@ -17,9 +17,10 @@ # # AUTHOR # Craig Barratt +# Josh Marshall # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2009 Craig Barratt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,7 +38,7 @@ # #======================================================================== # -# Version 2.1.0_CVS, released 8 Feb 2004. +# Version 3.2.0, released 31 Jul 2010. # # See http://backuppc.sourceforge.net. # @@ -76,6 +77,10 @@ die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); # Make sure the specified programs are executable # foreach my $prog ( ($tarCreate, $compPath, $splitPath, $parPath) ) { + if ( $prog =~ /[][;&()<>{}|^\n\r\t *\$\\'"`?]/ ) { + print("Error: executable path $prog contains suspicious characters\n"); + exit(1); + } next if ( $prog eq "" || -x $prog ); print("Error: $prog is not an executable program\n"); exit(1); @@ -85,15 +90,38 @@ my $mesg = "Writing tar archive for host $host, backup #$bkupNum"; # # Build the command we will run # -$share = $bpc->shellEscape($share); -$host = $bpc->shellEscape($host); +$share = $bpc->shellEscape($share); +$host = $bpc->shellEscape($host); +$bkupNum = $bpc->shellEscape($bkupNum); +$fileExt = $bpc->shellEscape($fileExt); +$splitSize = $bpc->shellEscape($splitSize); +$parfile = $bpc->shellEscape($parfile); +my $outLocE = $bpc->shellEscape($outLoc); + +# +# We prefer to use /bin/csh because the exit status of a pipeline +# is non-zero if any command is non zero. In contrast, /bin/sh +# and /bin/bash use the convention that the exit status is just +# the exit status of the last command of the pipeline. +# +my @shell; +if ( -x "/bin/csh" ) { + @shell = ("/bin/csh", "-cf"); +} elsif ( -x "/bin/sh" ) { + @shell = ("/bin/sh", "-c"); +} else { + print("Error: Can't find executable /bin/csh or /bin/sh\n"); + exit(1); +} my $cmd = "$tarCreate -t -h $host -n $bkupNum -s $share . "; -$cmd .= "| $compPath " if ( $compPath ne "cat" && $compPath ne "" ); +$cmd .= "| $compPath " if ( $compPath ne "cat" + && $compPath ne "/bin/cat" + && $compPath ne "" ); if ( -b $outLoc || -c $outLoc || -f $outLoc ) { # # Output file is a device or a regular file, so don't use split # - $cmd .= ">> $outLoc"; + $cmd .= ">> $outLocE"; $mesg .= " to $outLoc"; } else { mkpath($outLoc) if ( !-d $outLoc ); @@ -101,12 +129,12 @@ if ( -b $outLoc || -c $outLoc || -f $outLoc ) { print("Error: unable to create output directory $outLoc\n"); exit(1); } - if ( $splitSize && -x $splitPath ) { - $cmd .= "| $splitPath -b $splitSize - $outLoc/$host.$bkupNum.tar$fileExt."; - $mesg .= ", split to output files $outLoc/$host.$bkupNum.tar$fileExt.*"; + if ( $splitSize > 0 && -x $splitPath ) { + $cmd .= "| $splitPath -b $splitSize - $outLocE/$host.$bkupNum.tar$fileExt."; + $mesg .= ", split to output files $outLocE/$host.$bkupNum.tar$fileExt.*"; } else { - $cmd .= "> $outLoc/$host.$bkupNum.tar$fileExt"; - $mesg .= " to output file $outLoc/$host.$bkupNum.tar$fileExt"; + $cmd .= "> $outLocE/$host.$bkupNum.tar$fileExt"; + $mesg .= " to output file $outLocE/$host.$bkupNum.tar$fileExt"; } } print("$mesg\n"); @@ -114,8 +142,9 @@ print("$mesg\n"); # # Run the command # -my $ret = system($cmd); +my $ret = system(@shell, $cmd); if ( $ret ) { + print("Executing: @shell $cmd\n"); print("Error: $tarCreate, compress or split failed\n"); exit(1); } @@ -125,10 +154,14 @@ if ( $ret ) { # ie: not a tape device). # if ( -d $outLoc && -x $parPath ) { - print("Running $parPath to create parity files\n"); - $ret = system("$parPath a -n $parfile $outLoc/$host.$bkupNum.tar$fileExt.par $outLoc/$host.$bkupNum.tar$fileExt.*"); - if ( $ret ) { - print("Error: $parPath failed\n"); - exit(1); + if ( length($parfile) ) { + print("Running $parPath to create parity files\n"); + my $parCmd = "$parPath c -r$parfile $outLocE/$host.$bkupNum.tar$fileExt.par2 $outLocE/$host.$bkupNum.tar$fileExt*"; + $ret = system($parCmd); + if ( $ret ) { + print("Executing: $parCmd\n"); + print("Error: $parPath failed\n"); + exit(1); + } } }