2 * PROJECT: ReactOS Print Spooler Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions related to Printer Drivers
5 * COPYRIGHT: Copyright 2015 Colin Finck (colin@reactos.org)
9 #include "marshalling/printerdrivers.h"
12 _RpcAddPrinterDriver(WINSPOOL_HANDLE pName
, WINSPOOL_DRIVER_CONTAINER
* pDriverContainer
)
15 PBYTE pDriverInfo
= NULL
;
17 switch ( pDriverContainer
->Level
)
21 WINSPOOL_DRIVER_INFO_8
*pdi
= pDriverContainer
->DriverInfo
.Level8
;
22 PDRIVER_INFO_8W pdi8w
= DllAllocSplMem(sizeof(DRIVER_INFO_8W
));
23 pDriverInfo
= (PBYTE
)pdi8w
;
25 pdi8w
->pszPrintProcessor
= pdi
->pPrintProcessor
;
26 pdi8w
->pszVendorSetup
= pdi
->pVendorSetup
;
27 pdi8w
->pszzColorProfiles
= pdi
->pszzColorProfiles
;
28 pdi8w
->pszInfPath
= pdi
->pInfPath
;
29 pdi8w
->pszzCoreDriverDependencies
= pdi
->pszzCoreDriverDependencies
;
30 pdi8w
->ftMinInboxDriverVerDate
= pdi
->ftMinInboxDriverVerDate
;
31 pdi8w
->dwlMinInboxDriverVerVersion
= pdi
->dwlMinInboxDriverVerVersion
;
35 WINSPOOL_DRIVER_INFO_6
*pdi
= pDriverContainer
->DriverInfo
.Level6
;
36 PDRIVER_INFO_6W pdi6w
;
38 if ( pDriverInfo
== NULL
)
40 pdi6w
= DllAllocSplMem(sizeof(DRIVER_INFO_6W
));
41 pDriverInfo
= (PBYTE
)pdi6w
;
45 pdi6w
= (PDRIVER_INFO_6W
)pDriverInfo
;
48 pdi6w
->pszMfgName
= pdi
->pMfgName
;
49 pdi6w
->pszOEMUrl
= pdi
->pOEMUrl
;
50 pdi6w
->pszHardwareID
= pdi
->pHardwareID
;
51 pdi6w
->pszProvider
= pdi
->pProvider
;
52 pdi6w
->ftDriverDate
= pdi
->ftDriverDate
;
53 pdi6w
->dwlDriverVersion
= pdi
->dwlDriverVersion
;
57 WINSPOOL_DRIVER_INFO_4
*pdi
= pDriverContainer
->DriverInfo
.Level4
;
58 PDRIVER_INFO_4W pdi4w
;
60 if ( pDriverInfo
== NULL
)
62 pdi4w
= DllAllocSplMem(sizeof(DRIVER_INFO_4W
));
63 pDriverInfo
= (PBYTE
)pdi4w
;
67 pdi4w
= (PDRIVER_INFO_4W
)pDriverInfo
;
70 pdi4w
->pszzPreviousNames
= pdi
->pszzPreviousNames
;
74 WINSPOOL_DRIVER_INFO_3
*pdi
= pDriverContainer
->DriverInfo
.Level3
;
75 PDRIVER_INFO_3W pdi3w
;
77 if ( pDriverInfo
== NULL
)
79 pdi3w
= DllAllocSplMem(sizeof(DRIVER_INFO_3W
));
80 pDriverInfo
= (PBYTE
)pdi3w
;
84 pdi3w
= (PDRIVER_INFO_3W
)pDriverInfo
;
87 pdi3w
->pHelpFile
= pdi
->pHelpFile
;
88 pdi3w
->pDependentFiles
= pdi
->pDependentFiles
;
89 pdi3w
->pMonitorName
= pdi
->pMonitorName
;
90 pdi3w
->pDefaultDataType
= pdi
->pDefaultDataType
;
91 pdi3w
->pDependentFiles
= pdi
->pDependentFiles
;
95 WINSPOOL_DRIVER_INFO_2
*pdi
= pDriverContainer
->DriverInfo
.Level2
;
96 PDRIVER_INFO_2W pdi2w
;
98 if ( pDriverInfo
== NULL
)
100 pdi2w
= DllAllocSplMem(sizeof(DRIVER_INFO_2W
));
101 pDriverInfo
= (PBYTE
)pdi2w
;
105 pdi2w
= (PDRIVER_INFO_2W
)pDriverInfo
;
108 pdi2w
->pName
= pdi
->pName
;
109 pdi2w
->pEnvironment
= pdi
->pEnvironment
;
110 pdi2w
->pDriverPath
= pdi
->pDriverPath
;
111 pdi2w
->pDataFile
= pdi
->pDataFile
;
112 pdi2w
->pConfigFile
= pdi
->pConfigFile
;
116 // At this point pDriverInfo is null.
119 return ERROR_INVALID_LEVEL
;
122 dwErrorCode
= RpcImpersonateClient(NULL
);
123 if (dwErrorCode
!= ERROR_SUCCESS
)
125 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
129 if (!AddPrinterDriverW( pName
, pDriverContainer
->Level
, pDriverInfo
))
130 dwErrorCode
= GetLastError();
132 if ( pDriverInfo
) DllFreeSplMem( pDriverInfo
);
139 _RpcAddPrinterDriverEx(WINSPOOL_HANDLE pName
, WINSPOOL_DRIVER_CONTAINER
* pDriverContainer
, DWORD dwFileCopyFlags
)
142 PBYTE pDriverInfo
= NULL
;
144 switch ( pDriverContainer
->Level
)
148 WINSPOOL_DRIVER_INFO_8
*pdi
= pDriverContainer
->DriverInfo
.Level8
;
149 PDRIVER_INFO_8W pdi8w
= DllAllocSplMem(sizeof(DRIVER_INFO_8W
));
150 pDriverInfo
= (PBYTE
)pdi8w
;
152 pdi8w
->pszPrintProcessor
= pdi
->pPrintProcessor
;
153 pdi8w
->pszVendorSetup
= pdi
->pVendorSetup
;
154 pdi8w
->pszzColorProfiles
= pdi
->pszzColorProfiles
;
155 pdi8w
->pszInfPath
= pdi
->pInfPath
;
156 pdi8w
->pszzCoreDriverDependencies
= pdi
->pszzCoreDriverDependencies
;
157 pdi8w
->ftMinInboxDriverVerDate
= pdi
->ftMinInboxDriverVerDate
;
158 pdi8w
->dwlMinInboxDriverVerVersion
= pdi
->dwlMinInboxDriverVerVersion
;
162 WINSPOOL_DRIVER_INFO_6
*pdi
= pDriverContainer
->DriverInfo
.Level6
;
163 PDRIVER_INFO_6W pdi6w
;
165 if ( pDriverInfo
== NULL
)
167 pdi6w
= DllAllocSplMem(sizeof(DRIVER_INFO_6W
));
168 pDriverInfo
= (PBYTE
)pdi6w
;
172 pdi6w
= (PDRIVER_INFO_6W
)pDriverInfo
;
175 pdi6w
->pszMfgName
= pdi
->pMfgName
;
176 pdi6w
->pszOEMUrl
= pdi
->pOEMUrl
;
177 pdi6w
->pszHardwareID
= pdi
->pHardwareID
;
178 pdi6w
->pszProvider
= pdi
->pProvider
;
179 pdi6w
->ftDriverDate
= pdi
->ftDriverDate
;
180 pdi6w
->dwlDriverVersion
= pdi
->dwlDriverVersion
;
184 WINSPOOL_DRIVER_INFO_4
*pdi
= pDriverContainer
->DriverInfo
.Level4
;
185 PDRIVER_INFO_4W pdi4w
;
187 if ( pDriverInfo
== NULL
)
189 pdi4w
= DllAllocSplMem(sizeof(DRIVER_INFO_4W
));
190 pDriverInfo
= (PBYTE
)pdi4w
;
194 pdi4w
= (PDRIVER_INFO_4W
)pDriverInfo
;
197 pdi4w
->pszzPreviousNames
= pdi
->pszzPreviousNames
;
201 WINSPOOL_DRIVER_INFO_3
*pdi
= pDriverContainer
->DriverInfo
.Level3
;
202 PDRIVER_INFO_3W pdi3w
;
204 if ( pDriverInfo
== NULL
)
206 pdi3w
= DllAllocSplMem(sizeof(DRIVER_INFO_3W
));
207 pDriverInfo
= (PBYTE
)pdi3w
;
211 pdi3w
= (PDRIVER_INFO_3W
)pDriverInfo
;
214 pdi3w
->pHelpFile
= pdi
->pHelpFile
;
215 pdi3w
->pDependentFiles
= pdi
->pDependentFiles
;
216 pdi3w
->pMonitorName
= pdi
->pMonitorName
;
217 pdi3w
->pDefaultDataType
= pdi
->pDefaultDataType
;
218 pdi3w
->pDependentFiles
= pdi
->pDependentFiles
;
222 WINSPOOL_DRIVER_INFO_2
*pdi
= pDriverContainer
->DriverInfo
.Level2
;
223 PDRIVER_INFO_2W pdi2w
;
225 if ( pDriverInfo
== NULL
)
227 pdi2w
= DllAllocSplMem(sizeof(DRIVER_INFO_2W
));
228 pDriverInfo
= (PBYTE
)pdi2w
;
232 pdi2w
= (PDRIVER_INFO_2W
)pDriverInfo
;
235 pdi2w
->pName
= pdi
->pName
;
236 pdi2w
->pEnvironment
= pdi
->pEnvironment
;
237 pdi2w
->pDriverPath
= pdi
->pDriverPath
;
238 pdi2w
->pDataFile
= pdi
->pDataFile
;
239 pdi2w
->pConfigFile
= pdi
->pConfigFile
;
243 // At this point pDriverInfo is null.
246 return ERROR_INVALID_LEVEL
;
249 dwErrorCode
= RpcImpersonateClient(NULL
);
250 if (dwErrorCode
!= ERROR_SUCCESS
)
252 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
256 if (!AddPrinterDriverExW( pName
, pDriverContainer
->Level
, pDriverInfo
, dwFileCopyFlags
))
257 dwErrorCode
= GetLastError();
259 if ( pDriverInfo
) DllFreeSplMem( pDriverInfo
);
266 _RpcDeletePrinterDriver(WINSPOOL_HANDLE pName
, WCHAR
* pEnvironment
, WCHAR
* pDriverName
)
270 dwErrorCode
= RpcImpersonateClient(NULL
);
271 if (dwErrorCode
!= ERROR_SUCCESS
)
273 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
277 if (!DeletePrinterDriverW(pName
, pEnvironment
, pDriverName
))
278 dwErrorCode
= GetLastError();
285 _RpcDeletePrinterDriverEx(WINSPOOL_HANDLE pName
, WCHAR
* pEnvironment
, WCHAR
* pDriverName
, DWORD dwDeleteFlag
, DWORD dwVersionNum
)
289 dwErrorCode
= RpcImpersonateClient(NULL
);
290 if (dwErrorCode
!= ERROR_SUCCESS
)
292 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
296 if (!DeletePrinterDriverExW(pName
, pEnvironment
, pDriverName
, dwDeleteFlag
, dwVersionNum
))
297 dwErrorCode
= GetLastError();
304 _RpcEnumPrinterDrivers(WINSPOOL_HANDLE pName
, WCHAR
* pEnvironment
, DWORD Level
, BYTE
* pDrivers
, DWORD cbBuf
, DWORD
* pcbNeeded
, DWORD
* pcReturned
)
307 PBYTE pPrinterDriversEnumAligned
;
309 dwErrorCode
= RpcImpersonateClient(NULL
);
310 if (dwErrorCode
!= ERROR_SUCCESS
)
312 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
316 pPrinterDriversEnumAligned
= AlignRpcPtr(pDrivers
, &cbBuf
);
318 if (EnumPrinterDriversW(pName
, pEnvironment
, Level
, pPrinterDriversEnumAligned
, cbBuf
, pcbNeeded
, pcReturned
))
320 // Replace absolute pointer addresses in the output by relative offsets.
321 ASSERT(Level
<= 6 || Level
== 8);
322 MarshallDownStructuresArray(pPrinterDriversEnumAligned
, *pcReturned
, pPrinterDriverMarshalling
[Level
]->pInfo
, pPrinterDriverMarshalling
[Level
]->cbStructureSize
, TRUE
);
326 dwErrorCode
= GetLastError();
330 UndoAlignRpcPtr(pDrivers
, pPrinterDriversEnumAligned
, cbBuf
, pcbNeeded
);
336 _RpcGetPrinterDriver(WINSPOOL_PRINTER_HANDLE hPrinter
, WCHAR
* pEnvironment
, DWORD Level
, BYTE
* pDriver
, DWORD cbBuf
, DWORD
* pcbNeeded
)
339 PBYTE pDriverAligned
;
341 TRACE("_RpcGetPrinterDriver(%p, %lu, %lu, %p, %lu, %p)\n", hPrinter
, pEnvironment
, Level
, pDriver
, cbBuf
, pcbNeeded
);
343 dwErrorCode
= RpcImpersonateClient(NULL
);
344 if (dwErrorCode
!= ERROR_SUCCESS
)
346 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
350 pDriverAligned
= AlignRpcPtr(pDriver
, &cbBuf
);
352 if (GetPrinterDriverW(hPrinter
, pEnvironment
, Level
, pDriverAligned
, cbBuf
, pcbNeeded
))
354 // Replace relative offset addresses in the output by absolute pointers.
355 ASSERT(Level
<= 6 || Level
== 8);
356 MarshallDownStructure(pDriverAligned
, pPrinterDriverMarshalling
[Level
]->pInfo
, pPrinterDriverMarshalling
[Level
]->cbStructureSize
, TRUE
);
360 dwErrorCode
= GetLastError();
364 UndoAlignRpcPtr(pDriver
, pDriverAligned
, cbBuf
, pcbNeeded
);
369 BOOL WINAPI
YGetPrinterDriver2(
376 DWORD dwClientMajorVersion
,
377 DWORD dwClientMinorVersion
,
378 PDWORD pdwServerMajorVersion
,
379 PDWORD pdwServerMinorVersion
,
380 BOOL bRPC
) // Seems that all Y fuctions have this.
383 PBYTE pDriverAligned
;
385 FIXME("_Rpc(Y)GetPrinterDriver2(%p, %lu, %lu, %p, %lu, %p, %lu, %lu, %p, %p)\n", hPrinter
, pEnvironment
, Level
, pDriver
, cbBuf
, pcbNeeded
, dwClientMajorVersion
, dwClientMinorVersion
, pdwServerMajorVersion
, pdwServerMinorVersion
);
389 dwErrorCode
= RpcImpersonateClient(NULL
);
390 if (dwErrorCode
!= ERROR_SUCCESS
)
392 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
397 pDriverAligned
= AlignRpcPtr(pDriver
, &cbBuf
);
399 if (GetPrinterDriverExW(hPrinter
, pEnvironment
, Level
, pDriverAligned
, cbBuf
, pcbNeeded
, dwClientMajorVersion
, dwClientMinorVersion
, pdwServerMajorVersion
, pdwServerMinorVersion
))
401 // Replace relative offset addresses in the output by absolute pointers.
402 ASSERT(Level
<= 6 || Level
== 8);
403 MarshallDownStructure(pDriverAligned
, pPrinterDriverMarshalling
[Level
]->pInfo
, pPrinterDriverMarshalling
[Level
]->cbStructureSize
, TRUE
);
407 dwErrorCode
= GetLastError();
410 if ( bRPC
) RpcRevertToSelf();
411 UndoAlignRpcPtr(pDriver
, pDriverAligned
, cbBuf
, pcbNeeded
);
417 _RpcGetPrinterDriver2(WINSPOOL_PRINTER_HANDLE hPrinter
, WCHAR
* pEnvironment
, DWORD Level
, BYTE
* pDriver
, DWORD cbBuf
, DWORD
* pcbNeeded
, DWORD dwClientMajorVersion
, DWORD dwClientMinorVersion
, DWORD
* pdwServerMaxVersion
, DWORD
* pdwServerMinVersion
)
420 PBYTE pDriverAligned
;
422 FIXME("_RpcGetPrinterDriver2(%p, %lu, %lu, %p, %lu, %p, %lu, %lu, %p, %p)\n", hPrinter
, pEnvironment
, Level
, pDriver
, cbBuf
, pcbNeeded
, dwClientMajorVersion
, dwClientMinorVersion
, pdwServerMaxVersion
, pdwServerMinVersion
);
424 dwErrorCode
= RpcImpersonateClient(NULL
);
425 if (dwErrorCode
!= ERROR_SUCCESS
)
427 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
431 pDriverAligned
= AlignRpcPtr(pDriver
, &cbBuf
);
433 if (GetPrinterDriverExW(hPrinter
, pEnvironment
, Level
, pDriverAligned
, cbBuf
, pcbNeeded
, dwClientMajorVersion
, dwClientMinorVersion
, pdwServerMaxVersion
, pdwServerMinVersion
))
435 // Replace relative offset addresses in the output by absolute pointers.
436 ASSERT(Level
<= 6 || Level
== 8);
437 MarshallDownStructure(pDriverAligned
, pPrinterDriverMarshalling
[Level
]->pInfo
, pPrinterDriverMarshalling
[Level
]->cbStructureSize
, TRUE
);
441 dwErrorCode
= GetLastError();
445 UndoAlignRpcPtr(pDriver
, pDriverAligned
, cbBuf
, pcbNeeded
);
451 _RpcGetPrinterDriverDirectory(WINSPOOL_HANDLE pName
, WCHAR
* pEnvironment
, DWORD Level
, BYTE
* pDriverDirectory
, DWORD cbBuf
, DWORD
* pcbNeeded
)
455 dwErrorCode
= RpcImpersonateClient(NULL
);
456 if (dwErrorCode
!= ERROR_SUCCESS
)
458 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode
);
462 if (!GetPrinterDriverDirectoryW(pName
, pEnvironment
, Level
, pDriverDirectory
, cbBuf
, pcbNeeded
))
463 dwErrorCode
= GetLastError();