1 package System::Introspector::Sudoers;
6 default => sub { '/etc/sudoers' },
11 default => sub { scalar `hostname` },
16 my %file = $self->_gather_files($self->sudoers_file);
21 my ($self, $file) = @_;
22 open my $fh, '<', $file
23 or return $file => { error => "Unable to read: $!" };
25 my %file = ($file => { body => join '', @lines });
26 for my $line (@lines) {
28 if ($line =~ m{^#include\s+(.+)$}) {
29 my $inc_file = $self->_insert_hostname($1);
30 %file = (%file, $self->_gather_files($inc_file));
32 elsif ($line =~ m{^#includedir\s+(.+)$}) {
33 my $inc_dir = $self->_insert_hostname($1);
34 %file = (%file, $self->_gather_from_dir($inc_dir));
40 sub _gather_from_dir {
41 my ($self, $dir) = @_;
42 opendir(my $dh, $dir);
43 return $dir => { error => "Unable to read dir $dir: $!" }
46 while (my $file = readdir $dh) {
47 next if $file =~ m{\.} or $file =~ m{~$};
48 %file = (%file, $self->_gather_files("$dir/$file"));
53 sub _insert_hostname {
54 my ($self, $value) = @_;
55 my $hostname = $self->hostname;
56 $value =~ s{\%h}{$hostname}g;