- 2.0.0 release. Minor tweaks to disable utf8.
[BackupPC.git] / lib / BackupPC / Lib.pm
index 0da9356..b0d33df 100644 (file)
@@ -29,7 +29,7 @@
 #
 #========================================================================
 #
-# Version 2.0.0beta2, released 13 Apr 2003.
+# Version 2.0.0, released 14 Jun 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
@@ -52,13 +52,13 @@ use Digest::MD5;
 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
@@ -86,7 +86,8 @@ sub new
     #
     # 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");
@@ -186,6 +187,7 @@ sub BackupInfoRead
 
     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]*$)/ );
@@ -211,6 +213,7 @@ sub BackupInfoWrite
            "$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}}}));
@@ -228,6 +231,7 @@ sub RestoreInfoRead
 
     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+.*)/ );
@@ -253,6 +257,7 @@ sub RestoreInfoWrite
            "$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",
@@ -334,6 +339,7 @@ sub HostInfoRead
                      "Can't open $bpc->{TopDir}/conf/hosts\n");
         return {};
     }
+    binmode(HOST_INFO);
     while ( <HOST_INFO> ) {
         s/[\n\r]+//;
         s/#.*//;
@@ -605,6 +611,7 @@ sub File2MD5
     $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 ) {
@@ -1003,7 +1010,7 @@ sub cmdVarSubstitute
         $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
@@ -1047,7 +1054,7 @@ sub cmdExecOrEval
        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);
     }
@@ -1095,13 +1102,14 @@ sub cmdSystemOrEval
            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);
        }