106
__in LPCWSTR wzPath
107
);
108
static HRESULT CopyEngineToWorkingFolder(
109
+ __in BOOL fElevated,
110
__in BURN_CACHE* pCache,
111
__in_z LPCWSTR wzSourcePath,
112
__in_z LPCWSTR wzWorkingFolderName,
331
}
332
333
extern "C" HRESULT CacheEnsureBaseWorkingFolder(
334
+ __in BOOL fElevated,
335
__in BURN_CACHE* pCache,
336
__deref_out_z_opt LPWSTR* psczBaseWorkingFolder
337
)
340
341
HRESULT hr = S_OK;
342
LPWSTR sczPotential = NULL;
343
+ PSECURITY_DESCRIPTOR psd = NULL;
344
+ LPSECURITY_ATTRIBUTES pWorkingFolderAcl = NULL;
345
346
if (!pCache->fInitializedBaseWorkingFolder)
347
{
348
+ // If elevated, allocate the pWorkingFolderAcl to protect the working folder to only SYSTEM and Admins.
349
+ if (fElevated)
350
+ {
351
+ LPCWSTR wzSddl = L"D:PAI(A;;FA;;;BA)(A;OICIIO;GA;;;BA)(A;;FA;;;SY)(A;OICIIO;GA;;;SY)";
352
+ if (!::ConvertStringSecurityDescriptorToSecurityDescriptorW(wzSddl, SDDL_REVISION_1, &psd, NULL))
353
+ {
354
+ ExitWithLastError(hr, "Failed to create the security descriptor for the working folder.");
355
+ }
356
+
357
+ pWorkingFolderAcl = reinterpret_cast<LPSECURITY_ATTRIBUTES>(MemAlloc(sizeof(SECURITY_ATTRIBUTES), TRUE));
358
+ pWorkingFolderAcl->nLength = sizeof(SECURITY_ATTRIBUTES);
359
+ pWorkingFolderAcl->lpSecurityDescriptor = psd;
360
+ pWorkingFolderAcl->bInheritHandle = FALSE;
361
+ }
362
+
363
for (DWORD i = 0; i < pCache->cPotentialBaseWorkingFolders; ++i)
364
{
365
hr = PathConcatRelativeToFullyQualifiedBase(pCache->rgsczPotentialBaseWorkingFolders[i], pCache->wzGuid, &sczPotential);
366
if (SUCCEEDED(hr))
367
{
349
- hr = DirEnsureExists(sczPotential, NULL);
368
+ hr = DirEnsureExists(sczPotential, pWorkingFolderAcl);
369
if (SUCCEEDED(hr))
370
{
371
pCache->sczBaseWorkingFolder = sczPotential;
392
}
393
394
LExit:
395
+ ReleaseMem(pWorkingFolderAcl);
396
+ if (psd)
397
+ {
398
+ ::LocalFree(psd);
399
+ }
400
ReleaseStr(sczPotential);
401
402
return hr;
912
}
913
914
extern "C" HRESULT CacheBundleToWorkingDirectory(
915
+ __in BOOL fElevated,
916
__in BURN_CACHE* pCache,
917
__in_z LPCWSTR wzExecutableName,
918
__in BURN_SECTION* pSection,
937
}
938
else // otherwise, carry on putting the bundle in the working folder.
939
{
915
- hr = CopyEngineToWorkingFolder(pCache, sczSourcePath, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczEngineWorkingPath);
940
+ hr = CopyEngineToWorkingFolder(fElevated, pCache, sczSourcePath, BUNDLE_WORKING_FOLDER_NAME, wzExecutableName, pSection, psczEngineWorkingPath);
941
ExitOnFailure(hr, "Failed to copy engine to working folder.");
942
}
943
2088
2089
2090
static HRESULT CopyEngineToWorkingFolder(
2091
+ __in BOOL fElevated,
2092
__in BURN_CACHE* pCache,
2093
__in_z LPCWSTR wzSourcePath,
2094
__in_z LPCWSTR wzWorkingFolderName,
2105
LPWSTR sczPayloadSourcePath = NULL;
2106
LPWSTR sczPayloadTargetPath = NULL;
2107
2082
- hr = CacheEnsureBaseWorkingFolder(pCache, &sczWorkingFolder);
2108
+ hr = CacheEnsureBaseWorkingFolder(fElevated, pCache, &sczWorkingFolder);
2109
ExitOnFailure(hr, "Failed to create working path to copy engine.");
2110
2111
hr = PathConcatRelativeToFullyQualifiedBase(sczWorkingFolder, wzWorkingFolderName, &sczTargetDirectory);