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
|
|
2041
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
115
|
|
11
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
227
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$Config::Model::Backend::OpenSsh::Role::Reader::VERSION = '2.9.0.2'; |
14
|
|
|
|
|
|
|
use 5.10.1; |
15
|
4
|
|
|
4
|
|
45
|
|
|
4
|
|
|
|
|
13
|
|
16
|
|
|
|
|
|
|
use Config::Model 2.128; |
17
|
4
|
|
|
4
|
|
17
|
|
|
4
|
|
|
|
|
86
|
|
|
4
|
|
|
|
|
158
|
|
18
|
|
|
|
|
|
|
use Mouse::Role ; |
19
|
4
|
|
|
4
|
|
22
|
requires qw(read_global_comments associates_comments_with_data); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
26
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# sub stub known as "forward" declaration |
22
|
|
|
|
|
|
|
# required for Role consistency checks |
23
|
|
|
|
|
|
|
# See Moose::Manual::Roles for details |
24
|
|
|
|
|
|
|
sub current_node; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'current_node' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => 'Config::Model::Node', |
29
|
|
|
|
|
|
|
weak_ref => 1 |
30
|
|
|
|
|
|
|
) ; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Carp ; |
33
|
4
|
|
|
4
|
|
1462
|
use Log::Log4perl 1.11; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
245
|
|
34
|
4
|
|
|
4
|
|
24
|
|
|
4
|
|
|
|
|
79
|
|
|
4
|
|
|
|
|
25
|
|
35
|
|
|
|
|
|
|
my $logger = Log::Log4perl::get_logger("Backend::OpenSsh"); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my @dispatch = ( |
38
|
|
|
|
|
|
|
qr/match/i => 'match', |
39
|
|
|
|
|
|
|
qr/host\b/i => 'host', |
40
|
|
|
|
|
|
|
qr/(local|remote)forward/i => 'forward', |
41
|
|
|
|
|
|
|
qr/^PreferredAuthentications$/ => 'comma_list', |
42
|
|
|
|
|
|
|
qr/localcommand/i => 'assign', |
43
|
|
|
|
|
|
|
qr/\w/ => 'assign', |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $self = shift ; |
47
|
|
|
|
|
|
|
my %args = @_ ; |
48
|
26
|
|
|
26
|
0
|
2815786
|
my $config_root = $args{object} |
49
|
26
|
|
|
|
|
221
|
|| croak __PACKAGE__," read_ssh_file: undefined config root object"; |
50
|
|
|
|
|
|
|
|
51
|
26
|
|
33
|
|
|
145
|
return 0 unless $args{file_path}->is_file; |
52
|
|
|
|
|
|
|
|
53
|
26
|
100
|
|
|
|
136
|
$logger->info("loading config file ".$args{file_path}); |
54
|
|
|
|
|
|
|
|
55
|
23
|
|
|
|
|
464
|
my @lines = $args{file_path}->lines_utf8 ; |
56
|
|
|
|
|
|
|
# try to get global comments (comments before a blank line) |
57
|
23
|
|
|
|
|
341
|
$self->read_global_comments(\@lines,'#') ; |
58
|
|
|
|
|
|
|
|
59
|
23
|
|
|
|
|
3973
|
# need to reset this when reading user ssh file after system ssh file |
60
|
|
|
|
|
|
|
$self->current_node($config_root) ; |
61
|
|
|
|
|
|
|
|
62
|
23
|
|
|
|
|
3363
|
my @assoc = $self->associates_comments_with_data( \@lines, '#' ) ; |
63
|
|
|
|
|
|
|
foreach my $item (@assoc) { |
64
|
23
|
|
|
|
|
105
|
my ( $vdata, $comment ) = @$item; |
65
|
23
|
|
|
|
|
10575
|
|
66
|
314
|
|
|
|
|
798
|
my ( $k, @v ) = split /\s+/, $vdata; |
67
|
|
|
|
|
|
|
|
68
|
314
|
|
|
|
|
2202
|
my $i = 0; |
69
|
|
|
|
|
|
|
while ( $i < @dispatch ) { |
70
|
314
|
|
|
|
|
593
|
my ( $regexp, $sub ) = @dispatch[ $i++, $i++ ]; |
71
|
314
|
|
|
|
|
806
|
if ( $k =~ $regexp and $self->can($sub)) { |
72
|
1612
|
|
|
|
|
2817
|
$logger->trace("read_ssh_file: dispatch calls $sub"); |
73
|
1612
|
100
|
66
|
|
|
7245
|
$self->$sub( $config_root, $k, \@v, $comment, $args{check} ); |
74
|
314
|
|
|
|
|
1328
|
last; |
75
|
314
|
|
|
|
|
3501
|
} |
76
|
314
|
|
|
|
|
174214
|
|
77
|
|
|
|
|
|
|
warn __PACKAGE__, " unknown keyword: $k" if $i >= @dispatch; |
78
|
|
|
|
|
|
|
} |
79
|
1298
|
50
|
|
|
|
2905
|
} |
80
|
|
|
|
|
|
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
23
|
|
|
|
|
466
|
|
83
|
|
|
|
|
|
|
my ($self,$root, $raw_key,$arg,$comment, $check) = @_ ; |
84
|
|
|
|
|
|
|
$logger->debug("assign: $raw_key @$arg # $comment"); |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
3
|
0
|
14
|
my @list = map { split /\s*,\s*/ } @$arg; |
87
|
3
|
|
|
|
|
31
|
$self->assign($root, $raw_key,\@list,$comment, $check); |
88
|
|
|
|
|
|
|
} |
89
|
3
|
|
|
|
|
32
|
|
|
3
|
|
|
|
|
26
|
|
90
|
3
|
|
|
|
|
17
|
my ($self,$root, $raw_key,$arg,$comment, $check) = @_ ; |
91
|
|
|
|
|
|
|
$logger->debug("assign: $raw_key @$arg # $comment"); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
245
|
|
|
245
|
0
|
602
|
# keys are case insensitive, try to find a match |
95
|
245
|
|
|
|
|
1322
|
my $key = $self->current_node->find_element ($raw_key, case => 'any') ; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
if (not defined $key) { |
98
|
|
|
|
|
|
|
if ($check eq 'yes') { |
99
|
245
|
|
|
|
|
2174
|
# drop if -force is not set |
100
|
|
|
|
|
|
|
die "Error: unknown parameter: '$raw_key'. Use -force option to drop this parameter\n"; |
101
|
245
|
50
|
|
|
|
126501
|
} |
102
|
0
|
0
|
|
|
|
0
|
else { |
103
|
|
|
|
|
|
|
say "Dropping parameter '$raw_key'" ; |
104
|
0
|
|
|
|
|
0
|
} |
105
|
|
|
|
|
|
|
return; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
0
|
|
108
|
|
|
|
|
|
|
my $elt = $self->current_node->fetch_element($key) ; |
109
|
0
|
|
|
|
|
0
|
my $type = $elt->get_type; |
110
|
|
|
|
|
|
|
#print "got $key type $type and ",join('+',@$arg),"\n"; |
111
|
|
|
|
|
|
|
|
112
|
245
|
|
|
|
|
787
|
$elt->annotation($comment) if $comment and $type ne 'hash'; |
113
|
245
|
|
|
|
|
172586
|
|
114
|
|
|
|
|
|
|
if ($type eq 'leaf') { |
115
|
|
|
|
|
|
|
$elt->store( value => join(' ',@$arg), check => $check ) ; |
116
|
245
|
100
|
66
|
|
|
1436
|
} |
117
|
|
|
|
|
|
|
elsif ($type eq 'list') { |
118
|
245
|
100
|
|
|
|
2714
|
$elt->push_x ( values => $arg, check => $check ) ; |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
119
|
196
|
|
|
|
|
771
|
} |
120
|
|
|
|
|
|
|
elsif ($type eq 'hash') { |
121
|
|
|
|
|
|
|
my $hv = $elt->fetch_with_id($arg->[0]); |
122
|
46
|
|
|
|
|
154
|
$hv->store( value => $arg->[1], check => $check ); |
123
|
|
|
|
|
|
|
$hv->annotation($comment) if $comment; |
124
|
|
|
|
|
|
|
} |
125
|
3
|
|
|
|
|
15
|
elsif ($type eq 'check_list') { |
126
|
3
|
|
|
|
|
1549
|
my @check = split /\s*,\s*/,$arg->[0] ; |
127
|
3
|
50
|
|
|
|
1002
|
$elt->set_checked_list (\@check, check => 'skip') ; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
else { |
130
|
0
|
|
|
|
|
|
die "OpenSsh::assign did not expect $type for $key\n"; |
131
|
0
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
no Mouse; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
4
|
|
|
4
|
|
3334
|
# ABSTRACT: Role to read OpenSsh config files |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
30
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=pod |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=encoding UTF-8 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 NAME |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Config::Model::Backend::OpenSsh::Role::Reader - Role to read OpenSsh config files |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 VERSION |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
version 2.9.0.2 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SYNOPSIS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
None. Consumed by L<Config::Model::Backend::OpenSsh::Ssh> and |
156
|
|
|
|
|
|
|
L<Config::Model::Backend::OpenSsh::Sshd>. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 DESCRIPTION |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Read methods used by both L<Config::Model::Backend::OpenSsh::Ssh> and |
161
|
|
|
|
|
|
|
L<Config::Model::Backend::OpenSsh::Sshd>. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L<cme>, L<Config::Model>, L<Config::Model::OpenSsh> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Dominique Dumont |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This software is Copyright (c) 2008-2022 by Dominique Dumont. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is free software, licensed under: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |