1 package System::Introspector::Probe::Sudoers;
4 use System::Introspector::Util qw(
13 default => sub { '/etc/sudoers' },
18 default => sub { scalar `hostname` },
23 my %file = $self->_gather_files($self->sudoers_file);
28 my ($self, $file) = @_;
29 my $result = transform_exceptions {
30 my @lines = output_from_file $file;
31 my @result = ({ body => join '', @lines });
32 for my $line (@lines) {
34 if ($line =~ m{^#include\s+(.+)$}) {
35 my $inc_file = $self->_insert_hostname($1);
36 push @result, $self->_gather_files($inc_file);
38 elsif ($line =~ m{^#includedir\s+(.+)$}) {
39 my $inc_dir = $self->_insert_hostname($1);
40 push @result, $self->_gather_from_dir($inc_dir);
45 return $file => $result
46 if ref $result eq 'HASH';
47 return $file => @$result;
50 sub _gather_from_dir {
51 my ($self, $dir) = @_;
52 my @files = files_from_dir $dir;
54 for my $file (@files) {
55 next if $file =~ m{\.} or $file =~ m{~$};
56 %file = (%file, $self->_gather_files("$dir/$file"));
61 sub _insert_hostname {
62 my ($self, $value) = @_;
63 my $hostname = $self->hostname;
64 $value =~ s{\%h}{$hostname}g;
74 System::Introspector::Sudoers - Gather sudoer information
78 Reads C<sudoers> files to gather information about sudo abilities. This
79 probe will also read all included files.
85 The path to the original C<sudoers> file that should be read. Includes from this
86 file will be followed and provided as well.
90 The hostname used to resolve C<%h> hostname markers in inclusions.
96 =item L<System::Introspector>