ReactOS  0.4.15-dev-1207-g698a8e6
ports.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 Ports
5  * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 #include <marshalling/ports.h>
10 
11 DWORD
13 {
14  DWORD dwErrorCode;
15 
16  FIXME("AddPort(%S, %p, %s)\n", pName, hWnd, debugstr_w(pMonitorName));
17 
18  dwErrorCode = RpcImpersonateClient(NULL);
19  if (dwErrorCode != ERROR_SUCCESS)
20  {
21  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
22  return dwErrorCode;
23  }
24 
25  if (!AddPortW( pName, (HWND)hWnd, pMonitorName ))
26  dwErrorCode = GetLastError();
27 
29  return dwErrorCode;
30 }
31 
32 DWORD
34 {
35  DWORD dwErrorCode, Level = pPortContainer->Level;
36  WINSPOOL_PORT_INFO_FF PortInfoFF;
38 
39  FIXME("AddPortEx(%S, %lu, %s)\n", pName, Level, debugstr_w(pMonitorName));
40 
41  switch (Level)
42  {
43  case 1:
44  lpBuffer = (PBYTE)pPortContainer->PortInfo.pPortInfo1;
45  break;
46 
47  case 0xFFFFFFFF:
48  PortInfoFF.pPortName = pPortContainer->PortInfo.pPortInfoFF->pPortName;
49  PortInfoFF.cbMonitorData = pPortVarContainer->cbMonitorData;
50  PortInfoFF.pMonitorData = pPortVarContainer->pMonitorData;
51  lpBuffer = (PBYTE)&PortInfoFF;
52  break;
53 
54  default:
55  ERR("Level = %d, unsupported!\n", Level);
56  return ERROR_INVALID_LEVEL;
57  }
58 
59  dwErrorCode = RpcImpersonateClient(NULL);
60  if (dwErrorCode != ERROR_SUCCESS)
61  {
62  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
63  return dwErrorCode;
64  }
65 
66  if (!AddPortExW(pName, Level, lpBuffer, pMonitorName ))
67  dwErrorCode = GetLastError();
68 
70  return dwErrorCode;
71 }
72 
73 DWORD
75 {
76  DWORD dwErrorCode;
77 
78  dwErrorCode = RpcImpersonateClient(NULL);
79  if (dwErrorCode != ERROR_SUCCESS)
80  {
81  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
82  return dwErrorCode;
83  }
84 
85  if (!ConfigurePortW( pName, (HWND)hWnd, pPortName ))
86  dwErrorCode = GetLastError();
87 
89  return dwErrorCode;
90 }
91 
92 DWORD
94 {
95  DWORD dwErrorCode;
96 
97  dwErrorCode = RpcImpersonateClient(NULL);
98  if (dwErrorCode != ERROR_SUCCESS)
99  {
100  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
101  return dwErrorCode;
102  }
103 
104  if (!DeletePortW( pName, (HWND)hWnd, pPortName ))
105  dwErrorCode = GetLastError();
106 
107  RpcRevertToSelf();
108  return dwErrorCode;
109 }
110 
111 DWORD
113 {
114  DWORD dwErrorCode;
115  PBYTE pPortAligned;
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  pPortAligned = AlignRpcPtr(pPort, &cbBuf);
125 
126  if (EnumPortsW(pName, Level, pPortAligned, cbBuf, pcbNeeded, pcReturned))
127  {
128  // Replace absolute pointer addresses in the output by relative offsets.
129  ASSERT(Level >= 1 && Level <= 2);
130  MarshallDownStructuresArray(pPortAligned, *pcReturned, pPortInfoMarshalling[Level]->pInfo, pPortInfoMarshalling[Level]->cbStructureSize, TRUE);
131  }
132  else
133  {
134  dwErrorCode = GetLastError();
135  }
136 
137  RpcRevertToSelf();
138  UndoAlignRpcPtr(pPort, pPortAligned, cbBuf, pcbNeeded);
139 
140  return dwErrorCode;
141 }
142 
143 DWORD
145 {
146  DWORD dwErrorCode;
147 
148  dwErrorCode = RpcImpersonateClient(NULL);
149  if (dwErrorCode != ERROR_SUCCESS)
150  {
151  ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
152  return dwErrorCode;
153  }
154 
155  if (!SetPortW(pName, pPortName, pPortContainer->Level, (PBYTE)pPortContainer->PortInfo.pPortInfo3))
156  dwErrorCode = GetLastError();
157 
158  RpcRevertToSelf();
159  return dwErrorCode;
160 }
BOOL WINAPI SetPortW(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
Definition: ports.c:216
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD _RpcAddPort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pMonitorName)
Definition: ports.c:12
BOOL WINAPI ConfigurePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:81
#define TRUE
Definition: types.h:120
BOOL WINAPI EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: ports.c:147
HWND hWnd
Definition: settings.c:17
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
WINSPOOL_PORT_INFO_1 * pPortInfo1
Definition: winspool.idl:670
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
DWORD _RpcAddPortEx(WINSPOOL_HANDLE pName, WINSPOOL_PORT_CONTAINER *pPortContainer, WINSPOOL_PORT_VAR_CONTAINER *pPortVarContainer, WCHAR *pMonitorName)
Definition: ports.c:33
static const MARSHALLING * pPortInfoMarshalling[]
Definition: ports.h:28
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
BOOL WINAPI AddPortExW(PWSTR pName, DWORD Level, PBYTE lpBuffer, PWSTR lpMonitorName)
Definition: ports.c:11
smooth NULL
Definition: ftsmooth.c:416
DWORD _RpcSetPort(WINSPOOL_HANDLE pName, WCHAR *pPortName, WINSPOOL_PORT_CONTAINER *pPortContainer)
Definition: ports.c:144
WINSPOOL_PORT_INFO_3 * pPortInfo3
Definition: winspool.idl:674
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1459
static LPSTR pName
Definition: security.c:75
BOOL WINAPI AddPortW(PWSTR pName, HWND hWnd, PWSTR pMonitorName)
Definition: ports.c:46
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI DeletePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:114
unsigned char BYTE
Definition: xxhash.c:193
#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
DWORD _RpcEnumPorts(WINSPOOL_HANDLE pName, DWORD Level, BYTE *pPort, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: ports.c:112
DWORD _RpcDeletePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pPortName)
Definition: ports.c:93
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WINSPOOL_PORT_INFO_FF * pPortInfoFF
Definition: winspool.idl:676
BYTE * PBYTE
Definition: pedump.c:66
union _WINSPOOL_PORT_CONTAINER::@3406 PortInfo
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
DWORD _RpcConfigurePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pPortName)
Definition: ports.c:74
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15