2015-07-16 13:59:20 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Print Spooler Service
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-07-16 13:59:20 +00:00
|
|
|
* PURPOSE: Functions related to Ports
|
2018-01-17 11:52:12 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
|
2015-07-16 13:59:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
2018-01-17 11:52:12 +00:00
|
|
|
#include <marshalling/ports.h>
|
2015-07-17 10:57:10 +00:00
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcAddPort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR* pMonitorName)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
FIXME("AddPort(%S, %p, %s)\n", pName, hWnd, debugstr_w(pMonitorName));
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AddPortW( pName, (HWND)hWnd, pMonitorName ))
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcAddPortEx(WINSPOOL_HANDLE pName, WINSPOOL_PORT_CONTAINER* pPortContainer, WINSPOOL_PORT_VAR_CONTAINER* pPortVarContainer, WCHAR* pMonitorName)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
DWORD dwErrorCode, Level = pPortContainer->Level;
|
|
|
|
WINSPOOL_PORT_INFO_FF PortInfoFF;
|
|
|
|
PBYTE lpBuffer;
|
|
|
|
|
|
|
|
FIXME("AddPortEx(%S, %lu, %s)\n", pName, Level, debugstr_w(pMonitorName));
|
|
|
|
|
|
|
|
switch (Level)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
lpBuffer = (PBYTE)pPortContainer->PortInfo.pPortInfo1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFFFFFFFF:
|
|
|
|
PortInfoFF.pPortName = pPortContainer->PortInfo.pPortInfoFF->pPortName;
|
|
|
|
PortInfoFF.cbMonitorData = pPortVarContainer->cbMonitorData;
|
|
|
|
PortInfoFF.pMonitorData = pPortVarContainer->pMonitorData;
|
|
|
|
lpBuffer = (PBYTE)&PortInfoFF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Level = %d, unsupported!\n", Level);
|
|
|
|
return ERROR_INVALID_LEVEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AddPortExW(pName, Level, lpBuffer, pMonitorName ))
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcConfigurePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR* pPortName)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ConfigurePortW( pName, (HWND)hWnd, pPortName ))
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcDeletePort(WINSPOOL_HANDLE pName, ULONG_PTR hWnd, WCHAR* pPortName)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DeletePortW( pName, (HWND)hWnd, pPortName ))
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 13:59:20 +00:00
|
|
|
DWORD
|
|
|
|
_RpcEnumPorts(WINSPOOL_HANDLE pName, DWORD Level, BYTE* pPort, DWORD cbBuf, DWORD* pcbNeeded, DWORD* pcReturned)
|
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE pPortAligned;
|
2015-07-16 13:59:20 +00:00
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
pPortAligned = AlignRpcPtr(pPort, &cbBuf);
|
2015-07-16 13:59:20 +00:00
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
if (EnumPortsW(pName, Level, pPortAligned, cbBuf, pcbNeeded, pcReturned))
|
2015-07-17 10:57:10 +00:00
|
|
|
{
|
|
|
|
// Replace absolute pointer addresses in the output by relative offsets.
|
2018-01-17 11:52:12 +00:00
|
|
|
ASSERT(Level >= 1 && Level <= 2);
|
|
|
|
MarshallDownStructuresArray(pPortAligned, *pcReturned, pPortInfoMarshalling[Level]->pInfo, pPortInfoMarshalling[Level]->cbStructureSize, TRUE);
|
2017-07-05 15:29:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwErrorCode = GetLastError();
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-16 13:59:20 +00:00
|
|
|
RpcRevertToSelf();
|
2017-07-05 15:29:13 +00:00
|
|
|
UndoAlignRpcPtr(pPort, pPortAligned, cbBuf, pcbNeeded);
|
|
|
|
|
2015-07-16 13:59:20 +00:00
|
|
|
return dwErrorCode;
|
|
|
|
}
|
2015-07-17 10:57:10 +00:00
|
|
|
|
|
|
|
DWORD
|
|
|
|
_RpcSetPort(WINSPOOL_HANDLE pName, WCHAR* pPortName, WINSPOOL_PORT_CONTAINER* pPortContainer)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
|
|
|
dwErrorCode = RpcImpersonateClient(NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RpcImpersonateClient failed with error %lu!\n", dwErrorCode);
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SetPortW(pName, pPortName, pPortContainer->Level, (PBYTE)pPortContainer->PortInfo.pPortInfo3))
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
|
|
|
|
RpcRevertToSelf();
|
|
|
|
return dwErrorCode;
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|