[PATCH 5/6] s3-spoolss: Support opening ports via OpenPrinterEx
Justin Chevrier
jchevrier at gmail.com
Wed Aug 31 13:03:13 MDT 2011
Signed-off-by: Justin Chevrier <jchevrier at gmail.com>
---
librpc/idl/spoolss.idl | 1 +
source3/rpc_server/spoolss/srv_spoolss_nt.c | 43 +++++++++++++++++++++++++--
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/librpc/idl/spoolss.idl b/librpc/idl/spoolss.idl
index edd2490..46efe69 100644
--- a/librpc/idl/spoolss.idl
+++ b/librpc/idl/spoolss.idl
@@ -2102,6 +2102,7 @@ cpp_quote("#define spoolss_security_descriptor security_descriptor")
const string SPL_TCPIP_PORT = "Standard TCP/IP Port";
const string SPL_XCV_MONITOR_LOCALMON = ",XcvMonitor Local Port";
const string SPL_XCV_MONITOR_TCPMON = ",XcvMonitor Standard TCP/IP Port";
+ const string SPL_XCV_PORT = ",XcvPort ";
typedef [public,gensize] struct {
[relative] nstring *port_name;
diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index 3619e6c..db1d96a 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -539,9 +539,9 @@ static void prune_printername_cache(void)
/****************************************************************************
Set printer handle name.. Accept names like \\server, \\server\printer,
- \\server\SHARE, & "\\server\,XcvMonitor Standard TCP/IP Port" See
- the MSDN docs regarding OpenPrinter() for details on the XcvData() and
- XcvDataPort() interface.
+ \\server\SHARE, "\\server\,XcvMonitor Standard TCP/IP Port", &
+ "\\server\,XcvPort portname" See the MSDN docs regarding OpenPrinter()
+ for details on the XcvData() and XcvDataPort() interface.
****************************************************************************/
static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
@@ -553,10 +553,12 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
int snum;
int n_services=lp_numservices();
char *aprinter;
+ const char *portname;
const char *printername;
const char *servername = NULL;
fstring sname;
bool found = false;
+ struct spoolss_PortData1 *data1 = NULL;
struct spoolss_PrinterInfo2 *info2 = NULL;
WERROR result;
char *p;
@@ -578,6 +580,11 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
*aprinter = '\0';
aprinter++;
+ /* Ensure there isn't a second backslash */
+ if ( *aprinter == '\\' ) {
+ *aprinter = '\0';
+ aprinter++;
+ }
}
if (!is_myname_or_ipaddr(servername)) {
return WERR_INVALID_PRINTER_NAME;
@@ -627,7 +634,36 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
fstrcpy(sname, SPL_XCV_MONITOR_LOCALMON);
found = true;
}
+ else if ( strstr(aprinter, SPL_XCV_PORT) ) {
+ if ((portname = strchr_m(aprinter, ' ')) != NULL ) {
+ portname++;
+ /* Don't bother searching the registry for
+ dummy port name: "Samba Printer Port" */
+ if (!strequal(portname, SAMBA_PRINTER_PORT_NAME)) {
+
+ result = winreg_get_port_internal(mem_ctx,
+ session_info,
+ msg_ctx,
+ portname,
+ &data1);
+ if (!W_ERROR_IS_OK(result)) {
+ DEBUG(2,("set_printer_hnd_name: failed to lookup port [%s] -- result [%s]\n",
+ portname, win_errstr(result)));
+ return WERR_INVALID_PRINTER_NAME;
+ }
+ DEBUG(4, ("Found Port: [%s]\n", portname));
+ fstrcpy(sname, portname);
+ Printer->printer_type = SPLHND_PORTMON_TCP;
+
+ TALLOC_FREE(data1);
+ goto done;
+ }
+ }
+
+ DEBUGADD(4,("Port %s not found\n", portname));
+ return WERR_INVALID_PRINTER_NAME;
+ }
/*
* With hundreds of printers, the "for" loop iterating all
* shares can be quite expensive, as it is done on every
@@ -722,6 +758,7 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
TALLOC_FREE(cache_key);
}
+done:
DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));
strlcpy(Printer->sharename, sname, sizeof(Printer->sharename));
--
1.7.3.4
More information about the samba-technical
mailing list