Merge commit 'upstream/3.3.0'
[debian/amanda] / application-src / amsamba.pl
index 368b424b190dd02725acdc58e7d398d7dfcff0c0..f05ac08f31ca70c0cf6a34f2a4afd47b81125e76 100644 (file)
@@ -1,5 +1,5 @@
 #!@PERL@ 
-# Copyright (c) 2008,2009 Zmanda, Inc.  All Rights Reserved.
+# Copyright (c) 2008, 2009, 2010 Zmanda, Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published
@@ -19,6 +19,7 @@
 
 use lib '@amperldir@';
 use strict;
+use warnings;
 use Getopt::Long;
 
 package Amanda::Application::Amsamba;
@@ -101,6 +102,7 @@ sub new {
 #on exit:
 #  $self->{exclude}
 #  $self->{include}
+#  $self->{include_filename}
 sub validate_inexclude {
     my $self = shift;
 
@@ -127,22 +129,66 @@ sub validate_inexclude {
        }
        close(FF);
     }
-    if ($#{$self->{include_file}} >= 0) {
-       $self->{include} = [ @{$self->{include_file}} ];
-    }
-    foreach my $file (@{$self->{include_list}}) {
-       if (!open(FF, $file)) {
-           if ($self->{action} eq 'check' && !$self->{include_optional}) {
-               $self->print_to_server("Open of '$file' failed: $!",
-                                      $Amanda::Script_App::ERROR);
+
+    if ($self->{action} eq "restore" and defined $self->{'include_list'}) {
+       # put all include in a single file $self->{'include_filename'}
+       $self->{'include_filename'} = "$AMANDA_TMPDIR/amsamba.$$.include";
+       open INC_FILE, ">$self->{'include_filename'}";
+       if ($#{$self->{include_file}} >= 0) {
+           print INC_FILE "$self->{include_file}\n";
+       }
+       foreach my $file (@{$self->{include_list}}) {
+           if (!open(FF, $file)) {
+               if ($self->{action} eq 'check' && !$self->{include_optional}) {
+                   $self->print_to_server("Open of '$file' failed: $!",
+                                          $Amanda::Script_App::ERROR);
+               }
+               next;
            }
-           next;
+           while (<FF>) {
+               print INC_FILE;
+           }
+           close(FF);
        }
-       while (<FF>) {
-           chomp;
-           push @{$self->{include}}, $_;
+
+       # add command line include for amrestore
+       for(my $i=1;defined $ARGV[$i]; $i++) {
+           my $param = $ARGV[$i];
+           $param =~ /^(.*)$/;
+           print INC_FILE "$1\n";
+       }
+
+       close INC_FILE;
+    } else {
+       # put all include in $self->{'include'} they will be added on
+       # command line.
+       if ($#{$self->{include_file}} >= 0) {
+           $self->{include} = [ @{$self->{include_file}} ];
+       }
+
+       foreach my $file (@{$self->{include_list}}) {
+           if (!open(FF, $file)) {
+               if ($self->{action} eq 'check' && !$self->{include_optional}) {
+                   $self->print_to_server("Open of '$file' failed: $!",
+                                          $Amanda::Script_App::ERROR);
+               }
+               next;
+           }
+           while (<FF>) {
+               chomp;
+               push @{$self->{include}}, $_;
+           }
+           close(FF);
+       }
+
+       # add command line include for amrestore
+       if ($self->{action} eq "restore") {
+               for(my $i=1;defined $ARGV[$i]; $i++) {
+               my $param = $ARGV[$i];
+               $param =~ /^(.*)$/;
+               push @{$self->{include}}, $1;
+           }
        }
-       close(FF);
     }
 }
 
@@ -222,22 +268,10 @@ sub findpass {
     while ($line = <$amandapass>) {
        chomp $line;
        next if $line =~ /^#/;
-       my ($diskname, $userpasswd, $domain, $extra);
-       ($diskname, $userpasswd)   = Amanda::Util::skip_quoted_string($line);
-       if ($userpasswd) {
-           ($userpasswd, $domain) =
-                               Amanda::Util::skip_quoted_string($userpasswd);
-       }
-       if ($domain) {
-           ($domain, $extra) =
-                               Amanda::Util::skip_quoted_string($domain);
-       }
+       my ($diskname, $userpasswd, $domain, $extra) = Amanda::Util::split_quoted_string_friendly($line);
        if ($extra) {
            debug("Trailling characters ignored in amandapass line");
        }
-       $diskname = Amanda::Util::unquote_string($diskname);
-       $userpasswd = Amanda::Util::unquote_string($userpasswd);
-       $domain = Amanda::Util::unquote_string($domain);
        if (defined $diskname &&
            ($diskname eq '*' ||
             ($self->{unc}==0 && $diskname =~ m,^(//[^/]+)/\*$, && $1 eq $self->{cifshost}) ||
@@ -245,7 +279,7 @@ sub findpass {
             $diskname eq $self->{share} ||
             $diskname eq $self->{sambashare})) {
            if (defined $userpasswd && $userpasswd ne "") {
-               $self->{domain} = $domain if ($domain ne "");
+               $self->{domain} = $domain if defined $domain && $domain ne "";
                my ($username, $password) = split('%', $userpasswd, 2);
                $self->{username} = $username;
                $self->{password} = $password;
@@ -500,11 +534,6 @@ sub command_backup {
     my $self = shift;
 
     my $level = $self->{level}[0];
-    my $mesgout_fd;
-    open($mesgout_fd, '>&=3') ||
-       $self->print_to_server_and_die("Can't open mesgout_fd: $!",
-                                      $Amanda::Script_App::ERROR);
-    $self->{mesgout} = $mesgout_fd;
 
     $self->parsesharename();
     $self->findpass();
@@ -606,11 +635,11 @@ sub command_backup {
        open($indexout_fd, '>&=4') ||
            $self->print_to_server_and_die("Can't open indexout_fd: $!",
                                           $Amanda::Script_App::ERROR);
-       $self->parse_backup($index, $mesgout_fd, $indexout_fd);
+       $self->parse_backup($index, $self->{mesgout}, $indexout_fd);
        close($indexout_fd);
     }
     else {
-       $self->parse_backup($index_fd, $mesgout_fd, undef);
+       $self->parse_backup($index_fd, $self->{mesgout}, undef);
     }
     close($index);
 
@@ -634,8 +663,8 @@ sub command_backup {
        if ($ksize < 32) {
            $ksize = 32;
        }
-       print $mesgout_fd "sendbackup: size $ksize\n";
-       print $mesgout_fd "sendbackup: end\n";
+       print {$self->{mesgout}} "sendbackup: size $ksize\n";
+       print {$self->{mesgout}} "sendbackup: end\n";
     }
 
     waitpid $pid, 0;
@@ -708,14 +737,18 @@ sub command_restore {
        if (defined $self->{domain}) {
            push @cmd, "-W", $self->{domain};
        }
-       push @cmd, "-Tx", "-";
-       if ($#{$self->{include}} >= 0) {
-           push @cmd, @{$self->{include}};
-        }
-       for(my $i=1;defined $ARGV[$i]; $i++) {
-           my $param = $ARGV[$i];
-           $param =~ /^(.*)$/;
-           push @cmd, $1;
+       if (defined $self->{'include_filename'}) {
+           push @cmd, "-TFx", "-", "$self->{'include_filename'}";
+       } else {
+           push @cmd, "-Tx", "-";
+           if ($#{$self->{include}} >= 0) {
+               push @cmd, @{$self->{include}};
+            }
+           for(my $i=1;defined $ARGV[$i]; $i++) {
+               my $param = $ARGV[$i];
+               $param =~ /^(.*)$/;
+               push @cmd, $1;
+           }
        }
        my ($parent_rdr, $child_wtr);
        if (defined $self->{password}) {