#
#========================================================================
#
-# Version 2.0.0beta2, released 13 Apr 2003.
+# Version 2.0.0, released 14 Jun 2003.
#
# See http://backuppc.sourceforge.net.
#
sub new
{
my $class = shift;
- my($topDir, $installDir) = @_;
+ my($topDir, $installDir, $noUserCheck) = @_;
my $bpc = bless {
TopDir => $topDir || '/data/BackupPC',
BinDir => $installDir || '/usr/local/BackupPC',
LibDir => $installDir || '/usr/local/BackupPC',
- Version => '2.0.0beta2',
+ Version => '2.0.0',
BackupFields => [qw(
num type startTime endTime
nFiles size nFilesExist sizeExist nFilesNew sizeNew
#
# Verify we are running as the correct user
#
- if ( $bpc->{Conf}{BackupPCUserVerify}
+ if ( !$noUserCheck
+ && $bpc->{Conf}{BackupPCUserVerify}
&& $> != (my $uid = (getpwnam($bpc->{Conf}{BackupPCUser}))[2]) ) {
print("Wrong user: my userid is $>, instead of $uid"
. " ($bpc->{Conf}{BackupPCUser})\n");
flock(LOCK, LOCK_EX) if open(LOCK, "$bpc->{TopDir}/pc/$host/LOCK");
if ( open(BK_INFO, "$bpc->{TopDir}/pc/$host/backups") ) {
+ binmode(BK_INFO);
while ( <BK_INFO> ) {
s/[\n\r]+//;
next if ( !/^(\d+\t(incr|full)[\d\t]*$)/ );
"$bpc->{TopDir}/pc/$host/backups.old")
if ( -f "$bpc->{TopDir}/pc/$host/backups" );
if ( open(BK_INFO, ">$bpc->{TopDir}/pc/$host/backups") ) {
+ binmode(BK_INFO);
for ( $i = 0 ; $i < @Backups ; $i++ ) {
my %b = %{$Backups[$i]};
printf(BK_INFO "%s\n", join("\t", @b{@{$bpc->{BackupFields}}}));
flock(LOCK, LOCK_EX) if open(LOCK, "$bpc->{TopDir}/pc/$host/LOCK");
if ( open(RESTORE_INFO, "$bpc->{TopDir}/pc/$host/restores") ) {
+ binmode(RESTORE_INFO);
while ( <RESTORE_INFO> ) {
s/[\n\r]+//;
next if ( !/^(\d+.*)/ );
"$bpc->{TopDir}/pc/$host/restores.old")
if ( -f "$bpc->{TopDir}/pc/$host/restores" );
if ( open(RESTORE_INFO, ">$bpc->{TopDir}/pc/$host/restores") ) {
+ binmode(RESTORE_INFO);
for ( $i = 0 ; $i < @Restores ; $i++ ) {
my %b = %{$Restores[$i]};
printf(RESTORE_INFO "%s\n",
"Can't open $bpc->{TopDir}/conf/hosts\n");
return {};
}
+ binmode(HOST_INFO);
while ( <HOST_INFO> ) {
s/[\n\r]+//;
s/#.*//;
$name = $1 if ( $name =~ /(.*)/ );
return ("", 0) if ( $fileSize == 0 );
return ("", -1) if ( !open(N, $name) );
+ binmode(N);
$md5->reset();
$md5->add($fileSize);
if ( $fileSize > 262144 ) {
$arg =~ s{\$(\w+)(\+?)}{
exists($vars->{$1}) && ref($vars->{$1}) ne "ARRAY"
? ($2 eq "+" ? $bpc->shellEscape($vars->{$1}) : $vars->{$1})
- : "\$$1"
+ : "\$$1$2"
}eg;
#
# Now replicate any array arguments; this just works for just one
print("cmdExecOrEval: about to exec ",
$bpc->execCmd2ShellCmd(@$cmd), "\n")
if ( $bpc->{verbose} );
- exec(@$cmd);
+ exec(map { m/(.*)/ } @$cmd); # untaint
print(STDERR "Exec failed for @$cmd\n");
exit(1);
}
return $err if ( !defined($stdoutCB) );
return;
}
+ binmode(CHILD);
if ( !$pid ) {
#
# This is the child
#
close(STDERR);
open(STDERR, ">&STDOUT");
- exec(@$cmd);
+ exec(map { m/(.*)/ } @$cmd); # untaint
print("Exec of @$cmd failed\n");
exit(1);
}