ReactOS  0.4.15-dev-4570-g4f8bbd1
xcv.c File Reference
#include "precomp.h"
Include dependency graph for xcv.c:

Go to the source code of this file.

Functions

static DWORD _HandleAddPort (PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
 
_HandleConfigureLPTPortCommandOK

Writes the value for "TransmissionRetryTimeout" to the registry. Checks for granted SERVER_ACCESS_ADMINISTER access. Actually the opposite of _HandleGetTransmissionRetryTimeout, but name kept for compatibility.

Parameters
pXcvPointer to the LOCALMON_XCV structure of the currently opened Xcv port.
pInputDataPointer to a Unicode string containing the value to be written to the registry.
pcbOutputNeededPointer to a DWORD that will be zeroed on return.
Returns
An error code indicating success or failure.
static DWORD _HandleConfigureLPTPortCommandOK (PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
 
static DWORD _HandleDeletePort (PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
 
_HandleGetDefaultCommConfig

Gets the default configuration of a legacy port. The opposite function is _HandleSetDefaultCommConfig.

Parameters
pInputDataThe port name (without colon!) whose default configuration you want to get.
pOutputDataPointer to a COMMCONFIG structure that will receive the configuration information.
cbOutputDataSize of the variable pointed to by pOutputData.
pcbOutputNeededPointer to a DWORD that contains the required size for pOutputData on return.
Returns
An error code indicating success or failure.
static DWORD _HandleGetDefaultCommConfig (PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
_HandleGetTransmissionRetryTimeout

Reads the value for "TransmissionRetryTimeout" from the registry and converts it to a DWORD. The opposite function is _HandleConfigureLPTPortCommandOK.

Parameters
pOutputDataPointer to a DWORD that will receive the timeout value.
cbOutputDataSize of the variable pointed to by pOutputData.
pcbOutputNeededPointer to a DWORD that contains the required size for pOutputData on return.
Returns
An error code indicating success or failure.
static DWORD _HandleGetTransmissionRetryTimeout (PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
_HandleMonitorUI

Returns the filename of the associated UI DLL for this Port Monitor.

Parameters
pOutputDataPointer to a Unicode string that will receive the DLL filename.
cbOutputDataSize of the variable pointed to by pOutputData.
pcbOutputNeededPointer to a DWORD that contains the required size for pOutputData on return.
Returns
An error code indicating success or failure.
static DWORD _HandleMonitorUI (PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
_HandlePortExists

Checks all Port Monitors installed on the local system to find out if a given port already exists.

Parameters
pInputDataPointer to a Unicode string specifying the port name to check.
pOutputDataPointer to a BOOL that receives the result of the check.
cbOutputDataSize of the variable pointed to by pOutputData.
pcbOutputNeededPointer to a DWORD that contains the required size for pOutputData on return.
Returns
An error code indicating success or failure.
static DWORD _HandlePortExists (PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
static DWORD _HandlePortIsValid (PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
_HandleSetDefaultCommConfig

Sets the default configuration of a legacy port. Checks for granted SERVER_ACCESS_ADMINISTER access. You have to supply the port name (with colon!) in XcvOpenPort. The opposite function is _HandleGetDefaultCommConfig.

Parameters
pXcvPointer to the LOCALMON_XCV structure of the currently opened Xcv port.
pInputDataPointer to the COMMCONFIG structure that shall be passed to SetDefaultCommConfigW.
pcbOutputNeededPointer to a DWORD that will be zeroed on return.
Returns
An error code indicating success or failure.
static DWORD _HandleSetDefaultCommConfig (PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
 
BOOL WINAPI LocalmonXcvClosePort (HANDLE hXcv)
 
DWORD WINAPI LocalmonXcvDataPort (HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
 
BOOL WINAPI LocalmonXcvOpenPort (HANDLE hMonitor, PCWSTR pwszObject, ACCESS_MASK GrantedAccess, PHANDLE phXcv)
 

Function Documentation

◆ _HandleAddPort()

static DWORD _HandleAddPort ( PLOCALMON_XCV  pXcv,
PBYTE  pInputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 11 of file xcv.c.

12 {
13  DWORD res, cbPortName;
14  HKEY hroot;
15  HKEY hToken = NULL;
16  PLOCALMON_PORT pPort;
17  PLOCALMON_HANDLE pLocalmon = pXcv->pLocalmon;
18  PWSTR PortName = (PWSTR)pInputData;
19 
20  FIXME("LcmXcvAddPort : %s\n", debugstr_w( (LPWSTR) PortName ) );
21 
22  if (!pLocalmon )
23  {
25  goto Cleanup;
26  }
27 
28  // This action can only happen at SERVER_ACCESS_ADMINISTER access level.
30  {
32  goto Cleanup;
33  }
34 
35  // Switch to the SYSTEM context for modifying the registry.
36  hToken = RevertToPrinterSelf();
37  if (!hToken)
38  {
39  res = GetLastError();
40  ERR("RevertToPrinterSelf failed with error %lu!\n", res);
41  goto Cleanup;
42  }
43 
44  res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports", &hroot);
45  if (res == ERROR_SUCCESS)
46  {
47  if ( DoesPortExist( PortName ) )
48  {
49  RegCloseKey(hroot);
50  FIXME("=> %u\n", ERROR_ALREADY_EXISTS);
52  goto Cleanup;
53  }
54 
55  cbPortName = (wcslen( PortName ) + 1) * sizeof(WCHAR);
56 
57  // Create a new LOCALMON_PORT structure for it.
58  pPort = DllAllocSplMem(sizeof(LOCALMON_PORT) + cbPortName);
59  if (!pPort)
60  {
62  RegCloseKey( hroot );
63  goto Cleanup;
64  }
65  memset( pPort, 0, sizeof(LOCALMON_PORT) + cbPortName );
66 
67  pPort->hFile = INVALID_HANDLE_VALUE;
68  pPort->pLocalmon = pLocalmon;
69  pPort->pwszPortName = wcscpy( (PWSTR)(pPort+1), PortName );
70 
71  // Insert it into the Registry list.
72  InsertTailList(&pLocalmon->RegistryPorts, &pPort->Entry);
73 
74  res = RegSetValueExW(hroot, PortName, 0, REG_SZ, (const BYTE *) L"", sizeof(L""));
75  RegCloseKey(hroot);
76  }
77 
78  FIXME("=> %u\n", res);
79 
80 Cleanup:
81  if (hToken) ImpersonatePrinterClient(hToken);
83  return res;
84 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY Entry
Definition: precomp.h:54
uint16_t * PWSTR
Definition: typedefs.h:56
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define InsertTailList(ListHead, Entry)
#define L(x)
Definition: ntvdm.h:50
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3291
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
HANDLE WINAPI RevertToPrinterSelf(VOID)
Definition: context.c:64
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4899
BOOL DoesPortExist(PCWSTR pwszPortName)
Definition: tools.c:24
LIST_ENTRY RegistryPorts
Definition: precomp.h:43
PWSTR pwszPortName
Definition: precomp.h:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:56
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR Cleanup[]
Definition: register.c:80
HANDLE hFile
Definition: precomp.h:67
unsigned char BYTE
Definition: xxhash.c:193
#define ERR(fmt,...)
Definition: debug.h:110
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:81
#define NULL
Definition: types.h:112
#define SERVER_ACCESS_ADMINISTER
Definition: winspool.h:1366
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
GLuint res
Definition: glext.h:9613
BOOL WINAPI ImpersonatePrinterClient(_In_ HANDLE hToken)
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
#define RegCloseKey(hKey)
Definition: registry.h:47
IN PUNICODE_STRING PortName
Definition: conport.c:35
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
ACCESS_MASK GrantedAccess
Definition: precomp.h:80

Referenced by LocalmonXcvDataPort().

◆ _HandleConfigureLPTPortCommandOK()

static DWORD _HandleConfigureLPTPortCommandOK ( PLOCALMON_XCV  pXcv,
PBYTE  pInputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 105 of file xcv.c.

106 {
107  DWORD cbBuffer;
108  DWORD dwErrorCode;
109  HKEY hKey = NULL;
110  HKEY hToken = NULL;
111 
112  // Sanity checks
113  if (!pXcv || !pInputData || !pcbOutputNeeded)
114  {
115  dwErrorCode = ERROR_INVALID_PARAMETER;
116  goto Cleanup;
117  }
118 
119  *pcbOutputNeeded = 0;
120 
121  // This action can only happen at SERVER_ACCESS_ADMINISTER access level.
123  {
124  dwErrorCode = ERROR_ACCESS_DENIED;
125  goto Cleanup;
126  }
127 
128  // Switch to the SYSTEM context for modifying the registry.
129  hToken = RevertToPrinterSelf();
130  if (!hToken)
131  {
132  dwErrorCode = GetLastError();
133  ERR("RevertToPrinterSelf failed with error %lu!\n", dwErrorCode);
134  goto Cleanup;
135  }
136 
137  // Open the key where our value is stored.
138  dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Windows", 0, KEY_SET_VALUE, &hKey);
139  if (dwErrorCode != ERROR_SUCCESS)
140  {
141  ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode);
142  goto Cleanup;
143  }
144 
145  // We don't use cbInputData here, because the buffer pInputData could be bigger than the data it contains.
146  cbBuffer = (wcslen((PWSTR)pInputData) + 1) * sizeof(WCHAR);
147 
148  // Write the value to the registry.
149  dwErrorCode = (DWORD)RegSetValueExW(hKey, L"TransmissionRetryTimeout", 0, REG_SZ, pInputData, cbBuffer);
150  if (dwErrorCode != ERROR_SUCCESS)
151  {
152  ERR("RegSetValueExW failed with status %lu!\n", dwErrorCode);
153  goto Cleanup;
154  }
155 
156 Cleanup:
157  if (hKey)
158  RegCloseKey(hKey);
159 
160  if (hToken)
161  ImpersonatePrinterClient(hToken);
162 
163  return dwErrorCode;
164 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
uint16_t * PWSTR
Definition: typedefs.h:56
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
HANDLE WINAPI RevertToPrinterSelf(VOID)
Definition: context.c:64
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4899
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERR(fmt,...)
Definition: debug.h:110
FxAutoRegKey hKey
#define NULL
Definition: types.h:112
#define SERVER_ACCESS_ADMINISTER
Definition: winspool.h:1366
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
BOOL WINAPI ImpersonatePrinterClient(_In_ HANDLE hToken)
#define RegCloseKey(hKey)
Definition: registry.h:47
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
ACCESS_MASK GrantedAccess
Definition: precomp.h:80

Referenced by LocalmonXcvDataPort().

◆ _HandleDeletePort()

static DWORD _HandleDeletePort ( PLOCALMON_XCV  pXcv,
PBYTE  pInputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 167 of file xcv.c.

168 {
169  DWORD res;
170  HKEY hroot;
171  HKEY hToken = NULL;
172  PLOCALMON_HANDLE pLocalmon = pXcv->pLocalmon;
173  PLOCALMON_PORT pPort = NULL;
175  PWSTR pPortName = (PWSTR)pInputData;
176 
177  FIXME("LcmXcvDeletePort : %s\n", debugstr_w( pPortName ) );
178 
179  if (!pLocalmon )
180  {
182  goto Cleanup;
183  }
184 
185  // This action can only happen at SERVER_ACCESS_ADMINISTER access level.
187  {
189  goto Cleanup;
190  }
191 
192  // Switch to the SYSTEM context for modifying the registry.
193  hToken = RevertToPrinterSelf();
194  if (!hToken)
195  {
196  res = GetLastError();
197  ERR("RevertToPrinterSelf failed with error %lu!\n", res);
198  goto Cleanup;
199  }
200 
201  res = RegOpenKeyW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports", &hroot);
202  if ( res == ERROR_SUCCESS )
203  {
204  res = RegDeleteValueW(hroot, pPortName );
205 
206  RegCloseKey(hroot);
207 
208  if ( res == ERROR_SUCCESS )
209  {
210  EnterCriticalSection(&pLocalmon->Section);
211 
212  if (!IsListEmpty(&pLocalmon->RegistryPorts) )
213  {
214  for (pEntry = pLocalmon->RegistryPorts.Flink; pEntry != &pLocalmon->RegistryPorts; pEntry = pEntry->Flink)
215  {
217 
218  if (wcscmp(pPort->pwszPortName, pPortName) == 0)
219  break;
220  }
221  }
222 
223  LeaveCriticalSection(&pLocalmon->Section);
224 
225  if ( pPort )
226  {
227  FIXME("LcmXcvDeletePort removed Port Entry\n");
229  RemoveEntryList(&pPort->Entry);
231 
232  DllFreeSplMem(pPort);
233  }
234  }
235  FIXME("LcmXcvDeletePort => %u with %u\n", res, GetLastError() );
236  }
237 
238 Cleanup:
239  if (hToken) ImpersonatePrinterClient(hToken);
240  SetLastError(res);
241  return res;
242 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY Entry
Definition: precomp.h:54
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define L(x)
Definition: ntvdm.h:50
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3291
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:111
HANDLE WINAPI RevertToPrinterSelf(VOID)
Definition: context.c:64
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY RegistryPorts
Definition: precomp.h:43
PWSTR pwszPortName
Definition: precomp.h:55
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:56
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
CRITICAL_SECTION Section
Definition: precomp.h:40
Definition: typedefs.h:119
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERR(fmt,...)
Definition: debug.h:110
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:81
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2355
#define NULL
Definition: types.h:112
#define SERVER_ACCESS_ADMINISTER
Definition: winspool.h:1366
GLuint res
Definition: glext.h:9613
BOOL WINAPI ImpersonatePrinterClient(_In_ HANDLE hToken)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
#define RegCloseKey(hKey)
Definition: registry.h:47
base of all file and directory entries
Definition: entries.h:82
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
ACCESS_MASK GrantedAccess
Definition: precomp.h:80

Referenced by LocalmonXcvDataPort().

◆ _HandleGetDefaultCommConfig()

static DWORD _HandleGetDefaultCommConfig ( PBYTE  pInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 266 of file xcv.c.

267 {
268  // Sanity checks
269  if (!pInputData || !pcbOutputNeeded)
271 
272  *pcbOutputNeeded = sizeof(COMMCONFIG);
273 
274  // Check if the supplied buffer is large enough.
275  if (cbOutputData < *pcbOutputNeeded)
277 
278  // Finally get the port configuration.
279  if (!GetDefaultCommConfigW((PCWSTR)pInputData, (LPCOMMCONFIG)pOutputData, pcbOutputNeeded))
280  return GetLastError();
281 
282  return ERROR_SUCCESS;
283 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
struct _COMM_CONFIG COMMCONFIG
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
BOOL WINAPI GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
Definition: comm.c:1398
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by LocalmonXcvDataPort().

◆ _HandleGetTransmissionRetryTimeout()

static DWORD _HandleGetTransmissionRetryTimeout ( PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 304 of file xcv.c.

305 {
307 
308  // Sanity checks
309  if (!pOutputData || !pcbOutputNeeded)
311 
312  *pcbOutputNeeded = sizeof(DWORD);
313 
314  // Check if the supplied buffer is large enough.
315  if (cbOutputData < *pcbOutputNeeded)
317 
318  // Retrieve and copy the number.
320  CopyMemory(pOutputData, &dwTimeout, sizeof(DWORD));
321  return ERROR_SUCCESS;
322 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD
Definition: nt_native.h:44
DWORD GetLPTTransmissionRetryTimeout(VOID)
Definition: tools.c:85
#define CopyMemory
Definition: winbase.h:1665
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD dwTimeout
Definition: wincrypt.h:6077
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by LocalmonXcvDataPort().

◆ _HandleMonitorUI()

static DWORD _HandleMonitorUI ( PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 342 of file xcv.c.

343 {
344  const WCHAR wszMonitorUI[] = L"LocalUI.dll";
345 
346  // Sanity checks
347  if (!pcbOutputNeeded)
349 
350  *pcbOutputNeeded = sizeof(wszMonitorUI);
351 
352  // Check if the supplied buffer is large enough.
353  if (cbOutputData < *pcbOutputNeeded)
355 
356  if (!pOutputData)
358 
359  // Copy the string.
360  CopyMemory(pOutputData, wszMonitorUI, sizeof(wszMonitorUI));
361  return ERROR_SUCCESS;
362 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define L(x)
Definition: ntvdm.h:50
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1665
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by LocalmonXcvDataPort().

◆ _HandlePortExists()

static DWORD _HandlePortExists ( PBYTE  pInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 385 of file xcv.c.

386 {
387  // Sanity checks
388  if (!pInputData || !pOutputData || !pcbOutputNeeded)
390 
391  *pcbOutputNeeded = sizeof(BOOL);
392 
393  // Check if the supplied buffer is large enough.
394  if (cbOutputData < *pcbOutputNeeded)
396 
397  // Return the check result and error code.
398  *(PBOOL)pOutputData = DoesPortExist((PCWSTR)pInputData);
399  return GetLastError();
400 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
const uint16_t * PCWSTR
Definition: typedefs.h:57
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define BOOL
Definition: nt_native.h:43
BOOL * PBOOL
Definition: windef.h:161
BOOL DoesPortExist(PCWSTR pwszPortName)
Definition: tools.c:24
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by LocalmonXcvDataPort().

◆ _HandlePortIsValid()

static DWORD _HandlePortIsValid ( PBYTE  pInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 403 of file xcv.c.

404 {
405  DWORD res;
406 
407  TRACE("HandlePortIsValid : pInputData %s\n", debugstr_w( (LPWSTR) pInputData));
408 
409  res = GetTypeFromName((LPCWSTR) pInputData);
410 
411  TRACE("HandlePortIsValid : detected as %u\n", res);
412 
413  /* names, that we have recognized, are valid */
414  if (res) return ERROR_SUCCESS;
415 
416  TRACE("=> %u\n", GetLastError());
417 
418  /* ERROR_ACCESS_DENIED, ERROR_PATH_NOT_FOUND or something else */
419  return GetLastError();
420 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define debugstr_w
Definition: kernel32.h:32
DWORD GetTypeFromName(LPCWSTR name)
Definition: tools.c:215
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint res
Definition: glext.h:9613
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by LocalmonXcvDataPort().

◆ _HandleSetDefaultCommConfig()

static DWORD _HandleSetDefaultCommConfig ( PLOCALMON_XCV  pXcv,
PBYTE  pInputData,
PDWORD  pcbOutputNeeded 
)
static

Definition at line 442 of file xcv.c.

443 {
444  DWORD dwErrorCode;
445  HANDLE hToken = NULL;
446  LPCOMMCONFIG pCommConfig;
447  PWSTR pwszPortNameWithoutColon = NULL;
448 
449  // Sanity checks
450  // pwszObject needs to be at least 2 characters long to be a port name with a trailing colon.
451  if (!pXcv || !pXcv->pwszObject || !pXcv->pwszObject[0] || !pXcv->pwszObject[1] || !pInputData || !pcbOutputNeeded)
452  {
453  dwErrorCode = ERROR_INVALID_PARAMETER;
454  goto Cleanup;
455  }
456 
457  *pcbOutputNeeded = 0;
458 
459  // This action can only happen at SERVER_ACCESS_ADMINISTER access level.
461  {
462  dwErrorCode = ERROR_ACCESS_DENIED;
463  goto Cleanup;
464  }
465 
466  // SetDefaultCommConfigW needs the port name without colon.
467  dwErrorCode = GetPortNameWithoutColon(pXcv->pwszObject, &pwszPortNameWithoutColon);
468  if (dwErrorCode != ERROR_SUCCESS)
469  goto Cleanup;
470 
471  // Switch to the SYSTEM context for setting the port configuration.
472  hToken = RevertToPrinterSelf();
473  if (!hToken)
474  {
475  dwErrorCode = GetLastError();
476  ERR("RevertToPrinterSelf failed with error %lu!\n", dwErrorCode);
477  goto Cleanup;
478  }
479 
480  // Finally pass the parameters to SetDefaultCommConfigW.
481  pCommConfig = (LPCOMMCONFIG)pInputData;
482  if (!SetDefaultCommConfigW(pwszPortNameWithoutColon, pCommConfig, pCommConfig->dwSize))
483  {
484  dwErrorCode = GetLastError();
485  ERR("SetDefaultCommConfigW failed with error %lu!\n", dwErrorCode);
486  goto Cleanup;
487  }
488 
489  dwErrorCode = ERROR_SUCCESS;
490 
491 Cleanup:
492  if (hToken)
493  ImpersonatePrinterClient(hToken);
494 
495  if (pwszPortNameWithoutColon)
496  DllFreeSplMem(pwszPortNameWithoutColon);
497 
498  return dwErrorCode;
499 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
struct _COMM_CONFIG * LPCOMMCONFIG
Definition: confdlg.c:35
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI SetDefaultCommConfigW(LPCWSTR lpszDevice, LPCOMMCONFIG lpCommConfig, DWORD dwSize)
Definition: comm.c:1338
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
HANDLE WINAPI RevertToPrinterSelf(VOID)
Definition: context.c:64
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwSize
Definition: winbase.h:674
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERR(fmt,...)
Definition: debug.h:110
PWSTR pwszObject
Definition: precomp.h:82
#define NULL
Definition: types.h:112
#define SERVER_ACCESS_ADMINISTER
Definition: winspool.h:1366
BOOL WINAPI ImpersonatePrinterClient(_In_ HANDLE hToken)
DWORD GetPortNameWithoutColon(PCWSTR pwszPortName, PWSTR *ppwszPortNameWithoutColon)
Definition: tools.c:142
ACCESS_MASK GrantedAccess
Definition: precomp.h:80

Referenced by LocalmonXcvDataPort().

◆ LocalmonXcvClosePort()

BOOL WINAPI LocalmonXcvClosePort ( HANDLE  hXcv)

Definition at line 502 of file xcv.c.

503 {
505 
506  TRACE("LocalmonXcvClosePort(%p)\n", hXcv);
507 
508  // Sanity checks
509  if (!pXcv)
510  {
512  return FALSE;
513  }
514 
515  // Remove it from the list and free the memory.
517  RemoveEntryList(&pXcv->Entry);
519  DllFreeSplMem(pXcv);
520 
522  return TRUE;
523 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct _LOCALMON_XCV * PLOCALMON_XCV
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
LIST_ENTRY Entry
Definition: precomp.h:79
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
#define SetLastError(x)
Definition: compat.h:611
CRITICAL_SECTION Section
Definition: precomp.h:40
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:81
static HANDLE hXcv
Definition: localmon.c:73
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by LocalmonShutdown().

◆ LocalmonXcvDataPort()

DWORD WINAPI LocalmonXcvDataPort ( HANDLE  hXcv,
PCWSTR  pszDataName,
PBYTE  pInputData,
DWORD  cbInputData,
PBYTE  pOutputData,
DWORD  cbOutputData,
PDWORD  pcbOutputNeeded 
)

Definition at line 526 of file xcv.c.

527 {
528  FIXME("LocalmonXcvDataPort(%p, %S, %p, %lu, %p, %lu, %p)\n", hXcv, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
529 
530  // Sanity checks
531  if (!pszDataName)
533 
534  // Call the appropriate handler for the requested data name.
535  if (wcscmp(pszDataName, L"AddPort") == 0)
536  return _HandleAddPort((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
537 
538  if (wcscmp(pszDataName, L"ConfigureLPTPortCommandOK") == 0)
539  return _HandleConfigureLPTPortCommandOK((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
540 
541  if (wcscmp(pszDataName, L"DeletePort") == 0)
542  return _HandleDeletePort((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
543 
544  if (wcscmp(pszDataName, L"GetDefaultCommConfig") == 0)
545  return _HandleGetDefaultCommConfig(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
546 
547  if (wcscmp(pszDataName, L"GetTransmissionRetryTimeout") == 0)
548  return _HandleGetTransmissionRetryTimeout(pOutputData, cbOutputData, pcbOutputNeeded);
549 
550  if (wcscmp(pszDataName, L"MonitorUI") == 0)
551  return _HandleMonitorUI(pOutputData, cbOutputData, pcbOutputNeeded);
552 
553  if (wcscmp(pszDataName, L"PortExists") == 0)
554  return _HandlePortExists(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
555 
556  if (wcscmp(pszDataName, L"PortIsValid") == 0)
557  return _HandlePortIsValid(pInputData, pOutputData, cbOutputData, pcbOutputNeeded);
558 
559  if (wcscmp(pszDataName, L"SetDefaultCommConfig") == 0)
560  return _HandleSetDefaultCommConfig((PLOCALMON_XCV)hXcv, pInputData, pcbOutputNeeded);
561 
563 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static DWORD _HandleMonitorUI(PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:342
static DWORD _HandleConfigureLPTPortCommandOK(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:105
static DWORD _HandleGetDefaultCommConfig(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:266
#define L(x)
Definition: ntvdm.h:50
#define FIXME(fmt,...)
Definition: debug.h:111
static DWORD _HandleDeletePort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:167
static DWORD _HandleGetTransmissionRetryTimeout(PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:304
static DWORD _HandlePortIsValid(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:403
static DWORD _HandleAddPort(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:11
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static DWORD _HandlePortExists(PBYTE pInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:385
static HANDLE hXcv
Definition: localmon.c:73
static DWORD _HandleSetDefaultCommConfig(PLOCALMON_XCV pXcv, PBYTE pInputData, PDWORD pcbOutputNeeded)
Definition: xcv.c:442

◆ LocalmonXcvOpenPort()

BOOL WINAPI LocalmonXcvOpenPort ( HANDLE  hMonitor,
PCWSTR  pwszObject,
ACCESS_MASK  GrantedAccess,
PHANDLE  phXcv 
)

Definition at line 566 of file xcv.c.

567 {
568  DWORD cbObject = 0;
569  DWORD dwErrorCode;
570  PLOCALMON_HANDLE pLocalmon = (PLOCALMON_HANDLE)hMonitor;
571  PLOCALMON_XCV pXcv;
572 
573  FIXME("LocalmonXcvOpenPort(%p, %S, %lu, %p)\n", hMonitor, pwszObject, GrantedAccess, phXcv);
574 
575  // Sanity checks
576  if (!pLocalmon || !phXcv)
577  {
578  dwErrorCode = ERROR_INVALID_PARAMETER;
579  goto Cleanup;
580  }
581 
582  if (pwszObject)
583  cbObject = (wcslen(pwszObject) + 1) * sizeof(WCHAR);
584 
585  // Create a new LOCALMON_XCV structure and fill the relevant fields.
586  pXcv = DllAllocSplMem(sizeof(LOCALMON_XCV) + cbObject);
587  if (!pXcv)
588  {
589  dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
590  ERR("DllAllocSplMem failed with error %lu!\n", GetLastError());
591  goto Cleanup;
592  }
593 
594  pXcv->pLocalmon = pLocalmon;
596 
597  if (cbObject)
598  {
599  pXcv->pwszObject = (PWSTR)((PBYTE)pXcv + sizeof(LOCALMON_XCV));
600  CopyMemory(pXcv->pwszObject, pwszObject, cbObject);
601  }
602 
603  InsertTailList(&pLocalmon->XcvHandles, &pXcv->Entry);
604 
605  // Return it as the Xcv handle.
606  *phXcv = (HANDLE)pXcv;
607  dwErrorCode = ERROR_SUCCESS;
608 
609 Cleanup:
610  SetLastError(dwErrorCode);
611  return (dwErrorCode == ERROR_SUCCESS);
612 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
struct _LOCALMON_XCV LOCALMON_XCV
uint16_t * PWSTR
Definition: typedefs.h:56
LIST_ENTRY XcvHandles
Definition: precomp.h:44
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define InsertTailList(ListHead, Entry)
LIST_ENTRY Entry
Definition: precomp.h:79
#define FIXME(fmt,...)
Definition: debug.h:111
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1665
PVOID HANDLE
Definition: typedefs.h:73
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
static const WCHAR Cleanup[]
Definition: register.c:80
#define ERR(fmt,...)
Definition: debug.h:110
PWSTR pwszObject
Definition: precomp.h:82
PLOCALMON_HANDLE pLocalmon
Definition: precomp.h:81
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:13
BYTE * PBYTE
Definition: pedump.c:66
struct _LOCALMON_HANDLE * PLOCALMON_HANDLE
ACCESS_MASK GrantedAccess
Definition: precomp.h:80