From 345eba78f7fc72f067cd3d95a7698081e09be85f Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Thu, 4 Mar 2010 15:46:28 +0100 Subject: [PATCH] s3-rpcclient: fix rpcclient after spoolss_GetPrinterData{Ex} IDL change. Guenther --- source3/include/proto.h | 3 ++- source3/rpc_client/cli_spoolss.c | 16 ++++++++--- source3/rpcclient/cmd_spoolss.c | 57 +++++++++++++++++++++++++--------------- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index b241437503f..f078844a53f 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -5557,7 +5557,8 @@ WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, const char *value_name, uint32_t offered, enum winreg_Type *type, - union spoolss_PrinterData *data); + uint32_t *needed_p, + uint8_t **data_p); WERROR rpccli_spoolss_enumprinterkey(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, struct policy_handle *handle, diff --git a/source3/rpc_client/cli_spoolss.c b/source3/rpc_client/cli_spoolss.c index bc4a4e78ed5..1919da9af3f 100644 --- a/source3/rpc_client/cli_spoolss.c +++ b/source3/rpc_client/cli_spoolss.c @@ -715,34 +715,44 @@ WERROR rpccli_spoolss_getprinterdata(struct rpc_pipe_client *cli, const char *value_name, uint32_t offered, enum winreg_Type *type, - union spoolss_PrinterData *data) + uint32_t *needed_p, + uint8_t **data_p) { NTSTATUS status; WERROR werror; uint32_t needed; + uint8_t *data; + + data = talloc_zero_array(mem_ctx, uint8_t, offered); + W_ERROR_HAVE_NO_MEMORY(data); status = rpccli_spoolss_GetPrinterData(cli, mem_ctx, handle, value_name, - offered, type, data, + offered, &needed, &werror); if (W_ERROR_EQUAL(werror, WERR_MORE_DATA)) { offered = needed; + data = talloc_zero_array(mem_ctx, uint8_t, offered); + W_ERROR_HAVE_NO_MEMORY(data); status = rpccli_spoolss_GetPrinterData(cli, mem_ctx, handle, value_name, - offered, type, data, + offered, &needed, &werror); } + *data_p = data; + *needed_p = needed; + return werror; } diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index bd6bde5f17d..b0d52069fe5 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -751,20 +751,29 @@ static void display_reg_value(REGISTRY_VALUE value) static void display_printer_data(const char *v, enum winreg_Type type, - union spoolss_PrinterData *r) + uint8_t *data, + uint32_t length) { int i; + union spoolss_PrinterData r; + DATA_BLOB blob = data_blob_const(data, length); + WERROR result; + + result = pull_spoolss_PrinterData(talloc_tos(), &blob, &r, type); + if (!W_ERROR_IS_OK(result)) { + return; + } switch (type) { case REG_DWORD: - printf("%s: REG_DWORD: 0x%08x\n", v, r->value); + printf("%s: REG_DWORD: 0x%08x\n", v, r.value); break; case REG_SZ: - printf("%s: REG_SZ: %s\n", v, r->string); + printf("%s: REG_SZ: %s\n", v, r.string); break; case REG_BINARY: { char *hex = hex_encode_talloc(NULL, - r->binary.data, r->binary.length); + r.binary.data, r.binary.length); size_t len; printf("%s: REG_BINARY:", v); len = strlen(hex); @@ -783,8 +792,8 @@ static void display_printer_data(const char *v, } case REG_MULTI_SZ: printf("%s: REG_MULTI_SZ: ", v); - for (i=0; r->string_array[i] != NULL; i++) { - printf("%s ", r->string_array[i]); + for (i=0; r.string_array[i] != NULL; i++) { + printf("%s ", r.string_array[i]); } printf("\n"); break; @@ -806,7 +815,8 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli, fstring printername; const char *valuename; enum winreg_Type type; - union spoolss_PrinterData data; + uint8_t *data; + uint32_t needed; if (argc != 3) { printf("Usage: %s \n", argv[0]); @@ -839,13 +849,14 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli, valuename, 0, &type, + &needed, &data); if (!W_ERROR_IS_OK(result)) goto done; /* Display printer data */ - display_printer_data(valuename, type, &data); + display_printer_data(valuename, type, data, needed); done: if (is_valid_policy_hnd(&pol)) @@ -866,10 +877,9 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli, NTSTATUS status; fstring printername; const char *valuename, *keyname; - REGISTRY_VALUE value; enum winreg_Type type; - uint8_t *buffer = NULL; + uint8_t *data = NULL; uint32_t offered = 0; uint32_t needed; @@ -901,24 +911,32 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli, /* Get printer info */ + data = talloc_zero_array(mem_ctx, uint8_t, offered); + if (!data) { + goto done; + } + status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx, &pol, keyname, valuename, &type, - buffer, + data, offered, &needed, &result); if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) { offered = needed; - buffer = talloc_array(mem_ctx, uint8_t, needed); + data = talloc_zero_array(mem_ctx, uint8_t, offered); + if (!data) { + goto done; + } status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx, &pol, keyname, valuename, &type, - buffer, + data, offered, &needed, &result); @@ -938,12 +956,7 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli, /* Display printer data */ - fstrcpy(value.valuename, valuename); - value.type = type; - value.size = needed; - value.data_p = buffer; - - display_reg_value(value); + display_printer_data(valuename, type, data, needed); done: if (is_valid_policy_hnd(&pol)) @@ -2863,7 +2876,9 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli, const char **argv) { WERROR result; +#if 0 uint32_t i; +#endif const char *printername; struct policy_handle hnd; uint32_t count; @@ -2897,13 +2912,13 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli, if (!W_ERROR_IS_OK(result)) { goto done; } - +#if 0 for (i=0; i < count; i++) { display_printer_data(info[i].value_name, info[i].type, info[i].data); } - +#endif done: if (is_valid_policy_hnd(&hnd)) { rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL); -- 2.11.4.GIT