[SPOOLSV]
[reactos.git] / reactos / win32ss / printing / base / spoolsv / printers.c
1 /*
2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Functions related to Printers and printing
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 DWORD
11 _RpcClosePrinter(WINSPOOL_PRINTER_HANDLE *phPrinter)
12 {
13 DWORD dwErrorCode;
14
15 dwErrorCode = RpcImpersonateClient(NULL);
16 if (dwErrorCode != ERROR_SUCCESS)
17 {
18 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
19 return dwErrorCode;
20 }
21
22 if (ClosePrinter(*phPrinter))
23 *phPrinter = NULL;
24
25 dwErrorCode = GetLastError();
26
27 RpcRevertToSelf();
28 return dwErrorCode;
29 }
30
31 DWORD
32 _RpcEndDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
33 {
34 DWORD dwErrorCode;
35
36 dwErrorCode = RpcImpersonateClient(NULL);
37 if (dwErrorCode != ERROR_SUCCESS)
38 {
39 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
40 return dwErrorCode;
41 }
42
43 EndDocPrinter(hPrinter);
44 dwErrorCode = GetLastError();
45
46 RpcRevertToSelf();
47 return dwErrorCode;
48 }
49
50 DWORD
51 _RpcEndPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
52 {
53 DWORD dwErrorCode;
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 EndPagePrinter(hPrinter);
63 dwErrorCode = GetLastError();
64
65 RpcRevertToSelf();
66 return dwErrorCode;
67 }
68
69 DWORD
70 _RpcEnumPrinters(DWORD Flags, WINSPOOL_HANDLE Name, DWORD Level, BYTE* pPrinterEnum, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
71 {
72 DWORD dwErrorCode;
73
74 dwErrorCode = RpcImpersonateClient(NULL);
75 if (dwErrorCode != ERROR_SUCCESS)
76 {
77 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
78 return dwErrorCode;
79 }
80
81 EnumPrintersW(Flags, Name, Level, pPrinterEnum, cbBuf, pcbNeeded, pcReturned);
82 dwErrorCode = GetLastError();
83
84 RpcRevertToSelf();
85 return dwErrorCode;
86 }
87
88 DWORD
89 _RpcOpenPrinter(WINSPOOL_HANDLE pPrinterName, WINSPOOL_PRINTER_HANDLE* phPrinter, WCHAR* pDatatype, WINSPOOL_DEVMODE_CONTAINER* pDevModeContainer, DWORD AccessRequired)
90 {
91 DWORD dwErrorCode;
92 PRINTER_DEFAULTSW Default;
93
94 dwErrorCode = RpcImpersonateClient(NULL);
95 if (dwErrorCode != ERROR_SUCCESS)
96 {
97 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
98 return dwErrorCode;
99 }
100
101 Default.DesiredAccess = AccessRequired;
102 Default.pDatatype = pDatatype;
103 Default.pDevMode = (PDEVMODEW)pDevModeContainer->pDevMode;
104
105 OpenPrinterW(pPrinterName, phPrinter, &Default);
106 dwErrorCode = GetLastError();
107
108 RpcRevertToSelf();
109 return dwErrorCode;
110 }
111
112 DWORD
113 _RpcReadPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcNoBytesRead)
114 {
115 DWORD dwErrorCode;
116
117 dwErrorCode = RpcImpersonateClient(NULL);
118 if (dwErrorCode != ERROR_SUCCESS)
119 {
120 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
121 return dwErrorCode;
122 }
123
124 ReadPrinter(hPrinter, pBuf, cbBuf, pcNoBytesRead);
125 dwErrorCode = GetLastError();
126
127 RpcRevertToSelf();
128 return dwErrorCode;
129 }
130
131 DWORD
132 _RpcStartDocPrinter(WINSPOOL_PRINTER_HANDLE hPrinter, WINSPOOL_DOC_INFO_CONTAINER* pDocInfoContainer, DWORD* pJobId)
133 {
134 DWORD dwErrorCode;
135
136 dwErrorCode = RpcImpersonateClient(NULL);
137 if (dwErrorCode != ERROR_SUCCESS)
138 {
139 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
140 return dwErrorCode;
141 }
142
143 *pJobId = StartDocPrinterW(hPrinter, pDocInfoContainer->Level, (PBYTE)pDocInfoContainer->DocInfo.pDocInfo1);
144 dwErrorCode = GetLastError();
145
146 RpcRevertToSelf();
147 return dwErrorCode;
148 }
149
150 DWORD
151 _RpcStartPagePrinter(WINSPOOL_PRINTER_HANDLE hPrinter)
152 {
153 DWORD dwErrorCode;
154
155 dwErrorCode = RpcImpersonateClient(NULL);
156 if (dwErrorCode != ERROR_SUCCESS)
157 {
158 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
159 return dwErrorCode;
160 }
161
162 StartPagePrinter(hPrinter);
163 dwErrorCode = GetLastError();
164
165 RpcRevertToSelf();
166 return dwErrorCode;
167 }
168
169 DWORD
170 _RpcWritePrinter(WINSPOOL_PRINTER_HANDLE hPrinter, BYTE *pBuf, DWORD cbBuf, DWORD *pcWritten)
171 {
172 DWORD dwErrorCode;
173
174 dwErrorCode = RpcImpersonateClient(NULL);
175 if (dwErrorCode != ERROR_SUCCESS)
176 {
177 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
178 return dwErrorCode;
179 }
180
181 WritePrinter(hPrinter, pBuf, cbBuf, pcWritten);
182 dwErrorCode = GetLastError();
183
184 RpcRevertToSelf();
185 return dwErrorCode;
186 }