Skip to content

Commit

Permalink
[windows] Switch from ATL to base::win::SecurityDescriptor
Browse files Browse the repository at this point in the history
Bug: 5027
Change-Id: Ie8aa612bf5c0ef9ad08760be8c1a5c1596ebfaa7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4790201
Reviewed-by: Will Harris <[email protected]>
Commit-Queue: Greg Thompson <[email protected]>
Auto-Submit: Greg Thompson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1186314}
  • Loading branch information
GregTho authored and Chromium LUCI CQ committed Aug 22, 2023
1 parent 5cee16a commit ca0a44e
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions chrome/installer/util/delete_reg_key_work_item_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

#include "chrome/installer/util/delete_reg_key_work_item.h"

#include <windows.h>

#include <atlsecurity.h> // NOLINT
#include <stddef.h>
#include <windows.h>

#include <memory>

#include "base/logging.h"
#include "base/win/registry.h"
#include "base/win/security_descriptor.h"
#include "chrome/installer/util/registry_test_data.h"
#include "chrome/installer/util/work_item.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -103,17 +102,21 @@ TEST_F(DeleteRegKeyWorkItemTest, DISABLED_TestUndeletableKey) {
EXPECT_EQ(ERROR_SUCCESS,
subkey2.Create(subkey.Handle(), L"Subkey2", KEY_WRITE | WRITE_DAC));
EXPECT_EQ(ERROR_SUCCESS, subkey2.WriteValue(L"", 2U));
CSecurityDesc sec_desc;
sec_desc.FromString(L"D:PAI(A;OICI;KR;;;BU)"); // builtin users read
EXPECT_EQ(ERROR_SUCCESS,
RegSetKeySecurity(subkey.Handle(), DACL_SECURITY_INFORMATION,
const_cast<SECURITY_DESCRIPTOR*>(
sec_desc.GetPSECURITY_DESCRIPTOR())));
sec_desc.FromString(L"D:PAI(A;OICI;KA;;;BU)"); // builtin users all access
// builtin users read.
auto sd = base::win::SecurityDescriptor::FromSddl(L"D:PAI(A;OICI;KR;;;BU)");
ASSERT_TRUE(sd.has_value());
SECURITY_DESCRIPTOR sec_desc;
sd->ToAbsolute(sec_desc);
EXPECT_EQ(
ERROR_SUCCESS,
RegSetKeySecurity(subkey.Handle(), DACL_SECURITY_INFORMATION, &sec_desc));
// builtin users all access.
sd = base::win::SecurityDescriptor::FromSddl(L"D:PAI(A;OICI;KA;;;BU)");
ASSERT_TRUE(sd.has_value());
sd->ToAbsolute(sec_desc);
EXPECT_EQ(ERROR_SUCCESS,
RegSetKeySecurity(subkey2.Handle(), DACL_SECURITY_INFORMATION,
const_cast<SECURITY_DESCRIPTOR*>(
sec_desc.GetPSECURITY_DESCRIPTOR())));
&sec_desc));
subkey2.Close();
subkey.Close();
key.Close();
Expand All @@ -135,10 +138,9 @@ TEST_F(DeleteRegKeyWorkItemTest, DISABLED_TestUndeletableKey) {
EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"SomeValue", &dw_value));
EXPECT_EQ(1U, dw_value);
// Give users all access to the subkey so it can be deleted.
EXPECT_EQ(ERROR_SUCCESS,
RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION,
const_cast<SECURITY_DESCRIPTOR*>(
sec_desc.GetPSECURITY_DESCRIPTOR())));
EXPECT_EQ(
ERROR_SUCCESS,
RegSetKeySecurity(key.Handle(), DACL_SECURITY_INFORMATION, &sec_desc));
EXPECT_EQ(ERROR_SUCCESS, key.OpenKey(L"Subkey2", KEY_QUERY_VALUE));
EXPECT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"", &dw_value));
EXPECT_EQ(2U, dw_value);
Expand Down

0 comments on commit ca0a44e

Please sign in to comment.