line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of Config-Model-OpenSsh |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2008-2022 by Dominique Dumont. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The GNU Lesser General Public License, Version 2.1, February 1999 |
9
|
|
|
|
|
|
|
# |
10
|
2
|
|
|
2
|
|
53520
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
66
|
|
11
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
124
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Config::Model::Backend::OpenSsh::Ssh ; |
14
|
|
|
|
|
|
|
$Config::Model::Backend::OpenSsh::Ssh::VERSION = '2.9.4.1'; |
15
|
2
|
|
|
2
|
|
15
|
use Mouse ; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
29
|
|
16
|
2
|
|
|
2
|
|
1291
|
use 5.10.1; |
|
2
|
|
|
|
|
8
|
|
17
|
|
|
|
|
|
|
extends "Config::Model::Backend::Any" ; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
with ( |
20
|
|
|
|
|
|
|
'Config::Model::Backend::OpenSsh::Role::Reader', |
21
|
|
|
|
|
|
|
'Config::Model::Backend::OpenSsh::Role::Writer', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
13
|
use Carp ; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
144
|
|
26
|
2
|
|
|
2
|
|
1068
|
use IO::File ; |
|
2
|
|
|
|
|
4183
|
|
|
2
|
|
|
|
|
257
|
|
27
|
2
|
|
|
2
|
|
14
|
use Log::Log4perl; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
31
|
|
28
|
2
|
|
|
2
|
|
100
|
use File::Copy ; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
141
|
|
29
|
2
|
|
|
2
|
|
12
|
use File::Path ; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
99
|
|
30
|
2
|
|
|
2
|
|
13
|
use File::HomeDir ; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
2004
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $logger = Log::Log4perl::get_logger("Backend::OpenSsh"); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub write { |
35
|
9
|
|
|
9
|
1
|
5536738
|
my $self = shift; |
36
|
9
|
|
|
|
|
85
|
$self->ssh_write(@_, ssh_mode => 'custom') ; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub host { |
41
|
43
|
|
|
43
|
0
|
171
|
my ($self,$root,$key, $patterns,$comment) = @_; |
42
|
43
|
|
|
|
|
257
|
$logger->debug("host: pattern @$patterns # $comment"); |
43
|
43
|
|
|
|
|
429
|
my $hash_obj = $root->fetch_element('Host'); |
44
|
|
|
|
|
|
|
|
45
|
43
|
|
|
|
|
87136
|
$logger->info("ssh: load host patterns '".join("','", @$patterns)."'"); |
46
|
43
|
|
|
|
|
542
|
my $hv = $hash_obj->fetch_with_id("@$patterns") ; |
47
|
43
|
100
|
|
|
|
204954
|
$hv -> annotation($comment) if $comment ; |
48
|
|
|
|
|
|
|
|
49
|
43
|
|
|
|
|
842
|
$self->current_node($hv); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub forward { |
53
|
18
|
|
|
18
|
0
|
91
|
my ($self, $root, $key, $args, $comment, $check) = @_; |
54
|
18
|
|
|
|
|
160
|
$logger->debug("forward: $key @$args # $comment"); |
55
|
18
|
50
|
|
|
|
206
|
$self->current_node = $root unless defined $self->current_node ; |
56
|
|
|
|
|
|
|
|
57
|
18
|
50
|
|
|
|
110
|
my $elt_name = $key =~ /local/i ? 'Localforward' : 'RemoteForward' ; |
58
|
|
|
|
|
|
|
|
59
|
18
|
100
|
|
|
|
104
|
my $v6 = ($args->[1] =~ m![/\[\]]!) ? 1 : 0; |
60
|
|
|
|
|
|
|
|
61
|
18
|
100
|
|
|
|
146
|
$logger->info("ssh: load $key '".join("','", @$args)."' ". ( $v6 ? 'IPv6' : 'IPv4')); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# cleanup possible square brackets used for IPv6 |
64
|
18
|
|
|
|
|
166
|
foreach (@$args) { |
65
|
36
|
|
|
|
|
107
|
s/[\[\]]+//g; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# reverse enable to assign string to port even if no bind_adress |
69
|
|
|
|
|
|
|
# is specified |
70
|
18
|
100
|
|
|
|
115
|
my $re = $v6 ? qr!/! : qr!:! ; |
71
|
18
|
|
|
|
|
179
|
my ($port,$bind_adr ) = reverse split $re,$args->[0] ; |
72
|
18
|
|
|
|
|
127
|
my ($host,$host_port) = split $re,$args->[1] ; |
73
|
|
|
|
|
|
|
|
74
|
18
|
|
|
|
|
105
|
my $fw_list = $self->current_node->fetch_element($key); |
75
|
18
|
|
|
|
|
5214
|
my $size = $fw_list->fetch_size; |
76
|
|
|
|
|
|
|
# this creates a new node in the list |
77
|
18
|
|
|
|
|
159
|
my $fw_obj = $fw_list->fetch_with_id($size); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# $fw_obj->store_element_value( GatewayPorts => 1 ) if $bind_adr ; |
80
|
18
|
100
|
|
|
|
19065
|
$fw_obj->annotation($comment) if $comment; |
81
|
|
|
|
|
|
|
|
82
|
18
|
100
|
|
|
|
786
|
$fw_obj->store_element_value( ipv6 => 1) if $v6 ; |
83
|
|
|
|
|
|
|
|
84
|
18
|
100
|
|
|
|
8839
|
$fw_obj->store_element_value( check => $check, name => 'bind_address', value => $bind_adr) |
85
|
|
|
|
|
|
|
if defined $bind_adr ; |
86
|
18
|
|
|
|
|
8477
|
$fw_obj->store_element_value( check => $check, name => 'port', value => $port ); |
87
|
18
|
|
|
|
|
19786
|
$fw_obj->store_element_value( check => $check, name => 'host', value => $host ); |
88
|
18
|
|
|
|
|
17241
|
$fw_obj->store_element_value( check => $check, name => 'hostport', value => $host_port ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub write_all_host_block { |
93
|
9
|
|
|
9
|
0
|
30
|
my $self = shift ; |
94
|
9
|
|
|
|
|
24
|
my $host_elt = shift ; |
95
|
9
|
|
50
|
|
|
47
|
my $mode = shift || ''; |
96
|
|
|
|
|
|
|
|
97
|
9
|
|
|
|
|
26
|
my $result = '' ; |
98
|
|
|
|
|
|
|
|
99
|
9
|
|
|
|
|
42
|
foreach my $pattern ( $host_elt->fetch_all_indexes) { |
100
|
19
|
|
|
|
|
311
|
my $block_elt = $host_elt->fetch_with_id($pattern) ; |
101
|
19
|
|
|
|
|
1500
|
$logger->debug("write_all_host_block on ".$block_elt->location." mode $mode"); |
102
|
19
|
|
|
|
|
231
|
my $block_data = $self->write_node_content($block_elt,'custom') ; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# write data only if custom pattern or custom data is found this |
105
|
|
|
|
|
|
|
# is necessary to avoid writing data from /etc/ssh/ssh_config that |
106
|
|
|
|
|
|
|
# were entered as 'preset' data |
107
|
19
|
50
|
|
|
|
76
|
if ($block_data) { |
108
|
19
|
|
|
|
|
91
|
$result .= $self->write_line(Host => $pattern, $block_elt->annotation); |
109
|
19
|
|
|
|
|
577
|
$result .= "$block_data\n" ; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
9
|
|
|
|
|
138
|
return $result ; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub write_forward { |
116
|
8
|
|
|
8
|
0
|
29
|
my $self = shift ; |
117
|
8
|
|
|
|
|
16
|
my $forward_elt = shift ; |
118
|
8
|
|
50
|
|
|
34
|
my $mode = shift || ''; |
119
|
|
|
|
|
|
|
|
120
|
8
|
|
|
|
|
16
|
my $result = '' ; |
121
|
|
|
|
|
|
|
|
122
|
8
|
|
|
|
|
56
|
my $v6 = $forward_elt->grab_value('ipv6') ; |
123
|
8
|
100
|
|
|
|
6048
|
my $sep = $v6 ? '/' : ':'; |
124
|
|
|
|
|
|
|
|
125
|
8
|
|
|
|
|
17
|
my $line = ''; |
126
|
8
|
|
|
|
|
34
|
foreach my $name ($forward_elt->get_element_name() ) { |
127
|
40
|
100
|
|
|
|
1133
|
next if $name eq 'ipv6' ; |
128
|
32
|
|
|
|
|
107
|
my $elt = $forward_elt->fetch_element($name) ; |
129
|
32
|
|
|
|
|
2510
|
my $v = $elt->fetch($mode) ; |
130
|
32
|
100
|
|
|
|
7029
|
next unless length($v); |
131
|
28
|
100
|
|
|
|
308
|
$line |
|
|
100
|
|
|
|
|
|
132
|
|
|
|
|
|
|
.= $name =~ /bind|host$/ ? "$v$sep" |
133
|
|
|
|
|
|
|
: $name eq 'port' ? "$v " |
134
|
|
|
|
|
|
|
: $v ; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
8
|
|
|
|
|
86
|
return $self->write_line($forward_elt->element_name,$line,$forward_elt->annotation) ; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
2
|
|
|
2
|
|
16
|
no Mouse; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
19
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# ABSTRACT: Backend for ssh configuration files |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=pod |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=encoding UTF-8 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NAME |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Config::Model::Backend::OpenSsh::Ssh - Backend for ssh configuration files |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 VERSION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
version 2.9.4.1 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SYNOPSIS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
None |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 DESCRIPTION |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This module provides a backend to read and write ssh client configuration files. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 STOP |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The documentation provides details on the module used to read and |
171
|
|
|
|
|
|
|
write OpenSsh configuration files. These details are not needed for |
172
|
|
|
|
|
|
|
the basic usages explained in L<Config::Model::OpenSsh>. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 Methods |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
These read/write functions are part of C<OpenSsh::Ssh> read/write |
177
|
|
|
|
|
|
|
backend. They are declared in Ssh configuration model and are called |
178
|
|
|
|
|
|
|
back when needed to read and write the configuration file. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 read (object => <ssh_root>, config_dir => ...) |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Reads F<ssh_config> in C<config_dir> and load the data in the |
183
|
|
|
|
|
|
|
C<ssh_root> configuration tree. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 write (object => <ssh_root>, config_dir => ...) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Write F<ssh_config> in C<config_dir> from the data stored in |
188
|
|
|
|
|
|
|
C<ssh_root> configuration tree. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SEE ALSO |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
L<cme>, L<Config::Model>, L<Config::Model::OpenSsh> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Dominique Dumont |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This software is Copyright (c) 2008-2022 by Dominique Dumont. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This is free software, licensed under: |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |