1 /* 2 * PROJECT: ReactOS Print Spooler Service 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Functions related to Forms 5 * COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org) 6 */ 7 8 #include "precomp.h" 9 #include <marshalling/forms.h> 10 11 DWORD 12 _RpcAddForm(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_FORM_CONTAINER* pFormInfoContainer) 13 { 14 DWORD dwErrorCode; 15 16 dwErrorCode = RpcImpersonateClient(NULL); 17 if (dwErrorCode != ERROR_SUCCESS) 18 { 19 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); 20 return dwErrorCode; 21 } 22 23 if (!AddFormW(hPrinter, pFormInfoContainer->Level, (PBYTE)pFormInfoContainer->FormInfo.pFormInfo1)) 24 dwErrorCode = GetLastError(); 25 26 RpcRevertToSelf(); 27 return dwErrorCode; 28 } 29 30 DWORD 31 _RpcDeleteForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName) 32 { 33 DWORD dwErrorCode; 34 35 dwErrorCode = RpcImpersonateClient(NULL); 36 if (dwErrorCode != ERROR_SUCCESS) 37 { 38 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); 39 return dwErrorCode; 40 } 41 42 if (!DeleteFormW(hPrinter, pFormName)) 43 dwErrorCode = GetLastError(); 44 45 RpcRevertToSelf(); 46 return dwErrorCode; 47 } 48 49 DWORD 50 _RpcEnumForms(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned) 51 { 52 DWORD dwErrorCode; 53 PBYTE pFormsEnumAligned; 54 55 dwErrorCode = RpcImpersonateClient(NULL); 56 if (dwErrorCode != ERROR_SUCCESS) 57 { 58 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); 59 return dwErrorCode; 60 } 61 62 pFormsEnumAligned = AlignRpcPtr(pForm, &cbBuf); 63 64 if (EnumFormsW(hPrinter, Level, pFormsEnumAligned, cbBuf, pcbNeeded, pcReturned)) 65 { 66 // Replace absolute pointer addresses in the output by relative offsets. 67 ASSERT(Level >= 1 && Level <= 2); 68 MarshallDownStructuresArray(pFormsEnumAligned, *pcReturned, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE); 69 } 70 else 71 { 72 dwErrorCode = GetLastError(); 73 } 74 75 RpcRevertToSelf(); 76 UndoAlignRpcPtr(pForm, pFormsEnumAligned, cbBuf, pcbNeeded); 77 78 return dwErrorCode; 79 } 80 81 DWORD 82 _RpcGetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded) 83 { 84 DWORD dwErrorCode; 85 PBYTE pFormAligned; 86 87 dwErrorCode = RpcImpersonateClient(NULL); 88 if (dwErrorCode != ERROR_SUCCESS) 89 { 90 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); 91 return dwErrorCode; 92 } 93 94 pFormAligned = AlignRpcPtr(pForm, &cbBuf); 95 96 if (GetFormW(hPrinter, pFormName, Level, pFormAligned, cbBuf, pcbNeeded)) 97 { 98 // Replace absolute pointer addresses in the output by relative offsets. 99 ASSERT(Level >= 1 && Level <= 2); 100 MarshallDownStructure(pFormAligned, pFormInfoMarshalling[Level]->pInfo, pFormInfoMarshalling[Level]->cbStructureSize, TRUE); 101 } 102 else 103 { 104 dwErrorCode = GetLastError(); 105 } 106 107 RpcRevertToSelf(); 108 UndoAlignRpcPtr(pForm, pFormAligned, cbBuf, pcbNeeded); 109 110 return dwErrorCode; 111 } 112 113 DWORD 114 _RpcSetForm(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR* pFormName, WINSPOOL_FORM_CONTAINER* pFormInfoContainer) 115 { 116 DWORD dwErrorCode; 117 118 dwErrorCode = RpcImpersonateClient(NULL); 119 if (dwErrorCode != ERROR_SUCCESS) 120 { 121 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode); 122 return dwErrorCode; 123 } 124 125 if (!SetFormW(hPrinter, pFormName, pFormInfoContainer->Level, (PBYTE)pFormInfoContainer->FormInfo.pFormInfo1)) 126 dwErrorCode = GetLastError(); 127 128 RpcRevertToSelf(); 129 return dwErrorCode; 130 } 131