line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Rexec; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
848
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION @ISA @EXPORT_OK); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
178
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1017
|
use IO::Socket; |
|
1
|
|
|
|
|
36959
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
1603
|
use Net::Netrc; |
|
1
|
|
|
|
|
7085
|
|
|
1
|
|
|
|
|
38
|
|
8
|
1
|
|
|
1
|
|
8
|
use Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
601
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(rexec); |
12
|
|
|
|
|
|
|
$VERSION = '0.12'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Preloaded methods go here. |
15
|
|
|
|
|
|
|
sub rexec { |
16
|
0
|
|
|
0
|
0
|
|
my($host) = shift; |
17
|
0
|
|
|
|
|
|
my($sock) = IO::Socket::INET->new(PeerAddr => $host, |
18
|
|
|
|
|
|
|
PeerPort => 'exec(512)', |
19
|
|
|
|
|
|
|
Proto => 'tcp'); |
20
|
0
|
0
|
|
|
|
|
die "Error opening sock $!" if (!defined($sock)); |
21
|
0
|
|
|
|
|
|
$sock->syswrite("0\0", 2); |
22
|
0
|
|
|
|
|
|
my($cmd) = shift; |
23
|
0
|
|
|
|
|
|
my($user, $pswd); |
24
|
0
|
0
|
|
|
|
|
$user = shift if @_; |
25
|
0
|
0
|
|
|
|
|
$pswd = shift if @_; |
26
|
0
|
0
|
|
|
|
|
if (!defined($pswd)) { |
27
|
0
|
|
|
|
|
|
my $mach; |
28
|
0
|
0
|
|
|
|
|
if (defined($user)) { |
29
|
0
|
|
|
|
|
|
$mach = Net::Netrc->lookup($host, $user); |
30
|
0
|
0
|
|
|
|
|
die "Cannot find entry for $host, $user in netrc $!" if !defined($mach); |
31
|
0
|
|
|
|
|
|
$pswd = $mach->password; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
|
$mach = Net::Netrc->lookup($host); |
34
|
0
|
0
|
|
|
|
|
die "Cannot find $host in netrc $!" if !defined($mach); |
35
|
0
|
|
|
|
|
|
$user = $mach->login; |
36
|
0
|
|
|
|
|
|
$pswd = $mach->password; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
$sock->syswrite($user . "\0", length($user) + 1); |
40
|
0
|
|
|
|
|
|
$sock->syswrite($pswd . "\0", length($pswd) + 1); |
41
|
0
|
|
|
|
|
|
$sock->syswrite($cmd . "\0", length($cmd) + 1); |
42
|
0
|
|
|
|
|
|
my($result, $output, @return); |
43
|
0
|
|
|
|
|
|
$result = $sock->sysread($output, 1); |
44
|
0
|
0
|
|
|
|
|
if ($output eq chr(1)) { |
|
|
0
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
@return = (1, $sock->getline); |
46
|
|
|
|
|
|
|
} elsif ($output eq chr(0)) { |
47
|
0
|
|
|
|
|
|
@return = (0, $sock->getlines); |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
$output .= $sock->getline; |
50
|
0
|
|
|
|
|
|
@return = (2, $output); |
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
|
|
|
|
wantarray ? @return : $return[0]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |