Update upstream source from tag 'upstream/0.126'
Update to upstream version '0.126'
with Debian dir d43fae4f9b13ceb32cfef427e381b49a7fcfee6e
Dominique Dumont
2 years ago
45 | 45 | 'Test::More' => 0, |
46 | 46 | 'Test::Exception' => 0, |
47 | 47 | 'Test::Differences' => 0, |
48 | 'Test::Warn' => '0.11', # tests fail with 0.08 | |
49 | 48 | 'version' => '0.77' |
50 | 49 | }, |
51 | 50 |
0 | 2021-12-29 Dominique Dumont <domi.dumont@free.fr> v0.126 | |
1 | ||
2 | * fix doc related to backend configuration | |
3 | * fix grammar errors in doc | |
4 | * fix tests broken by Augeas 1.13.0 | |
5 | * rm dependency on Test::Warn | |
6 | ||
0 | 7 | 2018-02-26 Dominique Dumont <domi.dumont@free.fr> v0.125 |
1 | 8 | |
2 | 9 | * fix wiki url |
21 | 21 | "Test::Differences" : "0", |
22 | 22 | "Test::Exception" : "0", |
23 | 23 | "Test::More" : "0", |
24 | "Test::Warn" : "0.11", | |
25 | 24 | "version" : "0.77" |
26 | 25 | } |
27 | 26 | }, |
42 | 41 | "provides" : { |
43 | 42 | "Config::Model::Backend::Augeas" : { |
44 | 43 | "file" : "lib/Config/Model/Backend/Augeas.pm", |
45 | "version" : "0.125" | |
44 | "version" : "0.126" | |
46 | 45 | } |
47 | 46 | }, |
48 | 47 | "release_status" : "stable", |
51 | 50 | "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt" |
52 | 51 | ] |
53 | 52 | }, |
54 | "version" : "0.125", | |
53 | "version" : "0.126", | |
55 | 54 | "x_serialization_backend" : "JSON::PP version 4.04" |
56 | 55 | } |
8 | 8 | Test::Differences: '0' |
9 | 9 | Test::Exception: '0' |
10 | 10 | Test::More: '0' |
11 | Test::Warn: '0.11' | |
12 | 11 | version: '0.77' |
13 | 12 | configure_requires: |
14 | 13 | Module::Build: '0.36' |
22 | 21 | provides: |
23 | 22 | Config::Model::Backend::Augeas: |
24 | 23 | file: lib/Config/Model/Backend/Augeas.pm |
25 | version: '0.125' | |
24 | version: '0.126' | |
26 | 25 | requires: |
27 | 26 | Config::Augeas: '0.303' |
28 | 27 | Config::Model: '2.117' |
30 | 29 | Mouse: '0' |
31 | 30 | resources: |
32 | 31 | license: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt |
33 | version: '0.125' | |
32 | version: '0.126' | |
34 | 33 | x_serialization_backend: 'CPAN::Meta::YAML version 0.018' |
32 | 32 | eval { require Config::Augeas; }; |
33 | 33 | $has_augeas = 0 if $@; |
34 | 34 | |
35 | our $VERSION = '0.125'; | |
35 | our $VERSION = '0.126'; | |
36 | 36 | |
37 | 37 | my $logger = get_logger('Backend::Augeas'); |
38 | 38 | |
46 | 46 | { |
47 | 47 | config_class_name => 'OpenSsh::Sshd', |
48 | 48 | |
49 | # try Augeas and fall-back with custom method | |
50 | read_config => [ { backend => 'augeas' , | |
51 | file => '/etc/ssh/sshd_config', | |
52 | # declare "seq" Augeas elements | |
53 | sequential_lens => [/AcceptEnv AllowGroups [etc]/], | |
54 | }, | |
55 | { backend => 'custom' , # dir hardcoded in custom class | |
56 | class => 'Config::Model::Sshd' | |
57 | } | |
58 | ], | |
59 | # write_config will be written using read_config specifications | |
60 | ||
49 | read_config => { | |
50 | backend => 'augeas' , | |
51 | file => '/etc/ssh/sshd_config', | |
52 | # declare "seq" Augeas elements | |
53 | sequential_lens => [/AcceptEnv AllowGroups [etc]/], | |
54 | }, | |
55 | ||
56 | # config is written back using read_config specifications | |
61 | 57 | |
62 | 58 | element => ... |
63 | 59 | } |
66 | 62 | |
67 | 63 | This class provides a way to load or store configuration data through |
68 | 64 | L<Config::Augeas>. This way, the structure and comments of the |
69 | original configuration file will preserved. | |
65 | original configuration file are preserved. | |
70 | 66 | |
71 | 67 | To use Augeas as a backend, you must specify the following |
72 | 68 | C<read_config> parameters: |
96 | 92 | |
97 | 93 | For instance: |
98 | 94 | |
99 | read_config => [ { backend => 'augeas' , | |
100 | save => 'backup', | |
101 | file => '/etc/ssh/sshd_config', | |
102 | # declare "seq" Augeas elements | |
103 | sequential_lens => [/AcceptEnv AllowGroups/], | |
104 | }, | |
105 | ], | |
106 | ||
95 | read_config => { | |
96 | backend => 'augeas' , | |
97 | save => 'backup', | |
98 | file => '/etc/ssh/sshd_config', | |
99 | # declare "seq" Augeas elements | |
100 | sequential_lens => [/AcceptEnv AllowGroups/], | |
101 | }, | |
107 | 102 | |
108 | 103 | =head2 Sequential lens |
109 | 104 | |
150 | 145 | /files/etc/ssh/sshd_config/AcceptEnv[2]/4 |
151 | 146 | /files/etc/ssh/sshd_config/AcceptEnv[2]/5 |
152 | 147 | |
153 | Note that the first index between squarekeeps track of how are grouped | |
154 | the C<AcceptEnv> data, but the I<real> list index is after the slash. | |
148 | Note that the first index between square brackets keeps track of how | |
149 | the C<AcceptEnv> items are grouped, but the I<real> list index is | |
150 | after the slash. | |
155 | 151 | |
156 | 152 | Augeas does not require new elements to create C<AcceptEnv[3]>. A new |
157 | 153 | element can be added as : |
250 | 246 | # the model. I.e if the file "root" matches a list element (like |
251 | 247 | # for /etc/hosts), get this element name from "set_in" parameter |
252 | 248 | my $set_in = $args{set_in} || ''; |
253 | map { | |
254 | s!$mainpath!!; | |
255 | $_ = "/$set_in/$_" if $set_in; | |
256 | s!/+!/!g; | |
257 | } @cm_path; | |
249 | foreach my $path (@cm_path) { | |
250 | $path =~ s!$mainpath!!; | |
251 | $path = "/$set_in/$path" if $set_in; | |
252 | $path =~ s!/+!/!g; | |
253 | } | |
258 | 254 | |
259 | 255 | # Create a hash of sequential lenses |
260 | 256 | my %is_seq_lens = map { ( $_ => 1 ); } @{ $args{sequential_lens} || [] }; |
500 | 496 | # fail. But Augeas does return foo/1 if only one element is |
501 | 497 | # present in the tree :-/ |
502 | 498 | my $replace = $element_name . '[1]'; |
503 | map { s/$element_name(?!\[)/$replace/ } @matches; | |
499 | foreach (@matches) { | |
500 | s/$element_name(?!\[)/$replace/; | |
501 | } | |
504 | 502 | } |
505 | 503 | |
506 | 504 | my $logger = get_logger("Data::Write"); |
584 | 582 | # the tree :-/ |
585 | 583 | if ($is_seq) { |
586 | 584 | my $replace = $element_name . '[1]'; |
587 | map { s/$element_name(?!\[)/$replace/ } @matches; | |
585 | foreach (@matches) { | |
586 | s/$element_name(?!\[)/$replace/; | |
587 | } | |
588 | 588 | } |
589 | 589 | |
590 | 590 | my $logger = get_logger('Data::Write'); |
665 | 665 | |
666 | 666 | # cleanup indexes are we don't handle them now with element |
667 | 667 | # (later in lists and hashes) |
668 | map { s/\[\d+\]+$//; } @matches; | |
668 | foreach (@matches) { | |
669 | s/\[\d+\]+$//; | |
670 | } | |
669 | 671 | $logger->debug( "copy_in_augeas: Node path $p matches:\n\t" . join( "\n\t", @matches ), ); |
670 | 672 | |
671 | 673 | # store elements found in Augeas and their corresponding path |
0 | 0 | # -*- cperl -*- |
1 | ||
2 | use warnings; | |
3 | use strict; | |
1 | 4 | |
2 | 5 | # test augeas backend |
3 | 6 | |
18 | 21 | |
19 | 22 | use lib 't/lib'; |
20 | 23 | use LoadTest; |
21 | ||
22 | use warnings; | |
23 | use strict; | |
24 | 24 | |
25 | 25 | eval { require Config::Augeas ;} ; |
26 | 26 | if ( $@ ) { |
148 | 148 | #my @aug_content = $ssh_augeas_obj->match("/files/etc/ssh/sshd_config/*") ; |
149 | 149 | #print join("\n",@aug_content) ; |
150 | 150 | |
151 | my $assign = $Config::Model::VERSION >= 2.052 ? ':=' : ':' ; | |
152 | ||
153 | $expect = qq(AcceptEnv${assign}LC_PAPER,LC_NAME,LC_ADDRESS,LC_TELEPHONE,LC_MEASUREMENT,LC_IDENTIFICATION,LC_ALL | |
154 | AllowUsers${assign}foo,"bar\@192.168.0.*" | |
151 | $expect = qq(AcceptEnv:=LC_PAPER,LC_NAME,LC_ADDRESS,LC_TELEPHONE,LC_MEASUREMENT,LC_IDENTIFICATION,LC_ALL | |
152 | AllowUsers:=foo,"bar\@192.168.0.*" | |
155 | 153 | HostbasedAuthentication=no |
156 | HostKey${assign}/etc/ssh/ssh_host_key,/etc/ssh/ssh_host_rsa_key,/etc/ssh/ssh_host_dsa_key | |
154 | HostKey:=/etc/ssh/ssh_host_key,/etc/ssh/ssh_host_rsa_key,/etc/ssh/ssh_host_dsa_key | |
157 | 155 | Subsystem:rftp=/usr/lib/openssh/rftp-server |
158 | 156 | Subsystem:sftp=/usr/lib/openssh/sftp-server |
159 | 157 | Subsystem:tftp=/usr/lib/openssh/tftp-server |
222 | 220 | splice @mod, 32,2, @lines ; |
223 | 221 | pop @mod ; |
224 | 222 | |
223 | my $sarko = "Match User sarko Group pres.*\n"; | |
224 | if (version->parse($aug_version) ge version->parse('1.13.0')) { | |
225 | # tweak quotes added by augeas since version 1.13.0 | |
226 | $mod[32] =~ s/(white.house.\*)/"$1"/; | |
227 | $sarko =~ s/(sarko|pres.\*)/"$1"/g; | |
228 | } | |
229 | ||
225 | 230 | is_deeply([$sshd_config->lines],\@mod,"check content of $sshd_config after Match~1") ; |
226 | 231 | |
227 | 232 | $sshd_root->load("Match:2 Condition User=sarko Group=pres.* - |
230 | 235 | $i_sshd->write_back ; |
231 | 236 | |
232 | 237 | |
233 | push @mod,"Match User sarko Group pres.*\n","Banner /etc/bienvenue2.txt\n"; | |
234 | ||
235 | my @got = map {s/^[\t ]+//; $_; } $sshd_config->lines; | |
238 | push @mod, $sarko, "Banner /etc/bienvenue2.txt\n"; | |
239 | ||
240 | my @got = map {my $t=$_; $t =~ s/^[\t ]+//; $t; } $sshd_config->lines; | |
236 | 241 | eq_or_diff(\@got,\@mod,"check content of $sshd_config after Match:2 ...") ; |
237 | 242 | |
238 | 243 | $sshd_root->load("Match:2 Condition User=sarko Group=pres.* - |
244 | 249 | print "mod--\n",map { $i++ . ': '. $_} @mod,"---\n" if $trace ; |
245 | 250 | splice @mod,37,0,"AllowTcpForwarding yes\n"; |
246 | 251 | |
247 | @got = map {s/^[\t ]+//; $_; } $sshd_config->lines; | |
252 | @got = map {my $t=$_; $t =~ s/^[\t ]+//; $t; } $sshd_config->lines; | |
248 | 253 | eq_or_diff( \@got,\@mod,"check content of $sshd_config after Match:2 AllowTcpForwarding=yes") ; |
249 | 254 | |
250 | 255 | } # end SKIP section |