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

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: Fix missing rename from enterprise-user to entprise-managed 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
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 IsDeviceRegisteredWithMdm() {
501 static auto is_device_registered_with_mdm = []() {
502 using IsDeviceRegisteredWithManagementFunction =
503 decltype(&IsDeviceRegisteredWithManagement);
504
505 static IsDeviceRegisteredWithManagementFunction fn = nullptr;
grt (UTC plus 2) 2017/02/10 12:12:26 "Names should be descriptive; avoid abbreviation."
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
506 if (!fn) {
507 HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll");
grt (UTC plus 2) 2017/02/10 12:12:26 while presence of the library will almost certainl
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Let me double check. A larger question is whether
508 fn = reinterpret_cast<IsDeviceRegisteredWithManagementFunction>(
509 ::GetProcAddress(mdm_dll, "IsDeviceRegisteredWithManagement"));
510 if (!fn)
511 return false;
512 }
513
514 BOOL is_managed = false;
515 HRESULT hr = fn(&is_managed, 0, nullptr);
516 return SUCCEEDED(hr) && is_managed;
517 }();
518 return is_device_registered_with_mdm;
519 }
520
521 bool IsEnterpriseManaged() {
522 // TODO(rogerta): this function should really be:
523 //
524 // return IsEnrolledToDomain() || IsDeviceRegisteredWithMdm();
525 //
526 // However, for now it is decided to collected some UMA metrics about
grt (UTC plus 2) 2017/02/10 12:12:26 nit: "collect"
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
527 // IsDeviceRegisteredWithMdm() before changing chrome behavior.
grt (UTC plus 2) 2017/02/10 12:12:26 nit: "Chrome's"
Roger Tawa OOO till Jul 10th 2017/02/13 20:30:06 Done.
528 return IsEnrolledToDomain();
529 }
530
499 void SetDomainStateForTesting(bool state) { 531 void SetDomainStateForTesting(bool state) {
500 g_domain_state = state ? ENROLLED : NOT_ENROLLED; 532 g_domain_state = state ? ENROLLED : NOT_ENROLLED;
501 } 533 }
502 534
503 bool IsUser32AndGdi32Available() { 535 bool IsUser32AndGdi32Available() {
504 static auto is_user32_and_gdi32_available = []() { 536 static auto is_user32_and_gdi32_available = []() {
505 // If win32k syscalls aren't disabled, then user32 and gdi32 are available. 537 // If win32k syscalls aren't disabled, then user32 and gdi32 are available.
506 538
507 // Can't disable win32k prior to windows 8. 539 // Can't disable win32k prior to windows 8.
508 if (base::win::GetVersion() < base::win::VERSION_WIN8) 540 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) 634 awareness == PROCESS_PER_MONITOR_DPI_AWARE)
603 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 635 per_monitor_dpi_aware = PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
604 } 636 }
605 } 637 }
606 } 638 }
607 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE; 639 return per_monitor_dpi_aware == PerMonitorDpiAware::PER_MONITOR_DPI_AWARE;
608 } 640 }
609 641
610 } // namespace win 642 } // namespace win
611 } // namespace base 643 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698