Access/ssh.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 66 CC 5 SCAR 20.1
CC
5
Cov
0%
disconnect
12.0
start
12.0
incoming
2.0
CRAP 7.5
1 #
2 # $Id: ssh.pm,v 1.4 2003/03/02 11:12:10 dsw Exp $
3 #
4 # COPYRIGHT AND LICENSE
5 # Copyright (c) 2001-2003, Juniper Networks, Inc.
6 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
9 # met:
10 # 1. Redistributions of source code must retain the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer.
13 # 2. Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following disclaimer
15 # in the documentation and/or other materials provided with the
16 # distribution.
17 # 3. The name of the copyright owner may not be used to
18 # endorse or promote products derived from this software without specific
19 # prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 #
32 # The JUNOS::Access::ssh implements the ssh access method.
33 #
34  
35 package JUNOS::Access::ssh;
36  
37 use Net::SSH::Perl;
38 use JUNOS::Trace;
39 use JUNOS::Access;
40 use vars qw(@ISA);
41 @ISA = qw(JUNOS::Access);
42  
43 sub disconnect
44 {
45 my($self) = @_;
46  
47 if( $self->{INPUT} ) { close($self->{INPUT}); }
48 if( $self->{OUTPUT} ) { close($self->{OUTPUT}); }
49 $self->{INPUT} = undef;
50 $self->{OUTPUT} = undef;
51  
52 undef;
53 }
54  
55 sub start
56 {
57 my($self) = @_;
58  
59 # Get ssh port number if it exists
60 my $rport= (getservbyname('ssh', 'tcp'))[2];
61  
62 # Create Net::SSH::Perl object
63 my $ssh = Net::SSH::Perl->new($self->{hostname},
64 debug => $self->{'ssh-debug'},
65 protocol => '2,1',
66 port => $rport || 22,
67 interactive => $self->{'ssh-interactive'},
68 compression => (defined $self->{'ssh-compress'} &&
69 !$self->{'ssh-compress'}) ? 'no' : 'yes',
70 options => [ ForwardX11 => 'no' ]) || return;
71  
72  
73 # Have Net::SSH::Perl prompt for whatever is needed -
74 # passphrase or password
75 if ($self->{'ssh-interactive'})
76 {
77 $ssh->login || return;
78 }
79 else
80 {
81 $ssh->login($self->{login}, $self->{password}) || return;
82 }
83  
84 ($self->{INPUT},$self->{OUTPUT}) = $ssh->open2("junoscript");
85  
86 $self->{ssh_object} = $ssh;
87 }
88  
89 sub incoming
90 {
91 $_[0];
92 }
93  
94 1;
95  
96 __END__