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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/win_util.h" 5 #include "base/win/win_util.h"
6 6
7 #include <aclapi.h> 7 #include <aclapi.h>
8 #include <cfgmgr32.h> 8 #include <cfgmgr32.h>
9 #include <powrprof.h> 9 #include <powrprof.h>
10 #include <shobjidl.h> // Must be before propkey. 10 #include <shobjidl.h> // Must be before propkey.
11 #include <initguid.h> 11 #include <initguid.h>
12 #include <inspectable.h> 12 #include <inspectable.h>
13 #include <mdmregistration.h>
13 #include <propkey.h> 14 #include <propkey.h>
14 #include <propvarutil.h> 15 #include <propvarutil.h>
15 #include <psapi.h> 16 #include <psapi.h>
16 #include <roapi.h> 17 #include <roapi.h>
17 #include <sddl.h> 18 #include <sddl.h>
18 #include <setupapi.h> 19 #include <setupapi.h>
19 #include <shellscalingapi.h> 20 #include <shellscalingapi.h>
20 #include <shlwapi.h> 21 #include <shlwapi.h>
21 #include <signal.h> 22 #include <signal.h>
22 #include <stddef.h> 23 #include <stddef.h>
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (g_domain_state == UNKNOWN) { 490 if (g_domain_state == UNKNOWN) {
490 ::InterlockedCompareExchange(&g_domain_state, 491 ::InterlockedCompareExchange(&g_domain_state,
491 IsOS(OS_DOMAINMEMBER) ? 492 IsOS(OS_DOMAINMEMBER) ?
492 ENROLLED : NOT_ENROLLED, 493 ENROLLED : NOT_ENROLLED,
493 UNKNOWN); 494 UNKNOWN);
494 } 495 }
495 496
496 return g_domain_state == ENROLLED; 497 return g_domain_state == ENROLLED;
497 } 498 }
498 499
500 bool IsDeviceRegisteredWithManagement() {
501 static bool is_device_registered_with_management = []() {
502 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
503 if (!mdm_dll)
504 return false;
505
506 using IsDeviceRegisteredWithManagementFunction =
507 decltype(&::IsDeviceRegisteredWithManagement);
508 IsDeviceRegisteredWithManagementFunction
509 is_device_registered_with_management_function =
510 reinterpret_cast<IsDeviceRegisteredWithManagementFunction>(
511 ::GetProcAddress(mdm_dll, "IsDeviceRegisteredWithManagement"));
512 if (!is_device_registered_with_management_function)
513 return false;
514
515 BOOL is_managed = false;
516 HRESULT hr =
517 is_device_registered_with_management_function(&is_managed, 0, nullptr);
518 return SUCCEEDED(hr) && is_managed;
519 }();
520 return is_device_registered_with_management;
521 }
522
523 bool IsEnterpriseManaged() {
524 // TODO(rogerta): this function should really be:
525 //
526 // return IsEnrolledToDomain() || IsDeviceRegisteredWithManagement();
527 //
528 // However, for now it is decided to collect some UMA metrics about
529 // IsDeviceRegisteredWithMdm() before changing chrome's behavior.
530 return IsEnrolledToDomain();
531 }
532
499 void SetDomainStateForTesting(bool state) { 533 void SetDomainStateForTesting(bool state) {
500 g_domain_state = state ? ENROLLED : NOT_ENROLLED; 534 g_domain_state = state ? ENROLLED : NOT_ENROLLED;
501 } 535 }
502 536
503 bool IsUser32AndGdi32Available() { 537 bool IsUser32AndGdi32Available() {
504 static auto is_user32_and_gdi32_available = []() { 538 static auto is_user32_and_gdi32_available = []() {
505 // If win32k syscalls aren't disabled, then user32 and gdi32 are available. 539 // If win32k syscalls aren't disabled, then user32 and gdi32 are available.
506 540
507 // Can't disable win32k prior to windows 8. 541 // Can't disable win32k prior to windows 8.
508 if (base::win::GetVersion() < base::win::VERSION_WIN8) 542 if (base::win::GetVersion() < base::win::VERSION_WIN8)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 awareness == PROCESS_PER_MONITOR_DPI_AWARE) 636 awareness == PROCESS_PER_MONITOR_DPI_AWARE)
603 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 637 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
604 } 638 }
605 } 639 }
606 } 640 }
607 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 641 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
608 } 642 }
609 643
610 } // namespace win 644 } // namespace win
611 } // namespace base 645 } // namespace base
OLDNEW
« 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