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-2018 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 #include <marshalling/printprocessors.h>
10 
11 DWORD
12 _RpcAddPrintProcessor(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, WCHAR* pPathName, WCHAR* pPrintProcessorName)
13 {
14     DWORD dwErrorCode;
15 
16     dwErrorCode = RpcImpersonateClient(NULL);
17     if (dwErrorCode != ERROR_SUCCESS)
18     {
19         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
20         return dwErrorCode;
21     }
22 
23     if (!AddPrintProcessorW(pName, pEnvironment, pPathName, pPrintProcessorName))
24         dwErrorCode = GetLastError();
25 
26     RpcRevertToSelf();
27     return dwErrorCode;
28 }
29 
30 DWORD
31 _RpcDeletePrintProcessor(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, WCHAR* pPrintProcessorName)
32 {
33     DWORD dwErrorCode;
34 
35     dwErrorCode = RpcImpersonateClient(NULL);
36     if (dwErrorCode != ERROR_SUCCESS)
37     {
38         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
39         return dwErrorCode;
40     }
41 
42     if (!DeletePrintProcessorW(pName, pEnvironment, pPrintProcessorName))
43         dwErrorCode = GetLastError();
44 
45     RpcRevertToSelf();
46     return dwErrorCode;
47 }
48 
49 DWORD
50 _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR* pPrintProcessorName, DWORD Level, BYTE* pDatatypes, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
51 {
52     DWORD dwErrorCode;
53     PBYTE pDatatypesAligned;
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     pDatatypesAligned = AlignRpcPtr(pDatatypes, &cbBuf);
63 
64     if (EnumPrintProcessorDatatypesW(pName, pPrintProcessorName, Level, pDatatypesAligned, cbBuf, pcbNeeded, pcReturned))
65     {
66         // Replace absolute pointer addresses in the output by relative offsets.
67         MarshallDownStructuresArray(pDatatypesAligned, *pcReturned, DatatypesInfo1Marshalling.pInfo, DatatypesInfo1Marshalling.cbStructureSize, TRUE);
68     }
69     else
70     {
71         dwErrorCode = GetLastError();
72     }
73 
74     RpcRevertToSelf();
75     UndoAlignRpcPtr(pDatatypes, pDatatypesAligned, cbBuf, pcbNeeded);
76 
77     return dwErrorCode;
78 }
79 
80 DWORD
81 _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorInfo, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
82 {
83     DWORD dwErrorCode;
84     PBYTE pPrintProcessorInfoAligned;
85 
86     dwErrorCode = RpcImpersonateClient(NULL);
87     if (dwErrorCode != ERROR_SUCCESS)
88     {
89         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
90         return dwErrorCode;
91     }
92 
93     pPrintProcessorInfoAligned = AlignRpcPtr(pPrintProcessorInfo, &cbBuf);
94 
95     if (EnumPrintProcessorsW(pName, pEnvironment, Level, pPrintProcessorInfoAligned, cbBuf, pcbNeeded, pcReturned))
96     {
97         // Replace absolute pointer addresses in the output by relative offsets.
98         MarshallDownStructuresArray(pPrintProcessorInfoAligned, *pcReturned, PrintProcessorInfo1Marshalling.pInfo, PrintProcessorInfo1Marshalling.cbStructureSize, TRUE);
99     }
100     else
101     {
102         dwErrorCode = GetLastError();
103     }
104 
105     RpcRevertToSelf();
106     UndoAlignRpcPtr(pPrintProcessorInfo, pPrintProcessorInfoAligned, cbBuf, pcbNeeded);
107 
108     return dwErrorCode;
109 }
110 
111 DWORD
112 _RpcGetPrintProcessorDirectory(WINSPOOL_HANDLE pName, WCHAR* pEnvironment, DWORD Level, BYTE* pPrintProcessorDirectory, DWORD cbBuf, DWORD* pcbNeeded)
113 {
114     DWORD dwErrorCode;
115 
116     dwErrorCode = RpcImpersonateClient(NULL);
117     if (dwErrorCode != ERROR_SUCCESS)
118     {
119         ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
120         return dwErrorCode;
121     }
122 
123     if (!GetPrintProcessorDirectoryW(pName, pEnvironment, Level, pPrintProcessorDirectory, cbBuf, pcbNeeded))
124         dwErrorCode = GetLastError();
125 
126     RpcRevertToSelf();
127     return dwErrorCode;
128 }
129