# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2001-2003 Craig Barratt
+# Copyright (C) 2001-2007 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
#
#========================================================================
#
-# Version 3.0.0alpha, released 23 Jan 2006.
+# Version 3.1.0, released 25 Nov 2007.
#
# See http://backuppc.sourceforge.net.
#
package BackupPC::Xfer::Smb;
use strict;
-
-sub new
-{
- my($class, $bpc, $args) = @_;
-
- $args ||= {};
- my $t = bless {
- bpc => $bpc,
- conf => { $bpc->Conf },
- host => "",
- hostIP => "",
- shareName => "",
- pipeRH => undef,
- pipeWH => undef,
- badFiles => [],
- %$args,
- }, $class;
-
- return $t;
-}
-
-sub args
-{
- my($t, $args) = @_;
-
- foreach my $arg ( keys(%$args) ) {
- $t->{$arg} = $args->{$arg};
- }
-}
+use Encode qw/from_to encode/;
+use base qw(BackupPC::Xfer::Protocol);
sub useTar
{
$t->{fileIncludeHash} = {};
if ( defined($conf->{BackupFilesOnly}{$t->{shareName}}) ) {
foreach my $file ( @{$conf->{BackupFilesOnly}{$t->{shareName}}} ) {
+ $file = encode($conf->{ClientCharset}, $file)
+ if ( $conf->{ClientCharset} ne "" );
push(@fileList, $file);
$t->{fileIncludeHash}{$file} = 1;
}
} elsif ( defined($conf->{BackupFilesExclude}{$t->{shareName}}) ) {
foreach my $file ( @{$conf->{BackupFilesExclude}{$t->{shareName}}} )
{
+ $file = encode($conf->{ClientCharset}, $file)
+ if ( $conf->{ClientCharset} ne "" );
push(@fileList, $file);
}
#
X_option => $X_option,
timeStampFile => $timeStampFile,
};
+ from_to($args->{shareName}, "utf8", $conf->{ClientCharset})
+ if ( $conf->{ClientCharset} ne "" );
$smbClientCmd = $bpc->cmdVarSubstitute($smbClientCmd, $args);
if ( !defined($t->{xferPid} = open(SMB, "-|")) ) {
return;
}
my $str = "Running: " . $bpc->execCmd2ShellCmd(@$smbClientCmd) . "\n";
+ from_to($str, $conf->{ClientCharset}, "utf8")
+ if ( $conf->{ClientCharset} ne "" );
$t->{XferLOG}->write(\$str);
alarm($conf->{ClientTimeout});
$t->{_errStr} = undef;
#
alarm($conf->{ClientTimeout}) if ( !$t->{abort} );
$t->{lastOutputLine} = $_ if ( !/^$/ );
+
+ from_to($_, $conf->{ClientCharset}, "utf8")
+ if ( $conf->{ClientCharset} ne "" );
#
# This section is highly dependent on the version of smbclient.
# If you upgrade Samba, make sure that these regexp are still valid.
$t->{XferLOG}->write(\"$_\n") if ( $t->{logLevel} >= 0 );
} elsif ( /^\s*NT_STATUS_ACCESS_DENIED listing (.*)/
|| /^\s*ERRDOS - ERRnoaccess \(Access denied\.\) listing (.*)/ ) {
+ $t->{xferErrCnt}++;
my $badDir = $1;
$badDir =~ s{\\}{/}g;
$badDir =~ s{/+}{/}g;
return 1;
}
-sub abort
-{
- my($t, $reason) = @_;
-
- $t->{abort} = 1;
- $t->{abortReason} = $reason;
-}
-
sub setSelectMask
{
my($t, $FDreadRef) = @_;
vec($$FDreadRef, fileno($t->{pipeSMB}), 1) = 1;
}
-sub errStr
-{
- my($t) = @_;
-
- return $t->{_errStr};
-}
-
-sub xferPid
-{
- my($t) = @_;
-
- return ($t->{xferPid});
-}
-
-sub logMsg
-{
- my($t, $msg) = @_;
-
- push(@{$t->{_logMsg}}, $msg);
-}
-
-sub logMsgGet
-{
- my($t) = @_;
-
- return shift(@{$t->{_logMsg}});
-}
-
-#
-# Returns a hash ref giving various status information about
-# the transfer.
-#
-sub getStats
-{
- my($t) = @_;
-
- return { map { $_ => $t->{$_} }
- qw(byteCnt fileCnt xferErrCnt xferBadShareCnt xferBadFileCnt
- xferOK hostAbort hostError lastOutputLine)
- };
-}
-
-sub getBadFiles
-{
- my($t) = @_;
-
- return @{$t->{badFiles}};
-}
-
1;