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";
54 authorized => { file_name => "$ssh_dir/authorized_keys", body => '' }
57 for my $item (files_from_dir $ssh_dir) {
58 next unless $item =~ m{\.pub$};
59 $key{ $item } = transform_exceptions {
61 file_name => "$ssh_dir/$item",
62 body => scalar output_from_file "$ssh_dir/$item",
66 my $auth_keys = transform_exceptions {
68 file_name => "$ssh_dir/authorized_keys",
69 body => scalar output_from_file "$ssh_dir/authorized_keys",
72 return { files => \%key, authorized => $auth_keys };
75 sub _gather_user_groups {
76 my ($self, $user) = @_;
77 my $groups = output_from_command [groups => $user];
78 return { list => [split m{\s+}, $groups] };
81 sub _deparse_htpasswd_line {
82 my ($self, $line) = @_;
85 @value{qw( username uid gid comment home shell )}
86 = (split m{:}, $line)[0, 2..6];
92 return handle_from_file '/etc/passwd';
101 System::Introspector::Users - Gather user information
105 Gathers information for all users in C</etc/passwd>, including cronjobs and
106 installed SSH public keys.
112 =item L<System::Introspector>