line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Win32::License; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
51284074
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
69
|
|
4
|
1
|
|
|
1
|
|
14
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
32
|
|
|
1
|
|
|
|
|
20
|
|
7
|
|
|
|
|
|
|
use Win32::TieRegistry ( |
8
|
1
|
|
|
|
|
6
|
Delimiter => '/', |
9
|
|
|
|
|
|
|
ArrayValues => 0, |
10
|
|
|
|
|
|
|
qw/KEY_READ/ |
11
|
1
|
|
|
1
|
|
1302
|
); |
|
1
|
|
|
|
|
265
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
440
|
use FusionInventory::Agent::Tools::License; |
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
61
|
|
14
|
1
|
|
|
1
|
|
524
|
use FusionInventory::Agent::Tools::Win32; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
581
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub isEnabled { |
17
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
18
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{licenseinfo}; |
19
|
0
|
|
|
|
|
|
return 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub doInventory { |
23
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
26
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $is64bit = is64bit(); |
29
|
0
|
|
|
|
|
|
my @licenses; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if ($is64bit) { |
32
|
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
|
|
|
|
|
|
my $officeKey64 = $machKey64->{"SOFTWARE/Microsoft/Office"}; |
36
|
0
|
0
|
|
|
|
|
push @licenses, _scanOffice($officeKey64 ) if $officeKey64; |
37
|
|
|
|
|
|
|
|
38
|
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
|
|
|
|
|
|
my $officeKey32 = $machKey32->{"SOFTWARE/Microsoft/Office"}; |
43
|
0
|
0
|
|
|
|
|
push @licenses, _scanOffice($officeKey32) if $officeKey32; |
44
|
|
|
|
|
|
|
} else { |
45
|
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
|
|
|
|
|
|
my $officeKey = $machKey->{"SOFTWARE/Microsoft/Office"}; |
52
|
0
|
0
|
|
|
|
|
push @licenses, _scanOffice($officeKey) if $officeKey; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
foreach my $license (@licenses) { |
56
|
0
|
|
|
|
|
|
$inventory->addEntry( |
57
|
|
|
|
|
|
|
section => 'LICENSEINFOS', |
58
|
|
|
|
|
|
|
entry => $license |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _scanOffice { |
64
|
0
|
|
|
0
|
|
|
my ($key) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
0
|
|
|
|
my %license = ( |
|
|
|
0
|
|
|
|
|
67
|
|
|
|
|
|
|
PRODUCTID => $key->{ProductID}, |
68
|
|
|
|
|
|
|
UPDATE => $key->{SPLevel}, |
69
|
|
|
|
|
|
|
OEM => $key->{OEM}, |
70
|
|
|
|
|
|
|
FULLNAME => encodeFromRegistry($key->{ProductName}) || |
71
|
|
|
|
|
|
|
encodeFromRegistry($key->{ConvertToEdition}), |
72
|
|
|
|
|
|
|
NAME => encodeFromRegistry($key->{ProductNameNonQualified}) || |
73
|
|
|
|
|
|
|
encodeFromRegistry($key->{ProductNameVersion}) |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($key->{DigitalProductID}) { |
77
|
0
|
|
|
|
|
|
$license{KEY} = decodeMicrosoftKey($key->{DigitalProductID}); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
if ($key->{TrialType} && $key->{TrialType} =~ /(\d+)$/) { |
81
|
0
|
|
|
|
|
|
$license{TRIAL} = int($1); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my @products; |
85
|
0
|
|
|
|
|
|
foreach my $entry (keys %$key) { |
86
|
0
|
0
|
|
|
|
|
next unless $entry =~ s/\/(\w+)NameVersion$//; |
87
|
0
|
|
|
|
|
|
my $product = $1; |
88
|
0
|
0
|
|
|
|
|
next unless $key->{$product."NameVersion"}; |
89
|
0
|
|
|
|
|
|
push @products, $product; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
0
|
|
|
|
|
if (@products) { |
92
|
0
|
|
|
|
|
|
$license{COMPONENTS} = join('/', @products); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my @licenses; |
96
|
0
|
0
|
|
|
|
|
push @licenses, \%license if $license{KEY}; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
foreach my $subKey (keys %$key) { |
99
|
|
|
|
|
|
|
# skip variables |
100
|
0
|
0
|
|
|
|
|
next if $subKey =~ m{^/}; |
101
|
0
|
|
|
|
|
|
push @licenses, _scanOffice($key->{$subKey}); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return @licenses; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |