ReactOS 0.4.16-dev-197-g92996da
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
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
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);
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
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
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
108 return dwErrorCode;
109}
110
111DWORD
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
138 UndoAlignRpcPtr(pPort, pPortAligned, cbBuf, pcbNeeded);
139
140 return dwErrorCode;
141}
142
143DWORD
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
159 return dwErrorCode;
160}
HWND hWnd
Definition: settings.c:17
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
#define debugstr_w
Definition: kernel32.h:32
BOOL WINAPI MarshallDownStructuresArray(PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:91
#define ASSERT(a)
Definition: mode.c:44
static LPSTR pName
Definition: security.c:75
BYTE * PBYTE
Definition: pedump.c:66
RPC_STATUS WINAPI RpcRevertToSelf(void)
Definition: rpc_binding.c:1463
RPC_STATUS WINAPI RpcImpersonateClient(RPC_BINDING_HANDLE BindingHandle)
Definition: rpc_binding.c:1056
WINSPOOL_PORT_INFO_FF * pPortInfoFF
Definition: winspool.idl:676
WINSPOOL_PORT_INFO_3 * pPortInfo3
Definition: winspool.idl:674
union _WINSPOOL_PORT_CONTAINER::@3439 PortInfo
WINSPOOL_PORT_INFO_1 * pPortInfo1
Definition: winspool.idl:670
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID WINAPI AlignRpcPtr(PVOID pBuffer, PDWORD pcbBuffer)
Definition: memory.c:29
PDWORD WINAPI UndoAlignRpcPtr(PVOID pDestinationBuffer, PVOID pSourceBuffer, DWORD cbBuffer, PDWORD pcbNeeded)
Definition: memory.c:239
BOOL WINAPI SetPortW(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
Definition: ports.c:216
BOOL WINAPI AddPortExW(PWSTR pName, DWORD Level, PBYTE lpBuffer, PWSTR lpMonitorName)
Definition: ports.c:11
BOOL WINAPI ConfigurePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:81
BOOL WINAPI DeletePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
Definition: ports.c:114
BOOL WINAPI EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: ports.c:147
BOOL WINAPI AddPortW(PWSTR pName, HWND hWnd, PWSTR pMonitorName)
Definition: ports.c:46
DWORD _RpcConfigurePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pPortName)
Definition: ports.c:74
DWORD _RpcSetPort(WINSPOOL_HANDLE pName, WCHAR *pPortName, WINSPOOL_PORT_CONTAINER *pPortContainer)
Definition: ports.c:144
DWORD _RpcAddPortEx(WINSPOOL_HANDLE pName, WINSPOOL_PORT_CONTAINER *pPortContainer, WINSPOOL_PORT_VAR_CONTAINER *pPortVarContainer, WCHAR *pMonitorName)
Definition: ports.c:33
DWORD _RpcDeletePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pPortName)
Definition: ports.c:93
DWORD _RpcAddPort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR *pMonitorName)
Definition: ports.c:12
DWORD _RpcEnumPorts(WINSPOOL_HANDLE pName, DWORD Level, BYTE *pPort, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: ports.c:112
static const MARSHALLING * pPortInfoMarshalling[]
Definition: ports.h:28
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3828
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
WCHAR * WINSPOOL_HANDLE
Definition: winspool.idl:15
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193