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