ReactOS  0.4.14-dev-317-g96040ec
printers.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Print Spooler Service
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Functions related to Printers and printing
5  * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 #include <marshalling/printers.h>
10 
11 DWORD
13 {
16 }
17 
18 DWORD
20 {
23 }
24 
25 DWORD
27 {
30 }
31 
32 DWORD
34 {
35  DWORD dwErrorCode;
36 
37  dwErrorCode = RpcImpersonateClient(NULL);
38  if (dwErrorCode != ERROR_SUCCESS)
39  {
40  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
41  return dwErrorCode;
42  }
43 
44  if (ClosePrinter(*phPrinter))
45  *phPrinter = NULL;
46  else
47  dwErrorCode = GetLastError();
48 
50  return dwErrorCode;
51 }
52 
53 DWORD
55 {
58 }
59 
60 DWORD
62 {
63  DWORD dwErrorCode;
64 
65  dwErrorCode = RpcImpersonateClient(NULL);
66  if (dwErrorCode != ERROR_SUCCESS)
67  {
68  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
69  return dwErrorCode;
70  }
71 
72  if (!EndDocPrinter(hPrinter))
73  dwErrorCode = GetLastError();
74 
76  return dwErrorCode;
77 }
78 
79 DWORD
81 {
82  DWORD dwErrorCode;
83 
84  dwErrorCode = RpcImpersonateClient(NULL);
85  if (dwErrorCode != ERROR_SUCCESS)
86  {
87  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
88  return dwErrorCode;
89  }
90 
91  if (!EndPagePrinter(hPrinter))
92  dwErrorCode = GetLastError();
93 
95  return dwErrorCode;
96 }
97 
98 DWORD
100 {
101  DWORD dwErrorCode;
102  PBYTE pPrinterEnumAligned;
103 
104  dwErrorCode = RpcImpersonateClient(NULL);
105  if (dwErrorCode != ERROR_SUCCESS)
106  {
107  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
108  return dwErrorCode;
109  }
110 
111  pPrinterEnumAligned = AlignRpcPtr(pPrinterEnum, &cbBuf);
112 
113  if (EnumPrintersW(Flags, Name, Level, pPrinterEnumAligned, cbBuf, pcbNeeded, pcReturned))
114  {
115  // Replace absolute pointer addresses in the output by relative offsets.
116  ASSERT(Level <= 9);
117  MarshallDownStructuresArray(pPrinterEnumAligned, *pcReturned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
118  }
119  else
120  {
121  dwErrorCode = GetLastError();
122  }
123 
124  RpcRevertToSelf();
125  UndoAlignRpcPtr(pPrinterEnum, pPrinterEnumAligned, cbBuf, pcbNeeded);
126 
127  return dwErrorCode;
128 }
129 
130 DWORD
131 _RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcWritten, DWORD cSleep)
132 {
134  return ERROR_INVALID_FUNCTION;
135 }
136 
137 DWORD
139 {
140  DWORD dwErrorCode;
141  PBYTE pPrinterAligned;
142 
143  dwErrorCode = RpcImpersonateClient(NULL);
144  if (dwErrorCode != ERROR_SUCCESS)
145  {
146  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
147  return dwErrorCode;
148  }
149 
150  pPrinterAligned = AlignRpcPtr(pPrinter, &cbBuf);
151 
152  if (GetPrinterW(hPrinter, Level, pPrinterAligned, cbBuf, pcbNeeded))
153  {
154  // Replace absolute pointer addresses in the output by relative offsets.
155  ASSERT(Level <= 9);
156  MarshallDownStructure(pPrinterAligned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
157  }
158  else
159  {
160  dwErrorCode = GetLastError();
161  }
162 
163  RpcRevertToSelf();
164  UndoAlignRpcPtr(pPrinter, pPrinterAligned, cbBuf, pcbNeeded);
165 
166  return dwErrorCode;
167 }
168 
169 DWORD
170 _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* phPrinter, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired)
171 {
172  DWORD dwErrorCode;
174 
175  dwErrorCode = RpcImpersonateClient(NULL);
176  if (dwErrorCode != ERROR_SUCCESS)
177  {
178  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
179  return dwErrorCode;
180  }
181 
182  Default.DesiredAccess = AccessRequired;
183  Default.pDatatype = pDatatype;
184  Default.pDevMode = (PDEVMODEW)pDevModeContainer->pDevMode;
185 
186  if (!OpenPrinterW(pPrinterName, phPrinter, &Default))
187  dwErrorCode = GetLastError();
188 
189  RpcRevertToSelf();
190  return dwErrorCode;
191 }
192 
193 DWORD
194 _RpcOpenPrinterEx(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* pHandle, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired, WINSPOOL_SPLCLIENT_CONTAINER* pClientInfo)
195 {
197  return ERROR_INVALID_FUNCTION;
198 }
199 
200 DWORD
201 _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcNoBytesRead)
202 {
203  DWORD dwErrorCode;
204 
205  dwErrorCode = RpcImpersonateClient(NULL);
206  if (dwErrorCode != ERROR_SUCCESS)
207  {
208  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
209  return dwErrorCode;
210  }
211 
212  if (!ReadPrinter(hPrinter, pBuf, cbBuf, pcNoBytesRead))
213  dwErrorCode = GetLastError();
214 
215  RpcRevertToSelf();
216  return dwErrorCode;
217 }
218 
219 DWORD
221 {
223  return ERROR_INVALID_FUNCTION;
224 }
225 
226 DWORD
228 {
230  return ERROR_INVALID_FUNCTION;
231 }
232 
233 DWORD
235 {
237  return ERROR_INVALID_FUNCTION;
238 }
239 
240 DWORD
242 {
244  return ERROR_INVALID_FUNCTION;
245 }
246 
247 DWORD
249 {
250  DWORD dwErrorCode;
251 
252  dwErrorCode = RpcImpersonateClient(NULL);
253  if (dwErrorCode != ERROR_SUCCESS)
254  {
255  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
256  return dwErrorCode;
257  }
258 
259  *pJobId = StartDocPrinterW(hPrinter, pDocInfoContainer->Level, (PBYTE)pDocInfoContainer->DocInfo.pDocInfo1);
260  dwErrorCode = GetLastError();
261 
262  RpcRevertToSelf();
263  return dwErrorCode;
264 }
265 
266 DWORD
268 {
269  DWORD dwErrorCode;
270 
271  dwErrorCode = RpcImpersonateClient(NULL);
272  if (dwErrorCode != ERROR_SUCCESS)
273  {
274  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
275  return dwErrorCode;
276  }
277 
278  if (!StartPagePrinter(hPrinter))
279  dwErrorCode = GetLastError();
280 
281  RpcRevertToSelf();
282  return dwErrorCode;
283 }
284 
285 DWORD
286 _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcWritten)
287 {
288  DWORD dwErrorCode;
289 
290  dwErrorCode = RpcImpersonateClient(NULL);
291  if (dwErrorCode != ERROR_SUCCESS)
292  {
293  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
294  return dwErrorCode;
295  }
296 
297  if (!WritePrinter(hPrinter, pBuf, cbBuf, pcWritten))
298  dwErrorCode = GetLastError();
299 
300  RpcRevertToSelf();
301  return dwErrorCode;
302 }
BOOL WINAPI EnumPrintersW(DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: printers.c:66
DWORD _RpcStartPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:267
BOOL WINAPI ReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
Definition: printers.c:207
DWORD _RpcResetPrinterEx(VOID)
Definition: printers.c:227
#define TRUE
Definition: types.h:120
struct _devicemodeW * PDEVMODEW
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
DWORD _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:61
DWORD _RpcResetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer)
Definition: printers.c:220
DWORD _RpcDeletePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:54
DWORD _RpcEnumPrinters(DWORD Flags, WINSPOOL_HANDLE Name, DWORD Level, BYTE *pPrinterEnum, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: printers.c:99
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
Definition: printers.c:222
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
Definition: shell.h:41
DWORD _RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten, DWORD cSleep)
Definition: printers.c:131
DWORD _RpcAddPrinter(WINSPOOL_HANDLE pName, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, WINSPOOL_PRINTER_HANDLE *pHandle)
Definition: printers.c:19
union _WINSPOOL_DOC_INFO_CONTAINER::@3305 DocInfo
DWORD _RpcSeekPrinter(VOID)
Definition: printers.c:234
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
DWORD _RpcStartDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_DOC_INFO_CONTAINER *pDocInfoContainer, DWORD *pJobId)
Definition: printers.c:248
DWORD _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:80
smooth NULL
Definition: ftsmooth.c:416
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1460
BOOL WINAPI WritePrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
Definition: printers.c:252
BOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
Definition: printers.c:140
BOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:12
static LPSTR pName
Definition: security.c:75
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD _RpcOpenPrinterEx(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE *pHandle, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD AccessRequired, WINSPOOL_SPLCLIENT_CONTAINER *pClientInfo)
Definition: printers.c:194
DWORD _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten)
Definition: printers.c:286
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcNoBytesRead)
Definition: printers.c:201
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
BOOL WINAPI EndPagePrinter(HANDLE hPrinter)
Definition: printers.c:51
unsigned char BYTE
Definition: mem.h:68
DWORD _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE *phPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD AccessRequired)
Definition: printers.c:170
WINSPOOL_DOC_INFO_1 * pDocInfo1
Definition: winspool.idl:577
#define ERR(fmt,...)
Definition: debug.h:109
DWORD _RpcAddPrinterEx(WINSPOOL_HANDLE pName, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, WINSPOOL_SPLCLIENT_CONTAINER *pClientInfo, WINSPOOL_PRINTER_HANDLE *pHandle)
Definition: printers.c:26
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
static const MARSHALLING * pPrinterInfoMarshalling[]
Definition: printers.h:146
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:236
BOOL WINAPI StartPagePrinter(HANDLE hPrinter)
Definition: printers.c:237
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1053
BOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:36
DWORD _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE *phPrinter)
Definition: printers.c:33
BOOL WINAPI OpenPrinterW(PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
Definition: printers.c:155
DWORD _RpcAbortPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:12
DWORD _RpcSetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, DWORD Command)
Definition: printers.c:241
#define UNIMPLEMENTED
Definition: debug.h:114
BYTE * PBYTE
Definition: pedump.c:66
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
DWORD _RpcGetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pPrinter, DWORD cbBuf, DWORD *pcbNeeded)
Definition: printers.c:138
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15