rpcclient delete driver files
Martin Zielinski
mz at seh.de
Tue Nov 2 11:24:04 GMT 2004
Hello list!
If someone is interested in deleteting the Windows drivers on the server
including the driver files themself, here is a proposed patch for 3.0.8pre2
to include this functunality into rpcclient.
It's not more than a copy and paste from the deletedriver calls.
Perhaps it could make it's way into the release, if you find it useful.
Greetings,
Martin
--- samba-3.0.8pre2.orig/source/rpcclient/cmd_spoolss.c 2004-10-25
23:04:54.000000000 +0200
+++ samba-3.0.8pre2/source/rpcclient/cmd_spoolss.c 2004-11-02
11:41:23.000000000 +0100
@@ -1545,6 +1545,62 @@
}
+static WERROR cmd_spoolss_deletedriverex(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, const char **argv)
+{
+ WERROR result, ret = WERR_UNKNOWN_PRINTER_DRIVER;
+
+ fstring servername;
+ int i;
+ int vers = -1;
+
+ const char *arch = NULL;
+
+ /* parse the command arguements */
+ if (argc < 2 || argc > 4)
+ {
+ printf ("Usage: %s <driver> [arch] [version]\n", argv[0]);
+ return WERR_OK;
+ }
+ if (argc >= 3)
+ arch = argv[2];
+ if (argc == 4)
+ vers = atoi (argv[3]);
+
+
+ slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->desthost);
+ strupper_m(servername);
+
+ /* delete the driver for all architectures */
+ for (i=0; archi_table[i].long_archi; i++)
+ {
+ if (arch && strcmp ( archi_table[i].long_archi, arch))
+ continue;
+ if (vers >= 0 && archi_table[i].version != vers)
+ continue;
+ /* make the call to remove the driver */
+ result = cli_spoolss_deleteprinterdriverex(
+ cli, mem_ctx, archi_table[i].long_archi, argv[1]);
+ if ( !W_ERROR_IS_OK(result) ) {
+ if ( !W_ERROR_EQUAL(result, WERR_UNKNOWN_PRINTER_DRIVER) ) {
+ printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",
+ argv[1], archi_table[i].long_archi,
+ W_ERROR_V(result));
+ }
+ }
+ else
+ {
+ printf ("Driver %s and files removed for arch [%s].\n", argv[1],
+ archi_table[i].long_archi);
+ ret = WERR_OK;
+ }
+ }
+
+ return ret;
+}
+
+
static WERROR cmd_spoolss_deletedriver(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
@@ -2404,6 +2460,7 @@
{ "adddriver", RPC_RTYPE_WERROR, NULL, cmd_spoolss_addprinterdriver,
PI_SPOOLSS, "Add a print driver", "" },
{ "addprinter", RPC_RTYPE_WERROR, NULL, cmd_spoolss_addprinterex,
PI_SPOOLSS, "Add a printer", "" },
+ { "deldriverex", RPC_RTYPE_WERROR, NULL, cmd_spoolss_deletedriverex,
PI_SPOOLSS, "Delete a printer driver with files", "" },
{ "deldriver", RPC_RTYPE_WERROR, NULL, cmd_spoolss_deletedriver,
PI_SPOOLSS, "Delete a printer driver", "" },
{ "enumdata", RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_data, PI_SPOOLSS,
"Enumerate printer data", "" },
{ "enumdataex", RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_data_ex,
PI_SPOOLSS, "Enumerate printer data for a key", "" },
--- samba-3.0.8pre2.orig/source/rpc_parse/parse_spoolss.c 2004-10-25
23:05:05.000000000 +0200
+++ samba-3.0.8pre2/source/rpc_parse/parse_spoolss.c 2004-11-02
11:42:15.000000000 +0100
@@ -1221,6 +1221,32 @@
/*******************************************************************
* init a structure.
********************************************************************/
+BOOL make_spoolss_q_deleteprinterdriverex(
+ TALLOC_CTX *mem_ctx,
+ SPOOL_Q_DELETEPRINTERDRIVEREX *q_u,
+ const char *server,
+ const char* arch,
+ const char* driver
+)
+{
+ DEBUG(5,("make_spoolss_q_deleteprinterdriverex\n"));
+
+ q_u->server_ptr = (server!=NULL)?1:0;
+ q_u->delete_flags = DPD_DELETE_UNUSED_FILES;
+
+ /* these must be NULL terminated or else NT4 will
+ complain about invalid parameters --jerry */
+ init_unistr2(&q_u->server, server, UNI_STR_TERMINATE);
+ init_unistr2(&q_u->arch, arch, UNI_STR_TERMINATE);
+ init_unistr2(&q_u->driver, driver, UNI_STR_TERMINATE);
+
+ return True;
+}
+
+
+/*******************************************************************
+ * init a structure.
+ ********************************************************************/
BOOL make_spoolss_q_deleteprinterdriver(
TALLOC_CTX *mem_ctx,
SPOOL_Q_DELETEPRINTERDRIVER *q_u,
--- samba-3.0.8pre2.orig/source/rpc_client/cli_spoolss.c 2004-10-25
23:04:53.000000000 +0200
+++ samba-3.0.8pre2/source/rpc_client/cli_spoolss.c 2004-11-02
11:43:42.000000000 +0100
@@ -1083,6 +1083,56 @@
return result;
}
+/**********************************************************************
+ * Delete a Printer Driver from the server (DOES remove
+ * the driver files)
+ */
+WERROR cli_spoolss_deleteprinterdriverex (struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, const char *arch,
+ const char *driver)
+{
+ prs_struct qbuf, rbuf;
+ SPOOL_Q_DELETEPRINTERDRIVEREX q;
+ SPOOL_R_DELETEPRINTERDRIVEREX r;
+ WERROR result = W_ERROR(ERRgeneral);
+ fstring server;
+
+ 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);
+
+ slprintf(server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
+ strupper_m(server);
+
+ /* Write the request */
+ make_spoolss_q_deleteprinterdriverex(mem_ctx, &q, server, arch, driver);
+
+ /* Marshall data and send request */
+
+ if (!spoolss_io_q_deleteprinterdriverex ("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req (cli,SPOOLSS_DELETEPRINTERDRIVEREX , &qbuf, &rbuf))
+ goto done;
+
+ /* Unmarshall response */
+
+ if (!spoolss_io_r_deleteprinterdriverex ("", &r, &rbuf, 0))
+ goto done;
+
+ /* Return output parameters */
+
+ result = r.status;
+
+ done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
+ return result;
+}
+
/*********************************************************************************
Win32 API - DeltePrinterDriver()
********************************************************************************/
--
Martin Zielinski mz at seh.de
Software Development
SEH Computertechnik GmbH www.seh.de
More information about the samba-technical
mailing list