ReactOS  0.4.15-dev-1074-gffc96d2
printprocessors.c
Go to the documentation of this file.
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"
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 
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 
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.
68  }
69  else
70  {
71  dwErrorCode = GetLastError();
72  }
73 
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.
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 }
DWORD cbStructureSize
Definition: marshalling.h:25
BOOL WINAPI DeletePrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProcessorName)
MARSHALLING_INFO pInfo[]
Definition: marshalling.h:26
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
static const MARSHALLING DatatypesInfo1Marshalling
smooth NULL
Definition: ftsmooth.c:416
DWORD _RpcAddPrintProcessor(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, WCHAR *pPathName, WCHAR *pPrintProcessorName)
DWORD _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR *pPrintProcessorName, DWORD Level, BYTE *pDatatypes, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1459
static LPSTR pName
Definition: security.c:75
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
BOOL WINAPI AddPrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPathName, PWSTR pPrintProcessorName)
unsigned char BYTE
Definition: xxhash.c:193
DWORD _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, DWORD Level, BYTE *pPrintProcessorInfo, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
DWORD _RpcDeletePrintProcessor(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, WCHAR *pPrintProcessorName)
static const MARSHALLING PrintProcessorInfo1Marshalling
#define ERR(fmt,...)
Definition: debug.h:110
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:239
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1052
BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
DWORD _RpcGetPrintProcessorDirectory(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, DWORD Level, BYTE *pPrintProcessorDirectory, DWORD cbBuf, DWORD *pcbNeeded)
BYTE * PBYTE
Definition: pedump.c:66
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15
BOOL WINAPI EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)