handle_from_file
);
+has passwd_file => (is => 'ro', default => sub { '/etc/passwd' });
+
sub gather {
my ($self) = @_;
return transform_exceptions {
unless ($ok) {
return {}
if $err =~ m{^no crontab}i;
- return { error => $err };
+ return { __error__ => $err };
}
return { body => $out };
}
sub _gather_ssh_keys {
my ($self, $user, $home) = @_;
- my $ssh_dir = "$home/.ssh/";
- return {}
- unless -d $ssh_dir;
+ my $ssh_dir = "$home/.ssh";
+ my $ssh_authkeys = "$ssh_dir/authorized_keys";
+ return {
+ files => {},
+ authorized => { file_name => $ssh_authkeys, body => '' }
+ } unless -d $ssh_dir;
my %key;
for my $item (files_from_dir $ssh_dir) {
next unless $item =~ m{\.pub$};
$key{ $item } = transform_exceptions {
return {
+ file_name => "$ssh_dir/$item",
body => scalar output_from_file "$ssh_dir/$item",
};
};
}
- return { files => \%key };
+ my $auth_keys = (-e $ssh_authkeys) ? (transform_exceptions {
+ return {
+ file_name => $ssh_authkeys,
+ body => scalar output_from_file $ssh_authkeys,
+ };
+ }) : { file_name => $ssh_authkeys, body => '' };
+ return { files => \%key, authorized => $auth_keys };
}
sub _gather_user_groups {
my ($self, $user) = @_;
my $groups = output_from_command [groups => $user];
- return { list => [split m{\s+}, $groups] };
+ chomp $groups;
+ $groups =~ s{^ .* : \s* }{}x;
+ return [split m{\s+}, $groups];
}
sub _deparse_htpasswd_line {
sub _open_passwd_fh {
my ($self) = @_;
- return handle_from_file '/etc/passwd';
+ return handle_from_file $self->passwd_file;
}
1;