summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-07-25 21:07:46 +0000
committerGerald Carter <jerry@samba.org>2000-07-25 21:07:46 +0000
commit48a3e00224cf3dbfc903c99d6110a09a5efabca4 (patch)
tree7caac71c89482ecb5ec2517d4105af84dea089bf
parent5a98f9cb35835efdfe384b82e31e319276496ef4 (diff)
downloadsamba-48a3e00224cf3dbfc903c99d6110a09a5efabca4.tar.gz
samba-48a3e00224cf3dbfc903c99d6110a09a5efabca4.tar.bz2
samba-48a3e00224cf3dbfc903c99d6110a09a5efabca4.zip
some initial code for AddPrinterEx() project. Most is ifdef'd out
'cause it's not all written. -jerry (This used to be commit 2c0f6bcc8f926ee9c17de12671075e8a9239bb94)
-rw-r--r--source3/rpc_client/msrpc_spoolss.c32
-rw-r--r--source3/rpcclient/cmd_spoolss.c116
-rw-r--r--source3/rpcclient/spoolss_cmds.c4
3 files changed, 149 insertions, 3 deletions
diff --git a/source3/rpc_client/msrpc_spoolss.c b/source3/rpc_client/msrpc_spoolss.c
index 34e6d4404c..72ca7ee5c0 100644
--- a/source3/rpc_client/msrpc_spoolss.c
+++ b/source3/rpc_client/msrpc_spoolss.c
@@ -182,8 +182,11 @@ static void decode_printerdriverdir_info_1(NEW_BUFFER *buffer, DRIVER_DIRECTORY_
}
-static void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned,
- PORT_INFO_2 **info)
+/**********************************************************************
+ Decode a PORT_INFO_2 struct from a NEW_BUFFER
+**********************************************************************/
+void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned,
+ PORT_INFO_2 **info)
{
uint32 i;
PORT_INFO_2 *inf;
@@ -199,6 +202,28 @@ static void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned,
*info=inf;
}
+/**********************************************************************
+ Decode a PORT_INFO_1 struct from a NEW_BUFFER
+**********************************************************************/
+void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned,
+ PORT_INFO_1 **info)
+{
+ uint32 i;
+ PORT_INFO_1 *inf;
+
+ inf=(PORT_INFO_1*)malloc(returned*sizeof(PORT_INFO_1));
+
+ prs_set_offset(&buffer->prs, 0);
+
+ for (i=0; i<returned; i++) {
+ /* WRITEME!!!! yet to be written --jerry */
+ /* new_smb_io_port_info_1("", buffer, &(inf[i]), 0); */
+ ;;
+ }
+
+ *info=inf;
+}
+
/****************************************************************************
nt spoolss query
****************************************************************************/
@@ -282,6 +307,9 @@ BOOL msrpc_spoolss_enum_ports(char* srv_name,
if (returned != 0)
{
switch (level) {
+ case 1:
+ decode_port_info_1(&buffer, returned, &ctr->port.info_1);
+ break;
case 2:
decode_port_info_2(&buffer, returned, &ctr->port.info_2);
break;
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 3a80e5d0e7..7ed6dd80ce 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -5,6 +5,7 @@
Copyright (C) Andrew Tridgell 1994-2000
Copyright (C) Luke Kenneth Casson Leighton 1996-2000
Copyright (C) Jean-Francois Micouleau 1999-2000
+ Copyright (C) Gerald Carter 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -457,7 +458,7 @@ uint32 cmd_spoolss_getprinterdriverdir(struct client_info *info, int argc, char
uint32 level = 1;
fstring srv_name;
- fstring env;
+ fstring env;
fstrcpy(srv_name, "\\\\");
fstrcat(srv_name, info->dest_host);
@@ -483,3 +484,116 @@ uint32 cmd_spoolss_getprinterdriverdir(struct client_info *info, int argc, char
return NT_STATUS_NOPROBLEMO;
}
+/********************************************************************************
+ send an AddPrinterEx() request
+********************************************************************************/
+uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[])
+{
+#if 0
+ PRINTER_INFO_CTR ctr;
+ uint32 level = 2;
+ fstring srv_name,
+ printer_name,
+ driver_name,
+ port_name;
+ POLICY_HND hnd;
+ PRINTER_INFO_2 print_info_2;
+ PORT_INFO_1 *port_info_1 = NULL;
+ NEW_BUFFER buffer;
+ uint32 status,
+ needed,
+ returned;
+ uint32 i;
+ fstring srv_port_name;
+ BOOL valid_port = False;
+
+ fstrcpy(srv_name, "\\\\");
+ fstrcat(srv_name, info->dest_host);
+ strupper(srv_name);
+
+ /* check (and copy) the command line arguments */
+ if (argc < 2) {
+ report(out_hnd, "spooladdprinterex <name> <driver>\n");
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ fstrcpy(printer_name, argv[1]);
+ fstrcpy(driver_name, argv[2]);
+ fstrcpy(port_name, argv[3]);
+
+
+ /* Verify that the specified port is ok; spoolss_enum_ports() should
+ be a level 1 since all we need is the name */
+ init_buffer (&buffer, 0);
+
+ /* send a NULL buffer first */
+ status=spoolss_enum_ports(srv_name, 1, &buffer, 0,
+ &needed, &returned);
+
+ /* send the right amount of space this time */
+ if (status==ERROR_INSUFFICIENT_BUFFER) {
+ init_buffer(&buffer, needed);
+ status=spoolss_enum_ports(srv_name, 1, &buffer,
+ needed, &needed, &returned);
+
+ /* if the call succeeded, then decode the buffer into
+ an PRINTER_INFO_1 structre */
+ if (status == NT_STATUS_NO_PROBLEMO)
+ {
+ decode_port_info_1 (&buffer, returned, &port_info_1);
+ }
+ else
+ {
+ report (out_hnd, "cmd_spoolss_addprinterex: FAILED to enumerate ports\n"));
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ }
+
+ /*
+ * now we have an array of port names and we can interate
+ * through it to verify port_name before actually attempting
+ * to add the printer on the server.
+ */
+ for (i=0; i<returned; i++)
+ {
+ /* compare port_info_1[i].port_name to the port_name specified */
+ unistr_to_ascii(srv_port_name, port_info_1[i].port_name, sizeof(srv_port_name)-1);
+ if (strequal(srv_port_name, port_name))
+ {
+ valid_port = True;
+ break;
+ }
+ }
+ if (!valid_port)
+ {
+ report (out_hnd, "cmd_spoolss_addprinterex: Invalid port specified!\n");
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+
+ /*
+ * Need to build the PRINTER_INFO_2 struct here
+ */
+ ;;
+
+ /* if successful, spoolss_addprinterex() should return True and hnd
+ should be a valid handle to an open printer */
+ if (spoolss_addprinterex(&hnd, 2, &print_info_2))
+ {
+ if (!spoolss_closeprinter( &hnd ))
+ {
+ report (out_hnd, "cmd_spoolss_addprinterex: spoolss_closeprinter FAILED!\n");
+ }
+ }
+ else
+ {
+ report (out_hnd, "cmd_spoolss_addprinterex: spoolss_addprinterex FAILED!\n");
+ }
+
+
+#endif
+ return NT_STATUS_NOPROBLEMO;
+}
+
+
diff --git a/source3/rpcclient/spoolss_cmds.c b/source3/rpcclient/spoolss_cmds.c
index 630d2f2aa5..1041ae158c 100644
--- a/source3/rpcclient/spoolss_cmds.c
+++ b/source3/rpcclient/spoolss_cmds.c
@@ -68,6 +68,10 @@ static const struct command_set spl_commands[] = {
{"spoolgetprinterdriverdir", cmd_spoolss_getprinterdriverdir,
"Spool get printer driver directory",
{NULL, NULL}},
+
+ {"spooladdprinter", cmd_spoolss_addprinterex,
+ "<name> <driver> Spool AddPrinterEx()",
+ {NULL, NULL}},
/*
* oop!
*/