mirror of
https://github.com/samba-team/samba.git
synced 2025-03-01 04:58:35 +03:00
added command-completion printer enum code.
(This used to be commit 6947f8fac7d6d643a265fdcb56b2a390b9a9a1c0)
This commit is contained in:
parent
4dbd1c135c
commit
514be1cf73
@ -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 */
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
|
||||
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"));
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("cmd_spoolss_enum_printer: query failed\n"));
|
||||
report(out_hnd, "FAILED\n");
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user