diff options
Diffstat (limited to 'source3/rpcclient')
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 91 | ||||
-rw-r--r-- | source3/rpcclient/display_spool.c | 46 | ||||
-rw-r--r-- | source3/rpcclient/spoolss_cmds.c | 9 |
3 files changed, 121 insertions, 25 deletions
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index 00d5a4d7d1..5a614a38b5 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -102,14 +102,22 @@ nt spoolss query uint32 cmd_spoolss_enum_ports(struct client_info *info, int argc, char *argv[]) { PORT_INFO_CTR ctr; + uint32 level; + fstring srv_name; - uint32 level = 2; + if (argc < 1) + { + report (out_hnd, "spoolenumports <level>\n"); + return NT_STATUS_INVALID_PARAMETER; + } - fstring srv_name; + fstrcpy(srv_name, "\\\\"); fstrcat(srv_name, info->dest_host); strupper(srv_name); + level = atoi(argv[1]); + if (msrpc_spoolss_enum_ports(srv_name, level, &ctr)) DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n")); else @@ -489,9 +497,6 @@ uint32 cmd_spoolss_getprinterdriverdir(struct client_info *info, int argc, char ********************************************************************************/ 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, @@ -506,25 +511,32 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] uint32 i; fstring srv_port_name; BOOL valid_port = False; + TALLOC_CTX *mem_ctx = NULL; 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"); + if (argc < 3) { + report(out_hnd, "spooladdprinterex <name> <driver> <port>\n"); return NT_STATUS_NOPROBLEMO; } - - fstrcpy(printer_name, argv[1]); - fstrcpy(driver_name, argv[2]); - fstrcpy(port_name, argv[3]); - + else + { + 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); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0, ("cmd_spoolss_addprinterex: talloc_init() failed!\n")); + return NT_STATUS_INVALID_PARAMETER; + } + init_buffer (&buffer, 0, mem_ctx); /* send a NULL buffer first */ status=spoolss_enum_ports(srv_name, 1, &buffer, 0, @@ -532,7 +544,7 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] /* send the right amount of space this time */ if (status==ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status=spoolss_enum_ports(srv_name, 1, &buffer, needed, &needed, &returned); @@ -540,11 +552,11 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] an PRINTER_INFO_1 structre */ if (status == NT_STATUS_NO_PROBLEMO) { - decode_port_info_1 (&buffer, returned, &port_info_1); + decode_port_info_1(&buffer, returned, &port_info_1); } else { - report (out_hnd, "cmd_spoolss_addprinterex: FAILED to enumerate ports\n")); + report (out_hnd, "cmd_spoolss_addprinterex: FAILED to enumerate ports\n"); return NT_STATUS_NOPROBLEMO; } @@ -558,7 +570,8 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] 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); + unistr_to_ascii(srv_port_name, port_info_1[i].port_name.buffer, + sizeof(srv_port_name)-1); if (strequal(srv_port_name, port_name)) { valid_port = True; @@ -573,13 +586,39 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] /* - * Need to build the PRINTER_INFO_2 struct here + * Need to build the PRINTER_INFO_2 struct here. + * I think it would be better only to deal with a PRINTER_INFO_2 + * and the abstract the creation of a SPOOL_PRINTER_INFO_LEVEL_2 + * from that rather than dealing with the struct passed dircetly + * on the wire. We don't need the extra *_ptr fields, etc... + * here anyways. --jerry */ - ;; - + init_unistr( &print_info_2.servername, srv_name); + init_unistr( &print_info_2.printername, printer_name); + init_unistr( &print_info_2.sharename, printer_name); + init_unistr( &print_info_2.portname, port_name); + init_unistr( &print_info_2.drivername, driver_name); + init_unistr( &print_info_2.comment, "Created by rpcclient"); + init_unistr( &print_info_2.location, ""); + init_unistr (&print_info_2.sepfile, ""); + init_unistr( &print_info_2.printprocessor, "winprint"); + init_unistr( &print_info_2.datatype, "RAW"); + init_unistr( &print_info_2.parameters, ""); + print_info_2.devmode = NULL; + print_info_2.secdesc = NULL; + print_info_2.attributes = 0; + print_info_2.priority = 0; + print_info_2.defaultpriority = 0; + print_info_2.starttime = 0; + print_info_2.untiltime = 0; + print_info_2.status = 0; + print_info_2.cjobs = 0; + print_info_2.averageppm = 0; + + /* 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_addprinterex(&hnd, &print_info_2)) { if (!spoolss_closeprinter( &hnd )) { @@ -592,8 +631,14 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[] } -#endif return NT_STATUS_NOPROBLEMO; } - +/******************************************************************************** + send an AddPrinterDriver() request +********************************************************************************/ +uint32 cmd_spoolss_addprinterdriver(struct client_info *info, int argc, char *argv[]) +{ + + return NT_STATUS_NOPROBLEMO; +} diff --git a/source3/rpcclient/display_spool.c b/source3/rpcclient/display_spool.c index f2e9deccbd..1a88eed5ad 100644 --- a/source3/rpcclient/display_spool.c +++ b/source3/rpcclient/display_spool.c @@ -298,6 +298,28 @@ void display_printer_info_ctr(FILE *out_hnd, enum action_type action, uint32 lev /**************************************************************************** connection info level 3 container display function ****************************************************************************/ +static void display_port_info_1_ctr(FILE *out_hnd, enum action_type action, + uint32 count, PORT_INFO_CTR *ctr) +{ + uint32 i = 0; + switch (action) + { + case ACTION_HEADER: + report(out_hnd, "Port Info Level 1:\n"); + break; + case ACTION_ENUMERATE: + for (i=0; i<count; i++) + display_port_info_1(out_hnd, action, &ctr->port.info_1[i]); + break; + case ACTION_FOOTER: + report(out_hnd, "\n"); + break; + } +} + +/**************************************************************************** +connection info level 3 container display function +****************************************************************************/ static void display_port_info_2_ctr(FILE *out_hnd, enum action_type action, uint32 count, PORT_INFO_CTR *ctr) { @@ -324,6 +346,9 @@ void display_port_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, uint32 count, PORT_INFO_CTR *ctr) { switch (level) { + case 1: + display_port_info_1_ctr(out_hnd, action, count, ctr); + break; case 2: display_port_info_2_ctr(out_hnd, action, count, ctr); break; @@ -333,6 +358,27 @@ void display_port_info_ctr(FILE *out_hnd, enum action_type action, uint32 level, } } +/**************************************************************************** +connection info container display function +****************************************************************************/ +void display_port_info_1(FILE *out_hnd, enum action_type action, PORT_INFO_1 *i1) +{ + fstring buffer; + + switch (action) + { + case ACTION_HEADER: + report(out_hnd, "Port:\n"); + break; + case ACTION_ENUMERATE: + unistr_to_ascii(buffer, i1->port_name.buffer, sizeof(buffer)-1); + fprintf (out_hnd, "\tPort Name:\t[%s]\n\n", buffer); + break; + case ACTION_FOOTER: + report(out_hnd, "\n"); + break; + } +} /**************************************************************************** connection info container display function diff --git a/source3/rpcclient/spoolss_cmds.c b/source3/rpcclient/spoolss_cmds.c index 1041ae158c..b010aa4874 100644 --- a/source3/rpcclient/spoolss_cmds.c +++ b/source3/rpcclient/spoolss_cmds.c @@ -38,7 +38,7 @@ static const struct command_set spl_commands[] = { {NULL, NULL}}, {"spoolenumports", cmd_spoolss_enum_ports, - "Enumerate Ports", + "<port info level> Enumerate Ports", {NULL, NULL}}, {"spoolenumdatas", cmd_spoolss_enum_printerdata, @@ -72,7 +72,12 @@ static const struct command_set spl_commands[] = { {"spooladdprinter", cmd_spoolss_addprinterex, "<name> <driver> Spool AddPrinterEx()", {NULL, NULL}}, - /* + + {"spooladdprinterdriver", cmd_spoolss_addprinterdriver, + "<driver> Spool AddPrinterDriver()", + {NULL, NULL}}, + + /* * oop! */ {"", NULL, NULL, {NULL, NULL}} |