[SPOOLSV, WINSPOOL]
[reactos.git] / reactos / win32ss / printing / base / spoolsv / printprocessors.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 Print Processors
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 static void
11 _MarshallDownDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1)
12 {
13 // Replace absolute pointer addresses in the output by relative offsets.
14 pDatatypesInfo1->pName = (PWSTR)((ULONG_PTR)pDatatypesInfo1->pName - (ULONG_PTR)pDatatypesInfo1);
15 }
16
17 static void
18 _MarshallDownPrintProcessorInfo(PPRINTPROCESSOR_INFO_1W pPrintProcessorInfo1)
19 {
20 // Replace absolute pointer addresses in the output by relative offsets.
21 pPrintProcessorInfo1->pName = (PWSTR)((ULONG_PTR)pPrintProcessorInfo1->pName - (ULONG_PTR)pPrintProcessorInfo1);
22 }
23
24 DWORD
25 _RpcAddPrintProcessor(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, WCHAR* pPathName, WCHAR* pPrintProcessorName)
26 {
27 UNIMPLEMENTED;
28 return ERROR_INVALID_FUNCTION;
29 }
30
31 DWORD
32 _RpcDeletePrintProcessor(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, WCHAR* pPrintProcessorName)
33 {
34 UNIMPLEMENTED;
35 return ERROR_INVALID_FUNCTION;
36 }
37
38 DWORD
39 _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorName, DWORD Level, BYTE* pDatatypes, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
40 {
41 DWORD dwErrorCode;
42 DWORD i;
43 PBYTE p = pDatatypes;
44
45 dwErrorCode = RpcImpersonateClient(NULL);
46 if (dwErrorCode != ERROR_SUCCESS)
47 {
48 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
49 return dwErrorCode;
50 }
51
52 EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
53 dwErrorCode = GetLastError();
54
55 if (dwErrorCode == ERROR_SUCCESS)
56 {
57 // Replace absolute pointer addresses in the output by relative offsets.
58 for (i = 0; i < *pcReturned; i++)
59 {
60 _MarshallDownDatatypesInfo((PDATATYPES_INFO_1W)p);
61 p += sizeof(DATATYPES_INFO_1W);
62 }
63 }
64
65 RpcRevertToSelf();
66 return dwErrorCode;
67 }
68
69 DWORD
70 _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorInfo, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
71 {
72 DWORD dwErrorCode;
73 DWORD i;
74 PBYTE p = pPrintProcessorInfo;
75
76 dwErrorCode = RpcImpersonateClient(NULL);
77 if (dwErrorCode != ERROR_SUCCESS)
78 {
79 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
80 return dwErrorCode;
81 }
82
83 EnumPrintProcessorsW(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
84 dwErrorCode = GetLastError();
85
86 if (dwErrorCode == ERROR_SUCCESS)
87 {
88 // Replace absolute pointer addresses in the output by relative offsets.
89 for (i = 0; i < *pcReturned; i++)
90 {
91 _MarshallDownPrintProcessorInfo((PPRINTPROCESSOR_INFO_1W)p);
92 p += sizeof(PRINTPROCESSOR_INFO_1W);
93 }
94 }
95
96 RpcRevertToSelf();
97 return dwErrorCode;
98 }
99
100 DWORD
101 _RpcGetPrintProcessorDirectory(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorDirectory, DWORD cbBuf, DWORD* pcbNeeded)
102 {
103 DWORD dwErrorCode;
104
105 dwErrorCode = RpcImpersonateClient(NULL);
106 if (dwErrorCode != ERROR_SUCCESS)
107 {
108 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
109 return dwErrorCode;
110 }
111
112 GetPrintProcessorDirectoryW(pName, pEnvironment, Level, pPrintProcessorDirectory, cbBuf, pcbNeeded);
113 dwErrorCode = GetLastError();
114
115 RpcRevertToSelf();
116 return dwErrorCode;
117 }