|
4 | 4 | #include "../win/HrError.h" |
5 | 5 | #include "../str/String.h" |
6 | 6 | #include "../Exception.h" |
| 7 | +#include "../Memory.h" |
7 | 8 | #include <fstream> |
8 | 9 | #include <random> |
9 | 10 | #include <format> |
@@ -143,22 +144,18 @@ namespace pmon::util::file |
143 | 144 | BuildExplicitAccessWithNameA(&ea[2], (LPSTR)"Authenticated Users", |
144 | 145 | modifyMask, SET_ACCESS, NO_INHERITANCE); |
145 | 146 |
|
146 | | - PACL newDacl = nullptr; |
147 | | - DWORD dwRes = SetEntriesInAclA(3, ea, nullptr, &newDacl); |
148 | | - if (dwRes != ERROR_SUCCESS) { |
149 | | - throw Except<win::HrError>(dwRes, "SetEntriesInAcl failed"); |
| 147 | + UniqueLocalPtr<ACL> pNewDacl; |
| 148 | + if (auto res = SetEntriesInAclA(3, ea, nullptr, OutPtr(pNewDacl)); res != ERROR_SUCCESS) { |
| 149 | + throw Except<win::HrError>(HRESULT(res), "SetEntriesInAcl failed"); |
150 | 150 | } |
151 | 151 |
|
152 | | - dwRes = SetNamedSecurityInfoA( |
| 152 | + if (auto res = SetNamedSecurityInfoA( |
153 | 153 | (LPSTR)path_.string().c_str(), |
154 | 154 | SE_FILE_OBJECT, |
155 | 155 | DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, |
156 | | - nullptr, nullptr, newDacl, nullptr); |
157 | | - |
158 | | - LocalFree(newDacl); |
159 | | - |
160 | | - if (dwRes != ERROR_SUCCESS) { |
161 | | - throw Except<win::HrError>(dwRes, "SetNamedSecurityInfo failed"); |
| 156 | + nullptr, nullptr, pNewDacl.get(), nullptr); |
| 157 | + res != ERROR_SUCCESS) { |
| 158 | + throw Except<win::HrError>(HRESULT(res), "SetNamedSecurityInfo failed"); |
162 | 159 | } |
163 | 160 |
|
164 | 161 | return *this; |
|
0 commit comments