Bug 1418131: Part 1 - Add Windows Security Center info to nsSystemInfo; r=erahm,jimm

MozReview-Commit-ID: 7XUAIesDpRu

--HG--
extra : rebase_source : 2dbd3592e1fd31aae2c0d9946a7146b3a472d3fa
This commit is contained in:
Aaron Klotz 2017-11-16 17:59:51 -07:00
Родитель 6550a090f6
Коммит b62e509838
2 изменённых файлов: 133 добавлений и 0 удалений

Просмотреть файл

@ -89,6 +89,9 @@ if CONFIG['OS_ARCH'] == 'WINNT':
EXPORTS += [
'nsWindowsHelpers.h',
]
OS_LIBS += [
'wscapi',
]
EXPORTS.mozilla += [
'AutoRestore.h',

Просмотреть файл

@ -14,9 +14,12 @@
#include "mozilla/Sprintf.h"
#ifdef XP_WIN
#include <comutil.h>
#include <time.h>
#include <iwscapi.h>
#include <windows.h>
#include <winioctl.h>
#include <wscapi.h>
#include "base/scoped_handle_win.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
@ -235,6 +238,105 @@ nsresult GetCountryCode(nsAString& aCountryCode)
}
} // namespace
static HRESULT
EnumWSCProductList(nsAString& aOutput, NotNull<IWSCProductList*> aProdList)
{
MOZ_ASSERT(aOutput.IsEmpty());
LONG count;
HRESULT hr = aProdList->get_Count(&count);
if (FAILED(hr)) {
return hr;
}
for (LONG index = 0; index < count; ++index) {
RefPtr<IWscProduct> product;
hr = aProdList->get_Item(index, getter_AddRefs(product));
if (FAILED(hr)) {
return hr;
}
WSC_SECURITY_PRODUCT_STATE state;
hr = product->get_ProductState(&state);
if (FAILED(hr)) {
return hr;
}
// We only care about products that are active
if (state == WSC_SECURITY_PRODUCT_STATE_OFF ||
state == WSC_SECURITY_PRODUCT_STATE_SNOOZED) {
continue;
}
_bstr_t bName;
hr = product->get_ProductName(bName.GetAddress());
if (FAILED(hr)) {
return hr;
}
if (!aOutput.IsEmpty()) {
aOutput.AppendLiteral(u";");
}
aOutput.Append((wchar_t*)bName, bName.length());
}
return S_OK;
}
static nsresult
GetWindowsSecurityCenterInfo(nsAString& aAVInfo, nsAString& aAntiSpyInfo,
nsAString& aFirewallInfo)
{
aAVInfo.Truncate();
aAntiSpyInfo.Truncate();
aFirewallInfo.Truncate();
MOZ_ASSERT(XRE_IsParentProcess());
if (!XRE_IsParentProcess()) {
return NS_ERROR_NOT_AVAILABLE;
}
const CLSID clsid = __uuidof(WSCProductList);
const IID iid = __uuidof(IWSCProductList);
// NB: A separate instance of IWSCProductList is needed for each distinct
// security provider type; MSDN says that we cannot reuse the same object
// and call Initialize() to pave over the previous data.
WSC_SECURITY_PROVIDER providerTypes[] = { WSC_SECURITY_PROVIDER_ANTIVIRUS,
WSC_SECURITY_PROVIDER_ANTISPYWARE,
WSC_SECURITY_PROVIDER_FIREWALL };
// Each output must match the corresponding entry in providerTypes.
nsAString* outputs[] = { &aAVInfo, &aAntiSpyInfo, &aFirewallInfo };
static_assert(ArrayLength(providerTypes) == ArrayLength(outputs),
"Length of providerTypes and outputs arrays must match");
for (uint32_t index = 0; index < ArrayLength(providerTypes); ++index) {
RefPtr<IWSCProductList> prodList;
HRESULT hr = ::CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, iid,
getter_AddRefs(prodList));
if (FAILED(hr)) {
return NS_ERROR_NOT_AVAILABLE;
}
hr = prodList->Initialize(providerTypes[index]);
if (FAILED(hr)) {
return NS_ERROR_UNEXPECTED;
}
hr = EnumWSCProductList(*outputs[index], WrapNotNull(prodList.get()));
if (FAILED(hr)) {
return NS_ERROR_UNEXPECTED;
}
}
return NS_OK;
}
#endif // defined(XP_WIN)
#ifdef XP_MACOSX
@ -692,6 +794,34 @@ nsSystemInfo::Init()
return rv;
}
}
nsAutoString avInfo, antiSpyInfo, firewallInfo;
if (NS_SUCCEEDED(GetWindowsSecurityCenterInfo(avInfo, antiSpyInfo,
firewallInfo))) {
if (!avInfo.IsEmpty()) {
rv = SetPropertyAsAString(NS_LITERAL_STRING("registeredAntiVirus"),
avInfo);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (!antiSpyInfo.IsEmpty()) {
rv = SetPropertyAsAString(NS_LITERAL_STRING("registeredAntiSpyware"),
antiSpyInfo);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
if (!firewallInfo.IsEmpty()) {
rv = SetPropertyAsAString(NS_LITERAL_STRING("registeredFirewall"),
firewallInfo);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}
#endif
#if defined(XP_MACOSX)