File Coverage

blib/lib/Net/Dropbear/SSHd.pm
Criterion Covered Total %
statement 37 57 64.9
branch 1 8 12.5
condition 1 3 33.3
subroutine 11 15 73.3
pod 3 4 75.0
total 53 87 60.9


line stmt bran cond sub pod time code
1             package Net::Dropbear::SSHd;
2              
3 10     10   439195 use strict;
  10         21  
  10         241  
4 10     10   114 use v5.12;
  10         30  
5             our $VERSION = '0.03';
6              
7 10     10   6939 use Child;
  10         54950  
  10         414  
8              
9 10     10   7840 use autodie;
  10         272998  
  10         52  
10 10     10   64438 use Carp;
  10         22  
  10         671  
11 10     10   9921 use Moo;
  10         186274  
  10         69  
12 10     10   31915 use Types::Standard qw/ArrayRef HashRef GlobRef Str Int Bool InstanceOf/;
  10         702402  
  10         126  
13              
14             has addrs => (
15             is => 'rw',
16             isa => ArrayRef[Str],
17             coerce => sub { ref $_[0] ? $_[0] : [ $_[0] ] },
18             );
19              
20             has keys => (
21             is => 'rw',
22             isa => ArrayRef[Str],
23             coerce => sub {
24             my $value = shift;
25             $value = ref $value ? $value : [ $value ];
26             foreach my $key ( @$value )
27             {
28             carp "Key file does not exist: $key"
29             if !-e $key;
30             }
31             return $value;
32             },
33             );
34              
35             has hooks => (
36             is => 'ro',
37             isa => HashRef,
38             default => sub { {} },
39             );
40              
41             has debug => ( is => "rw", isa => Bool, default => 0, );
42             has forkbg => ( is => "rw", isa => Bool, default => 0, );
43             has usingsyslog => ( is => "rw", isa => Bool, default => 0, );
44             has inetdmode => ( is => "rw", isa => Bool, default => 0, );
45             has norootlogin => ( is => "rw", isa => Bool, default => 1, );
46             has noauthpass => ( is => "rw", isa => Bool, default => 1, );
47             has norootpass => ( is => "rw", isa => Bool, default => 1, );
48             has allowblankpass => ( is => "rw", isa => Bool, default => 0, );
49             has delay_hostkey => ( is => "rw", isa => Bool, default => 0, );
50             has domotd => ( is => "rw", isa => Bool, default => 0, );
51             has noremotetcp => ( is => "rw", isa => Bool, default => 1, );
52             has nolocaltcp => ( is => "rw", isa => Bool, default => 1, );
53              
54             has child => (
55             is => 'rwp',
56             isa => InstanceOf['Child::Link::Proc'],
57             );
58              
59             has comm => (
60             is => 'rwp',
61             isa => GlobRef,
62             );
63              
64             sub is_running
65             {
66 0     0 1 0 my $self = shift;
67 0         0 return defined $self->child;
68             }
69              
70             sub run
71             {
72 9     9 1 1139 my $self = shift;
73 9         21 my $child_hook = shift;
74              
75 9 50 33     83 if (defined $child_hook && ref $child_hook ne 'CODE')
76             {
77 0         0 croak '$child_hook was not a code ref when calling run';
78             }
79              
80 10     10   28099 use Socket;
  10         40436  
  10         6736  
81 10     10   986 use IO::Handle;
  10         6941  
  10         5843  
82 9         62 socketpair(my $child_comm, my $parent_comm, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
83              
84             my $child = Child->new(sub {
85 0     0   0 my $parent = shift;
86 0         0 $0 .= " [Net::Dropbear Child]";
87              
88 0         0 $parent_comm->close;
89 0         0 $self->_set_comm($child_comm);
90              
91 0         0 require Net::Dropbear::XS;
92              
93 0         0 Net::Dropbear::XS->setup_svr_opts($self);
94              
95 0 0       0 $child_hook->($parent)
96             if defined $child_hook;
97              
98 0         0 Net::Dropbear::XS->svr_main();
99              
100             # Should never return
101 0         0 croak 'Unexpected return from dropbear';
102 9         16518 });
103              
104 9         121 $self->_set_child($child->start);
105 9         33670 $child_comm->close;
106 9         317 $self->_set_comm($parent_comm);
107              
108 9         7092 return;
109             }
110              
111             sub kill
112             {
113             my $self = shift;
114             if ($self->is_running)
115             {
116             $self->child->kill(15);
117             }
118             }
119              
120             sub wait
121             {
122 0     0 1 0 my $self = shift;
123 0 0       0 if ($self->is_running)
124             {
125 0         0 $self->child->wait;
126             }
127             }
128              
129             sub auto_hook
130             {
131 0     0 0 0 my $self = shift;
132 0         0 my $hook = shift;
133              
134 0 0       0 if (exists $self->hooks->{$hook})
135             {
136 0         0 return $self->hooks->{$hook}->(@_);
137             }
138              
139 0         0 return Net::Dropbear::XS::HOOK_CONTINUE();
140             }
141              
142             sub import
143             {
144 19     19   12716 require Net::Dropbear::XS;
145 19         1829 Net::Dropbear::XS->export_to_level(1, @_);
146             }
147              
148             1;
149             __END__