1 package System::Introspector::Probe::Users;
4 use System::Introspector::Util qw(
15 return transform_exceptions {
16 my $fh = $self->_open_passwd_fh;
18 while (defined( my $line = <$fh> )) {
19 my $data = $self->_deparse_htpasswd_line($line);
20 my $user = $data->{username};
21 my $home = $data->{home};
22 $data->{groups} = transform_exceptions {
23 $self->_gather_user_groups($user);
25 $data->{ssh}{keys} = transform_exceptions {
26 $self->_gather_ssh_keys($user, $home);
28 $data->{crontab} = transform_exceptions {
29 $self->_gather_crontab($user);
31 $user{ $data->{username} } = $data;
33 return { users => \%user };
38 my ($self, $user) = @_;
39 my ($out, $err, $ok) = output_from_command
40 ['crontab', '-u', $user, '-l'];
43 if $err =~ m{^no crontab}i;
44 return { error => $err };
46 return { body => $out };
49 sub _gather_ssh_keys {
50 my ($self, $user, $home) = @_;
51 my $ssh_dir = "$home/.ssh/";
55 for my $item (files_from_dir $ssh_dir) {
56 next unless $item =~ m{\.pub$};
57 $key{ $item } = transform_exceptions {
59 body => scalar output_from_file "$ssh_dir/$item",
63 return { files => \%key };
66 sub _gather_user_groups {
67 my ($self, $user) = @_;
68 my $groups = output_from_command [groups => $user];
69 return { list => [split m{\s+}, $groups] };
72 sub _deparse_htpasswd_line {
73 my ($self, $line) = @_;
76 @value{qw( username uid gid comment home shell )}
77 = (split m{:}, $line)[0, 2..6];
83 return handle_from_file '/etc/passwd';
92 System::Introspector::Users - Gather user information
96 Gathers information for all users in C</etc/passwd>, including cronjobs and
97 installed SSH public keys.
103 =item L<System::Introspector>