line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Generic::Users; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
100806878
|
use strict; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
73
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
434
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
745
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub isEnabled { |
9
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
return if $params{no_category}->{user}; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
return |
14
|
0
|
|
0
|
|
|
|
canRun('who') || |
15
|
|
|
|
|
|
|
canRun('last') || |
16
|
|
|
|
|
|
|
-r '/etc/passwd'; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub doInventory { |
20
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
23
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my %users; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (!$params{no_category}->{local_user}) { |
28
|
0
|
|
|
|
|
|
foreach my $user (_getLocalUsers(logger => $logger)) { |
29
|
|
|
|
|
|
|
# record user -> primary group relationship |
30
|
0
|
|
|
|
|
|
push @{$users{$user->{gid}}}, $user->{LOGIN}; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
delete $user->{gid}; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$inventory->addEntry( |
34
|
|
|
|
|
|
|
section => 'LOCAL_USERS', |
35
|
|
|
|
|
|
|
entry => $user |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if (!$params{no_category}->{local_group}) { |
41
|
0
|
|
|
|
|
|
foreach my $group (_getLocalGroups(logger => $logger)) { |
42
|
|
|
|
|
|
|
# add users having this group as primary group, if any |
43
|
0
|
0
|
|
|
|
|
push @{$group->{MEMBER}}, @{$users{$group->{ID}}} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if $users{$group->{ID}}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$inventory->addEntry( |
47
|
|
|
|
|
|
|
section => 'LOCAL_GROUPS', |
48
|
|
|
|
|
|
|
entry => $group |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
foreach my $user (_getLoggedUsers(logger => $logger)) { |
54
|
0
|
|
|
|
|
|
$inventory->addEntry( |
55
|
|
|
|
|
|
|
section => 'USERS', |
56
|
|
|
|
|
|
|
entry => $user |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $last = _getLastUser(logger => $logger); |
61
|
0
|
|
|
|
|
|
$inventory->setHardware($last); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _getLocalUsers { |
65
|
0
|
|
|
0
|
|
|
my (%params) = ( |
66
|
|
|
|
|
|
|
file => '/etc/passwd', |
67
|
|
|
|
|
|
|
@_ |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
71
|
0
|
0
|
|
|
|
|
return unless $handle; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my @users; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
76
|
0
|
0
|
|
|
|
|
next if $line =~ /^#/; |
77
|
0
|
0
|
|
|
|
|
next if $line =~ /^[+-]/; # old format for external inclusion, see #2460 |
78
|
0
|
|
|
|
|
|
my ($login, undef, $uid, $gid, $gecos, $home, $shell) = |
79
|
|
|
|
|
|
|
split(/:/, $line); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
push @users, { |
82
|
|
|
|
|
|
|
LOGIN => $login, |
83
|
|
|
|
|
|
|
ID => $uid, |
84
|
|
|
|
|
|
|
gid => $gid, |
85
|
|
|
|
|
|
|
NAME => $gecos, |
86
|
|
|
|
|
|
|
HOME => $home, |
87
|
|
|
|
|
|
|
SHELL => $shell |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
close $handle; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return @users; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _getLocalGroups { |
96
|
0
|
|
|
0
|
|
|
my (%params) = ( |
97
|
|
|
|
|
|
|
file => '/etc/group', |
98
|
|
|
|
|
|
|
@_ |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
102
|
0
|
0
|
|
|
|
|
return unless $handle; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my @groups; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
107
|
0
|
0
|
|
|
|
|
next if $line =~ /^#/; |
108
|
0
|
|
|
|
|
|
chomp $line; |
109
|
0
|
|
|
|
|
|
my ($name, undef, $gid, $members) = split(/:/, $line); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# prevent warning for malformed group file (#2384) |
112
|
0
|
0
|
|
|
|
|
next unless $members; |
113
|
0
|
|
|
|
|
|
my @members = split(/,/, $members); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
push @groups, { |
116
|
|
|
|
|
|
|
ID => $gid, |
117
|
|
|
|
|
|
|
NAME => $name, |
118
|
|
|
|
|
|
|
MEMBER => \@members, |
119
|
|
|
|
|
|
|
}; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
close $handle; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return @groups; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _getLoggedUsers { |
127
|
0
|
|
|
0
|
|
|
my (%params) = ( |
128
|
|
|
|
|
|
|
command => 'who', |
129
|
|
|
|
|
|
|
@_ |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
133
|
0
|
0
|
|
|
|
|
return unless $handle; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my @users; |
136
|
|
|
|
|
|
|
my $seen; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
139
|
0
|
0
|
|
|
|
|
next unless $line =~ /^(\S+)/; |
140
|
0
|
0
|
|
|
|
|
next if $seen->{$1}++; |
141
|
0
|
|
|
|
|
|
push @users, { LOGIN => $1 }; |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
close $handle; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return @users; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub _getLastUser { |
149
|
0
|
|
|
0
|
|
|
my (%params) = ( |
150
|
|
|
|
|
|
|
command => 'last', |
151
|
|
|
|
|
|
|
@_ |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $last = getFirstLine(%params); |
155
|
0
|
0
|
|
|
|
|
return unless $last; |
156
|
|
|
|
|
|
|
return unless |
157
|
0
|
0
|
|
|
|
|
$last =~ /^(\S+) \s+ \S+ \s+ \S+ \s+ (\S+ \s+ \S+ \s+ \S+ \s+ \S+)/x; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
return { |
160
|
0
|
|
|
|
|
|
LASTLOGGEDUSER => $1, |
161
|
|
|
|
|
|
|
DATELASTLOGGEDUSER => $2 |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |