mirror of
https://github.com/samba-team/samba.git
synced 2025-03-11 16:58:40 +03:00
r1101: Implement 'rpcclient setprintername'.
Thanks to Guenther Deschner <gd@sernet.de>. This needs to be generalized somewhat. Jerry, which of the parameters in the printer_info_2 struct are settable via cli_spoolss_setprinter? Volker
This commit is contained in:
parent
c8a55e92dd
commit
473dd03833
@ -546,6 +546,76 @@ static WERROR cmd_spoolss_setprinter(struct cli_state *cli,
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Set printer name - use a level2 set.
|
||||
*/
|
||||
static WERROR cmd_spoolss_setprintername(struct cli_state *cli,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
int argc, const char **argv)
|
||||
{
|
||||
POLICY_HND pol;
|
||||
WERROR result;
|
||||
uint32 needed;
|
||||
uint32 info_level = 2;
|
||||
BOOL opened_hnd = False;
|
||||
PRINTER_INFO_CTR ctr;
|
||||
fstring printername,
|
||||
servername,
|
||||
user,
|
||||
new_printername;
|
||||
|
||||
if (argc == 1 || argc > 3) {
|
||||
printf("Usage: %s printername new_printername\n", argv[0]);
|
||||
|
||||
return WERR_OK;
|
||||
}
|
||||
|
||||
/* Open a printer handle */
|
||||
if (argc == 3) {
|
||||
fstrcpy(new_printername, argv[2]);
|
||||
}
|
||||
|
||||
slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->desthost);
|
||||
strupper_m(servername);
|
||||
fstrcpy(printername, argv[1]);
|
||||
fstrcpy(user, cli->user_name);
|
||||
|
||||
/* get a printer handle */
|
||||
result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
|
||||
PRINTER_ALL_ACCESS, servername,
|
||||
user, &pol);
|
||||
|
||||
if (!W_ERROR_IS_OK(result))
|
||||
goto done;
|
||||
|
||||
opened_hnd = True;
|
||||
|
||||
/* Get printer info */
|
||||
result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, info_level, &ctr);
|
||||
|
||||
if (W_ERROR_V(result) == ERRinsufficientbuffer)
|
||||
result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, info_level, &ctr);
|
||||
|
||||
if (!W_ERROR_IS_OK(result))
|
||||
goto done;
|
||||
|
||||
|
||||
/* Modify the printername. */
|
||||
init_unistr(&ctr.printers_2->printername, new_printername);
|
||||
ctr.printers_2->devmode = NULL;
|
||||
ctr.printers_2->secdesc = NULL;
|
||||
|
||||
result = cli_spoolss_setprinter(cli, mem_ctx, &pol, info_level, &ctr, 0);
|
||||
if (W_ERROR_IS_OK(result))
|
||||
printf("Success in setting printername.\n");
|
||||
|
||||
done:
|
||||
if (opened_hnd)
|
||||
cli_spoolss_close_printer(cli, mem_ctx, &pol);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Get printer information
|
||||
*/
|
||||
@ -2331,6 +2401,7 @@ struct cmd_set spoolss_commands[] = {
|
||||
{ "deleteform", RPC_RTYPE_WERROR, NULL, cmd_spoolss_deleteform, PI_SPOOLSS, "Delete form", "" },
|
||||
{ "enumforms", RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_forms, PI_SPOOLSS, "Enumerate forms", "" },
|
||||
{ "setprinter", RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprinter, PI_SPOOLSS, "Set printer comment", "" },
|
||||
{ "setprintername", RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprintername, PI_SPOOLSS, "Set printername", "" },
|
||||
{ "setprinterdata", RPC_RTYPE_WERROR, NULL, cmd_spoolss_setprinterdata, PI_SPOOLSS, "Set REG_SZ printer data", "" },
|
||||
{ "rffpcnex", RPC_RTYPE_WERROR, NULL, cmd_spoolss_rffpcnex, PI_SPOOLSS, "Rffpcnex test", "" },
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user