[PRINTING]
[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* 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
82 dwErrorCode = RpcImpersonateClient(NULL);
83 if (dwErrorCode != ERROR_SUCCESS)
84 {
85 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
86 return dwErrorCode;
87 }
88
89 EnumPrintProcessorsW(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
90 dwErrorCode = GetLastError();
91
92 if (dwErrorCode == ERROR_SUCCESS)
93 {
94 // Replace absolute pointer addresses in the output by relative offsets.
95 DWORD i;
96 PPRINTPROCESSOR_INFO_1W p = (PPRINTPROCESSOR_INFO_1W)pPrintProcessorInfo;
97
98 for (i = 0; i < *pcReturned; i++)
99 _MarshallDownPrintProcessorInfo(&p);
100 }
101
102 RpcRevertToSelf();
103 return dwErrorCode;
104 }
105
106 DWORD
107 _RpcGetPrintProcessorDirectory(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorDirectory, DWORD cbBuf, DWORD* pcbNeeded)
108 {
109 DWORD dwErrorCode;
110
111 dwErrorCode = RpcImpersonateClient(NULL);
112 if (dwErrorCode != ERROR_SUCCESS)
113 {
114 ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
115 return dwErrorCode;
116 }
117
118 GetPrintProcessorDirectoryW(pName, pEnvironment, Level, pPrintProcessorDirectory, cbBuf, pcbNeeded);
119 dwErrorCode = GetLastError();
120
121 RpcRevertToSelf();
122 return dwErrorCode;
123 }