line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Win32::License; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69080342
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
86
|
|
4
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
118
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
17
|
use English qw(-no_match_vars); |
|
2
|
|
|
|
|
71
|
|
|
2
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
use Win32::TieRegistry ( |
8
|
2
|
|
|
|
|
12
|
Delimiter => '/', |
9
|
|
|
|
|
|
|
ArrayValues => 0, |
10
|
|
|
|
|
|
|
qw/KEY_READ/ |
11
|
2
|
|
|
2
|
|
3067
|
); |
|
2
|
|
|
|
|
385
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1191
|
use FusionInventory::Agent::Tools::License; |
|
2
|
|
|
|
|
22
|
|
|
2
|
|
|
|
|
130
|
|
14
|
2
|
|
|
2
|
|
1347
|
use FusionInventory::Agent::Tools::Win32; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1520
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub isEnabled { |
17
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
18
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{licenseinfo}; |
19
|
0
|
|
|
|
|
0
|
return 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub doInventory { |
23
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
26
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $is64bit = is64bit(); |
29
|
0
|
|
|
|
|
0
|
my @licenses; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
0
|
if ($is64bit) { |
32
|
0
|
0
|
|
|
|
0
|
my $machKey64 = $Registry->Open('LMachine', { |
33
|
|
|
|
|
|
|
Access => KEY_READ | KEY_WOW64_64 ## no critic (ProhibitBitwise) |
34
|
|
|
|
|
|
|
}) or $logger->error("Can't open HKEY_LOCAL_MACHINE key: $EXTENDED_OS_ERROR"); |
35
|
0
|
|
|
|
|
0
|
my $officeKey64 = $machKey64->{"SOFTWARE/Microsoft/Office"}; |
36
|
0
|
0
|
|
|
|
0
|
push @licenses, _scanOfficeLicences($officeKey64 ) if $officeKey64; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
0
|
my $machKey32 = $Registry->Open('LMachine', { |
39
|
|
|
|
|
|
|
Access => KEY_READ | KEY_WOW64_32 ## no critic (ProhibitBitwise) |
40
|
|
|
|
|
|
|
}) or $logger->error("Can't open HKEY_LOCAL_MACHINE key: $EXTENDED_OS_ERROR"); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $officeKey32 = $machKey32->{"SOFTWARE/Microsoft/Office"}; |
43
|
0
|
0
|
|
|
|
0
|
push @licenses, _scanOfficeLicences($officeKey32) if $officeKey32; |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
0
|
|
|
|
0
|
my $machKey = $Registry->Open('LMachine', { |
46
|
|
|
|
|
|
|
Access => KEY_READ ## no critic (ProhibitBitwise) |
47
|
|
|
|
|
|
|
}) or $logger->error( |
48
|
|
|
|
|
|
|
"Can't open HKEY_LOCAL_MACHINE key: $EXTENDED_OS_ERROR" |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my $officeKey = $machKey->{"SOFTWARE/Microsoft/Office"}; |
52
|
0
|
0
|
|
|
|
0
|
push @licenses, _scanOfficeLicences($officeKey) if $officeKey; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
foreach my $license (@licenses) { |
56
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
57
|
|
|
|
|
|
|
section => 'LICENSEINFOS', |
58
|
|
|
|
|
|
|
entry => $license |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _scanOfficeLicences { |
64
|
0
|
|
|
0
|
|
0
|
my ($key) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# registry data structure: |
67
|
|
|
|
|
|
|
# SOFTWARE/Microsoft/Office |
68
|
|
|
|
|
|
|
# └── x.y |
69
|
|
|
|
|
|
|
# └── Registration |
70
|
|
|
|
|
|
|
# └── UUID |
71
|
|
|
|
|
|
|
# └── DigitalProductID:value |
72
|
|
|
|
|
|
|
# └── ProductID:value |
73
|
|
|
|
|
|
|
# └── ... |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my @licences; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
foreach my $versionKey (keys %{$key}) { |
|
0
|
|
|
|
|
0
|
|
78
|
0
|
|
|
|
|
0
|
my $registrationKey = $key->{$versionKey}->{'Registration/'}; |
79
|
0
|
0
|
|
|
|
0
|
next unless $registrationKey; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
foreach my $uuidKey (keys %{$registrationKey}) { |
|
0
|
|
|
|
|
0
|
|
82
|
0
|
0
|
|
|
|
0
|
next unless $registrationKey->{$uuidKey}->{'/DigitalProductID'}; |
83
|
0
|
|
|
|
|
0
|
push @licences, _getOfficeLicense($registrationKey->{$uuidKey}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
return @licences; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _getOfficeLicense { |
91
|
2
|
|
|
2
|
|
43679
|
my ($key) = @_; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $license = { |
94
|
|
|
|
|
|
|
KEY => decodeMicrosoftKey($key->{'/DigitalProductID'}), |
95
|
|
|
|
|
|
|
PRODUCTID => $key->{'/ProductID'}, |
96
|
|
|
|
|
|
|
UPDATE => $key->{'/SPLevel'}, |
97
|
|
|
|
|
|
|
OEM => $key->{'/OEM'}, |
98
|
|
|
|
|
|
|
FULLNAME => encodeFromRegistry($key->{'/ProductName'}) || |
99
|
|
|
|
|
|
|
encodeFromRegistry($key->{'/ConvertToEdition'}), |
100
|
|
|
|
|
|
|
NAME => encodeFromRegistry($key->{'/ProductNameNonQualified'}) || |
101
|
2
|
|
66
|
|
|
19
|
encodeFromRegistry($key->{'/ProductNameVersion'}) |
|
|
|
33
|
|
|
|
|
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
2
|
50
|
33
|
|
|
28
|
if ($key->{'/TrialType'} && $key->{'/TrialType'} =~ /(\d+)$/) { |
105
|
2
|
|
|
|
|
10
|
$license->{TRIAL} = int($1); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
4
|
my @products; |
109
|
2
|
|
|
|
|
34
|
foreach my $variable (keys %$key) { |
110
|
102
|
100
|
|
|
|
290
|
next unless $variable =~ m/\/(\w+)NameVersion$/; |
111
|
34
|
|
|
|
|
78
|
push @products, $1; |
112
|
|
|
|
|
|
|
} |
113
|
2
|
50
|
|
|
|
13
|
if (@products) { |
114
|
2
|
|
|
|
|
30
|
$license->{COMPONENTS} = join('/', sort @products); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
9
|
return $license; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |