ReactOS  0.4.15-dev-1171-gab82533
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 {
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 (!AbortPrinter(hPrinter))
24  dwErrorCode = GetLastError();
25 
27  return dwErrorCode;
28 }
29 
30 DWORD
32 {
35 }
36 
37 DWORD
39 {
42 }
43 
44 DWORD
46 {
47  DWORD dwErrorCode;
48 
49  dwErrorCode = RpcImpersonateClient(NULL);
50  if (dwErrorCode != ERROR_SUCCESS)
51  {
52  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
53  return dwErrorCode;
54  }
55 
56  if (ClosePrinter(*phPrinter))
57  *phPrinter = NULL;
58  else
59  dwErrorCode = GetLastError();
60 
62  return dwErrorCode;
63 }
64 
65 DWORD
67 {
68  DWORD dwErrorCode;
69 
70  dwErrorCode = RpcImpersonateClient(NULL);
71  if (dwErrorCode != ERROR_SUCCESS)
72  {
73  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
74  return dwErrorCode;
75  }
76 
77  if (!DeletePrinter(hPrinter))
78  dwErrorCode = GetLastError();
79 
81  return dwErrorCode;
82 }
83 
84 DWORD
86 {
87  DWORD dwErrorCode;
88 
89  dwErrorCode = RpcImpersonateClient(NULL);
90  if (dwErrorCode != ERROR_SUCCESS)
91  {
92  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
93  return dwErrorCode;
94  }
95 
96  if (!EndDocPrinter(hPrinter))
97  dwErrorCode = GetLastError();
98 
100  return dwErrorCode;
101 }
102 
103 DWORD
105 {
106  DWORD dwErrorCode;
107 
108  dwErrorCode = RpcImpersonateClient(NULL);
109  if (dwErrorCode != ERROR_SUCCESS)
110  {
111  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
112  return dwErrorCode;
113  }
114 
115  if (!EndPagePrinter(hPrinter))
116  dwErrorCode = GetLastError();
117 
118  RpcRevertToSelf();
119  return dwErrorCode;
120 }
121 
122 DWORD
124 {
125  DWORD dwErrorCode;
126  PBYTE pPrinterEnumAligned;
127 
128  dwErrorCode = RpcImpersonateClient(NULL);
129  if (dwErrorCode != ERROR_SUCCESS)
130  {
131  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
132  return dwErrorCode;
133  }
134 
135  pPrinterEnumAligned = AlignRpcPtr(pPrinterEnum, &cbBuf);
136 
137  if (EnumPrintersW(Flags, Name, Level, pPrinterEnumAligned, cbBuf, pcbNeeded, pcReturned))
138  {
139  // Replace absolute pointer addresses in the output by relative offsets.
140  ASSERT(Level <= 9);
141  MarshallDownStructuresArray(pPrinterEnumAligned, *pcReturned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
142  }
143  else
144  {
145  dwErrorCode = GetLastError();
146  }
147 
148  RpcRevertToSelf();
149  UndoAlignRpcPtr(pPrinterEnum, pPrinterEnumAligned, cbBuf, pcbNeeded);
150 
151  return dwErrorCode;
152 }
153 
154 DWORD
155 _RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcWritten, DWORD cSleep)
156 {
158  return ERROR_INVALID_FUNCTION;
159 }
160 
161 DWORD
163 {
164  DWORD dwErrorCode;
165  PBYTE pPrinterAligned;
166 
167  dwErrorCode = RpcImpersonateClient(NULL);
168  if (dwErrorCode != ERROR_SUCCESS)
169  {
170  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
171  return dwErrorCode;
172  }
173 
174  pPrinterAligned = AlignRpcPtr(pPrinter, &cbBuf);
175 
176  if (GetPrinterW(hPrinter, Level, pPrinterAligned, cbBuf, pcbNeeded))
177  {
178  // Replace absolute pointer addresses in the output by relative offsets.
179  ASSERT(Level <= 9);
180  MarshallDownStructure(pPrinterAligned, pPrinterInfoMarshalling[Level]->pInfo, pPrinterInfoMarshalling[Level]->cbStructureSize, TRUE);
181  }
182  else
183  {
184  dwErrorCode = GetLastError();
185  }
186 
187  RpcRevertToSelf();
188  UndoAlignRpcPtr(pPrinter, pPrinterAligned, cbBuf, pcbNeeded);
189 
190  return dwErrorCode;
191 }
192 
193 DWORD
194 _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* phPrinter, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired)
195 {
196  DWORD dwErrorCode;
198 
199  dwErrorCode = RpcImpersonateClient(NULL);
200  if (dwErrorCode != ERROR_SUCCESS)
201  {
202  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
203  return dwErrorCode;
204  }
205 
206  Default.DesiredAccess = AccessRequired;
207  Default.pDatatype = pDatatype;
208  Default.pDevMode = (PDEVMODEW)pDevModeContainer->pDevMode;
209 
210  if (!OpenPrinterW(pPrinterName, phPrinter, &Default))
211  dwErrorCode = GetLastError();
212 
213  RpcRevertToSelf();
214  return dwErrorCode;
215 }
216 
217 DWORD
218 _RpcOpenPrinterEx(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* pHandle, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired, WINSPOOL_SPLCLIENT_CONTAINER* pClientInfo)
219 {
221  return ERROR_INVALID_FUNCTION;
222 }
223 
224 DWORD
225 _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcNoBytesRead)
226 {
227  DWORD dwErrorCode;
228 
229  dwErrorCode = RpcImpersonateClient(NULL);
230  if (dwErrorCode != ERROR_SUCCESS)
231  {
232  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
233  return dwErrorCode;
234  }
235 
236  if (!ReadPrinter(hPrinter, pBuf, cbBuf, pcNoBytesRead))
237  dwErrorCode = GetLastError();
238 
239  RpcRevertToSelf();
240  return dwErrorCode;
241 }
242 
243 DWORD
245 {
247  return ERROR_INVALID_FUNCTION;
248 }
249 
250 DWORD
252 {
253  DWORD dwErrorCode;
254  PRINTER_DEFAULTSW pdw;
255 
256  if (pDatatype)
257  {
258  pdw.pDatatype = pDatatype;
259  }
260  else
261  {
263  }
264 
265  if (pDevModeContainer->pDevMode)
266  {
267  pdw.pDevMode = (PDEVMODEW)pDevModeContainer->pDevMode;
268  // Fixme : Need to check DevMode before forward call, by copy devmode.c from WinSpool.
269  // Local SV!SplIsValidDevmode((PDW)pDevModeContainer->pDevMode, pDevModeContainer->cbBuf)
270  }
271  else
272  {
274 
275  }
276  pdw.DesiredAccess = 0;
277 
278  dwErrorCode = RpcImpersonateClient(NULL);
279  if (dwErrorCode != ERROR_SUCCESS)
280  {
281  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
282  return dwErrorCode;
283  }
284 
285  if (!ResetPrinterW(hPrinter, &pdw))
286  dwErrorCode = GetLastError();
287 
288  RpcRevertToSelf();
289  return dwErrorCode;
290 }
291 
292 DWORD
293 _RpcSeekPrinter( WINSPOOL_PRINTER_HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite )
294 {
295  DWORD dwErrorCode;
296 
297  dwErrorCode = RpcImpersonateClient(NULL);
298  if (dwErrorCode != ERROR_SUCCESS)
299  {
300  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
301  return dwErrorCode;
302  }
303 
304  if (!SeekPrinter(hPrinter, liDistanceToMove, pliNewPointer, dwMoveMethod, bWrite))
305  dwErrorCode = GetLastError();
306 
307  RpcRevertToSelf();
308  return dwErrorCode;
309 }
310 
311 DWORD
313 {
315  return ERROR_INVALID_FUNCTION;
316 }
317 
318 DWORD
320 {
321  DWORD dwErrorCode;
322 
323  dwErrorCode = RpcImpersonateClient(NULL);
324  if (dwErrorCode != ERROR_SUCCESS)
325  {
326  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
327  return dwErrorCode;
328  }
329 
330  *pJobId = StartDocPrinterW(hPrinter, pDocInfoContainer->Level, (PBYTE)pDocInfoContainer->DocInfo.pDocInfo1);
331  dwErrorCode = GetLastError();
332 
333  RpcRevertToSelf();
334  return dwErrorCode;
335 }
336 
337 DWORD
339 {
340  DWORD dwErrorCode;
341 
342  dwErrorCode = RpcImpersonateClient(NULL);
343  if (dwErrorCode != ERROR_SUCCESS)
344  {
345  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
346  return dwErrorCode;
347  }
348 
349  if (!StartPagePrinter(hPrinter))
350  dwErrorCode = GetLastError();
351 
352  RpcRevertToSelf();
353  return dwErrorCode;
354 }
355 
356 DWORD
357 _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcWritten)
358 {
359  DWORD dwErrorCode;
360 
361  dwErrorCode = RpcImpersonateClient(NULL);
362  if (dwErrorCode != ERROR_SUCCESS)
363  {
364  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
365  return dwErrorCode;
366  }
367 
368  if (!WritePrinter(hPrinter, pBuf, cbBuf, pcWritten))
369  dwErrorCode = GetLastError();
370 
371  RpcRevertToSelf();
372  return dwErrorCode;
373 }
DWORD _RpcSeekPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
Definition: printers.c:293
BOOL WINAPI EnumPrintersW(DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: printers.c:247
DWORD _RpcStartPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:338
BOOL WINAPI ReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
Definition: printers.c:397
union _WINSPOOL_DOC_INFO_CONTAINER::@3401 DocInfo
struct _devicemodeW * PDEVMODEW
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
DWORD _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:85
DWORD _RpcResetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer)
Definition: printers.c:244
DWORD _RpcDeletePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:66
BOOL WINAPI AbortPrinter(HANDLE hPrinter)
Definition: printers.c:11
BOOL WINAPI SeekPrinter(HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
Definition: printers.c:412
DWORD _RpcEnumPrinters(DWORD Flags, WINSPOOL_HANDLE Name, DWORD Level, BYTE *pPrinterEnum, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: printers.c:123
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
Definition: printers.c:442
_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:155
LPDEVMODEW pDevMode
Definition: winspool.h:862
DWORD _RpcAddPrinter(WINSPOOL_HANDLE pName, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, WINSPOOL_PRINTER_HANDLE *pHandle)
Definition: printers.c:31
#define RESETPRINTERDEFAULTDATATYPE
Definition: spoolss.h:11
_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:319
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:104
BOOL WINAPI ResetPrinterW(HANDLE hPrinter, PPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2931
smooth NULL
Definition: ftsmooth.c:416
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1459
BOOL WINAPI WritePrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
Definition: printers.c:472
BOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
Definition: printers.c:312
BOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
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:218
DWORD _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten)
Definition: printers.c:357
unsigned long DWORD
Definition: ntddk_ex.h:95
ACCESS_MASK DesiredAccess
Definition: winspool.h:863
DWORD _RpcResetPrinterEx(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD dwFlags)
Definition: printers.c:251
DWORD _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcNoBytesRead)
Definition: printers.c:225
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
BOOL WINAPI EndPagePrinter(HANDLE hPrinter)
Definition: printers.c:232
DWORD _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE *phPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD AccessRequired)
Definition: printers.c:194
WINSPOOL_DOC_INFO_1 * pDocInfo1
Definition: winspool.idl:577
unsigned char BYTE
Definition: xxhash.c:193
#define ERR(fmt,...)
Definition: debug.h:110
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:38
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:239
BOOL WINAPI DeletePrinter(HANDLE hPrinter)
Definition: printers.c:202
BOOL WINAPI StartPagePrinter(HANDLE hPrinter)
Definition: printers.c:457
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1052
BOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:217
DWORD _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE *phPrinter)
Definition: printers.c:45
BOOL WINAPI OpenPrinterW(PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
Definition: printers.c:345
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:312
#define UNIMPLEMENTED
Definition: debug.h:115
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:162
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15
#define RESETPRINTERDEFAULTDEVMODE
Definition: spoolss.h:12