Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop+windows registry lowlevel access #1047

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/FusionInventory/Agent/Task/Inventory/Generic/Screen.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use parent 'FusionInventory::Agent::Task::Inventory::Module';
use English qw(-no_match_vars);
use MIME::Base64;
use UNIVERSAL::require;

use File::Find;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Screen;
Expand Down Expand Up @@ -148,8 +147,11 @@ sub _getScreensFromWindows {

foreach my $screen (@screens) {
next unless $screen->{id};
$screen->{edid} = getRegistryValue(
path => "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Enum/$screen->{id}/Device Parameters/EDID",
# $screen->{id} =~ s/\\/\//g;
$screen->{edid} = getNewRegistryValues(
root => "HKEY_LOCAL_MACHINE",
path => "SYSTEM/CurrentControlSet/Enum/$screen->{id}/Device Parameters",
keyName => "EDID",
logger => $params{logger}
);
$screen->{edid} =~ s/^\s+$// if $screen->{edid};
Expand Down
26 changes: 10 additions & 16 deletions lib/FusionInventory/Agent/Task/Inventory/Win32/AntiVirus.pm
Original file line number Diff line number Diff line change
Expand Up @@ -461,31 +461,25 @@ sub _setNortonInfos {
sub _getSoftwareRegistryKeys {
my ($base, $values, $callback) = @_;

my $reg;
if (is64bit()) {
$reg = getRegistryKey(
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/'.$base,
wmiopts => { # Only used for remote WMI optimization
values => $values
}
my %reg = getNewRegistryValues(
root => "HKEY_LOCAL_MACHINE",
path => 'SOFTWARE/Wow6432Node/'.$base
);
if ($reg) {
if (%reg) {
if ($callback) {
my $filter = &{$callback}($reg);
my $filter = &{$callback}(%reg);
return $filter if $filter;
} else {
return $reg;
return %reg;
}
}
}

$reg = getRegistryKey(
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/'.$base,
wmiopts => { # Only used for remote WMI optimization
values => $values
}
my %reg = getNewRegistryValues(
root => "HKEY_LOCAL_MACHINE",
path => 'SOFTWARE/'.$base
);
return ($callback && $reg) ? &{$callback}($reg) : $reg;
return ($callback && %reg) ? &{$callback}(%reg) : %reg;
}

1;
21 changes: 10 additions & 11 deletions lib/FusionInventory/Agent/Task/Inventory/Win32/CPU.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ sub _getCPUs {
my @dmidecodeInfos = $remotewmi || Win32::GetOSName() eq 'Win2003' ?
() : getCpusFromDmidecode();

# the CPU description in WMI is false, we use the registry instead
my $registryInfos = getRegistryKey(
path => "HKEY_LOCAL_MACHINE/Hardware/Description/System/CentralProcessor",
wmiopts => { # Only used for remote WMI optimization
values => [ qw/Identifier ProcessorNameString VendorIdentifier/ ]
}
my %registryInfos = getNewRegistryAll(
logger => $params{logger},
root => "HKEY_LOCAL_MACHINE",
path => "Hardware/Description/System/CentralProcessor",
%params
);

my $cpuId = 0;
Expand All @@ -77,26 +76,26 @@ sub _getCPUs {
)) {

my $dmidecodeInfo = $dmidecodeInfos[$cpuId];
my $registryInfo = $registryInfos->{"$logicalId/"};
my $registryInfo = $registryInfos{"$logicalId"};

# Compute WMI threads for this CPU if not available in dmidecode, this is the case on win2003r2 with 932370 hotfix applied (see #2894)
my $wmi_threads = !$dmidecodeInfo->{THREAD} && $object->{NumberOfCores} ? $object->{NumberOfLogicalProcessors}/$object->{NumberOfCores} : undef;

# Split CPUID from its value inside registry
my @splitted_identifier = split(/ |\n/, $registryInfo->{'/Identifier'} || $object->{Description});
my @splitted_identifier = split(/ |\n/, $registryInfo->{Identifier} || $object->{Description});

my $name = $dmidecodeInfo->{NAME};
unless ($name) {
$name = trimWhitespace($registryInfo->{'/ProcessorNameString'} || $object->{Name});
$name = trimWhitespace($registryInfo->{ProcessorNameString} || $object->{Name});
$name =~ s/\((R|TM)\)//gi if $name;
}

my $cpu = {
CORE => $dmidecodeInfo->{CORE} || $object->{NumberOfCores},
THREAD => $dmidecodeInfo->{THREAD} || $wmi_threads,
DESCRIPTION => $dmidecodeInfo->{DESCRIPTION} || $registryInfo->{'/Identifier'} || $object->{Description},
DESCRIPTION => $dmidecodeInfo->{DESCRIPTION} || $registryInfo->{Identifier} || $object->{Description},
NAME => $name,
MANUFACTURER => $dmidecodeInfo->{MANUFACTURER} || getCanonicalManufacturer($registryInfo->{'/VendorIdentifier'} || $object->{Manufacturer}),
MANUFACTURER => $dmidecodeInfo->{MANUFACTURER} || getCanonicalManufacturer($registryInfo->{VendorIdentifier} || $object->{Manufacturer}),
SERIAL => $dmidecodeInfo->{SERIAL} || $object->{SerialNumber},
SPEED => $dmidecodeInfo->{SPEED} || $object->{MaxClockSpeed},
FAMILYNUMBER => $dmidecodeInfo->{FAMILYNUMBER} || $splitted_identifier[2],
Expand Down
26 changes: 17 additions & 9 deletions lib/FusionInventory/Agent/Task/Inventory/Win32/License.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,26 @@ sub doInventory {

my @licenses;

my $officeKey = getRegistryKey(
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Office"
my %officeKey = getNewRegistryAll(
logger => $params{logger},
root => "HKEY_LOCAL_MACHINE",
path => "SOFTWARE/Microsoft/Office",
%params
);
_scanOfficeLicences($officeKey) if $officeKey;

_scanOfficeLicences(%officeKey) if %officeKey;

my $fileAdobe = 'C:\Program Files\Common Files\Adobe\Adobe PCD\cache\cache.db';
if (is64bit()) {
$fileAdobe = 'C:\Program Files (x86)\Common Files\Adobe\Adobe PCD\cache\cache.db';
my $officeKey32 = getRegistryKey(
path => "HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/Office"
my %officeKey32 = getNewRegistryAll(
logger => $params{logger},
root => "HKEY_LOCAL_MACHINE",
path => "SOFTWARE/Wow6432Node/Microsoft/Office",
%params
);
_scanOfficeLicences($officeKey32) if $officeKey32;

_scanOfficeLicences(%officeKey32) if %officeKey32;
}

push @licenses, getAdobeLicensesWithoutSqlite($fileAdobe) if (-e $fileAdobe);
Expand Down Expand Up @@ -116,7 +124,7 @@ sub _scanWmiSoftwareLicensingProducts {
}

sub _scanOfficeLicences {
my ($key) = @_;
my (%key) = @_;

# registry data structure:
# SOFTWARE/Microsoft/Office
Expand All @@ -127,8 +135,8 @@ sub _scanOfficeLicences {
# └── ProductID:value
# └── ...

foreach my $versionKey (keys %{$key}) {
my $registrationKey = $key->{$versionKey}->{'Registration/'};
foreach my $versionKey (keys %key) {
my $registrationKey = $key{$versionKey}->{Registration};
next unless $registrationKey;

foreach my $uuidKey (keys %{$registrationKey}) {
Expand Down
27 changes: 13 additions & 14 deletions lib/FusionInventory/Agent/Task/Inventory/Win32/Networks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ sub doInventory {
my $inventory = $params{inventory};
my (@gateways, @dns, @ips);

my $keys;
my %keys;

foreach my $interface (getInterfaces()) {
push @gateways, $interface->{IPGATEWAY}
Expand All @@ -44,14 +44,13 @@ sub doInventory {
delete $interface->{GUID};

# Don't reload registry keys between interfaces checks
$keys = getRegistryKey(
path => "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Network/{4D36E972-E325-11CE-BFC1-08002BE10318}",
wmiopts => { # Only used for remote WMI optimization
values => [ qw/PnpInstanceID MediaSubType/ ]
}
) unless $keys;
%keys = getNewRegistryAll(
logger => $params{logger},
root => "HKEY_LOCAL_MACHINE",
path => "SYSTEM/CurrentControlSet/Control/Network/{4D36E972-E325-11CE-BFC1-08002BE10318}",
) unless %keys;

$interface->{TYPE} = _getMediaType($interface->{PNPDEVICEID}, $keys);
$interface->{TYPE} = _getMediaType($interface->{PNPDEVICEID}, %keys);

$inventory->addEntry(
section => 'NETWORKS',
Expand All @@ -68,23 +67,23 @@ sub doInventory {
}

sub _getMediaType {
my ($deviceid, $keys) = @_;
my ($deviceid, %keys) = @_;

return unless defined $deviceid && $keys;
return unless defined $deviceid && %keys;

my $subtype;

foreach my $subkey_name (keys %{$keys}) {
foreach my $subkey_name (keys %keys) {
# skip variables
next if $subkey_name =~ m{^/};
my $subkey_connection = $keys->{$subkey_name}->{'Connection/'}
my $subkey_connection = $keys{$subkey_name}->{Connection}
or next;
my $subkey_deviceid = $subkey_connection->{'/PnpInstanceID'}
my $subkey_deviceid = $subkey_connection->{PnpInstanceID}
or next;
# Normalize PnpInstanceID
$subkey_deviceid =~ s/\\\\/\\/g;
if (lc($subkey_deviceid) eq lc($deviceid)) {
$subtype = $subkey_connection->{'/MediaSubType'};
$subtype = $subkey_connection->{MediaSubType};
last;
}
}
Expand Down
Loading