diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/ntdomain.h | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 7 | ||||
-rw-r--r-- | source3/rpc_client/cli_spoolss.c | 2 | ||||
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 52 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 47 |
5 files changed, 91 insertions, 19 deletions
diff --git a/source3/include/ntdomain.h b/source3/include/ntdomain.h index 789a02e086..5bb0888151 100644 --- a/source3/include/ntdomain.h +++ b/source3/include/ntdomain.h @@ -171,5 +171,7 @@ struct acct_info #define TPRT_INFO_FN(fn) void (*fn)(SRV_TPRT_INFO_CTR *) +#define PRINT_INFO_FN(fn) void (*fn)(const char*, uint32, uint32, void **) + #endif /* _NT_DOMAIN_H */ diff --git a/source3/include/proto.h b/source3/include/proto.h index d56fbf6fa6..65cb7677b2 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2044,7 +2044,7 @@ BOOL samr_query_dispinfo(struct cli_state *cli, uint16 fnum, /*The following definitions come from rpc_client/cli_spoolss.c */ BOOL spoolss_enum_printers(struct cli_state *cli, uint16 fnum, - uint32 flags, char *servername, + uint32 flags, const char *servername, uint32 level, uint32 *count, void ***printers); @@ -3431,6 +3431,11 @@ void cmd_sam_enum_groups(struct client_info *info); /*The following definitions come from rpcclient/cmd_spoolss.c */ +BOOL msrpc_spoolss_enum_printers(struct cli_state *cli, + uint32 level, + uint32 *num, + void ***ctr, + PRINT_INFO_FN(fn)); void cmd_spoolss_enum_printers(struct client_info *info); void cmd_spoolss_open_printer_ex(struct client_info *info); diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index 9d8d5f5736..ee76a908d0 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -36,7 +36,7 @@ extern int DEBUGLEVEL; do a SPOOLSS Enum Printers ****************************************************************************/ BOOL spoolss_enum_printers(struct cli_state *cli, uint16 fnum, - uint32 flags, char *servername, + uint32 flags, const char *servername, uint32 level, uint32 *count, void ***printers) diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index 257f32aa8b..469b5b1a72 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -40,41 +40,61 @@ extern int smb_tidx; /**************************************************************************** nt spoolss query ****************************************************************************/ -void cmd_spoolss_enum_printers(struct client_info *info) +BOOL msrpc_spoolss_enum_printers(struct cli_state *cli, + uint32 level, + uint32 *num, + void ***ctr, + PRINT_INFO_FN(fn)) { uint16 nt_pipe_fnum; fstring srv_name; - void **ctr = NULL; - uint32 num = 0; - uint32 level = 1; - BOOL res = True; fstrcpy(srv_name, "\\\\"); fstrcat(srv_name, smb_cli->desthost); strupper(srv_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 = cli_nt_session_open(cli, PIPE_SPOOLSS, &nt_pipe_fnum); - res = res ? spoolss_enum_printers(smb_cli, nt_pipe_fnum, - 0x40, srv_name, level, &num, &ctr) : False; + res = res ? spoolss_enum_printers(cli, nt_pipe_fnum, + 0x40, srv_name, level, num, ctr) : False; /* close the session */ - cli_nt_session_close(smb_cli, nt_pipe_fnum); + cli_nt_session_close(cli, nt_pipe_fnum); - if (res) + if (res && fn != NULL) + { + fn(srv_name, level, *num, *ctr); + } + + return res; +} + +static void spool_print_info_ctr(const char* srv_name, uint32 level, + uint32 num, void **ctr) +{ + display_printer_info_ctr(out_hnd, ACTION_HEADER , level, num, ctr); + display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, num, ctr); + display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, num, ctr); +} + +/**************************************************************************** +nt spoolss query +****************************************************************************/ +void cmd_spoolss_enum_printers(struct client_info *info) +{ + void **ctr = NULL; + uint32 num = 0; + uint32 level = 1; + + if (msrpc_spoolss_enum_printers(smb_cli, level, &num, &ctr, + spool_print_info_ctr)) { DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n")); - display_printer_info_ctr(out_hnd, ACTION_HEADER , level, num, ctr); - display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, num, ctr); - display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, num, ctr); } else { - DEBUG(5,("cmd_spoolss_enum_printer: query failed\n")); report(out_hnd, "FAILED\n"); } diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 2231824b95..e9ddbd3f31 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -105,6 +105,7 @@ static void rpcclient_stop(void) #define COMPL_SAMGRP 4 #define COMPL_SAMALS 5 #define COMPL_SVCLST 6 +#define COMPL_PRTLST 7 /**************************************************************************** This defines the commands supported by this client @@ -245,7 +246,7 @@ commands[] = "spoolopen", cmd_spoolss_open_printer_ex, "<printer name> Spool Printer Open Test", - {COMPL_NONE, COMPL_NONE} + {COMPL_PRTLST, COMPL_NONE} }, /* * server @@ -1086,6 +1087,47 @@ static char *complete_svcenum(char *text, int state) return NULL; } +static char *complete_printersenum(char *text, int state) +{ + static uint32 i = 0; + static uint32 num = 0; + static PRINTER_INFO_1 **ctr = NULL; + + if (state == 0) + { + free_print1_array(num, ctr); + ctr = NULL; + num = 0; + + /* Iterate all users */ + if (!msrpc_spoolss_enum_printers(smb_cli, 1, &num, + (void***)&ctr, + NULL)) + { + return NULL; + } + + i = 0; + } + + for (; i < num; i++) + { + fstring name; + unistr_to_ascii(name, ctr[i]->name.buffer, + sizeof(name)-1); + + if (text == NULL || text[0] == 0 || + strnequal(text, name, strlen(text))) + { + char *copy = strdup(name); + i++; + return copy; + } + } + + return NULL; +} + /* Complete an rpcclient command */ static char *complete_cmd(char *text, int state) @@ -1189,6 +1231,9 @@ static char **completion_fn(char *text, int start, int end) case COMPL_SVCLST: return completion_matches(text, complete_svcenum); + case COMPL_PRTLST: + return completion_matches(text, complete_printersenum); + case COMPL_REGKEY: return completion_matches(text, complete_regenum); |