svn commit: samba r3640 - in trunk/source: rpc_client rpc_parse rpcclient

jerry at samba.org jerry at samba.org
Tue Nov 9 21:20:27 GMT 2004


Author: jerry
Date: 2004-11-09 21:20:27 +0000 (Tue, 09 Nov 2004)
New Revision: 3640

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=3640

Log:
patch from Martin Zielinski <mz at seh.de> to add DeleteDriverEx() function to rpcclient
Modified:
   trunk/source/rpc_client/cli_spoolss.c
   trunk/source/rpc_parse/parse_spoolss.c
   trunk/source/rpcclient/cmd_spoolss.c


Changeset:
Modified: trunk/source/rpc_client/cli_spoolss.c
===================================================================
--- trunk/source/rpc_client/cli_spoolss.c	2004-11-09 21:15:14 UTC (rev 3639)
+++ trunk/source/rpc_client/cli_spoolss.c	2004-11-09 21:20:27 UTC (rev 3640)
@@ -1083,6 +1083,58 @@
 	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()
  ********************************************************************************/

Modified: trunk/source/rpc_parse/parse_spoolss.c
===================================================================
--- trunk/source/rpc_parse/parse_spoolss.c	2004-11-09 21:15:14 UTC (rev 3639)
+++ trunk/source/rpc_parse/parse_spoolss.c	2004-11-09 21:20:27 UTC (rev 3640)
@@ -1221,6 +1221,30 @@
 /*******************************************************************
  * 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, 

Modified: trunk/source/rpcclient/cmd_spoolss.c
===================================================================
--- trunk/source/rpcclient/cmd_spoolss.c	2004-11-09 21:15:14 UTC (rev 3639)
+++ trunk/source/rpcclient/cmd_spoolss.c	2004-11-09 21:20:27 UTC (rev 3640)
@@ -1545,6 +1545,65 @@
 }
 
 
+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)
@@ -2403,13 +2462,14 @@
 	{ "SPOOLSS"  },
 
 	{ "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",                       "" },
+	{ "addprinter",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_addprinterex,	PI_SPOOLSS, "Add a printer",                       "" },
 	{ "deldriver",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_deletedriver,	PI_SPOOLSS, "Delete a printer driver",             "" },
+	{ "deldriverex",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_deletedriverex, PI_SPOOLSS, "Delete a printer driver with files",      "" },
 	{ "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",    "" },
+	{ "enumdataex",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_data_ex,	PI_SPOOLSS, "Enumerate printer data for a key",    "" },
 	{ "enumkey",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_printerkey,	PI_SPOOLSS, "Enumerate printer keys",              "" },
 	{ "enumjobs",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_jobs,          PI_SPOOLSS, "Enumerate print jobs",                "" },
-	{ "enumports", 	RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_ports, 	PI_SPOOLSS, "Enumerate printer ports",             "" },
+	{ "enumports", 		RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_ports, 	PI_SPOOLSS, "Enumerate printer ports",             "" },
 	{ "enumdrivers", 	RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_drivers, 	PI_SPOOLSS, "Enumerate installed printer drivers", "" },
 	{ "enumprinters", 	RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_printers, 	PI_SPOOLSS, "Enumerate printers",                  "" },
 	{ "getdata",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprinterdata,	PI_SPOOLSS, "Get print driver data",               "" },
@@ -2418,14 +2478,14 @@
 	{ "getdriverdir",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_getdriverdir,	PI_SPOOLSS, "Get print driver upload directory",   "" },
 	{ "getprinter", 	RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprinter, 	PI_SPOOLSS, "Get printer info",                    "" },
 	{ "openprinter",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer_ex,	PI_SPOOLSS, "Open printer handle",                 "" },
-	{ "setdriver", 	RPC_RTYPE_WERROR, NULL, cmd_spoolss_setdriver,		PI_SPOOLSS, "Set printer driver",                  "" },
+	{ "setdriver", 		RPC_RTYPE_WERROR, NULL, cmd_spoolss_setdriver,		PI_SPOOLSS, "Set printer driver",                  "" },
 	{ "getprintprocdir",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprintprocdir,    PI_SPOOLSS, "Get print processor directory",       "" },
 	{ "addform",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_addform,            PI_SPOOLSS, "Add form",                            "" },
 	{ "setform",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_setform,            PI_SPOOLSS, "Set form",                            "" },
 	{ "getform",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_getform,            PI_SPOOLSS, "Get form",                            "" },
-	{ "deleteform",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_deleteform,         PI_SPOOLSS, "Delete form",                         "" },
+	{ "deleteform",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_deleteform,         PI_SPOOLSS, "Delete form",                         "" },
 	{ "enumforms",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_forms,         PI_SPOOLSS, "Enumerate forms",                     "" },
-	{ "setprinter",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprinter,         PI_SPOOLSS, "Set printer comment",                 "" },
+	{ "setprinter",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprinter,         PI_SPOOLSS, "Set printer comment",                 "" },
 	{ "setprintername",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprintername,         PI_SPOOLSS, "Set printername",                 "" },
 	{ "setprinterdata",	RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprinterdata,     PI_SPOOLSS, "Set REG_SZ printer data",             "" },
 	{ "rffpcnex",		RPC_RTYPE_WERROR, NULL, cmd_spoolss_rffpcnex,           PI_SPOOLSS, "Rffpcnex test", "" },



More information about the samba-cvs mailing list