diff options
Diffstat (limited to 'source3/rpcclient')
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 127 | ||||
-rw-r--r-- | source3/rpcclient/display.c | 238 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 17 |
3 files changed, 373 insertions, 9 deletions
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index 073ee24495..9b5aa5b3e0 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -41,19 +41,15 @@ extern int smb_tidx; nt spoolss query ****************************************************************************/ BOOL msrpc_spoolss_enum_printers(struct cli_state *cli, + const char* srv_name, uint32 level, uint32 *num, void ***ctr, PRINT_INFO_FN(fn)) { uint16 nt_pipe_fnum; - fstring srv_name; BOOL res = True; - fstrcpy(srv_name, "\\\\"); - fstrcat(srv_name, smb_cli->desthost); - strupper(srv_name); - /* open SPOOLSS session. */ res = cli_nt_session_open(cli, PIPE_SPOOLSS, &nt_pipe_fnum); @@ -88,7 +84,12 @@ void cmd_spoolss_enum_printers(struct client_info *info) uint32 num = 0; uint32 level = 1; - if (msrpc_spoolss_enum_printers(smb_cli, level, &num, &ctr, + fstring srv_name; + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, smb_cli->desthost); + strupper(srv_name); + + if (msrpc_spoolss_enum_printers(smb_cli, srv_name, level, &num, &ctr, spool_print_info_ctr)) { DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n")); @@ -153,3 +154,117 @@ void cmd_spoolss_open_printer_ex(struct client_info *info) } } +/**************************************************************************** +nt spoolss query +****************************************************************************/ +BOOL msrpc_spoolss_enum_jobs(struct cli_state *cli, + const char* srv_name, + const char* user_name, + const char* printer_name, + uint32 level, + uint32 *num, + void ***ctr, + JOB_INFO_FN(fn)) +{ + uint16 nt_pipe_fnum; + PRINTER_HND hnd; + uint32 buf_size = 0x0; + uint32 status = 0x0; + + BOOL res = True; + BOOL res1 = True; + + DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n", + printer_name, srv_name, user_name)); + + DEBUG(5, ("cmd_spoolss_open_printer_ex: smb_cli->fd:%d\n", smb_cli->fd)); + + /* open SPOOLSS session. */ + res = res ? cli_nt_session_open(smb_cli, PIPE_SPOOLSS, &nt_pipe_fnum) : False; + + res = res ? spoolss_open_printer_ex(smb_cli, nt_pipe_fnum, + printer_name, + 0, 0, 0, + srv_name, user_name, + &hnd) : False; + + if (status == 0x0) + { + status = spoolss_enum_jobs(smb_cli, nt_pipe_fnum, + &hnd, + 0, 1000, level, &buf_size, + num, ctr); + } + + if (status == ERROR_INSUFFICIENT_BUFFER) + { + status = spoolss_enum_jobs(smb_cli, nt_pipe_fnum, + &hnd, + 0, 1000, level, &buf_size, + num, ctr); + } + + res1 = (status == 0x0); + + res = res ? spoolss_closeprinter(smb_cli, nt_pipe_fnum, &hnd) : False; + + /* close the session */ + cli_nt_session_close(smb_cli, nt_pipe_fnum); + + if (res1 && fn != NULL) + { + fn(srv_name, printer_name, level, *num, *ctr); + } + + return res1; +} + +static void spool_job_info_ctr(const char* srv_name, const char* printer_name, + uint32 level, + uint32 num, void *const *const ctr) +{ + display_job_info_ctr(out_hnd, ACTION_HEADER , level, num, ctr); + display_job_info_ctr(out_hnd, ACTION_ENUMERATE, level, num, ctr); + display_job_info_ctr(out_hnd, ACTION_FOOTER , level, num, ctr); +} + +/**************************************************************************** +nt spoolss query +****************************************************************************/ +void cmd_spoolss_enum_jobs(struct client_info *info) +{ + fstring srv_name; + fstring printer_name; + + void **ctr = NULL; + uint32 num = 0; + uint32 level = 1; + + if (!next_token(NULL, printer_name, NULL, sizeof(printer_name))) + { + report(out_hnd, "spoolopen <printer name>\n"); + return; + } + + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, info->myhostname); + strupper(srv_name); + + DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n", + printer_name, srv_name, smb_cli->user_name)); + + if (msrpc_spoolss_enum_jobs(smb_cli, + srv_name, smb_cli->user_name, printer_name, + level, &num, &ctr, + spool_job_info_ctr)) + { + DEBUG(5,("cmd_spoolss_enum_jobs: query succeeded\n")); + } + else + { + report(out_hnd, "FAILED\n"); + } + + free_void_array(num, ctr, free); +} + diff --git a/source3/rpcclient/display.c b/source3/rpcclient/display.c index 5bd4fb324b..d1dfbd117d 100644 --- a/source3/rpcclient/display.c +++ b/source3/rpcclient/display.c @@ -2724,6 +2724,244 @@ void display_printer_info_ctr(FILE *out_hnd, enum action_type action, } } +/**************************************************************************** +job info level 2 display function +****************************************************************************/ +void display_job_info_2(FILE *out_hnd, enum action_type action, + JOB_INFO_2 *const i2) +{ + if (i2 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Job Info Level 2:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring tmp; + + fprintf(out_hnd, "\tjob id:\t%d\n", i2->jobid); + unistr_to_ascii(tmp, i2->printername.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tprinter name:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->machinename.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tmachine name:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->username.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tusername:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->document.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tdocument:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->notifyname.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tnotify name:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->datatype.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tdata type:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->printprocessor.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tprint processor:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->parameters.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tparameters:\t%s\n", tmp); + unistr_to_ascii(tmp, i2->drivername.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tdriver name:\t%s\n", tmp); + fprintf(out_hnd, "\tDevice Mode:\tNOT DISPLAYED YET\n"); +/* + DEVICEMODE *devmode; +*/ + unistr_to_ascii(tmp, i2->text_status.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\ttext status:\t%s\n", tmp); + /* SEC_DESC sec_desc;*/ + fprintf(out_hnd, "\tstatus:\t%d\n", i2->status); + fprintf(out_hnd, "\tpriority:\t%d\n", i2->priority); + fprintf(out_hnd, "\tposition:\t%d\n", i2->position); + fprintf(out_hnd, "\tstarttime:\t%d\n", i2->starttime); + fprintf(out_hnd, "\tuntiltime:\t%d\n", i2->untiltime); + fprintf(out_hnd, "\ttotalpages:\t%d\n", i2->totalpages); + fprintf(out_hnd, "\tsize:\t%d\n", i2->size); +/* + SYSTEMTIME submitted; +*/ + fprintf(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); + fprintf(out_hnd, "\ttimeelapsed:\t%d\n", i2->timeelapsed); + fprintf(out_hnd, "\tpagesprinted:\t%d\n", i2->pagesprinted); + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +job info level 1 display function +****************************************************************************/ +void display_job_info_1(FILE *out_hnd, enum action_type action, + JOB_INFO_1 *const i1) +{ + if (i1 == NULL) + { + return; + } + + switch (action) + { + case ACTION_HEADER: + { + fprintf(out_hnd, "Job Info Level 1:\n"); + + break; + } + case ACTION_ENUMERATE: + { + fstring tmp; + + fprintf(out_hnd, "\tjob id:\t%d\n", i1->jobid); + unistr_to_ascii(tmp, i1->printername.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tprinter name:\t%s\n", tmp); + unistr_to_ascii(tmp, i1->machinename.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tmachine name:\t%s\n", tmp); + unistr_to_ascii(tmp, i1->username.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tusername:\t%s\n", tmp); + unistr_to_ascii(tmp, i1->document.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tdocument:\t%s\n", tmp); + unistr_to_ascii(tmp, i1->datatype.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\tdata type:\t%s\n", tmp); + unistr_to_ascii(tmp, i1->text_status.buffer, sizeof(tmp)-1); + fprintf(out_hnd, "\ttext status:\t%s\n", tmp); + fprintf(out_hnd, "\tstatus:\t%d\n", i1->status); + fprintf(out_hnd, "\tpriority:\t%d\n", i1->priority); + fprintf(out_hnd, "\tposition:\t%d\n", i1->position); + fprintf(out_hnd, "\ttotalpages:\t%d\n", i1->totalpages); +/* + SYSTEMTIME submitted; +*/ + fprintf(out_hnd, "\tsubmitted:\tNOT DISPLAYED YET\n"); + fprintf(out_hnd, "\tpagesprinted:\t%d\n", i1->pagesprinted); + + break; + } + case ACTION_FOOTER: + { + fprintf(out_hnd, "\n"); + break; + } + } + +} + +/**************************************************************************** +connection info level 2 container display function +****************************************************************************/ +void display_job_info_2_ctr(FILE *out_hnd, enum action_type action, + uint32 count, JOB_INFO_2 *const *const ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_job_info_2_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < count; i++) + { + display_job_info_2(out_hnd, ACTION_HEADER , ctr[i]); + display_job_info_2(out_hnd, ACTION_ENUMERATE, ctr[i]); + display_job_info_2(out_hnd, ACTION_FOOTER , ctr[i]); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +connection info level 1 container display function +****************************************************************************/ +void display_job_info_1_ctr(FILE *out_hnd, enum action_type action, + uint32 count, JOB_INFO_1 *const *const ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_job_info_1_ctr: unavailable due to an internal error\n"); + return; + } + + switch (action) + { + case ACTION_HEADER: + { + break; + } + case ACTION_ENUMERATE: + { + int i; + + for (i = 0; i < count; i++) + { + display_job_info_1(out_hnd, ACTION_HEADER , ctr[i]); + display_job_info_1(out_hnd, ACTION_ENUMERATE, ctr[i]); + display_job_info_1(out_hnd, ACTION_FOOTER , ctr[i]); + } + break; + } + case ACTION_FOOTER: + { + break; + } + } +} + +/**************************************************************************** +connection info container display function +****************************************************************************/ +void display_job_info_ctr(FILE *out_hnd, enum action_type action, + uint32 level, uint32 count, + void *const *const ctr) +{ + if (ctr == NULL) + { + fprintf(out_hnd, "display_job_info_ctr: unavailable due to an internal error\n"); + return; + } + + switch (level) + { + case 1: + { + display_job_info_1_ctr(out_hnd, action, + count, (JOB_INFO_1*const*const)ctr); + break; + } + case 2: + { + display_job_info_2_ctr(out_hnd, action, + count, (JOB_INFO_2*const*const)ctr); + break; + } + default: + { + fprintf(out_hnd, "display_job_info_ctr: Unknown Info Level\n"); + break; + } + } +} + #if COPY_THIS_TEMPLATE /**************************************************************************** display structure diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index e465a63767..06e6d0c089 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -239,10 +239,16 @@ commands[] = { "spoolenum", cmd_spoolss_enum_printers, - "Spool Printer Enum Test", + "Enumerate Printers", {COMPL_NONE, COMPL_NONE} }, { + "spooljobs", + cmd_spoolss_enum_jobs, + "<printer name> Enumerate Printer Jobs", + {COMPL_PRTLST, COMPL_NONE} + }, + { "spoolopen", cmd_spoolss_open_printer_ex, "<printer name> Spool Printer Open Test", @@ -1152,13 +1158,18 @@ static char *complete_printersenum(char *text, int state) if (state == 0) { + fstring srv_name; + fstrcpy(srv_name, "\\\\"); + fstrcat(srv_name, smb_cli->desthost); + strupper(srv_name); + free_print1_array(num, ctr); ctr = NULL; num = 0; /* Iterate all users */ - if (!msrpc_spoolss_enum_printers(smb_cli, 1, &num, - (void***)&ctr, + if (!msrpc_spoolss_enum_printers(smb_cli, srv_name, + 1, &num, (void***)&ctr, NULL)) { return NULL; |