Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: base/win/win_util.cc

Issue 2581353002: Use the Windows MDM API to check if the machine is being managed. (Closed)
Patch Set: rebased Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/win_util.h ('k') | chrome/app/chrome_crash_reporter_client_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/win_util.cc
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index a1b7f8985590dd709c89ba6cb1b579e14222e0ce..d380821c71889ee9d9f5287040395e1bd50fbff6 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -10,6 +10,7 @@
#include <shobjidl.h> // Must be before propkey.
#include <initguid.h>
#include <inspectable.h>
+#include <mdmregistration.h>
#include <propkey.h>
#include <propvarutil.h>
#include <psapi.h>
@@ -496,6 +497,39 @@ bool IsEnrolledToDomain() {
return g_domain_state == ENROLLED;
}
+bool IsDeviceRegisteredWithManagement() {
+ static bool is_device_registered_with_management = []() {
+ HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll");
S. Ganesh 2017/03/01 03:04:01 I noticed here that the DLL is not being freed. In
Will Harris 2017/03/01 18:01:09 perhaps just use base::ScopedNativeLibrary here
+ if (!mdm_dll)
+ return false;
+
+ using IsDeviceRegisteredWithManagementFunction =
+ decltype(&::IsDeviceRegisteredWithManagement);
+ IsDeviceRegisteredWithManagementFunction
+ is_device_registered_with_management_function =
+ reinterpret_cast<IsDeviceRegisteredWithManagementFunction>(
+ ::GetProcAddress(mdm_dll, "IsDeviceRegisteredWithManagement"));
+ if (!is_device_registered_with_management_function)
+ return false;
+
+ BOOL is_managed = false;
+ HRESULT hr =
+ is_device_registered_with_management_function(&is_managed, 0, nullptr);
+ return SUCCEEDED(hr) && is_managed;
+ }();
+ return is_device_registered_with_management;
+}
+
+bool IsEnterpriseManaged() {
+ // TODO(rogerta): this function should really be:
+ //
+ // return IsEnrolledToDomain() || IsDeviceRegisteredWithManagement();
+ //
+ // However, for now it is decided to collect some UMA metrics about
+ // IsDeviceRegisteredWithMdm() before changing chrome's behavior.
+ return IsEnrolledToDomain();
+}
+
void SetDomainStateForTesting(bool state) {
g_domain_state = state ? ENROLLED : NOT_ENROLLED;
}
« no previous file with comments | « base/win/win_util.h ('k') | chrome/app/chrome_crash_reporter_client_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698