summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2002-04-02 01:10:41 +0000
committerGerald Carter <jerry@samba.org>2002-04-02 01:10:41 +0000
commit9cb6a94406906b88bbab1103594694ed37c3a682 (patch)
tree8421dc932971c56c41bc26fcecf4b8f9681bfb6e /source3
parentace98925bef8213d900ae0c7820df1045eba0ee6 (diff)
downloadsamba-9cb6a94406906b88bbab1103594694ed37c3a682.tar.gz
samba-9cb6a94406906b88bbab1103594694ed37c3a682.tar.bz2
samba-9cb6a94406906b88bbab1103594694ed37c3a682.zip
some mergee from SAMBA_2_2. Does compile, but needs some more testing.
This is an intermediate check-in. More to come.... (This used to be commit 5b9b152971aa635d484cde45413a7880424ee22d)
Diffstat (limited to 'source3')
-rw-r--r--source3/libsmb/cli_spoolss.c474
-rw-r--r--source3/rpcclient/cmd_spoolss.c173
2 files changed, 426 insertions, 221 deletions
diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c
index 2d81f63f89..cbe7da7d50 100644
--- a/source3/libsmb/cli_spoolss.c
+++ b/source3/libsmb/cli_spoolss.c
@@ -1,8 +1,8 @@
-/*
+/*
Unix SMB/CIFS implementation.
RPC pipe client
- Copyright (C) Gerald Carter 2001,
+ Copyright (C) Gerald Carter 2001-2002,
Copyright (C) Tim Potter 2000-2002,
Copyright (C) Andrew Tridgell 1994-2000,
Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
@@ -12,12 +12,12 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program 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 General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -38,140 +38,16 @@
* @param creds User credentials to connect as.
* @returns Initialised client handle.
*/
-struct cli_state *cli_spoolss_initialise(struct cli_state *cli,
- char *system_name,
+struct cli_state *cli_spoolss_initialise(struct cli_state *cli,
+ char *system_name,
struct ntuser_creds *creds)
{
return cli_pipe_initialise(cli, system_name, PIPE_SPOOLSS, creds);
}
-/** Return a handle to the specified printer or print server.
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- *
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param printername The name of the printer or print server to be
- * opened in UNC format.
- *
- * @param datatype Specifies the default data type for the printer.
- *
- * @param access_required The access rights requested on the printer or
- * print server.
- *
- * @param station The UNC name of the requesting workstation.
- *
- * @param username The name of the user requesting the open.
- *
- * @param pol Returned policy handle.
- */
-
-WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- char *printername, char *datatype,
- uint32 access_required, char *station,
- char *username, POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_OPEN_PRINTER_EX q;
- SPOOL_R_OPEN_PRINTER_EX r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_open_printer_ex(&q, printername, datatype,
- access_required, station, username);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result))
- *pol = r.handle;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/** Close a printer handle
- *
- * @param cli Pointer to client state structure which is open
- * on the SPOOLSS pipe.
- *
- * @param mem_ctx Pointer to an initialised talloc context.
- *
- * @param pol Policy handle of printer or print server to close.
- */
-
-WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
- POLICY_HND *pol)
-{
- prs_struct qbuf, rbuf;
- SPOOL_Q_CLOSEPRINTER q;
- SPOOL_R_CLOSEPRINTER r;
- WERROR result = W_ERROR(ERRgeneral);
-
- ZERO_STRUCT(q);
- ZERO_STRUCT(r);
-
- /* Initialise parse structures */
-
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
- /* Initialise input parameters */
-
- make_spoolss_q_closeprinter(&q, pol);
-
- /* Marshall data and send request */
-
- if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
- goto done;
-
- /* Unmarshall response */
-
- if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
- goto done;
-
- /* Return output parameters */
-
- result = r.status;
-
- if (W_ERROR_IS_OK(result))
- *pol = r.handle;
-
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
-
- return result;
-}
-
-/* Initialize a spoolss NEW_BUFFER */
-
+/**********************************************************************
+ Initialize a new spoolss buff for use by a client rpc
+**********************************************************************/
static void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx)
{
buffer->ptr = (size != 0);
@@ -181,15 +57,14 @@ static void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx)
buffer->struct_start = prs_offset(&buffer->prs);
}
-/* Decode various printer info levels - perhaps this should live in
- parse_spoolss.c? */
+/*********************************************************************
+ Decode various spoolss rpc's and info levels
+ ********************************************************************/
-static void decode_printer_info_0(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PRINTER_INFO_0 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_info_0(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PRINTER_INFO_0 **info)
{
uint32 i;
PRINTER_INFO_0 *inf;
@@ -205,12 +80,10 @@ static void decode_printer_info_0(
*info=inf;
}
-static void decode_printer_info_1(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PRINTER_INFO_1 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PRINTER_INFO_1 **info)
{
uint32 i;
PRINTER_INFO_1 *inf;
@@ -226,12 +99,10 @@ static void decode_printer_info_1(
*info=inf;
}
-static void decode_printer_info_2(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PRINTER_INFO_2 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PRINTER_INFO_2 **info)
{
uint32 i;
PRINTER_INFO_2 *inf;
@@ -249,12 +120,10 @@ static void decode_printer_info_2(
*info=inf;
}
-static void decode_printer_info_3(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PRINTER_INFO_3 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_info_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PRINTER_INFO_3 **info)
{
uint32 i;
PRINTER_INFO_3 *inf;
@@ -272,14 +141,9 @@ static void decode_printer_info_3(
}
/**********************************************************************
- Decode a PORT_INFO_1 struct from a NEW_BUFFER
**********************************************************************/
-static void decode_port_info_1(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PORT_INFO_1 **info
-)
+static void decode_port_info_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PORT_INFO_1 **info)
{
uint32 i;
PORT_INFO_1 *inf;
@@ -296,13 +160,9 @@ static void decode_port_info_1(
}
/**********************************************************************
- Decode a PORT_INFO_2 struct from a NEW_BUFFER
**********************************************************************/
-static void decode_port_info_2(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- PORT_INFO_2 **info)
+static void decode_port_info_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, PORT_INFO_2 **info)
{
uint32 i;
PORT_INFO_2 *inf;
@@ -318,12 +178,10 @@ static void decode_port_info_2(
*info=inf;
}
-static void decode_printer_driver_1(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- DRIVER_INFO_1 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_driver_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, DRIVER_INFO_1 **info)
{
uint32 i;
DRIVER_INFO_1 *inf;
@@ -339,12 +197,10 @@ static void decode_printer_driver_1(
*info=inf;
}
-static void decode_printer_driver_2(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- DRIVER_INFO_2 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_driver_2(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, DRIVER_INFO_2 **info)
{
uint32 i;
DRIVER_INFO_2 *inf;
@@ -360,12 +216,10 @@ static void decode_printer_driver_2(
*info=inf;
}
-static void decode_printer_driver_3(
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- DRIVER_INFO_3 **info
-)
+/**********************************************************************
+**********************************************************************/
+static void decode_printer_driver_3(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, DRIVER_INFO_3 **info)
{
uint32 i;
DRIVER_INFO_3 *inf;
@@ -381,11 +235,10 @@ static void decode_printer_driver_3(
*info=inf;
}
-static void decode_printerdriverdir_1 (
- TALLOC_CTX *mem_ctx,
- NEW_BUFFER *buffer,
- uint32 returned,
- DRIVER_DIRECTORY_1 **info
+/**********************************************************************
+**********************************************************************/
+static void decode_printerdriverdir_1 (TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
+ uint32 returned, DRIVER_DIRECTORY_1 **info
)
{
DRIVER_DIRECTORY_1 *inf;
@@ -399,6 +252,137 @@ static void decode_printerdriverdir_1 (
*info=inf;
}
+/** Return a handle to the specified printer or print server.
+ *
+ * @param cli Pointer to client state structure which is open
+ * on the SPOOLSS pipe.
+ *
+ * @param mem_ctx Pointer to an initialised talloc context.
+ *
+ * @param printername The name of the printer or print server to be
+ * opened in UNC format.
+ *
+ * @param datatype Specifies the default data type for the printer.
+ *
+ * @param access_required The access rights requested on the printer or
+ * print server.
+ *
+ * @param station The UNC name of the requesting workstation.
+ *
+ * @param username The name of the user requesting the open.
+ *
+ * @param pol Returned policy handle.
+ */
+
+/*********************************************************************************
+ Win32 API - OpenPrinter()
+ ********************************************************************************/
+
+WERROR cli_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ char *printername, char *datatype, uint32 access_required,
+ char *station, char *username, POLICY_HND *pol)
+{
+ prs_struct qbuf, rbuf;
+ SPOOL_Q_OPEN_PRINTER_EX q;
+ SPOOL_R_OPEN_PRINTER_EX r;
+ WERROR result = W_ERROR(ERRgeneral);
+
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* Initialise parse structures */
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+ /* Initialise input parameters */
+
+ make_spoolss_q_open_printer_ex(&q, printername, datatype,
+ access_required, station, username);
+
+ /* Marshall data and send request */
+
+ if (!spoolss_io_q_open_printer_ex("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SPOOLSS_OPENPRINTEREX, &qbuf, &rbuf))
+ goto done;
+
+ /* Unmarshall response */
+
+ if (!spoolss_io_r_open_printer_ex("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ result = r.status;
+
+ if (W_ERROR_IS_OK(result))
+ *pol = r.handle;
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
+}
+
+/** Close a printer handle
+ *
+ * @param cli Pointer to client state structure which is open
+ * on the SPOOLSS pipe.
+ *
+ * @param mem_ctx Pointer to an initialised talloc context.
+ *
+ * @param pol Policy handle of printer or print server to close.
+ */
+/*********************************************************************************
+ Win32 API - ClosePrinter()
+ ********************************************************************************/
+
+WERROR cli_spoolss_close_printer(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol)
+{
+ prs_struct qbuf, rbuf;
+ SPOOL_Q_CLOSEPRINTER q;
+ SPOOL_R_CLOSEPRINTER r;
+ WERROR result = W_ERROR(ERRgeneral);
+
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* Initialise parse structures */
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+ /* Initialise input parameters */
+
+ make_spoolss_q_closeprinter(&q, pol);
+
+ /* Marshall data and send request */
+
+ if (!spoolss_io_q_closeprinter("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SPOOLSS_CLOSEPRINTER, &qbuf, &rbuf))
+ goto done;
+
+ /* Unmarshall response */
+
+ if (!spoolss_io_r_closeprinter("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ result = r.status;
+
+ if (W_ERROR_IS_OK(result))
+ *pol = r.handle;
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
+}
+
/** Enumerate printers on a print server.
*
* @param cli Pointer to client state structure which is open
@@ -417,6 +401,9 @@ static void decode_printerdriverdir_1 (
* @param ctr Return structure for printer information. May
* be NULL.
*/
+/*********************************************************************************
+ Win32 API - EnumPrinters()
+ ********************************************************************************/
WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
uint32 offered, uint32 *needed,
@@ -498,6 +485,9 @@ WERROR cli_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
+/*********************************************************************************
+ Win32 API - EnumPorts()
+ ********************************************************************************/
/** Enumerate printer ports on a print server.
*
* @param cli Pointer to client state structure which is open
@@ -585,7 +575,9 @@ WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
-/* Get printer info */
+/*********************************************************************************
+ Win32 API - GetPrinter()
+ ********************************************************************************/
WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
uint32 offered, uint32 *needed,
@@ -602,7 +594,7 @@ WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
ZERO_STRUCT(r);
/* Initialise input parameters */
-
+
init_buffer(&buffer, offered, mem_ctx);
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
@@ -652,6 +644,9 @@ WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
+/*********************************************************************************
+ Win32 API - SetPrinter()
+ ********************************************************************************/
/** Set printer info
*
* @param cli Pointer to client state structure which is open
@@ -706,6 +701,9 @@ done:
return result;
}
+/*********************************************************************************
+ Win32 API - GetPrinterDriver()
+ ********************************************************************************/
/** Get installed printer drivers for a given printer
*
* @param cli Pointer to client state structure which is open
@@ -787,7 +785,7 @@ WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
case 3:
decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3);
break;
- }
+ }
done:
prs_mem_free(&qbuf);
@@ -796,6 +794,9 @@ WERROR cli_spoolss_getprinterdriver(struct cli_state *cli,
return result;
}
+/*********************************************************************************
+ Win32 API - EnumPrinterDrivers()
+ ********************************************************************************/
/**********************************************************************
* Get installed printer drivers for a given printer
*/
@@ -865,7 +866,7 @@ WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
case 3:
decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3);
break;
- }
+ }
}
done:
@@ -876,6 +877,9 @@ WERROR cli_spoolss_enumprinterdrivers (struct cli_state *cli,
}
+/*********************************************************************************
+ Win32 API - GetPrinterDriverDirectory()
+ ********************************************************************************/
/**********************************************************************
* Get installed printer drivers for a given printer
*/
@@ -944,6 +948,9 @@ WERROR cli_spoolss_getprinterdriverdir (struct cli_state *cli,
return result;
}
+/*********************************************************************************
+ Win32 API - AddPrinterDriver()
+ ********************************************************************************/
/**********************************************************************
* Install a printer driver
*/
@@ -994,8 +1001,11 @@ done:
return result;
}
+/*********************************************************************************
+ Win32 API - AddPrinter()
+ ********************************************************************************/
/**********************************************************************
- * Install a printer
+ * Install a printer
*/
WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
uint32 level, PRINTER_INFO_CTR*ctr)
@@ -1049,6 +1059,9 @@ WERROR cli_spoolss_addprinterex (struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
+/*********************************************************************************
+ Win32 API - DeltePrinterDriver()
+ ********************************************************************************/
/**********************************************************************
* Delete a Printer Driver from the server (does not remove
* the driver files
@@ -1066,8 +1079,8 @@ WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
ZERO_STRUCT(q);
ZERO_STRUCT(r);
- /* Initialise input parameters */
+ /* Initialise input parameters */
prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
@@ -1083,7 +1096,7 @@ WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
if (!spoolss_io_q_deleteprinterdriver ("", &q, &qbuf, 0) ||
!rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVER , &qbuf, &rbuf))
goto done;
-
+
/* Unmarshall response */
if (!spoolss_io_r_deleteprinterdriver ("", &r, &rbuf, 0))
@@ -1100,7 +1113,9 @@ WERROR cli_spoolss_deleteprinterdriver (struct cli_state *cli,
return result;
}
-/* Get print processor directory */
+/*********************************************************************************
+ Win32 API - GetPrinterProcessorDirectory()
+ ********************************************************************************/
WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
@@ -1133,7 +1148,7 @@ WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
/* Marshall data and send request */
if (!spoolss_io_q_getprintprocessordirectory("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
+ !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTPROCESSORDIRECTORY,
&qbuf, &rbuf))
goto done;
@@ -1165,7 +1180,7 @@ WERROR cli_spoolss_getprintprocessordirectory(struct cli_state *cli,
* on the SPOOLSS pipe.
* @param mem_ctx Pointer to an initialised talloc context.
*
- * @param handle Policy handle opened with cli_spoolss_open_printer_ex
+ * @param handle Policy handle opened with cli_spoolss_open_printer_ex
* or cli_spoolss_addprinterex.
* @param level Form info level to add - should always be 1.
* @param form A pointer to the form to be added.
@@ -1403,7 +1418,7 @@ static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
*forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
buffer->prs.data_offset = 0;
- for (i = 0; i < num_forms; i++)
+ for (i = 0; i < num_forms; i++)
smb_io_form_1("", buffer, &((*forms)[i]), 0);
}
@@ -1418,7 +1433,7 @@ static void decode_forms_1(TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer,
* may be NULL.
* or cli_spoolss_addprinterex.
* @param level Form info level to get - should always be 1.
- * @param handle Open policy handle
+ * @param handle Open policy handle
*
*/
@@ -1446,7 +1461,7 @@ WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* Initialise input parameters */
make_spoolss_q_enumforms(&q, handle, level, &buffer, offered);
-
+
/* Marshall data and send request */
if (!spoolss_io_q_enumforms("", &q, &qbuf, 0) ||
@@ -1477,4 +1492,47 @@ WERROR cli_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return result;
}
+/*********************************************************************************
+ Win32 API - SetPrinterData()
+ ********************************************************************************/
+
+WERROR cli_spoolss_setprinterdata (struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol, char* valname, char* value)
+{
+ prs_struct qbuf, rbuf;
+ SPOOL_Q_SETPRINTERDATA q;
+ SPOOL_R_SETPRINTERDATA r;
+ WERROR result = W_ERROR(ERRgeneral);
+
+ ZERO_STRUCT(q);
+ ZERO_STRUCT(r);
+
+ /* Initialise input parameters */
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+
+
+ /* write the request */
+ make_spoolss_q_setprinterdata(&q, mem_ctx, pol, valname, value);
+
+ /* Marshall data and send request */
+ if (!spoolss_io_q_setprinterdata ("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req (cli, SPOOLSS_SETPRINTERDATA, &qbuf, &rbuf))
+ goto done;
+
+ /* Unmarshall response */
+ if (spoolss_io_r_setprinterdata ("", &r, &rbuf, 0))
+ goto done;
+
+ result = r.status;
+
+done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
+}
+
+
/** @} **/
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 98ed6e2713..64a84e25df 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -1,4 +1,4 @@
-/*
+/*
Unix SMB/CIFS implementation.
RPC pipe client
@@ -453,9 +453,79 @@ static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
}
/***********************************************************************
+ * Set printer comment - use a level2 set.
+ */
+static NTSTATUS cmd_spoolss_setprinter(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ POLICY_HND pol;
+ WERROR result;
+ uint32 needed;
+ uint32 info_level = 2;
+ BOOL opened_hnd = False;
+ PRINTER_INFO_CTR ctr;
+ fstring printername,
+ servername,
+ user,
+ comment;
+
+ if (argc == 1 || argc > 3) {
+ printf("Usage: %s printername comment\n", argv[0]);
+
+ return NT_STATUS_OK;
+ }
+
+ /* Open a printer handle */
+ if (argc == 3) {
+ fstrcpy(comment, argv[2]);
+ }
+
+ slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
+ strupper (servername);
+ fstrcpy (printername, argv[1]);
+ fstrcpy (user, cli->user_name);
+
+ /* get a printer handle */
+ result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
+ MAXIMUM_ALLOWED_ACCESS, servername,
+ user, &pol);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ opened_hnd = True;
+
+ /* Get printer info */
+ result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, info_level, &ctr);
+
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, info_level, &ctr);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+
+ /* Modify the comment. */
+ init_unistr(&ctr.printers_2->comment, comment);
+ ctr.printers_2->devmode = NULL;
+ ctr.printers_2->secdesc = NULL;
+
+ result = cli_spoolss_setprinter(cli, mem_ctx, &pol, info_level, &ctr, 0);
+ if (W_ERROR_IS_OK(result))
+ printf("Success in setting comment.\n");
+
+ done:
+ if (opened_hnd)
+ cli_spoolss_close_printer(cli, mem_ctx, &pol);
+
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
+/***********************************************************************
* Get printer information
*/
-static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
+static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, char **argv)
{
@@ -464,7 +534,7 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
uint32 info_level = 1;
BOOL opened_hnd = False;
PRINTER_INFO_CTR ctr;
- fstring printername,
+ fstring printername,
servername,
user;
uint32 needed;
@@ -1014,7 +1084,7 @@ static NTSTATUS cmd_spoolss_addprinterdriver(struct cli_state *cli,
if (W_ERROR_IS_OK(result)) {
rpcstr_pull(driver_name, info3.name.buffer,
sizeof(driver_name), 0, STR_TERMINATE);
- printf ("Printer Driver %s successfully installed.\n",
+ printf ("Printer Driver %s successfully installed.\n",
driver_name);
}
@@ -1023,7 +1093,7 @@ static NTSTATUS cmd_spoolss_addprinterdriver(struct cli_state *cli,
static NTSTATUS cmd_spoolss_addprinterex(struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
+ TALLOC_CTX *mem_ctx,
int argc, char **argv)
{
WERROR result;
@@ -1109,7 +1179,7 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli,
/* Get a printer handle */
result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
- MAXIMUM_ALLOWED_ACCESS,
+ MAXIMUM_ALLOWED_ACCESS,
servername, user, &pol);
if (!W_ERROR_IS_OK(result))
@@ -1152,7 +1222,7 @@ done:
if (opened_hnd)
cli_spoolss_close_printer(cli, mem_ctx, &pol);
-
+
return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
@@ -1533,6 +1603,80 @@ static NTSTATUS cmd_spoolss_enum_forms(struct cli_state *cli,
return W_ERROR_IS_OK(werror) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
+static NTSTATUS cmd_spoolss_setprinterdata(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
+{
+ WERROR result;
+ uint32 needed;
+ fstring servername, printername, user;
+ POLICY_HND pol;
+ BOOL opened_hnd = False;
+ PRINTER_INFO_CTR ctr;
+ PRINTER_INFO_0 *info = NULL;
+
+ /* parse the command arguements */
+ if (argc != 4) {
+ printf ("Usage: %s <printer> <value> <data>\n", argv[0]);
+ return NT_STATUS_OK;
+ }
+
+ slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
+ strupper (servername);
+ slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]);
+ fstrcpy (user, cli->user_name);
+
+ /* get a printer handle */
+ result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
+ MAXIMUM_ALLOWED_ACCESS, servername,
+ user, &pol);
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ opened_hnd = True;
+
+ result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed,
+ &pol, 0, &ctr);
+
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ printf("%s\n", timestring(True));
+ printf("\tchange_id (before set)\t:[0x%x]\n", info->change_id);
+
+
+ /* Set the printer data */
+
+ result = cli_spoolss_setprinterdata(cli, mem_ctx, &pol, argv[2], argv[3]);
+ if (!W_ERROR_IS_OK(result)) {
+ printf ("Unable to set [%s=%s]!\n", argv[2], argv[3]);
+ goto done;
+ }
+ printf("\tSetPrinterData succeeded [%s: %s]\n", argv[2], argv[3]);
+
+ result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, 0, &ctr);
+
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr);
+
+ if (!W_ERROR_IS_OK(result))
+ goto done;
+
+ printf("%s\n", timestring(True));
+ printf("\tchange_id (after set)\t:[0x%x]\n", info->change_id);
+
+done:
+ /* cleanup */
+ if (opened_hnd)
+ cli_spoolss_close_printer(cli, mem_ctx, &pol);
+
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
+
/* List of commands exported by this module */
struct cmd_set spoolss_commands[] = {
@@ -1550,14 +1694,17 @@ struct cmd_set spoolss_commands[] = {
{ "getdriver", cmd_spoolss_getdriver, PIPE_SPOOLSS, "Get print driver information", "" },
{ "getdriverdir", cmd_spoolss_getdriverdir, PIPE_SPOOLSS, "Get print driver upload directory", "" },
{ "getprinter", cmd_spoolss_getprinter, PIPE_SPOOLSS, "Get printer info", "" },
+ { "getprintprocdir", cmd_spoolss_getprintprocdir, PIPE_SPOOLSS, "Get print processor directory", "" },
{ "openprinter", cmd_spoolss_open_printer_ex, PIPE_SPOOLSS, "Open printer handle", "" },
{ "setdriver", cmd_spoolss_setdriver, PIPE_SPOOLSS, "Set printer driver", "" },
- { "getprintprocdir", cmd_spoolss_getprintprocdir, PIPE_SPOOLSS, "Get print processor directory", "" },
- { "addform", cmd_spoolss_addform, PIPE_SPOOLSS, "Add form", "" },
- { "setform", cmd_spoolss_setform, PIPE_SPOOLSS, "Set form", "" },
- { "getform", cmd_spoolss_getform, PIPE_SPOOLSS, "Get form", "" },
- { "deleteform", cmd_spoolss_deleteform, PIPE_SPOOLSS, "Delete form", "" },
- { "enumforms", cmd_spoolss_enum_forms, PIPE_SPOOLSS, "Enumerate forms", "" },
+ { "getprintprocdir", cmd_spoolss_getprintprocdir, PIPE_SPOOLSS, "Get print processor directory", "" },
+ { "addform", cmd_spoolss_addform, PIPE_SPOOLSS, "Add form", "" },
+ { "setform", cmd_spoolss_setform, PIPE_SPOOLSS, "Set form", "" },
+ { "getform", cmd_spoolss_getform, PIPE_SPOOLSS, "Get form", "" },
+ { "deleteform", cmd_spoolss_deleteform, PIPE_SPOOLSS, "Delete form", "" },
+ { "enumforms", cmd_spoolss_enum_forms, PIPE_SPOOLSS, "Enumerate forms", "" },
+ { "setprinter", cmd_spoolss_setprinter, PIPE_SPOOLSS, "Set printer comment", "" },
+ { "setprinterdata", cmd_spoolss_setprinterdata, PIPE_SPOOLSS, "Set REG_SZ printer data", "" },
{ NULL }
};