| 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
|
4
|
|
|
4
|
|
1902
|
use strict; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
129
|
|
|
11
|
4
|
|
|
4
|
|
29
|
use warnings; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
197
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$Config::Model::Backend::OpenSsh::Role::Writer::VERSION = '2.9.0.1'; |
|
14
|
|
|
|
|
|
|
use Mouse::Role ; |
|
15
|
4
|
|
|
4
|
|
20
|
|
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
54
|
|
|
16
|
|
|
|
|
|
|
with 'Config::Model::Backend::OpenSsh::Role::MatchBlock'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
requires qw(write_global_comments write_data_and_comments); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use 5.10.1; |
|
21
|
4
|
|
|
4
|
|
1250
|
|
|
|
4
|
|
|
|
|
12
|
|
|
22
|
|
|
|
|
|
|
use Config::Model 2.128; |
|
23
|
4
|
|
|
4
|
|
24
|
|
|
|
4
|
|
|
|
|
45
|
|
|
|
4
|
|
|
|
|
127
|
|
|
24
|
|
|
|
|
|
|
use Carp ; |
|
25
|
4
|
|
|
4
|
|
21
|
use IO::File ; |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
220
|
|
|
26
|
4
|
|
|
4
|
|
32
|
use Log::Log4perl 1.11; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
589
|
|
|
27
|
4
|
|
|
4
|
|
25
|
|
|
|
4
|
|
|
|
|
49
|
|
|
|
4
|
|
|
|
|
29
|
|
|
28
|
|
|
|
|
|
|
my $logger = Log::Log4perl::get_logger("Backend::OpenSsh"); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $self = shift ; |
|
31
|
|
|
|
|
|
|
my %args = @_ ; |
|
32
|
12
|
|
|
12
|
0
|
35
|
|
|
33
|
12
|
|
|
|
|
85
|
my $config_root = $args{object} |
|
34
|
|
|
|
|
|
|
|| croak __PACKAGE__," ssh_write: undefined config root object"; |
|
35
|
|
|
|
|
|
|
|
|
36
|
12
|
|
33
|
|
|
85
|
$logger->info("writing config file $args{file_path}"); |
|
37
|
|
|
|
|
|
|
|
|
38
|
12
|
|
|
|
|
75
|
my $comment = $self->write_global_comment('#') ; |
|
39
|
|
|
|
|
|
|
|
|
40
|
12
|
|
|
|
|
253
|
my $result = $self->write_node_content($config_root,$args{ssh_mode}); |
|
41
|
|
|
|
|
|
|
|
|
42
|
12
|
|
|
|
|
774
|
if ($result) { |
|
43
|
|
|
|
|
|
|
$args{file_path}->spew_utf8($comment.$result); |
|
44
|
12
|
100
|
|
|
|
56
|
return 1; |
|
45
|
10
|
|
|
|
|
154
|
} |
|
46
|
10
|
|
|
|
|
7340
|
|
|
47
|
|
|
|
|
|
|
return 0; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
2
|
|
|
|
|
24
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my ($self, $k, $v, $note) = @_ ; |
|
52
|
|
|
|
|
|
|
return '' unless length($v) ; |
|
53
|
|
|
|
|
|
|
return $self->write_data_and_comments('#',sprintf("%-20s %s",$k,$v),$note) ; |
|
54
|
2572
|
|
|
2572
|
0
|
8886
|
} |
|
55
|
2572
|
100
|
|
|
|
8417
|
|
|
56
|
116
|
|
|
|
|
720
|
my ($self,$name,$mode,$elt) = @_; |
|
57
|
|
|
|
|
|
|
my @r = map { $self->write_line($name,$_->fetch($mode), $_->annotation) ;} $elt->fetch_all() ; |
|
58
|
|
|
|
|
|
|
return join('',@r) ; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
240
|
|
|
240
|
0
|
467
|
|
|
61
|
240
|
|
|
|
|
707
|
|
|
|
21
|
|
|
|
|
1674
|
|
|
62
|
240
|
|
|
|
|
9164
|
my ($self,$name,$mode,$elt) = @_; |
|
63
|
|
|
|
|
|
|
my @v = $elt->fetch_all_values(mode => $mode) ; |
|
64
|
|
|
|
|
|
|
return $self->write_line($name,join(' ',@v)) ; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
8
|
|
|
8
|
0
|
30
|
# list there list element that must be written on one line with items |
|
68
|
8
|
|
|
|
|
42
|
# separated by a white space |
|
69
|
8
|
|
|
|
|
1387
|
my %list_as_one_line = ( |
|
70
|
|
|
|
|
|
|
'AuthorizedKeysFile' => 1 , |
|
71
|
|
|
|
|
|
|
) ; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $self= shift ; |
|
74
|
|
|
|
|
|
|
my $node = shift ; |
|
75
|
|
|
|
|
|
|
my $mode = shift || ''; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $result = '' ; |
|
78
|
|
|
|
|
|
|
my $match = '' ; |
|
79
|
30
|
|
|
30
|
0
|
72
|
|
|
80
|
30
|
|
|
|
|
55
|
foreach my $name ($node->get_element_name() ) { |
|
81
|
30
|
|
100
|
|
|
121
|
next unless $node->is_element_defined($name) ; |
|
82
|
|
|
|
|
|
|
my $elt = $node->fetch_element($name) ; |
|
83
|
30
|
|
|
|
|
64
|
my $type = $elt->get_type; |
|
84
|
30
|
|
|
|
|
54
|
my $note = $elt->annotation ; |
|
85
|
|
|
|
|
|
|
|
|
86
|
30
|
|
|
|
|
111
|
#print "got $key type $type and ",join('+',@arg),"\n"; |
|
87
|
2833
|
50
|
|
|
|
49718
|
if ($name eq 'Match') { |
|
88
|
2833
|
|
|
|
|
22993
|
$match .= $self->write_all_match_block($elt,$mode) ; |
|
89
|
2833
|
|
|
|
|
173969
|
} |
|
90
|
2833
|
|
|
|
|
10150
|
elsif ($name eq 'Host') { |
|
91
|
|
|
|
|
|
|
$match .= $self->write_all_host_block($elt,$mode) ; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
2833
|
100
|
|
|
|
24194
|
elsif ($name =~ /^(Local|Remote)Forward$/) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
94
|
12
|
|
|
|
|
96
|
foreach ($elt->fetch_all()) { |
|
95
|
|
|
|
|
|
|
$result .= $self->write_forward($_,$mode); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
8
|
|
|
|
|
106
|
} |
|
98
|
|
|
|
|
|
|
elsif ($type eq 'leaf') { |
|
99
|
|
|
|
|
|
|
my $v = $elt->fetch($mode) ; |
|
100
|
44
|
|
|
|
|
159
|
$result .= $self->write_line($name,$v,$note); |
|
101
|
6
|
|
|
|
|
461
|
} |
|
102
|
|
|
|
|
|
|
elsif ($type eq 'check_list') { |
|
103
|
|
|
|
|
|
|
my $v = $elt->fetch($mode) ; |
|
104
|
|
|
|
|
|
|
$result .= $self->write_line($name,$v,$note); |
|
105
|
2517
|
|
|
|
|
5418
|
} |
|
106
|
2517
|
|
|
|
|
439623
|
elsif ($type eq 'list') { |
|
107
|
|
|
|
|
|
|
$result .= $self->write_data_and_comments('#', undef, $note) ; |
|
108
|
|
|
|
|
|
|
$result .= $list_as_one_line{$name} ? $self->write_list_in_one_line($name,$mode,$elt) |
|
109
|
0
|
|
|
|
|
0
|
: $self->write_list($name,$mode,$elt) ; |
|
110
|
0
|
|
|
|
|
0
|
} |
|
111
|
|
|
|
|
|
|
elsif ($type eq 'hash') { |
|
112
|
|
|
|
|
|
|
foreach my $k ( $elt->fetch_all_indexes ) { |
|
113
|
248
|
|
|
|
|
792
|
my $o = $elt->fetch_with_id($k); |
|
114
|
248
|
100
|
|
|
|
4530
|
my $v = $o->fetch($mode) ; |
|
115
|
|
|
|
|
|
|
$result .= $self->write_line($name,"$k $v", $o->annotation) ; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
4
|
|
|
|
|
27
|
else { |
|
119
|
2
|
|
|
|
|
51
|
die "OpenSsh::write did not expect $type for $name\n"; |
|
120
|
2
|
|
|
|
|
105
|
} |
|
121
|
2
|
|
|
|
|
324
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
return $result.$match ; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
0
|
|
|
|
|
0
|
|
|
126
|
|
|
|
|
|
|
no Mouse; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
|
129
|
30
|
|
|
|
|
500
|
|
|
130
|
|
|
|
|
|
|
# ABSTRACT: Role to write OpenSsh config files |
|
131
|
|
|
|
|
|
|
|
|
132
|
4
|
|
|
4
|
|
2838
|
|
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
32
|
|
|
133
|
|
|
|
|
|
|
=pod |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=encoding UTF-8 |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Config::Model::Backend::OpenSsh::Role::Writer - Role to write OpenSsh config files |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 VERSION |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
version 2.9.0.1 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
None. Consumed by L<Config::Model::Backend::OpenSsh::Ssh> and |
|
148
|
|
|
|
|
|
|
L<Config::Model::Backend::OpenSsh::Sshd>. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Write methods used by both L<Config::Model::Backend::OpenSsh::Ssh> and |
|
153
|
|
|
|
|
|
|
L<Config::Model::Backend::OpenSsh::Sshd>. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L<cme>, L<Config::Model>, L<Config::Model::OpenSsh> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Dominique Dumont |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This software is Copyright (c) 2008-2022 by Dominique Dumont. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This is free software, licensed under: |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |