diff --git a/lib/Net/Cmd.pm b/lib/Net/Cmd.pm index ef1896b..b76c213 100644 --- a/lib/Net/Cmd.pm +++ b/lib/Net/Cmd.pm @@ -188,11 +188,26 @@ sub set_status { 1; } +# The default encode/decode methods +sub encode { + my ($cmd, $text, $len) = @_; + + $text; +} + + +sub decode { + my ($cmd, $text, $len) = @_; + + $text; +} + + sub _syswrite_with_timeout { my $cmd = shift; - my $line = shift; + my $line = $cmd->encode($_[0], $_[1]); + my $len = length($line); - my $len = length($line); my $offset = 0; my $win = ""; vec($win, fileno($cmd), 1) = 1; @@ -352,6 +367,8 @@ sub getline { substr($buf, 0, 0) = $partial; ## prepend from last sysread + $buf = $cmd->decode($buf, length($buf)); ## decode it + my @buf = split(/\015?\012/, $buf, -1); ## break into lines $partial = pop @buf; diff --git a/lib/Net/SMTP.pm b/lib/Net/SMTP.pm index 3b82a60..455f22c 100644 --- a/lib/Net/SMTP.pm +++ b/lib/Net/SMTP.pm @@ -158,6 +158,28 @@ sub etrn { } +# Overload encode method when Authen::SASL is available +sub encode { + my ($self, $text, $len) = @_; + my $sasl = ${*$self}{'net_smtp_sasl'}; + + return ($sasl) + ? $sasl->encode($text, $len) + : $self->SUPER::encode($text, $len); +} + + +# Overload decode method when Authen::SASL is available +sub decode { + my ($self, $text, $len) = @_; + my $sasl = ${*$self}{'net_smtp_sasl'}; + + return ($sasl) + ? $sasl->decode($text, $len) + : $self->SUPER::decode($text, $len); +} + + sub auth { my ($self, $username, $password) = @_; @@ -216,13 +238,6 @@ sub auth { # todo that we would really need to change the ISA hierarchy # so we don't inherit from IO::Socket, but instead hold it in an attribute - # DIGEST-MD5 can support integrity and/or confidentiality protection - # over the socket traffic (auth-int and auth-conf) which we do not - # support here for now. To disable them, set maxssf=minssf=0. - - $client->property('maxssf' => 0, 'minssf' => 0) - if ($client->mechanism eq 'DIGEST-MD5'); - my @cmd = ("AUTH", $client->mechanism); my $code; @@ -241,6 +256,13 @@ sub auth { $self->debug_print(1, "(decoded) " . $str . "\n") if $self->debug; } + # Some mechanisms in Authen::SASL offer additional security layers + # for integrity and/or confidentiality and define encode() and + # decode() methods. To support them, store # the Authen::SASL + # object in {net_smtp_sasl}. + # + ${*$self}{'net_smtp_sasl'} = $sasl->{conn}; + $code == CMD_OK; }