OLD | NEW |
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 // This file contains the definitions of the installer functions that build | 5 // This file contains the definitions of the installer functions that build |
6 // the WorkItemList used to install the application. | 6 // the WorkItemList used to install the application. |
7 | 7 |
8 #include "chrome/installer/setup/install_worker.h" | 8 #include "chrome/installer/setup/install_worker.h" |
9 | 9 |
| 10 #include <windows.h> // NOLINT |
| 11 #include <atlsecurity.h> |
10 #include <oaidl.h> | 12 #include <oaidl.h> |
11 #include <shlobj.h> | 13 #include <shlobj.h> |
12 #include <stddef.h> | 14 #include <stddef.h> |
13 #include <stdint.h> | 15 #include <stdint.h> |
14 #include <time.h> | 16 #include <time.h> |
15 | 17 |
16 #include <memory> | 18 #include <memory> |
17 #include <vector> | 19 #include <vector> |
18 | 20 |
19 #include "base/bind.h" | 21 #include "base/bind.h" |
20 #include "base/command_line.h" | 22 #include "base/command_line.h" |
21 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
22 #include "base/files/file_util.h" | 24 #include "base/files/file_util.h" |
23 #include "base/logging.h" | 25 #include "base/logging.h" |
24 #include "base/macros.h" | 26 #include "base/macros.h" |
25 #include "base/path_service.h" | 27 #include "base/path_service.h" |
26 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
27 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
28 #include "base/version.h" | 30 #include "base/version.h" |
29 #include "base/win/registry.h" | 31 #include "base/win/registry.h" |
30 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
31 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/installer/setup/app_launcher_installer.h" | 35 #include "chrome/installer/setup/app_launcher_installer.h" |
34 #include "chrome/installer/setup/install.h" | 36 #include "chrome/installer/setup/install.h" |
35 #include "chrome/installer/setup/installer_metrics.h" | 37 #include "chrome/installer/setup/persistent_histogram_storage.h" |
36 #include "chrome/installer/setup/setup_constants.h" | 38 #include "chrome/installer/setup/setup_constants.h" |
37 #include "chrome/installer/setup/setup_util.h" | 39 #include "chrome/installer/setup/setup_util.h" |
38 #include "chrome/installer/setup/update_active_setup_version_work_item.h" | 40 #include "chrome/installer/setup/update_active_setup_version_work_item.h" |
39 #include "chrome/installer/util/app_registration_data.h" | 41 #include "chrome/installer/util/app_registration_data.h" |
40 #include "chrome/installer/util/browser_distribution.h" | 42 #include "chrome/installer/util/browser_distribution.h" |
41 #include "chrome/installer/util/callback_work_item.h" | 43 #include "chrome/installer/util/callback_work_item.h" |
42 #include "chrome/installer/util/conditional_work_item_list.h" | 44 #include "chrome/installer/util/conditional_work_item_list.h" |
43 #include "chrome/installer/util/create_reg_key_work_item.h" | 45 #include "chrome/installer/util/create_reg_key_work_item.h" |
44 #include "chrome/installer/util/firewall_manager_win.h" | 46 #include "chrome/installer/util/firewall_manager_win.h" |
45 #include "chrome/installer/util/google_update_constants.h" | 47 #include "chrome/installer/util/google_update_constants.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 386 |
385 const HKEY root = installer_state.root_key(); | 387 const HKEY root = installer_state.root_key(); |
386 base::string16 delegate_execute_path(L"Software\\Classes\\CLSID\\"); | 388 base::string16 delegate_execute_path(L"Software\\Classes\\CLSID\\"); |
387 delegate_execute_path.append(handler_class_uuid); | 389 delegate_execute_path.append(handler_class_uuid); |
388 // Delete both 64 and 32 keys to handle 32->64 or 64->32 migration. | 390 // Delete both 64 and 32 keys to handle 32->64 or 64->32 migration. |
389 list->AddDeleteRegKeyWorkItem(root, delegate_execute_path, KEY_WOW64_32KEY); | 391 list->AddDeleteRegKeyWorkItem(root, delegate_execute_path, KEY_WOW64_32KEY); |
390 list->AddDeleteRegKeyWorkItem(root, delegate_execute_path, KEY_WOW64_64KEY); | 392 list->AddDeleteRegKeyWorkItem(root, delegate_execute_path, KEY_WOW64_64KEY); |
391 } | 393 } |
392 } | 394 } |
393 | 395 |
| 396 // Add to the ACL of an object on disk. This follows the method from MSDN: |
| 397 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa379283.aspx |
| 398 // This is done using explicit flags rather than the "security string" format |
| 399 // because strings do not necessarily read what is written which makes it |
| 400 // difficult to de-dup. Working with the binary format is always exact and the |
| 401 // system libraries will properly ignore duplicate ACL entries. |
| 402 bool AddAclToPath(const base::FilePath& path, |
| 403 const CSid& trustee, |
| 404 ACCESS_MASK access_mask, |
| 405 BYTE ace_flags) { |
| 406 DCHECK(!path.empty()); |
| 407 DCHECK(trustee); |
| 408 |
| 409 // Get the existing DACL. |
| 410 ATL::CDacl dacl; |
| 411 if (!ATL::AtlGetDacl(path.value().c_str(), SE_FILE_OBJECT, &dacl)) { |
| 412 DPLOG(ERROR) << "Failed getting DACL for path \"" << path.value() << "\""; |
| 413 return false; |
| 414 } |
| 415 |
| 416 // Check if the requested access already exists and return if so. |
| 417 for (UINT i = 0; i < dacl.GetAceCount(); ++i) { |
| 418 ATL::CSid sid; |
| 419 ACCESS_MASK mask = 0; |
| 420 BYTE type = 0; |
| 421 BYTE flags = 0; |
| 422 dacl.GetAclEntry(i, &sid, &mask, &type, &flags); |
| 423 if (sid == trustee && type == ACCESS_ALLOWED_ACE_TYPE && |
| 424 (flags & ace_flags) == ace_flags && |
| 425 (mask & access_mask) == access_mask) { |
| 426 return true; |
| 427 } |
| 428 } |
| 429 |
| 430 // Add the new access to the DACL. |
| 431 if (!dacl.AddAllowedAce(trustee, access_mask, ace_flags)) { |
| 432 DPLOG(ERROR) << "Failed adding ACE to DACL"; |
| 433 return false; |
| 434 } |
| 435 |
| 436 // Attach the updated ACL as the object's DACL. |
| 437 if (!ATL::AtlSetDacl(path.value().c_str(), SE_FILE_OBJECT, dacl)) { |
| 438 DPLOG(ERROR) << "Failed setting DACL for path \"" << path.value() << "\""; |
| 439 return false; |
| 440 } |
| 441 |
| 442 return true; |
| 443 } |
| 444 |
394 } // namespace | 445 } // namespace |
395 | 446 |
396 // This method adds work items to create (or update) Chrome uninstall entry in | 447 // This method adds work items to create (or update) Chrome uninstall entry in |
397 // either the Control Panel->Add/Remove Programs list or in the Omaha client | 448 // either the Control Panel->Add/Remove Programs list or in the Omaha client |
398 // state key if running under an MSI installer. | 449 // state key if running under an MSI installer. |
399 void AddUninstallShortcutWorkItems(const InstallerState& installer_state, | 450 void AddUninstallShortcutWorkItems(const InstallerState& installer_state, |
400 const base::FilePath& setup_path, | 451 const base::FilePath& setup_path, |
401 const base::Version& new_version, | 452 const base::Version& new_version, |
402 const Product& product, | 453 const Product& product, |
403 WorkItemList* install_list) { | 454 WorkItemList* install_list) { |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 WorkItemList* install_list) { | 1085 WorkItemList* install_list) { |
1035 DCHECK(install_list); | 1086 DCHECK(install_list); |
1036 | 1087 |
1037 const base::FilePath& target_path = installer_state.target_path(); | 1088 const base::FilePath& target_path = installer_state.target_path(); |
1038 | 1089 |
1039 // A temp directory that work items need and the actual install directory. | 1090 // A temp directory that work items need and the actual install directory. |
1040 install_list->AddCreateDirWorkItem(temp_path); | 1091 install_list->AddCreateDirWorkItem(temp_path); |
1041 install_list->AddCreateDirWorkItem(target_path); | 1092 install_list->AddCreateDirWorkItem(target_path); |
1042 | 1093 |
1043 // Create the directory in which persistent metrics will be stored. | 1094 // Create the directory in which persistent metrics will be stored. |
1044 install_list->AddCreateDirWorkItem( | 1095 const base::FilePath histogram_storage_dir( |
1045 GetPersistentHistogramStorageDir(target_path)); | 1096 PersistentHistogramStorage::GetReportedStorageDir(target_path)); |
| 1097 install_list->AddCreateDirWorkItem(histogram_storage_dir); |
| 1098 |
| 1099 if (installer_state.system_install()) { |
| 1100 WorkItem* add_acl_to_histogram_storage_dir_work_item = |
| 1101 install_list->AddCallbackWorkItem(base::Bind( |
| 1102 [](const base::FilePath& histogram_storage_dir, |
| 1103 const CallbackWorkItem& work_item) { |
| 1104 DCHECK(!work_item.IsRollback()); |
| 1105 return AddAclToPath(histogram_storage_dir, |
| 1106 ATL::Sids::AuthenticatedUser(), |
| 1107 FILE_GENERIC_READ | FILE_DELETE_CHILD, |
| 1108 CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE); |
| 1109 }, |
| 1110 histogram_storage_dir)); |
| 1111 add_acl_to_histogram_storage_dir_work_item->set_best_effort(true); |
| 1112 add_acl_to_histogram_storage_dir_work_item->set_rollback_enabled(false); |
| 1113 } |
1046 | 1114 |
1047 if (installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER) || | 1115 if (installer_state.FindProduct(BrowserDistribution::CHROME_BROWSER) || |
1048 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES)) { | 1116 installer_state.FindProduct(BrowserDistribution::CHROME_BINARIES)) { |
1049 AddChromeWorkItems(original_state, | 1117 AddChromeWorkItems(original_state, |
1050 installer_state, | 1118 installer_state, |
1051 setup_path, | 1119 setup_path, |
1052 archive_path, | 1120 archive_path, |
1053 src_path, | 1121 src_path, |
1054 temp_path, | 1122 temp_path, |
1055 current_version, | 1123 current_version, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1345 // Unconditionally remove the legacy Quick Enable command from the binaries. | 1413 // Unconditionally remove the legacy Quick Enable command from the binaries. |
1346 // Do this even if multi-install Chrome isn't installed to ensure that it is | 1414 // Do this even if multi-install Chrome isn't installed to ensure that it is |
1347 // not left behind in any case. | 1415 // not left behind in any case. |
1348 work_item_list->AddDeleteRegKeyWorkItem( | 1416 work_item_list->AddDeleteRegKeyWorkItem( |
1349 installer_state.root_key(), cmd_key, KEY_WOW64_32KEY) | 1417 installer_state.root_key(), cmd_key, KEY_WOW64_32KEY) |
1350 ->set_log_message("removing " + base::UTF16ToASCII(kCmdQuickEnableCf) + | 1418 ->set_log_message("removing " + base::UTF16ToASCII(kCmdQuickEnableCf) + |
1351 " command"); | 1419 " command"); |
1352 } | 1420 } |
1353 | 1421 |
1354 } // namespace installer | 1422 } // namespace installer |
OLD | NEW |