From 8cfd711f775e8501836162538998b5b6d8efbf89 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 11 Jan 2024 00:00:27 -0800 Subject: [PATCH] Update Burn to use pipeutil for low-level pipe operations --- src/burn/engine/burnpipe.cpp | 317 +++---------------- src/burn/engine/burnpipe.h | 11 +- src/burn/engine/elevation.cpp | 54 ++-- src/burn/engine/embedded.cpp | 10 +- src/burn/engine/externalengine.cpp | 4 +- src/burn/engine/precomp.h | 1 + src/burn/test/BurnUnitTest/ElevationTest.cpp | 16 +- src/burn/test/BurnUnitTest/precomp.h | 1 + 8 files changed, 86 insertions(+), 328 deletions(-) diff --git a/src/burn/engine/burnpipe.cpp b/src/burn/engine/burnpipe.cpp index 5003622c3..297dc77a4 100644 --- a/src/burn/engine/burnpipe.cpp +++ b/src/burn/engine/burnpipe.cpp @@ -2,34 +2,9 @@ #include "precomp.h" -static const DWORD PIPE_64KB = 64 * 1024; -static const DWORD PIPE_WAIT_FOR_CONNECTION = 100; // wait a 10th of a second, -static const DWORD PIPE_RETRY_FOR_CONNECTION = 1800; // for up to 3 minutes. +static const LPCWSTR CACHE_PIPE_NAME_FORMAT_STRING = L"%ls.Cache"; +static const LPCWSTR LOGGING_PIPE_NAME_FORMAT_STRING = L"%ls.Log"; -static const LPCWSTR PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls"; -static const LPCWSTR CACHE_PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls.Cache"; -static const LPCWSTR LOGGING_PIPE_NAME_FORMAT_STRING = L"\\\\.\\pipe\\%ls.Log"; - -static HRESULT AllocatePipeMessage( - __in DWORD dwMessage, - __in_bcount_opt(cbData) LPVOID pvData, - __in SIZE_T cbData, - __out_bcount(cb) LPVOID* ppvMessage, - __out SIZE_T* pcbMessage - ); -static void FreePipeMessage( - __in BURN_PIPE_MESSAGE *pMsg - ); -static HRESULT WritePipeMessage( - __in HANDLE hPipe, - __in DWORD dwMessage, - __in_bcount_opt(cbData) LPVOID pvData, - __in SIZE_T cbData - ); -static HRESULT GetPipeMessage( - __in HANDLE hPipe, - __in BURN_PIPE_MESSAGE* pMsg - ); static HRESULT ChildPipeConnected( __in HANDLE hPipe, __in_z LPCWSTR wzSecret, @@ -37,7 +12,6 @@ static HRESULT ChildPipeConnected( ); - /******************************************************************* PipeConnectionInitialize - initialize pipe connection data. @@ -60,9 +34,9 @@ void PipeConnectionUninitialize( __in BURN_PIPE_CONNECTION* pConnection ) { - ReleaseFileHandle(pConnection->hLoggingPipe); - ReleaseFileHandle(pConnection->hCachePipe); - ReleaseFileHandle(pConnection->hPipe); + ReleasePipeHandle(pConnection->hLoggingPipe); + ReleasePipeHandle(pConnection->hCachePipe); + ReleasePipeHandle(pConnection->hPipe); ReleaseHandle(pConnection->hProcess); ReleaseStr(pConnection->sczSecret); ReleaseStr(pConnection->sczName); @@ -71,7 +45,7 @@ void PipeConnectionUninitialize( } /******************************************************************* - PipeSendMessage - + PipeSendMessage - *******************************************************************/ extern "C" HRESULT PipeSendMessage( @@ -87,7 +61,7 @@ extern "C" HRESULT PipeSendMessage( HRESULT hr = S_OK; BURN_PIPE_RESULT result = { }; - hr = WritePipeMessage(hPipe, dwMessage, pvData, cbData); + hr = PipeWriteMessage(hPipe, dwMessage, pvData, cbData); ExitOnFailure(hr, "Failed to write send message to pipe."); hr = PipePumpMessages(hPipe, pfnCallback, pvContext, &result); @@ -100,7 +74,7 @@ extern "C" HRESULT PipeSendMessage( } /******************************************************************* - PipePumpMessages - + PipePumpMessages - *******************************************************************/ extern "C" HRESULT PipePumpMessages( @@ -111,15 +85,15 @@ extern "C" HRESULT PipePumpMessages( ) { HRESULT hr = S_OK; - BURN_PIPE_MESSAGE msg = { }; + PIPE_MESSAGE msg = { }; SIZE_T iData = 0; LPSTR sczMessage = NULL; DWORD dwResult = 0; // Pump messages from child process. - while (S_OK == (hr = GetPipeMessage(hPipe, &msg))) + while (S_OK == (hr = PipeReadMessage(hPipe, &msg))) { - switch (msg.dwMessage) + switch (msg.dwMessageType) { case BURN_PIPE_MESSAGE_TYPE_LOG: iData = 0; @@ -166,15 +140,15 @@ extern "C" HRESULT PipePumpMessages( { hr = E_INVALIDARG; } - ExitOnFailure(hr, "Failed to process message: %u", msg.dwMessage); + ExitOnFailure(hr, "Failed to process message: %u", msg.dwMessageType); break; } // post result - hr = WritePipeMessage(hPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_COMPLETE), &dwResult, sizeof(dwResult)); + hr = PipeWriteMessage(hPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_COMPLETE), &dwResult, sizeof(dwResult)); ExitOnFailure(hr, "Failed to post result to child process."); - FreePipeMessage(&msg); + ReleasePipeMessage(&msg); } ExitOnFailure(hr, "Failed to get message over pipe"); @@ -185,13 +159,13 @@ extern "C" HRESULT PipePumpMessages( LExit: ReleaseStr(sczMessage); - FreePipeMessage(&msg); + ReleasePipeMessage(&msg); return hr; } /******************************************************************* - PipeCreateNameAndSecret - + PipeCreateNameAndSecret - *******************************************************************/ extern "C" HRESULT PipeCreateNameAndSecret( @@ -247,7 +221,7 @@ extern "C" HRESULT PipeCreatePipes( HRESULT hr = S_OK; PSECURITY_DESCRIPTOR psd = NULL; SECURITY_ATTRIBUTES sa = { }; - LPWSTR sczFullPipeName = NULL; + LPWSTR sczPipeName = NULL; HANDLE hPipe = INVALID_HANDLE_VALUE; HANDLE hCachePipe = INVALID_HANDLE_VALUE; HANDLE hLoggingPipe = INVALID_HANDLE_VALUE; @@ -269,37 +243,24 @@ extern "C" HRESULT PipeCreatePipes( } // Create the pipe. - hr = StrAllocFormatted(&sczFullPipeName, PIPE_NAME_FORMAT_STRING, pConnection->sczName); - ExitOnFailure(hr, "Failed to allocate full name of pipe: %ls", pConnection->sczName); - - // TODO: consider using overlapped IO to do waits on the pipe and still be able to cancel and such. - hPipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, psd ? &sa : NULL); - if (INVALID_HANDLE_VALUE == hPipe) - { - ExitWithLastError(hr, "Failed to create pipe: %ls", sczFullPipeName); - } + hr = PipeCreate(pConnection->sczName, psd ? &sa : NULL, &hPipe); + ExitOnFailure(hr, "Failed to create pipe: %ls", pConnection->sczName); if (fCompanion) { // Create the cache pipe. - hr = StrAllocFormatted(&sczFullPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName); + hr = StrAllocFormatted(&sczPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName); ExitOnFailure(hr, "Failed to allocate full name of cache pipe: %ls", pConnection->sczName); - hCachePipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, NULL); - if (INVALID_HANDLE_VALUE == hCachePipe) - { - ExitWithLastError(hr, "Failed to create cache pipe: %ls", sczFullPipeName); - } + hr = PipeCreate(sczPipeName, NULL, &hCachePipe); + ExitOnFailure(hr, "Failed to create cache pipe: %ls", sczPipeName); // Create the logging pipe. - hr = StrAllocFormatted(&sczFullPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName); + hr = StrAllocFormatted(&sczPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName); ExitOnFailure(hr, "Failed to allocate full name of logging pipe: %ls", pConnection->sczName); - hLoggingPipe = ::CreateNamedPipeW(sczFullPipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, PIPE_64KB, PIPE_64KB, 1, NULL); - if (INVALID_HANDLE_VALUE == hLoggingPipe) - { - ExitWithLastError(hr, "Failed to create logging pipe: %ls", sczFullPipeName); - } + hr = PipeCreate(sczPipeName, NULL, &hLoggingPipe); + ExitOnFailure(hr, "Failed to create logging pipe: %ls", sczPipeName); } pConnection->hLoggingPipe = hLoggingPipe; @@ -312,10 +273,10 @@ extern "C" HRESULT PipeCreatePipes( hPipe = INVALID_HANDLE_VALUE; LExit: - ReleaseFileHandle(hLoggingPipe); - ReleaseFileHandle(hCachePipe); - ReleaseFileHandle(hPipe); - ReleaseStr(sczFullPipeName); + ReleasePipeHandle(hLoggingPipe); + ReleasePipeHandle(hCachePipe); + ReleasePipeHandle(hPipe); + ReleaseStr(sczPipeName); if (psd) { @@ -326,7 +287,7 @@ extern "C" HRESULT PipeCreatePipes( } /******************************************************************* - PipeWaitForChildConnect - + PipeWaitForChildConnect - *******************************************************************/ extern "C" HRESULT PipeWaitForChildConnect( @@ -343,58 +304,10 @@ extern "C" HRESULT PipeWaitForChildConnect( for (DWORD i = 0; i < countof(hPipes) && INVALID_HANDLE_VALUE != hPipes[i]; ++i) { HANDLE hPipe = hPipes[i]; - DWORD dwPipeState = PIPE_READMODE_BYTE | PIPE_NOWAIT; - // Temporarily make the pipe non-blocking so we will not get stuck in ::ConnectNamedPipe() forever - // if the child decides not to show up. - if (!::SetNamedPipeHandleState(hPipe, &dwPipeState, NULL, NULL)) - { - ExitWithLastError(hr, "Failed to set pipe to non-blocking."); - } - - // Loop for a while waiting for a connection from child process. - DWORD cRetry = 0; - do - { - if (!::ConnectNamedPipe(hPipe, NULL)) - { - DWORD er = ::GetLastError(); - if (ERROR_PIPE_CONNECTED == er) - { - hr = S_OK; - break; - } - else if (ERROR_PIPE_LISTENING == er) - { - if (cRetry < PIPE_RETRY_FOR_CONNECTION) - { - hr = HRESULT_FROM_WIN32(er); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); - break; - } - - ++cRetry; - ::Sleep(PIPE_WAIT_FOR_CONNECTION); - } - else - { - hr = HRESULT_FROM_WIN32(er); - break; - } - } - } while (HRESULT_FROM_WIN32(ERROR_PIPE_LISTENING) == hr); + hr = PipeServerWaitForClientConnect(hPipe); ExitOnRootFailure(hr, "Failed to wait for child to connect to pipe."); - // Put the pipe back in blocking mode. - dwPipeState = PIPE_READMODE_BYTE | PIPE_WAIT; - if (!::SetNamedPipeHandleState(hPipe, &dwPipeState, NULL, NULL)) - { - ExitWithLastError(hr, "Failed to reset pipe to blocking."); - } - // Prove we are the one that created the elevated process by passing the secret. hr = FileWriteHandle(hPipe, reinterpret_cast(&cbSecret), sizeof(cbSecret)); ExitOnFailure(hr, "Failed to write secret length to pipe."); @@ -422,7 +335,7 @@ extern "C" HRESULT PipeWaitForChildConnect( } /******************************************************************* - PipeTerminateLoggingPipe - + PipeTerminateLoggingPipe - *******************************************************************/ extern "C" HRESULT PipeTerminateLoggingPipe( @@ -438,7 +351,7 @@ extern "C" HRESULT PipeTerminateLoggingPipe( hr = BuffWriteNumber(&pbData, &cbData, dwParentExitCode); ExitOnFailure(hr, "Failed to write exit code to message buffer."); - hr = WritePipeMessage(hLoggingPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_COMPLETE), pbData, cbData); + hr = PipeWriteMessage(hLoggingPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_COMPLETE), pbData, cbData); ExitOnFailure(hr, "Failed to post complete message to logging pipe."); LExit: @@ -448,7 +361,7 @@ extern "C" HRESULT PipeTerminateLoggingPipe( } /******************************************************************* - PipeTerminateChildProcess - + PipeTerminateChildProcess - *******************************************************************/ extern "C" HRESULT PipeTerminateChildProcess( @@ -472,11 +385,11 @@ extern "C" HRESULT PipeTerminateChildProcess( // Send the messages. if (INVALID_HANDLE_VALUE != pConnection->hCachePipe) { - hr = WritePipeMessage(pConnection->hCachePipe, static_cast(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData); + hr = PipeWriteMessage(pConnection->hCachePipe, static_cast(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData); ExitOnFailure(hr, "Failed to post terminate message to child process cache thread."); } - hr = WritePipeMessage(pConnection->hPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData); + hr = PipeWriteMessage(pConnection->hPipe, static_cast(BURN_PIPE_MESSAGE_TYPE_TERMINATE), pbData, cbData); ExitOnFailure(hr, "Failed to post terminate message to child process."); // If we were able to get a handle to the other process, wait for it to exit. @@ -532,28 +445,7 @@ extern "C" HRESULT PipeChildConnect( LPWSTR sczPipeName = NULL; // Try to connect to the parent. - hr = StrAllocFormatted(&sczPipeName, PIPE_NAME_FORMAT_STRING, pConnection->sczName); - ExitOnFailure(hr, "Failed to allocate name of parent pipe."); - - hr = E_UNEXPECTED; - for (DWORD cRetry = 0; FAILED(hr) && cRetry < PIPE_RETRY_FOR_CONNECTION; ++cRetry) - { - pConnection->hPipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (INVALID_HANDLE_VALUE == pConnection->hPipe) - { - hr = HRESULT_FROM_WIN32(::GetLastError()); - if (E_FILENOTFOUND == hr) // if the pipe isn't created, call it a timeout waiting on the parent. - { - hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); - } - - ::Sleep(PIPE_WAIT_FOR_CONNECTION); - } - else // we have a connection, go with it. - { - hr = S_OK; - } - } + hr = PipeClientConnect(pConnection->sczName, &pConnection->hPipe); ExitOnRootFailure(hr, "Failed to open parent pipe: %ls", sczPipeName) // Verify the parent and notify it that the child connected. @@ -566,11 +458,8 @@ extern "C" HRESULT PipeChildConnect( hr = StrAllocFormatted(&sczPipeName, CACHE_PIPE_NAME_FORMAT_STRING, pConnection->sczName); ExitOnFailure(hr, "Failed to allocate name of parent cache pipe."); - pConnection->hCachePipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (INVALID_HANDLE_VALUE == pConnection->hCachePipe) - { - ExitWithLastError(hr, "Failed to open parent cache pipe: %ls", sczPipeName) - } + hr = PipeClientConnect(sczPipeName, &pConnection->hCachePipe); + ExitOnFailure(hr, "Failed to open parent cache pipe: %ls", sczPipeName) // Verify the parent and notify it that the child connected. hr = ChildPipeConnected(pConnection->hCachePipe, pConnection->sczSecret, &pConnection->dwProcessId); @@ -580,11 +469,8 @@ extern "C" HRESULT PipeChildConnect( hr = StrAllocFormatted(&sczPipeName, LOGGING_PIPE_NAME_FORMAT_STRING, pConnection->sczName); ExitOnFailure(hr, "Failed to allocate name of parent logging pipe."); - pConnection->hLoggingPipe = ::CreateFileW(sczPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); - if (INVALID_HANDLE_VALUE == pConnection->hLoggingPipe) - { - ExitWithLastError(hr, "Failed to open parent logging pipe: %ls", sczPipeName) - } + hr = PipeClientConnect(sczPipeName, &pConnection->hLoggingPipe); + ExitOnFailure(hr, "Failed to open parent cache pipe: %ls", sczPipeName) // Verify the parent and notify it that the child connected. hr = ChildPipeConnected(pConnection->hLoggingPipe, pConnection->sczSecret, &pConnection->dwProcessId); @@ -600,127 +486,6 @@ extern "C" HRESULT PipeChildConnect( return hr; } - -static HRESULT AllocatePipeMessage( - __in DWORD dwMessage, - __in_bcount_opt(cbData) LPVOID pvData, - __in SIZE_T cbData, - __out_bcount(cb) LPVOID* ppvMessage, - __out SIZE_T* pcbMessage - ) -{ - HRESULT hr = S_OK; - LPVOID pv = NULL; - size_t cb = 0; - DWORD dwcbData = 0; - - // If no data was provided, ensure the count of bytes is zero. - if (!pvData) - { - cbData = 0; - } - else if (MAXDWORD < cbData) - { - ExitWithRootFailure(hr, E_INVALIDDATA, "Pipe message is too large."); - } - - hr = ::SizeTAdd(sizeof(dwMessage) + sizeof(dwcbData), cbData, &cb); - ExitOnRootFailure(hr, "Failed to calculate total pipe message size"); - - dwcbData = (DWORD)cbData; - - // Allocate the message. - pv = MemAlloc(cb, FALSE); - ExitOnNull(pv, hr, E_OUTOFMEMORY, "Failed to allocate memory for message."); - - memcpy_s(pv, cb, &dwMessage, sizeof(dwMessage)); - memcpy_s(static_cast(pv) + sizeof(dwMessage), cb - sizeof(dwMessage), &dwcbData, sizeof(dwcbData)); - if (dwcbData) - { - memcpy_s(static_cast(pv) + sizeof(dwMessage) + sizeof(dwcbData), cb - sizeof(dwMessage) - sizeof(dwcbData), pvData, dwcbData); - } - - *pcbMessage = cb; - *ppvMessage = pv; - pv = NULL; - -LExit: - ReleaseMem(pv); - return hr; -} - -static void FreePipeMessage( - __in BURN_PIPE_MESSAGE *pMsg - ) -{ - if (pMsg->fAllocatedData) - { - ReleaseNullMem(pMsg->pvData); - pMsg->fAllocatedData = FALSE; - } -} - -static HRESULT WritePipeMessage( - __in HANDLE hPipe, - __in DWORD dwMessage, - __in_bcount_opt(cbData) LPVOID pvData, - __in SIZE_T cbData - ) -{ - HRESULT hr = S_OK; - LPVOID pv = NULL; - SIZE_T cb = 0; - - hr = AllocatePipeMessage(dwMessage, pvData, cbData, &pv, &cb); - ExitOnFailure(hr, "Failed to allocate message to write."); - - // Write the message. - hr = FileWriteHandle(hPipe, reinterpret_cast(pv), cb); - ExitOnFailure(hr, "Failed to write message type to pipe."); - -LExit: - ReleaseMem(pv); - return hr; -} - -static HRESULT GetPipeMessage( - __in HANDLE hPipe, - __in BURN_PIPE_MESSAGE* pMsg - ) -{ - HRESULT hr = S_OK; - BYTE pbMessageAndByteCount[sizeof(DWORD) + sizeof(DWORD)] = { }; - - hr = FileReadHandle(hPipe, pbMessageAndByteCount, sizeof(pbMessageAndByteCount)); - if (HRESULT_FROM_WIN32(ERROR_BROKEN_PIPE) == hr) - { - memset(pbMessageAndByteCount, 0, sizeof(pbMessageAndByteCount)); - hr = S_FALSE; - } - ExitOnFailure(hr, "Failed to read message from pipe."); - - pMsg->dwMessage = *(DWORD*)(pbMessageAndByteCount); - pMsg->cbData = *(DWORD*)(pbMessageAndByteCount + sizeof(DWORD)); - if (pMsg->cbData) - { - pMsg->pvData = MemAlloc(pMsg->cbData, FALSE); - ExitOnNull(pMsg->pvData, hr, E_OUTOFMEMORY, "Failed to allocate data for message."); - - hr = FileReadHandle(hPipe, reinterpret_cast(pMsg->pvData), pMsg->cbData); - ExitOnFailure(hr, "Failed to read data for message."); - - pMsg->fAllocatedData = TRUE; - } - -LExit: - if (!pMsg->fAllocatedData && pMsg->pvData) - { - MemFree(pMsg->pvData); - } - - return hr; -} - static HRESULT ChildPipeConnected( __in HANDLE hPipe, __in_z LPCWSTR wzSecret, diff --git a/src/burn/engine/burnpipe.h b/src/burn/engine/burnpipe.h index 6571c0e23..c878ad94b 100644 --- a/src/burn/engine/burnpipe.h +++ b/src/burn/engine/burnpipe.h @@ -25,15 +25,6 @@ typedef enum _BURN_PIPE_MESSAGE_TYPE : DWORD BURN_PIPE_MESSAGE_TYPE_TERMINATE = 0xF0000003, } BURN_PIPE_MESSAGE_TYPE; -typedef struct _BURN_PIPE_MESSAGE -{ - DWORD dwMessage; - DWORD cbData; - - BOOL fAllocatedData; - LPVOID pvData; -} BURN_PIPE_MESSAGE; - typedef struct _BURN_PIPE_RESULT { DWORD dwResult; @@ -42,7 +33,7 @@ typedef struct _BURN_PIPE_RESULT typedef HRESULT (*PFN_PIPE_MESSAGE_CALLBACK)( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); diff --git a/src/burn/engine/elevation.cpp b/src/burn/engine/elevation.cpp index 63a76c2cc..10ae74a44 100644 --- a/src/burn/engine/elevation.cpp +++ b/src/burn/engine/elevation.cpp @@ -129,43 +129,43 @@ static HRESULT WaitForElevatedChildCacheThread( __in DWORD dwExpectedExitCode ); static HRESULT ProcessApplyInitializeMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessBurnCacheMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessGenericExecuteMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessMsiPackageMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessLaunchApprovedExeMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessProgressRoutineMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPPROGRESS_ROUTINE pfnProgress, __in LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessElevatedChildMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessElevatedChildCacheMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); @@ -1739,7 +1739,7 @@ static HRESULT WaitForElevatedChildCacheThread( } static HRESULT ProcessApplyInitializeMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -1752,7 +1752,7 @@ static HRESULT ProcessApplyInitializeMessages( HRESULT hrBA = S_OK; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_APPLY_INITIALIZE_PAUSE_AU_BEGIN: pContext->fPauseCompleteNeeded = TRUE; @@ -1801,7 +1801,7 @@ static HRESULT ProcessApplyInitializeMessages( } static HRESULT ProcessBurnCacheMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPVOID pvContext, __out DWORD* pdwResult ) @@ -1813,7 +1813,7 @@ static HRESULT ProcessBurnCacheMessages( BOOL fProgressRoutine = FALSE; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_BURN_CACHE_BEGIN: // read message parameters @@ -1872,7 +1872,7 @@ static HRESULT ProcessBurnCacheMessages( } static HRESULT ProcessGenericExecuteMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPVOID pvContext, __out DWORD* pdwResult ) @@ -1885,7 +1885,7 @@ static HRESULT ProcessGenericExecuteMessages( LPWSTR* rgwzFiles = NULL; GENERIC_EXECUTE_MESSAGE message = { }; - if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessage) + if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessageType) { hr = ProcessExecuteActionCompleteMessage((BYTE*)pMsg->pvData, pMsg->cbData, &pContext->restart, pdwResult); ExitOnFailure(hr, "Failed to process BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE message."); @@ -1897,7 +1897,7 @@ static HRESULT ProcessGenericExecuteMessages( ExitOnFailure(hr, "Failed to allowed results."); // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_PROGRESS: message.type = GENERIC_EXECUTE_MESSAGE_PROGRESS; @@ -1979,7 +1979,7 @@ static HRESULT ProcessGenericExecuteMessages( } static HRESULT ProcessMsiPackageMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -1993,7 +1993,7 @@ static HRESULT ProcessMsiPackageMessages( LPWSTR sczMessage = NULL; BOOL fRestartManager = FALSE; - if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessage) + if (BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE == pMsg->dwMessageType) { hr = ProcessExecuteActionCompleteMessage((BYTE*)pMsg->pvData, pMsg->cbData, &pContext->restart, pdwResult); ExitOnFailure(hr, "Failed to process BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_ACTION_COMPLETE message."); @@ -2024,7 +2024,7 @@ static HRESULT ProcessMsiPackageMessages( ExitOnFailure(hr, "Failed to read UI flags."); // Process the rest of the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_EXECUTE_PROGRESS: // read message parameters @@ -2093,7 +2093,7 @@ static HRESULT ProcessMsiPackageMessages( } static HRESULT ProcessLaunchApprovedExeMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -2104,7 +2104,7 @@ static HRESULT ProcessLaunchApprovedExeMessages( DWORD dwProcessId = 0; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_LAUNCH_APPROVED_EXE_PROCESSID: // read message parameters @@ -2126,7 +2126,7 @@ static HRESULT ProcessLaunchApprovedExeMessages( } static HRESULT ProcessProgressRoutineMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in LPPROGRESS_ROUTINE pfnProgress, __in LPVOID pvContext, __out DWORD* pdwResult @@ -2156,7 +2156,7 @@ static HRESULT ProcessProgressRoutineMessage( } static HRESULT ProcessElevatedChildMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -2167,7 +2167,7 @@ static HRESULT ProcessElevatedChildMessage( BOOTSTRAPPER_APPLY_RESTART restart = BOOTSTRAPPER_APPLY_RESTART_NONE; BOOL fSendRestart = FALSE; - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_BEGIN_MSI_TRANSACTION: hrResult = OnMsiBeginTransaction(pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData); @@ -2263,7 +2263,7 @@ static HRESULT ProcessElevatedChildMessage( break; default: - ExitWithRootFailure(hr, E_INVALIDARG, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessage); + ExitWithRootFailure(hr, E_INVALIDARG, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessageType); } if (fSendRestart) @@ -2279,7 +2279,7 @@ static HRESULT ProcessElevatedChildMessage( } static HRESULT ProcessElevatedChildCacheMessage( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -2288,7 +2288,7 @@ static HRESULT ProcessElevatedChildCacheMessage( BURN_ELEVATION_CHILD_MESSAGE_CONTEXT* pContext = static_cast(pvContext); HRESULT hrResult = S_OK; - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_ELEVATION_MESSAGE_TYPE_CACHE_PREPARE_PACKAGE: hrResult = OnCachePreparePackage(pContext->pCache, pContext->pPackages, (BYTE*)pMsg->pvData, pMsg->cbData); @@ -2313,7 +2313,7 @@ static HRESULT ProcessElevatedChildCacheMessage( default: hr = E_INVALIDARG; - ExitOnRootFailure(hr, "Unexpected elevated cache message sent to child process, msg: %u", pMsg->dwMessage); + ExitOnRootFailure(hr, "Unexpected elevated cache message sent to child process, msg: %u", pMsg->dwMessageType); } *pdwResult = (DWORD)hrResult; diff --git a/src/burn/engine/embedded.cpp b/src/burn/engine/embedded.cpp index b9335cdf4..1e0759d14 100644 --- a/src/burn/engine/embedded.cpp +++ b/src/burn/engine/embedded.cpp @@ -14,7 +14,7 @@ struct BURN_EMBEDDED_CALLBACK_CONTEXT // internal function declarations static HRESULT ProcessEmbeddedMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); @@ -36,7 +36,7 @@ static HRESULT OnEmbeddedProgress( // function definitions /******************************************************************* - EmbeddedRunBundle - + EmbeddedRunBundle - *******************************************************************/ extern "C" HRESULT EmbeddedRunBundle( @@ -108,7 +108,7 @@ extern "C" HRESULT EmbeddedRunBundle( // internal function definitions static HRESULT ProcessEmbeddedMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -118,7 +118,7 @@ static HRESULT ProcessEmbeddedMessages( DWORD dwResult = 0; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case BURN_EMBEDDED_MESSAGE_TYPE_ERROR: hr = OnEmbeddedErrorMessage(pContext->pfnGenericMessageHandler, pContext->pvContext, static_cast(pMsg->pvData), pMsg->cbData, &dwResult); @@ -131,7 +131,7 @@ static HRESULT ProcessEmbeddedMessages( break; default: - LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessage); + LogStringLine(REPORT_DEBUG, "Unexpected embedded message received from child process, msg: %u", pMsg->dwMessageType); dwResult = (DWORD)E_NOTIMPL; } diff --git a/src/burn/engine/externalengine.cpp b/src/burn/engine/externalengine.cpp index c38d8fc39..77af79cee 100644 --- a/src/burn/engine/externalengine.cpp +++ b/src/burn/engine/externalengine.cpp @@ -9,7 +9,7 @@ static HRESULT CopyStringToExternal( __inout SIZE_T* pcchBuffer ); static HRESULT ProcessUnknownEmbeddedMessages( - __in BURN_PIPE_MESSAGE* /*pMsg*/, + __in PIPE_MESSAGE* /*pMsg*/, __in_opt LPVOID /*pvContext*/, __out DWORD* pdwResult ); @@ -877,7 +877,7 @@ static HRESULT CopyStringToExternal( } static HRESULT ProcessUnknownEmbeddedMessages( - __in BURN_PIPE_MESSAGE* /*pMsg*/, + __in PIPE_MESSAGE* /*pMsg*/, __in_opt LPVOID /*pvContext*/, __out DWORD* pdwResult ) diff --git a/src/burn/engine/precomp.h b/src/burn/engine/precomp.h index d9a98f073..50df77ca7 100644 --- a/src/burn/engine/precomp.h +++ b/src/burn/engine/precomp.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/src/burn/test/BurnUnitTest/ElevationTest.cpp b/src/burn/test/BurnUnitTest/ElevationTest.cpp index 713d9e07a..857873b6b 100644 --- a/src/burn/test/BurnUnitTest/ElevationTest.cpp +++ b/src/burn/test/BurnUnitTest/ElevationTest.cpp @@ -16,12 +16,12 @@ static DWORD CALLBACK ElevateTest_ThreadProc( __in LPVOID lpThreadParameter ); static HRESULT ProcessParentMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); static HRESULT ProcessChildMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ); @@ -155,7 +155,7 @@ static DWORD CALLBACK ElevateTest_ThreadProc( } static HRESULT ProcessParentMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID /*pvContext*/, __out DWORD* pdwResult ) @@ -164,7 +164,7 @@ static HRESULT ProcessParentMessages( HRESULT hrResult = E_INVALIDDATA; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case TEST_CHILD_SENT_MESSAGE_ID: if (sizeof(TEST_MESSAGE_DATA) == pMsg->cbData && 0 == memcmp(TEST_MESSAGE_DATA, pMsg->pvData, sizeof(TEST_MESSAGE_DATA))) @@ -175,7 +175,7 @@ static HRESULT ProcessParentMessages( default: hr = E_INVALIDARG; - ExitOnRootFailure(hr, "Unexpected elevated message sent to parent process, msg: %u", pMsg->dwMessage); + ExitOnRootFailure(hr, "Unexpected elevated message sent to parent process, msg: %u", pMsg->dwMessageType); } *pdwResult = static_cast(hrResult); @@ -185,7 +185,7 @@ static HRESULT ProcessParentMessages( } static HRESULT ProcessChildMessages( - __in BURN_PIPE_MESSAGE* pMsg, + __in PIPE_MESSAGE* pMsg, __in_opt LPVOID pvContext, __out DWORD* pdwResult ) @@ -195,7 +195,7 @@ static HRESULT ProcessChildMessages( DWORD dwResult = 0; // Process the message. - switch (pMsg->dwMessage) + switch (pMsg->dwMessageType) { case TEST_PARENT_SENT_MESSAGE_ID: // send test message @@ -205,7 +205,7 @@ static HRESULT ProcessChildMessages( default: hr = E_INVALIDARG; - ExitOnRootFailure(hr, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessage); + ExitOnRootFailure(hr, "Unexpected elevated message sent to child process, msg: %u", pMsg->dwMessageType); } *pdwResult = dwResult; diff --git a/src/burn/test/BurnUnitTest/precomp.h b/src/burn/test/BurnUnitTest/precomp.h index 1aa182049..33ca6d5f0 100644 --- a/src/burn/test/BurnUnitTest/precomp.h +++ b/src/burn/test/BurnUnitTest/precomp.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include