2006-09-27 23:22:33 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Local Printmonitor
|
|
|
|
*
|
|
|
|
* Copyright 2006 Detlef Riekenberg
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2019-06-10 10:55:52 +02:00
|
|
|
#include <stdlib.h>
|
2006-09-27 23:22:33 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
|
|
|
|
#include "winspool.h"
|
|
|
|
#include "ddk/winsplp.h"
|
2006-10-27 19:24:07 +02:00
|
|
|
#include "localspl_private.h"
|
2006-09-27 23:22:33 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2018-01-25 20:55:42 +01:00
|
|
|
#include "wine/heap.h"
|
2007-01-11 15:02:24 +01:00
|
|
|
#include "wine/list.h"
|
2006-09-27 23:22:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(localspl);
|
|
|
|
|
2006-10-27 19:24:07 +02:00
|
|
|
/*****************************************************/
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
static CRITICAL_SECTION port_handles_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG port_handles_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &port_handles_cs,
|
|
|
|
{ &port_handles_cs_debug.ProcessLocksList, &port_handles_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": port_handles_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION port_handles_cs = { &port_handles_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
|
2007-01-11 15:02:24 +01:00
|
|
|
static CRITICAL_SECTION xcv_handles_cs;
|
|
|
|
static CRITICAL_SECTION_DEBUG xcv_handles_cs_debug =
|
|
|
|
{
|
|
|
|
0, 0, &xcv_handles_cs,
|
|
|
|
{ &xcv_handles_cs_debug.ProcessLocksList, &xcv_handles_cs_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": xcv_handles_cs") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION xcv_handles_cs = { &xcv_handles_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
/* ############################### */
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
typedef struct {
|
|
|
|
struct list entry;
|
|
|
|
DWORD type;
|
|
|
|
WCHAR nameW[1];
|
|
|
|
} port_t;
|
|
|
|
|
2007-01-11 15:02:24 +01:00
|
|
|
typedef struct {
|
|
|
|
struct list entry;
|
|
|
|
ACCESS_MASK GrantedAccess;
|
|
|
|
WCHAR nameW[1];
|
|
|
|
} xcv_t;
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
static struct list port_handles = LIST_INIT( port_handles );
|
2007-01-11 15:02:24 +01:00
|
|
|
static struct list xcv_handles = LIST_INIT( xcv_handles );
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
static const WCHAR WinNT_CV_PortsW[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Ports";
|
|
|
|
static const WCHAR WinNT_CV_WindowsW[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows";
|
2007-02-20 00:00:18 +01:00
|
|
|
|
2021-02-26 11:40:32 +01:00
|
|
|
static HINSTANCE LOCALSPL_hInstance;
|
|
|
|
|
|
|
|
/*****************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n",hinstDLL, fdwReason, lpvReserved);
|
|
|
|
|
|
|
|
switch(fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls( hinstDLL );
|
|
|
|
LOCALSPL_hInstance = hinstDLL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-15 20:41:06 +01:00
|
|
|
|
2007-04-17 23:20:34 +02:00
|
|
|
/******************************************************************
|
|
|
|
* does_port_exist (internal)
|
|
|
|
*
|
|
|
|
* returns TRUE, when the Port already exists
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL does_port_exist(LPCWSTR myname)
|
|
|
|
{
|
|
|
|
|
|
|
|
LPPORT_INFO_1W pi;
|
|
|
|
DWORD needed = 0;
|
|
|
|
DWORD returned;
|
|
|
|
DWORD id;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(myname));
|
|
|
|
|
|
|
|
id = EnumPortsW(NULL, 1, NULL, 0, &needed, &returned);
|
2007-12-09 16:30:24 +01:00
|
|
|
pi = heap_alloc(needed);
|
2007-04-17 23:20:34 +02:00
|
|
|
returned = 0;
|
|
|
|
if (pi)
|
|
|
|
id = EnumPortsW(NULL, 1, (LPBYTE) pi, needed, &needed, &returned);
|
|
|
|
|
|
|
|
if (id && returned > 0) {
|
|
|
|
/* we got a number of valid names. */
|
|
|
|
for (id = 0; id < returned; id++)
|
|
|
|
{
|
|
|
|
if (lstrcmpiW(myname, pi[id].pName) == 0) {
|
|
|
|
TRACE("(%u) found %s\n", id, debugstr_w(pi[id].pName));
|
2007-12-09 16:30:24 +01:00
|
|
|
heap_free(pi);
|
2007-04-17 23:20:34 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 16:30:24 +01:00
|
|
|
heap_free(pi);
|
2007-04-17 23:20:34 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-10-27 19:24:07 +02:00
|
|
|
/******************************************************************
|
|
|
|
* enumerate the local Ports from the Registry (internal)
|
|
|
|
*
|
|
|
|
* See localmon_EnumPortsW.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* returns the needed size (in bytes) for pPorts
|
|
|
|
* and *lpreturned is set to number of entries returned in pPorts
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DWORD get_ports_from_reg(DWORD level, LPBYTE pPorts, DWORD cbBuf, LPDWORD lpreturned)
|
|
|
|
{
|
|
|
|
HKEY hroot = 0;
|
|
|
|
LPWSTR ptr;
|
|
|
|
LPPORT_INFO_2W out;
|
|
|
|
WCHAR portname[MAX_PATH];
|
2006-11-15 21:02:26 +01:00
|
|
|
WCHAR res_PortW[IDS_LOCALPORT_MAXLEN];
|
|
|
|
WCHAR res_MonitorW[IDS_LOCALMONITOR_MAXLEN];
|
2006-10-27 19:24:07 +02:00
|
|
|
INT reslen_PortW;
|
|
|
|
INT reslen_MonitorW;
|
|
|
|
DWORD len;
|
|
|
|
DWORD res;
|
|
|
|
DWORD needed = 0;
|
|
|
|
DWORD numentries;
|
|
|
|
DWORD entrysize;
|
|
|
|
DWORD id = 0;
|
|
|
|
|
|
|
|
TRACE("(%d, %p, %d, %p)\n", level, pPorts, cbBuf, lpreturned);
|
|
|
|
|
|
|
|
entrysize = (level == 1) ? sizeof(PORT_INFO_1W) : sizeof(PORT_INFO_2W);
|
|
|
|
|
|
|
|
numentries = *lpreturned; /* this is 0, when we scan the registry */
|
|
|
|
needed = entrysize * numentries;
|
|
|
|
ptr = (LPWSTR) &pPorts[needed];
|
|
|
|
|
|
|
|
if (needed > cbBuf) pPorts = NULL; /* No buffer for the structs */
|
|
|
|
|
|
|
|
numentries = 0;
|
|
|
|
needed = 0;
|
|
|
|
|
|
|
|
/* we do not check more parameters as done in windows */
|
|
|
|
if ((level < 1) || (level > 2)) {
|
|
|
|
goto getports_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "+1" for '\0' */
|
2006-11-15 21:02:26 +01:00
|
|
|
reslen_MonitorW = LoadStringW(LOCALSPL_hInstance, IDS_LOCALMONITOR, res_MonitorW, IDS_LOCALMONITOR_MAXLEN) + 1;
|
|
|
|
reslen_PortW = LoadStringW(LOCALSPL_hInstance, IDS_LOCALPORT, res_PortW, IDS_LOCALPORT_MAXLEN) + 1;
|
2006-10-27 19:24:07 +02:00
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
|
|
|
|
/* Scan all Port-Names */
|
|
|
|
while (res == ERROR_SUCCESS) {
|
|
|
|
len = MAX_PATH;
|
|
|
|
portname[0] = '\0';
|
|
|
|
res = RegEnumValueW(hroot, id, portname, &len, NULL, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if ((res == ERROR_SUCCESS) && (portname[0])) {
|
|
|
|
numentries++;
|
2008-01-03 00:46:32 +01:00
|
|
|
/* calculate the required size */
|
2006-10-27 19:24:07 +02:00
|
|
|
needed += entrysize;
|
|
|
|
needed += (len + 1) * sizeof(WCHAR);
|
|
|
|
if (level > 1) {
|
|
|
|
needed += (reslen_MonitorW + reslen_PortW) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now fill the user-buffer, if available */
|
|
|
|
if (pPorts && (cbBuf >= needed)){
|
|
|
|
out = (LPPORT_INFO_2W) pPorts;
|
|
|
|
pPorts += entrysize;
|
|
|
|
TRACE("%p: writing PORT_INFO_%dW #%d (%s)\n", out, level, numentries, debugstr_w(portname));
|
|
|
|
out->pPortName = ptr;
|
|
|
|
lstrcpyW(ptr, portname); /* Name of the Port */
|
|
|
|
ptr += (len + 1);
|
|
|
|
if (level > 1) {
|
|
|
|
out->pMonitorName = ptr;
|
|
|
|
lstrcpyW(ptr, res_MonitorW); /* Name of the Monitor */
|
|
|
|
ptr += reslen_MonitorW;
|
|
|
|
|
|
|
|
out->pDescription = ptr;
|
|
|
|
lstrcpyW(ptr, res_PortW); /* Port Description */
|
|
|
|
ptr += reslen_PortW;
|
|
|
|
|
|
|
|
out->fPortType = PORT_TYPE_WRITE;
|
|
|
|
out->Reserved = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(hroot);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("failed with %d for %s\n", res, debugstr_w(WinNT_CV_PortsW));
|
|
|
|
SetLastError(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
getports_cleanup:
|
|
|
|
*lpreturned = numentries;
|
|
|
|
TRACE("need %d byte for %d entries (%d)\n", needed, numentries, GetLastError());
|
|
|
|
return needed;
|
|
|
|
}
|
|
|
|
|
2007-01-16 00:42:15 +01:00
|
|
|
/*****************************************************
|
|
|
|
* get_type_from_name (internal)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DWORD get_type_from_name(LPCWSTR name)
|
|
|
|
{
|
|
|
|
HANDLE hfile;
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!wcsncmp(name, L"LPT", ARRAY_SIZE(L"LPT") - 1))
|
2007-01-16 00:42:15 +01:00
|
|
|
return PORT_IS_LPT;
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!wcsncmp(name, L"COM", ARRAY_SIZE(L"COM") - 1))
|
2007-01-16 00:42:15 +01:00
|
|
|
return PORT_IS_COM;
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(name, L"FILE:"))
|
2007-01-16 00:42:15 +01:00
|
|
|
return PORT_IS_FILE;
|
|
|
|
|
|
|
|
if (name[0] == '/')
|
|
|
|
return PORT_IS_UNIXNAME;
|
|
|
|
|
|
|
|
if (name[0] == '|')
|
|
|
|
return PORT_IS_PIPE;
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!wcsncmp(name, L"CUPS:", ARRAY_SIZE(L"CUPS:") - 1))
|
2007-01-16 00:42:15 +01:00
|
|
|
return PORT_IS_CUPS;
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!wcsncmp(name, L"LPR:", ARRAY_SIZE(L"LPR:") - 1))
|
2007-01-16 00:42:15 +01:00
|
|
|
return PORT_IS_LPR;
|
|
|
|
|
|
|
|
/* Must be a file or a directory. Does the file exist ? */
|
|
|
|
hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
TRACE("%p for OPEN_EXISTING on %s\n", hfile, debugstr_w(name));
|
|
|
|
if (hfile == INVALID_HANDLE_VALUE) {
|
|
|
|
/* Can we create the file? */
|
|
|
|
hfile = CreateFileW(name, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
|
|
|
|
TRACE("%p for OPEN_ALWAYS\n", hfile);
|
|
|
|
}
|
|
|
|
if (hfile != INVALID_HANDLE_VALUE) {
|
|
|
|
CloseHandle(hfile);
|
|
|
|
return PORT_IS_FILENAME;
|
|
|
|
}
|
|
|
|
/* We can't use the name. use GetLastError() for the reason */
|
|
|
|
return PORT_IS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
/*****************************************************
|
|
|
|
* get_type_from_local_name (internal)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DWORD get_type_from_local_name(LPCWSTR nameW)
|
|
|
|
{
|
|
|
|
LPPORT_INFO_1W pi;
|
|
|
|
LPWSTR myname = NULL;
|
|
|
|
DWORD needed = 0;
|
|
|
|
DWORD numentries = 0;
|
|
|
|
DWORD id = 0;
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(myname));
|
|
|
|
|
|
|
|
needed = get_ports_from_reg(1, NULL, 0, &numentries);
|
2007-12-09 16:30:24 +01:00
|
|
|
pi = heap_alloc(needed);
|
2007-09-10 15:02:58 +02:00
|
|
|
if (pi)
|
|
|
|
needed = get_ports_from_reg(1, (LPBYTE) pi, needed, &numentries);
|
|
|
|
|
|
|
|
if (pi && needed && numentries > 0) {
|
|
|
|
/* we got a number of valid ports. */
|
|
|
|
|
|
|
|
while ((myname == NULL) && (id < numentries))
|
|
|
|
{
|
|
|
|
if (lstrcmpiW(nameW, pi[id].pName) == 0) {
|
|
|
|
TRACE("(%u) found %s\n", id, debugstr_w(pi[id].pName));
|
|
|
|
myname = pi[id].pName;
|
|
|
|
}
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
id = (myname) ? get_type_from_name(myname) : PORT_IS_UNKNOWN;
|
|
|
|
|
2007-12-09 16:30:24 +01:00
|
|
|
heap_free(pi);
|
2007-09-10 15:02:58 +02:00
|
|
|
return id;
|
|
|
|
|
|
|
|
}
|
2007-06-14 01:01:11 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* localmon_AddPortExW [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Add a Port, without presenting a user interface
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pName [I] Servername or NULL (local Computer)
|
|
|
|
* level [I] Structure-Level (1) for pBuffer
|
|
|
|
* pBuffer [I] PTR to the Input-Data (PORT_INFO_1)
|
|
|
|
* pMonitorName [I] Name of the Monitor that manage the Port
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Level 2 is documented on MSDN for Portmonitors, but not supported by the
|
|
|
|
* "Local Port" Portmonitor (localspl.dll / localmon.dll)
|
|
|
|
*/
|
2007-06-14 13:16:06 +02:00
|
|
|
static BOOL WINAPI localmon_AddPortExW(LPWSTR pName, DWORD level, LPBYTE pBuffer, LPWSTR pMonitorName)
|
2007-06-14 01:01:11 +02:00
|
|
|
{
|
|
|
|
PORT_INFO_1W * pi;
|
|
|
|
HKEY hroot;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
pi = (PORT_INFO_1W *) pBuffer;
|
|
|
|
TRACE("(%s, %d, %p, %s) => %s\n", debugstr_w(pName), level, pBuffer,
|
|
|
|
debugstr_w(pMonitorName), debugstr_w(pi ? pi->pName : NULL));
|
|
|
|
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if ((pMonitorName == NULL) || (lstrcmpiW(pMonitorName, L"Local Port") != 0 ) ||
|
2007-06-14 01:01:11 +02:00
|
|
|
(pi == NULL) || (pi->pName == NULL) || (pi->pName[0] == '\0') ) {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level != 1) {
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
if (does_port_exist(pi->pName)) {
|
|
|
|
RegCloseKey(hroot);
|
|
|
|
TRACE("=> FALSE with %u\n", ERROR_INVALID_PARAMETER);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-12-03 00:32:53 +01:00
|
|
|
res = RegSetValueExW(hroot, pi->pName, 0, REG_SZ, (const BYTE *) L"", sizeof(L""));
|
2007-06-14 01:01:11 +02:00
|
|
|
RegCloseKey(hroot);
|
|
|
|
}
|
|
|
|
if (res != ERROR_SUCCESS) SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
TRACE("=> %u with %u\n", (res == ERROR_SUCCESS), GetLastError());
|
|
|
|
return (res == ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_ClosePort [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Close a
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hPort [i] The Handle to close
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL WINAPI localmon_ClosePort(HANDLE hPort)
|
|
|
|
{
|
2009-01-27 11:37:19 +01:00
|
|
|
port_t * port = hPort;
|
2007-09-10 15:02:58 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", port);
|
|
|
|
EnterCriticalSection(&port_handles_cs);
|
|
|
|
list_remove(&port->entry);
|
|
|
|
LeaveCriticalSection(&port_handles_cs);
|
2007-12-09 16:30:24 +01:00
|
|
|
heap_free(port);
|
2007-09-10 15:02:58 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-10-27 19:24:07 +02:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_EnumPortsW [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Enumerate all local Ports
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pName [I] Servername (ignored)
|
|
|
|
* level [I] Structure-Level (1 or 2)
|
|
|
|
* pPorts [O] PTR to Buffer that receives the Result
|
|
|
|
* cbBuf [I] Size of Buffer at pPorts
|
|
|
|
* pcbNeeded [O] PTR to DWORD that receives the size in Bytes used / required for pPorts
|
|
|
|
* pcReturned [O] PTR to DWORD that receives the number of Ports in pPorts
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE and in pcbNeeded the Bytes required for pPorts, if cbBuf is too small
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*| Windows ignores pName
|
|
|
|
*| Windows crash the app, when pPorts, pcbNeeded or pcReturned are NULL
|
|
|
|
*| Windows >NT4.0 does not check for illegal levels (TRUE is returned)
|
|
|
|
*
|
|
|
|
* ToDo
|
|
|
|
* "HCU\Software\Wine\Spooler\<portname>" - redirection
|
|
|
|
*
|
|
|
|
*/
|
2007-06-14 13:16:06 +02:00
|
|
|
static BOOL WINAPI localmon_EnumPortsW(LPWSTR pName, DWORD level, LPBYTE pPorts,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
|
2006-10-27 19:24:07 +02:00
|
|
|
{
|
|
|
|
BOOL res = FALSE;
|
|
|
|
DWORD needed;
|
|
|
|
DWORD numentries;
|
|
|
|
|
|
|
|
TRACE("(%s, %d, %p, %d, %p, %p)\n",
|
|
|
|
debugstr_w(pName), level, pPorts, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
|
|
|
|
numentries = 0;
|
|
|
|
needed = get_ports_from_reg(level, NULL, 0, &numentries);
|
|
|
|
/* we calculated the needed buffersize. now do the error-checks */
|
|
|
|
if (cbBuf < needed) {
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the buffer with the Port-Names */
|
|
|
|
needed = get_ports_from_reg(level, pPorts, cbBuf, &numentries);
|
|
|
|
res = TRUE;
|
|
|
|
|
|
|
|
if (pcReturned) *pcReturned = numentries;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (pcbNeeded) *pcbNeeded = needed;
|
|
|
|
|
|
|
|
TRACE("returning %d with %d (%d byte for %d entries)\n",
|
|
|
|
res, GetLastError(), needed, numentries);
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2007-09-10 15:02:58 +02:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_OpenPort [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Open a Data-Channel for a Port
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pName [i] Name of selected Object
|
|
|
|
* phPort [o] The resulting Handle is stored here
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static BOOL WINAPI localmon_OpenPortW(LPWSTR pName, PHANDLE phPort)
|
|
|
|
{
|
|
|
|
port_t * port;
|
|
|
|
DWORD type;
|
|
|
|
|
|
|
|
TRACE("%s, %p)\n", debugstr_w(pName), phPort);
|
|
|
|
|
|
|
|
/* an empty name is invalid */
|
|
|
|
if (!pName[0]) return FALSE;
|
|
|
|
|
|
|
|
/* does the port exist? */
|
|
|
|
type = get_type_from_local_name(pName);
|
|
|
|
if (!type) return FALSE;
|
|
|
|
|
2012-11-02 15:11:26 +01:00
|
|
|
port = heap_alloc(FIELD_OFFSET(port_t, nameW[lstrlenW(pName) + 1]));
|
2007-09-10 15:02:58 +02:00
|
|
|
if (!port) return FALSE;
|
|
|
|
|
|
|
|
port->type = type;
|
2012-11-02 15:11:26 +01:00
|
|
|
lstrcpyW(port->nameW, pName);
|
2009-01-27 11:37:19 +01:00
|
|
|
*phPort = port;
|
2007-09-10 15:02:58 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&port_handles_cs);
|
|
|
|
list_add_tail(&port_handles, &port->entry);
|
|
|
|
LeaveCriticalSection(&port_handles_cs);
|
|
|
|
|
|
|
|
TRACE("=> %p\n", port);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-11 15:02:24 +01:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_XcvClosePort [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Close a Communication-Channel
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hXcv [i] The Handle to close
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
*/
|
2007-06-14 13:16:06 +02:00
|
|
|
static BOOL WINAPI localmon_XcvClosePort(HANDLE hXcv)
|
2007-01-11 15:02:24 +01:00
|
|
|
{
|
2009-01-27 11:37:19 +01:00
|
|
|
xcv_t * xcv = hXcv;
|
2007-01-11 15:02:24 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", xcv);
|
|
|
|
/* No checks are done in Windows */
|
|
|
|
EnterCriticalSection(&xcv_handles_cs);
|
|
|
|
list_remove(&xcv->entry);
|
|
|
|
LeaveCriticalSection(&xcv_handles_cs);
|
2007-12-09 16:30:24 +01:00
|
|
|
heap_free(xcv);
|
2007-01-11 15:02:24 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-16 00:38:02 +01:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_XcvDataPort [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Execute command through a Communication-Channel
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hXcv [i] The Handle to work with
|
|
|
|
* pszDataName [i] Name of the command to execute
|
|
|
|
* pInputData [i] Buffer for extra Input Data (needed only for some commands)
|
|
|
|
* cbInputData [i] Size in Bytes of Buffer at pInputData
|
|
|
|
* pOutputData [o] Buffer to receive additional Data (needed only for some commands)
|
|
|
|
* cbOutputData [i] Size in Bytes of Buffer at pOutputData
|
|
|
|
* pcbOutputNeeded [o] PTR to receive the minimal Size in Bytes of the Buffer at pOutputData
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: ERROR_SUCCESS
|
2007-04-30 10:35:50 +02:00
|
|
|
* Failure: win32 error code
|
2007-01-16 00:38:02 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
*
|
|
|
|
* Minimal List of commands, that every Printmonitor DLL should support:
|
|
|
|
*
|
|
|
|
*| "MonitorUI" : Return the Name of the Userinterface-DLL as WSTR in pOutputData
|
|
|
|
*| "AddPort" : Add a Port (Name as WSTR in pInputData)
|
|
|
|
*| "DeletePort": Delete a Port (Name as WSTR in pInputData)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2007-06-14 13:16:06 +02:00
|
|
|
static DWORD WINAPI localmon_XcvDataPort(HANDLE hXcv, LPCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData,
|
|
|
|
PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded)
|
2007-01-16 00:38:02 +01:00
|
|
|
{
|
2007-02-20 00:00:18 +01:00
|
|
|
WCHAR buffer[16]; /* buffer for a decimal number */
|
2007-02-20 18:12:06 +01:00
|
|
|
LPWSTR ptr;
|
2007-01-16 00:42:15 +01:00
|
|
|
DWORD res;
|
2007-02-20 00:00:18 +01:00
|
|
|
DWORD needed;
|
|
|
|
HKEY hroot;
|
|
|
|
|
2007-01-16 00:38:02 +01:00
|
|
|
TRACE("(%p, %s, %p, %d, %p, %d, %p)\n", hXcv, debugstr_w(pszDataName),
|
|
|
|
pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded);
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"AddPort")) {
|
2007-04-17 23:20:34 +02:00
|
|
|
TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
|
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
if (does_port_exist((LPWSTR) pInputData)) {
|
|
|
|
RegCloseKey(hroot);
|
2007-04-30 10:35:50 +02:00
|
|
|
TRACE("=> %u\n", ERROR_ALREADY_EXISTS);
|
2007-04-17 23:20:34 +02:00
|
|
|
return ERROR_ALREADY_EXISTS;
|
|
|
|
}
|
2020-12-03 00:32:53 +01:00
|
|
|
res = RegSetValueExW(hroot, (LPWSTR)pInputData, 0, REG_SZ, (const BYTE*)L"", sizeof(L""));
|
2007-04-17 23:20:34 +02:00
|
|
|
RegCloseKey(hroot);
|
|
|
|
}
|
2007-04-30 10:35:50 +02:00
|
|
|
TRACE("=> %u\n", res);
|
2007-04-17 23:20:34 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2007-03-15 23:03:33 +01:00
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"ConfigureLPTPortCommandOK")) {
|
2007-02-20 00:00:40 +01:00
|
|
|
TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
|
|
|
|
res = RegCreateKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
2020-12-03 00:32:53 +01:00
|
|
|
res = RegSetValueExW(hroot, L"TransmissionRetryTimeout", 0, REG_SZ, pInputData, cbInputData);
|
2007-02-20 00:00:40 +01:00
|
|
|
RegCloseKey(hroot);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"DeletePort")) {
|
2007-03-07 00:20:25 +01:00
|
|
|
TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
|
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_PortsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
res = RegDeleteValueW(hroot, (LPWSTR) pInputData);
|
|
|
|
RegCloseKey(hroot);
|
|
|
|
TRACE("=> %u with %u\n", res, GetLastError() );
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"GetDefaultCommConfig")) {
|
2007-02-20 18:11:53 +01:00
|
|
|
TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
|
|
|
|
*pcbOutputNeeded = cbOutputData;
|
|
|
|
res = GetDefaultCommConfigW((LPWSTR) pInputData, (LPCOMMCONFIG) pOutputData, pcbOutputNeeded);
|
|
|
|
TRACE("got %u with %u\n", res, GetLastError() );
|
|
|
|
return res ? ERROR_SUCCESS : GetLastError();
|
|
|
|
}
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"GetTransmissionRetryTimeout")) {
|
2007-02-20 00:00:18 +01:00
|
|
|
* pcbOutputNeeded = sizeof(DWORD);
|
|
|
|
if (cbOutputData >= sizeof(DWORD)) {
|
|
|
|
/* the w2k resource kit documented a default of 90, but that's wrong */
|
|
|
|
*((LPDWORD) pOutputData) = 45;
|
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_LOCAL_MACHINE, WinNT_CV_WindowsW, &hroot);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
needed = sizeof(buffer) - sizeof(WCHAR);
|
2020-12-03 00:32:53 +01:00
|
|
|
res = RegQueryValueExW(hroot, L"TransmissionRetryTimeout", NULL, NULL, (BYTE*)buffer, &needed);
|
2007-02-20 00:00:18 +01:00
|
|
|
if ((res == ERROR_SUCCESS) && (buffer[0])) {
|
2019-06-10 10:55:52 +02:00
|
|
|
*((LPDWORD) pOutputData) = wcstoul(buffer, NULL, 0);
|
2007-02-20 00:00:18 +01:00
|
|
|
}
|
|
|
|
RegCloseKey(hroot);
|
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
|
2007-01-16 00:38:02 +01:00
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"MonitorUI")) {
|
|
|
|
* pcbOutputNeeded = sizeof(L"localui.dll");
|
|
|
|
if (cbOutputData >= sizeof(L"localui.dll")) {
|
|
|
|
memcpy(pOutputData, L"localui.dll", sizeof(L"localui.dll"));
|
2007-01-16 00:38:02 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
2007-01-16 00:42:15 +01:00
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"PortIsValid")) {
|
2007-01-16 00:42:15 +01:00
|
|
|
TRACE("InputData (%d): %s\n", cbInputData, debugstr_w( (LPWSTR) pInputData));
|
|
|
|
res = get_type_from_name((LPCWSTR) pInputData);
|
|
|
|
TRACE("detected as %u\n", res);
|
|
|
|
/* names, that we have recognized, are valid */
|
|
|
|
if (res) return ERROR_SUCCESS;
|
|
|
|
|
2007-04-30 10:35:50 +02:00
|
|
|
/* ERROR_ACCESS_DENIED, ERROR_PATH_NOT_FOUND or something else */
|
|
|
|
TRACE("=> %u\n", GetLastError());
|
2007-01-16 00:42:15 +01:00
|
|
|
return GetLastError();
|
2007-02-20 18:12:06 +01:00
|
|
|
}
|
|
|
|
|
2020-12-03 00:32:53 +01:00
|
|
|
if (!lstrcmpW(pszDataName, L"SetDefaultCommConfig")) {
|
2007-02-20 18:12:06 +01:00
|
|
|
/* get the portname from the Handle */
|
2019-06-10 10:55:52 +02:00
|
|
|
ptr = wcschr(((xcv_t *)hXcv)->nameW, ' ');
|
2007-03-06 05:40:50 +01:00
|
|
|
if (ptr) {
|
|
|
|
ptr++; /* skip the space */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr = ((xcv_t *)hXcv)->nameW;
|
|
|
|
}
|
2018-07-20 21:45:42 +02:00
|
|
|
lstrcpynW(buffer, ptr, ARRAY_SIZE(buffer));
|
2007-02-20 18:12:06 +01:00
|
|
|
if (buffer[0]) buffer[lstrlenW(buffer)-1] = '\0'; /* remove the ':' */
|
|
|
|
res = SetDefaultCommConfigW(buffer, (LPCOMMCONFIG) pInputData, cbInputData);
|
|
|
|
TRACE("got %u with %u\n", res, GetLastError() );
|
|
|
|
return res ? ERROR_SUCCESS : GetLastError();
|
2007-01-16 00:42:15 +01:00
|
|
|
}
|
|
|
|
|
2007-01-16 00:38:02 +01:00
|
|
|
FIXME("command not supported: %s\n", debugstr_w(pszDataName));
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2007-01-11 15:02:24 +01:00
|
|
|
/*****************************************************
|
|
|
|
* localmon_XcvOpenPort [exported through MONITOREX]
|
|
|
|
*
|
|
|
|
* Open a Communication-Channel
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pName [i] Name of selected Object
|
|
|
|
* GrantedAccess [i] Access-Rights to use
|
|
|
|
* phXcv [o] The resulting Handle is stored here
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*
|
|
|
|
*/
|
2007-06-14 13:16:06 +02:00
|
|
|
static BOOL WINAPI localmon_XcvOpenPort(LPCWSTR pName, ACCESS_MASK GrantedAccess, PHANDLE phXcv)
|
2007-01-11 15:02:24 +01:00
|
|
|
{
|
|
|
|
xcv_t * xcv;
|
|
|
|
|
|
|
|
TRACE("%s, 0x%x, %p)\n", debugstr_w(pName), GrantedAccess, phXcv);
|
|
|
|
/* No checks for any field is done in Windows */
|
2012-11-02 15:11:26 +01:00
|
|
|
xcv = heap_alloc(FIELD_OFFSET(xcv_t, nameW[lstrlenW(pName) + 1]));
|
2007-01-11 15:02:24 +01:00
|
|
|
if (xcv) {
|
|
|
|
xcv->GrantedAccess = GrantedAccess;
|
2012-11-02 15:11:26 +01:00
|
|
|
lstrcpyW(xcv->nameW, pName);
|
2009-01-27 11:37:19 +01:00
|
|
|
*phXcv = xcv;
|
2007-01-11 15:02:24 +01:00
|
|
|
EnterCriticalSection(&xcv_handles_cs);
|
|
|
|
list_add_tail(&xcv_handles, &xcv->entry);
|
|
|
|
LeaveCriticalSection(&xcv_handles_cs);
|
|
|
|
TRACE("=> %p\n", xcv);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-18 11:36:02 +01:00
|
|
|
*phXcv = NULL;
|
2007-01-11 15:02:24 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-27 23:22:33 +02:00
|
|
|
/*****************************************************
|
|
|
|
* InitializePrintMonitor (LOCALSPL.@)
|
|
|
|
*
|
|
|
|
* Initialize the Monitor for the Local Ports
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* regroot [I] Registry-Path, where the settings are stored
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to a MONITOREX Structure
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
2006-10-19 23:48:29 +02:00
|
|
|
* The fixed location "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Ports"
|
|
|
|
* is used to store the Ports (IniFileMapping from "win.ini", Section "Ports").
|
|
|
|
* Native localspl.dll fails, when no valid Port-Entry is present.
|
2006-09-27 23:22:33 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
LPMONITOREX WINAPI InitializePrintMonitor(LPWSTR regroot)
|
|
|
|
{
|
2006-10-19 23:48:29 +02:00
|
|
|
static MONITOREX mymonitorex =
|
|
|
|
{
|
2019-09-09 08:57:45 +02:00
|
|
|
sizeof(MONITOR),
|
2006-10-27 19:24:07 +02:00
|
|
|
{
|
2006-11-15 20:41:06 +01:00
|
|
|
localmon_EnumPortsW,
|
2007-09-10 15:02:58 +02:00
|
|
|
localmon_OpenPortW,
|
2006-11-15 20:41:06 +01:00
|
|
|
NULL, /* localmon_OpenPortExW */
|
|
|
|
NULL, /* localmon_StartDocPortW */
|
|
|
|
NULL, /* localmon_WritePortW */
|
|
|
|
NULL, /* localmon_ReadPortW */
|
|
|
|
NULL, /* localmon_EndDocPortW */
|
2007-09-10 15:02:58 +02:00
|
|
|
localmon_ClosePort,
|
2007-06-14 01:01:11 +02:00
|
|
|
NULL, /* Use AddPortUI in localui.dll */
|
|
|
|
localmon_AddPortExW,
|
2007-04-19 22:59:56 +02:00
|
|
|
NULL, /* Use ConfigurePortUI in localui.dll */
|
2007-04-19 00:41:19 +02:00
|
|
|
NULL, /* Use DeletePortUI in localui.dll */
|
2007-01-11 15:02:24 +01:00
|
|
|
NULL, /* localmon_GetPrinterDataFromPort */
|
|
|
|
NULL, /* localmon_SetPortTimeOuts */
|
|
|
|
localmon_XcvOpenPort,
|
2007-01-16 00:38:02 +01:00
|
|
|
localmon_XcvDataPort,
|
2007-01-11 15:02:24 +01:00
|
|
|
localmon_XcvClosePort
|
2006-10-27 19:24:07 +02:00
|
|
|
}
|
2006-10-19 23:48:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_w(regroot));
|
|
|
|
/* Parameter "regroot" is ignored on NT4.0 (localmon.dll) */
|
2006-09-27 23:22:33 +02:00
|
|
|
if (!regroot || !regroot[0]) {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-10-19 23:48:29 +02:00
|
|
|
TRACE("=> %p\n", &mymonitorex);
|
|
|
|
/* Native windows returns always the same pointer on success */
|
|
|
|
return &mymonitorex;
|
2006-09-27 23:22:33 +02:00
|
|
|
}
|