From 20bbfa5624e95815174010eb0215806abbbf0b06 Mon Sep 17 00:00:00 2001 From: Colin Finck Date: Tue, 27 Jun 2017 07:25:04 +0000 Subject: [PATCH] [PRINTING] Fix all EnumPrintProcessorDatatypes API tests. svn path=/trunk/; revision=75215 --- .../printing/base/spoolss/printprocessors.c | 13 +++++- .../printing/base/spoolsv/printprocessors.c | 40 +++++++++++-------- .../printing/base/winspool/printprocessors.c | 38 ++++++++++-------- .../printing/processors/winprint/main.c | 22 ++++------ 4 files changed, 63 insertions(+), 50 deletions(-) diff --git a/reactos/win32ss/printing/base/spoolss/printprocessors.c b/reactos/win32ss/printing/base/spoolss/printprocessors.c index 31fb1668d07..e782243927b 100644 --- a/reactos/win32ss/printing/base/spoolss/printprocessors.c +++ b/reactos/win32ss/printing/base/spoolss/printprocessors.c @@ -2,7 +2,7 @@ * PROJECT: ReactOS Spooler Router * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation * PURPOSE: Functions related to Print Processors - * COPYRIGHT: Copyright 2015-2016 Colin Finck + * COPYRIGHT: Copyright 2015-2017 Colin Finck */ #include "precomp.h" @@ -10,8 +10,17 @@ BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { + PSPOOLSS_PRINT_PROVIDER pPrintProvider; + + // Sanity checks + if (cbBuf && !pDatatypes) + { + SetLastError(ERROR_INVALID_USER_BUFFER); + return FALSE; + } + // Always call this function on the Local Spooler. - PSPOOLSS_PRINT_PROVIDER pPrintProvider = CONTAINING_RECORD(PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry); + pPrintProvider = CONTAINING_RECORD(PrintProviderList.Flink, SPOOLSS_PRINT_PROVIDER, Entry); return pPrintProvider->PrintProvider.fpEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned); } diff --git a/reactos/win32ss/printing/base/spoolsv/printprocessors.c b/reactos/win32ss/printing/base/spoolsv/printprocessors.c index ef224e559d0..4e709c5d896 100644 --- a/reactos/win32ss/printing/base/spoolsv/printprocessors.c +++ b/reactos/win32ss/printing/base/spoolsv/printprocessors.c @@ -8,17 +8,21 @@ #include "precomp.h" static void -_MarshallDownDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1) +_MarshallDownDatatypesInfo(PDATATYPES_INFO_1W* ppDatatypesInfo1) { // Replace absolute pointer addresses in the output by relative offsets. + PDATATYPES_INFO_1W pDatatypesInfo1 = *ppDatatypesInfo1; pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName - (ULONG_PTR)pDatatypesInfo1); + *ppDatatypesInfo1 += sizeof(DATATYPES_INFO_1W); } static void -_MarshallDownPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1) +_MarshallDownPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W* ppPrintProcessorInfo1) { // Replace absolute pointer addresses in the output by relative offsets. + PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1 = *ppPrintProcessorInfo1; pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName - (ULONG_PTR)pPrintProcessorInfo1); + *ppPrintProcessorInfo1 += sizeof(PRINTPROCESSOR_INFO_1W); } DWORD @@ -39,8 +43,7 @@ DWORD _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorName, DWORD Level, BYTE* pDatatypes, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned) { DWORD dwErrorCode; - DWORD i; - PBYTE p = pDatatypes; + PBYTE pDatatypesAligned; dwErrorCode = RpcImpersonateClient(NULL); if (dwErrorCode != ERROR_SUCCESS) @@ -49,20 +52,25 @@ _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorNam return dwErrorCode; } - EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned); - dwErrorCode = GetLastError(); + pDatatypesAligned = AlignRpcPtr(pDatatypes, &cbBuf); - if (dwErrorCode == ERROR_SUCCESS) + if (EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypesAligned, cbBuf, pcbNeeded, pcReturned)) { // Replace absolute pointer addresses in the output by relative offsets. + DWORD i; + PDATATYPES_INFO_1W p = (PDATATYPES_INFO_1W)pDatatypesAligned; + for (i = 0; i < *pcReturned; i++) - { - _MarshallDownDatatypesInfo((PDATATYPES_INFO_1W)p); - p += sizeof(DATATYPES_INFO_1W); - } + _MarshallDownDatatypesInfo(&p); + } + else + { + dwErrorCode = GetLastError(); } RpcRevertToSelf(); + UndoAlignRpcPtr(pDatatypes, pDatatypesAligned, cbBuf, pcbNeeded); + return dwErrorCode; } @@ -70,8 +78,6 @@ DWORD _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorInfo, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned) { DWORD dwErrorCode; - DWORD i; - PBYTE p = pPrintProcessorInfo; dwErrorCode = RpcImpersonateClient(NULL); if (dwErrorCode != ERROR_SUCCESS) @@ -86,11 +92,11 @@ _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, if (dwErrorCode == ERROR_SUCCESS) { // Replace absolute pointer addresses in the output by relative offsets. + DWORD i; + PPRINTPROCESSOR_INFO_1W p = (PPRINTPROCESSOR_INFO_1W)pPrintProcessorInfo; + for (i = 0; i < *pcReturned; i++) - { - _MarshallDownPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p); - p += sizeof(PRINTPROCESSOR_INFO_1W); - } + _MarshallDownPrintProcessorInfo(&p); } RpcRevertToSelf(); diff --git a/reactos/win32ss/printing/base/winspool/printprocessors.c b/reactos/win32ss/printing/base/winspool/printprocessors.c index bac7d9ee88e..60006a8b58f 100644 --- a/reactos/win32ss/printing/base/winspool/printprocessors.c +++ b/reactos/win32ss/printing/base/winspool/printprocessors.c @@ -9,17 +9,21 @@ #include static void -_MarshallUpDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1) +_MarshallUpDatatypesInfo(PDATATYPES_INFO_1W* ppDatatypesInfo1) { // Replace relative offset addresses in the output by absolute pointers. + PDATATYPES_INFO_1W pDatatypesInfo1 = *ppDatatypesInfo1; pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName + (ULONG_PTR)pDatatypesInfo1); + *ppDatatypesInfo1 += sizeof(DATATYPES_INFO_1W); } static void -_MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1) +_MarshallUpPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W* ppPrintProcessorInfo1) { // Replace relative offset addresses in the output by absolute pointers. + PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1 = *ppPrintProcessorInfo1; pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName + (ULONG_PTR)pPrintProcessorInfo1); + *ppPrintProcessorInfo1 += sizeof(PRINTPROCESSOR_INFO_1W); } BOOL WINAPI @@ -47,8 +51,13 @@ BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { DWORD dwErrorCode; - DWORD i; - PBYTE p = pDatatypes; + + // Sanity checks + if (Level != 1) + { + dwErrorCode = ERROR_INVALID_LEVEL; + goto Cleanup; + } // Do the RPC call RpcTryExcept @@ -64,14 +73,14 @@ EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Leve if (dwErrorCode == ERROR_SUCCESS) { - // Replace relative offset addresses in the output by absolute pointers. + DWORD i; + PDATATYPES_INFO_1W p = (PDATATYPES_INFO_1W)pDatatypes; + for (i = 0; i < *pcReturned; i++) - { - _MarshallUpDatatypesInfo((PDATATYPES_INFO_1W)p); - p += sizeof(DATATYPES_INFO_1W); - } + _MarshallUpDatatypesInfo(&p); } +Cleanup: SetLastError(dwErrorCode); return (dwErrorCode == ERROR_SUCCESS); } @@ -80,8 +89,6 @@ BOOL WINAPI EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned) { DWORD dwErrorCode; - DWORD i; - PBYTE p = pPrintProcessorInfo; // Choose our current environment if the caller didn't give any. if (!pEnvironment) @@ -100,12 +107,11 @@ EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintP if (dwErrorCode == ERROR_SUCCESS) { - // Replace relative offset addresses in the output by absolute pointers. + DWORD i; + PPRINTPROCESSOR_INFO_1W p = (PPRINTPROCESSOR_INFO_1W)pPrintProcessorInfo; + for (i = 0; i < *pcReturned; i++) - { - _MarshallUpPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p); - p += sizeof(PRINTPROCESSOR_INFO_1W); - } + _MarshallUpPrintProcessorInfo(&p); } SetLastError(dwErrorCode); diff --git a/reactos/win32ss/printing/processors/winprint/main.c b/reactos/win32ss/printing/processors/winprint/main.c index ce4d2849bd2..268575ea6a1 100644 --- a/reactos/win32ss/printing/processors/winprint/main.c +++ b/reactos/win32ss/printing/processors/winprint/main.c @@ -2,7 +2,7 @@ * PROJECT: ReactOS Standard Print Processor * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation * PURPOSE: Main functions - * COPYRIGHT: Copyright 2015 Colin Finck + * COPYRIGHT: Copyright 2015-2017 Colin Finck */ #include "precomp.h" @@ -112,7 +112,6 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level { DWORD cbDatatype; DWORD dwDatatypeCount = 0; - DWORD dwErrorCode; DWORD dwOffsets[_countof(_pwszDatatypes)]; PWSTR* pCurrentDatatype; PDWORD pCurrentOffset = dwOffsets; @@ -121,10 +120,7 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level // Sanity checks if (Level != 1 || !pcbNeeded || !pcReturned) - { - dwErrorCode = ERROR_INVALID_PARAMETER; - goto Cleanup; - } + return FALSE; // Count the required buffer size and the number of datatypes. *pcbNeeded = 0; @@ -145,15 +141,15 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level // Check if the supplied buffer is large enough. if (cbBuf < *pcbNeeded) { - dwErrorCode = ERROR_INSUFFICIENT_BUFFER; - goto Cleanup; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + return FALSE; } // Check if a buffer was supplied at all. if (!pDatatypes) { - dwErrorCode = ERROR_INVALID_PARAMETER; - goto Cleanup; + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; } // Copy over all datatypes. @@ -161,11 +157,7 @@ EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]); *pcReturned = dwDatatypeCount; - dwErrorCode = ERROR_SUCCESS; - -Cleanup: - SetLastError(dwErrorCode); - return (dwErrorCode == ERROR_SUCCESS); + return TRUE; }