ReactOS 0.4.15-dev-8408-g466a198
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"
10
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
32{
35}
36
39{
42}
43
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
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
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
103DWORD
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
119 return dwErrorCode;
120}
121
122DWORD
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
149 UndoAlignRpcPtr(pPrinterEnum, pPrinterEnumAligned, cbBuf, pcbNeeded);
150
151 return dwErrorCode;
152}
153
154DWORD
155_RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE* pBuf, DWORD cbBuf, DWORD* pcWritten, DWORD cSleep)
156{
159}
160
161DWORD
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
188 UndoAlignRpcPtr(pPrinter, pPrinterAligned, cbBuf, pcbNeeded);
189
190 return dwErrorCode;
191}
192
193DWORD
194_RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* phPrinter, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired)
195{
196 DWORD dwErrorCode;
197 PRINTER_DEFAULTSW Default;
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
214 return dwErrorCode;
215}
216
217DWORD
218_RpcOpenPrinterEx(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* pHandle, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired, WINSPOOL_SPLCLIENT_CONTAINER* pClientInfo)
219{
222}
223
224DWORD
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
240 return dwErrorCode;
241}
242
243DWORD
245{
248}
249
250DWORD
252{
253 DWORD dwErrorCode;
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
289 return dwErrorCode;
290}
291
292DWORD
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
308 return dwErrorCode;
309}
310
311DWORD
313{
316}
317
318DWORD
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
334 return dwErrorCode;
335}
336
337DWORD
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
353 return dwErrorCode;
354}
355
356DWORD
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
372 return dwErrorCode;
373}
#define ERR(fmt,...)
Definition: precomp.h:57
BOOL WINAPI DeletePrinter(HANDLE hPrinter)
Definition: printers.c:202
DWORD WINAPI StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
Definition: printers.c:442
BOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
Definition: printers.c:312
BOOL WINAPI EnumPrintersW(DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: printers.c:247
BOOL WINAPI EndDocPrinter(HANDLE hPrinter)
Definition: printers.c:217
BOOL WINAPI WritePrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
Definition: printers.c:472
BOOL WINAPI ClosePrinter(HANDLE hPrinter)
Definition: printers.c:176
BOOL WINAPI AbortPrinter(HANDLE hPrinter)
Definition: printers.c:11
BOOL WINAPI ReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
Definition: printers.c:397
BOOL WINAPI OpenPrinterW(PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
Definition: printers.c:345
BOOL WINAPI EndPagePrinter(HANDLE hPrinter)
Definition: printers.c:232
BOOL WINAPI SeekPrinter(HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
Definition: printers.c:412
BOOL WINAPI StartPagePrinter(HANDLE hPrinter)
Definition: printers.c:457
DWORD _RpcSetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_PRINTER_CONTAINER *pPrinterContainer, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, WINSPOOL_SECURITY_CONTAINER *pSecurityContainer, DWORD Command)
Definition: printers.c:312
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
DWORD _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcNoBytesRead)
Definition: printers.c:225
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 _RpcSeekPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite)
Definition: printers.c:293
DWORD _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:85
DWORD _RpcAbortPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:12
DWORD _RpcStartDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_DOC_INFO_CONTAINER *pDocInfoContainer, DWORD *pJobId)
Definition: printers.c:319
DWORD _RpcGetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pPrinter, DWORD cbBuf, DWORD *pcbNeeded)
Definition: printers.c:162
DWORD _RpcResetPrinterEx(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD dwFlags)
Definition: printers.c:251
DWORD _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE *phPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer, DWORD AccessRequired)
Definition: printers.c:194
DWORD _RpcFlushPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten, DWORD cSleep)
Definition: printers.c:155
DWORD _RpcStartPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:338
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
DWORD _RpcResetPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WCHAR *pDatatype, WINSPOOL_DEVMODE_CONTAINER *pDevModeContainer)
Definition: printers.c:244
DWORD _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE *phPrinter)
Definition: printers.c:45
DWORD _RpcDeletePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:66
DWORD _RpcEnumPrinters(DWORD Flags, WINSPOOL_HANDLE Name, DWORD Level, BYTE *pPrinterEnum, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: printers.c:123
DWORD _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
Definition: printers.c:104
DWORD _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten)
Definition: printers.c:357
#define UNIMPLEMENTED
Definition: debug.h:118
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
if(dx< 0)
Definition: linetemp.h:194
BOOL WINAPI MarshallDownStructure(PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:38
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
#define ASSERT(a)
Definition: mode.c:44
static LPSTR pName
Definition: security.c:75
BYTE * PBYTE
Definition: pedump.c:66
static const MARSHALLING * pPrinterInfoMarshalling[]
Definition: printers.h:146
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1463
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1056
#define RESETPRINTERDEFAULTDATATYPE
Definition: spoolss.h:11
#define RESETPRINTERDEFAULTDEVMODE
Definition: spoolss.h:12
Definition: shell.h:41
LPDEVMODEW pDevMode
Definition: winspool.h:862
ACCESS_MASK DesiredAccess
Definition: winspool.h:863
WINSPOOL_DOC_INFO_1 * pDocInfo1
Definition: winspool.idl:577
union _WINSPOOL_DOC_INFO_CONTAINER::@3434 DocInfo
uint16_t * PWSTR
Definition: typedefs.h:56
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:239
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
struct _devicemodeW * PDEVMODEW
WINBOOL WINAPI ResetPrinterW(HANDLE hPrinter, LPPRINTER_DEFAULTSW pDefault)
Definition: printers.c:2965
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193