1 package System::Introspector::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;
48 sub _gather_from_dir {
49 my ($self, $dir) = @_;
50 my @files = files_from_dir $dir;
52 for my $file (@files) {
53 next if $file =~ m{\.} or $file =~ m{~$};
54 %file = (%file, $self->_gather_files("$dir/$file"));
59 sub _insert_hostname {
60 my ($self, $value) = @_;
61 my $hostname = $self->hostname;
62 $value =~ s{\%h}{$hostname}g;
72 System::Introspector::Sudoers - Gather sudoer information
76 Reads C<sudoers> files to gather information about sudo abilities. This
77 probe will also read all included files.
83 The path to the original C<sudoers> file that should be read. Includes from this
84 file will be followed and provided as well.
88 The hostname used to resolve C<%h> hostname markers in inclusions.
94 =item L<System::Introspector>