Blocking.pm: Filter for password in Authenticate (Forum #46380)

git-svn-id: https://svn.fhem.de/fhem/trunk@10329 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2016-01-02 13:55:33 +00:00
parent 0b68b24ea1
commit 6035ace0ce

View File

@ -33,38 +33,37 @@ BlockingCall($$@)
{ {
my ($blockingFn, $arg, $finishFn, $timeout, $abortFn, $abortArg) = @_; my ($blockingFn, $arg, $finishFn, $timeout, $abortFn, $abortArg) = @_;
# Look for the telnetport # Look for the telnetport. Must be done before forking to be able to create a
# must be done before forking to be able to create a temporary device # temporary device. Do it each time, as the old telnet may got a password
my $tName = "telnetForBlockingFn";
$telnetDevice = $tName if($defs{$tName});
if(!$telnetDevice) { $telnetDevice = undef;
foreach my $d (sort keys %defs) { foreach my $d (sort keys %defs) { #
my $h = $defs{$d}; my $h = $defs{$d};
next if(!$h->{TYPE} || $h->{TYPE} ne "telnet" || $h->{SNAME}); next if(!$h->{TYPE} || $h->{TYPE} ne "telnet" || $h->{SNAME});
next if($attr{$d}{SSL} || $attr{$d}{password} || next if($attr{$d}{SSL} ||
AttrVal($d, "allowfrom", "127.0.0.1") ne "127.0.0.1"); AttrVal($d, "allowfrom", "127.0.0.1") ne "127.0.0.1");
next if($h->{DEF} !~ m/^\d+( global)?$/); next if($h->{DEF} !~ m/^\d+( global)?$/);
next if($h->{DEF} =~ m/IPV6/);
next if($h->{DEF} =~ m/IPV6/); my %cDev = ( SNAME=>$d, TYPE=>$h->{TYPE}, NAME=>$d.time() );
$telnetDevice = $d; next if(Authenticate(\%cDev, undef) == 2); # Needs password
last; $telnetDevice = $d;
} last;
} }
# If not suitable telnet device found, create a temporary one # If not suitable telnet device found, create a temporary one
if(!$telnetDevice) { if(!$telnetDevice) {
my $ret = CommandDefine(undef, "$tName telnet 0"); $telnetDevice = "telnetForBlockingFn_".time();
my $ret = CommandDefine(undef, "$telnetDevice telnet 0");
if($ret) { if($ret) {
$ret = "BlockingCall ($blockingFn): ". $ret = "BlockingCall ($blockingFn): ".
"No telnet port found and cannot create one: $ret"; "No telnet port found and cannot create one: $ret";
Log 1, $ret; Log 1, $ret;
return $ret; return $ret;
} }
CommandAttr(undef, "$tName room hidden"); CommandAttr(undef, "$telnetDevice room hidden");
$telnetDevice = $tName; $defs{$telnetDevice}{TEMPORARY} = 1;
$defs{$tName}{TEMPORARY} = 1; $attr{$telnetDevice}{allowfrom} = "127.0.0.1";
$attr{$tName}{allowfrom} = "127.0.0.1";
} }
# do fork # do fork
@ -75,8 +74,8 @@ BlockingCall($$@)
} }
if($pid) { if($pid) {
Log 4, "BlockingCall ($blockingFn) created child ($pid), ". Log 4, "BlockingCall ($blockingFn): created child ($pid), ".
"uses $tName to connect back"; "uses $telnetDevice to connect back";
my %h = ( pid=>$pid, fn=>$blockingFn, finishFn=>$finishFn, my %h = ( pid=>$pid, fn=>$blockingFn, finishFn=>$finishFn,
abortFn=>$abortFn, abortArg=>$abortArg ); abortFn=>$abortFn, abortArg=>$abortArg );
if($timeout) { if($timeout) {