s3-rpcclient: use struct based dcerpc_spoolss_EnumPrinterData_r() call.
authorGünther Deschner <gd@samba.org>
Fri, 28 Jan 2011 17:07:07 +0000 (18:07 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 28 Jan 2011 20:16:46 +0000 (21:16 +0100)
This is a workaround for a string issue we currently have with argument based
generated dcerpc client code (see bug #7804 for details).

Guenther

source3/rpcclient/cmd_spoolss.c

index 3e6752cf4bc782ae93cecfcfb49b2bbf1bbde6b0..248996e2745c047ade09fa821b44204af6724173 100644 (file)
@@ -2972,17 +2972,13 @@ static WERROR cmd_spoolss_enum_data(struct rpc_pipe_client *cli,
 {
        WERROR result;
        NTSTATUS status;
-       uint32_t i = 0;
        const char *printername;
        struct policy_handle hnd;
-       uint32_t value_offered = 0;
-       const char *value_name = NULL;
        uint32_t value_needed;
        enum winreg_Type type;
-       uint8_t *data = NULL;
-       uint32_t data_offered = 0;
        uint32_t data_needed;
        struct dcerpc_binding_handle *b = cli->binding_handle;
+       struct spoolss_EnumPrinterData r;
 
        if (argc != 2) {
                printf("Usage: %s printername\n", argv[0]);
@@ -3003,53 +2999,55 @@ static WERROR cmd_spoolss_enum_data(struct rpc_pipe_client *cli,
 
        /* Enumerate data */
 
-       status = dcerpc_spoolss_EnumPrinterData(b, mem_ctx,
-                                               &hnd,
-                                               i,
-                                               value_name,
-                                               value_offered,
-                                               &value_needed,
-                                               &type,
-                                               data,
-                                               data_offered,
-                                               &data_needed,
-                                               &result);
-
+       r.in.handle = &hnd;
+       r.in.enum_index = 0;
+       r.in.value_offered = 0;
+       r.in.data_offered = 0;
+       r.out.value_name = NULL;
+       r.out.value_needed = &value_needed;
+       r.out.type = &type;
+       r.out.data = NULL;
+       r.out.data_needed = &data_needed;
+
+       status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r);
        if (!NT_STATUS_IS_OK(status)) {
                result = ntstatus_to_werror(status);
                goto done;
        }
 
-       if (!W_ERROR_IS_OK(result)) {
+       if (!W_ERROR_IS_OK(r.out.result)) {
+               result = r.out.result;
                goto done;
        }
 
-       data_offered    = data_needed;
-       value_offered   = value_needed;
-       data            = talloc_zero_array(mem_ctx, uint8_t, data_needed);
-       value_name      = talloc_zero_array(mem_ctx, char, value_needed);
+       r.in.data_offered       = *r.out.data_needed;
+       r.in.value_offered      = *r.out.value_needed;
+       r.out.data              = talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered);
+       r.out.value_name        = talloc_zero_array(mem_ctx, char, r.in.value_offered);
+
+       do {
+
+               status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r);
+               if (!NT_STATUS_IS_OK(status)) {
+                       result = ntstatus_to_werror(status);
+                       goto done;
+               }
+
+               if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
+                       result = WERR_OK;
+                       break;
+               }
 
-       while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
+               r.in.enum_index++;
 
-               status = dcerpc_spoolss_EnumPrinterData(b, mem_ctx,
-                                                       &hnd,
-                                                       i++,
-                                                       value_name,
-                                                       value_offered,
-                                                       &value_needed,
-                                                       &type,
-                                                       data,
-                                                       data_offered,
-                                                       &data_needed,
-                                                       &result);
-               if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
+               {
                        struct regval_blob *v;
 
                        v = regval_compose(talloc_tos(),
-                                          value_name,
-                                          type,
-                                          data,
-                                          data_offered);
+                                          r.out.value_name,
+                                          *r.out.type,
+                                          r.out.data,
+                                          r.in.data_offered);
                        if (v == NULL) {
                                result = WERR_NOMEM;
                                goto done;
@@ -3058,11 +3056,8 @@ static WERROR cmd_spoolss_enum_data(struct rpc_pipe_client *cli,
                        display_reg_value(v);
                        talloc_free(v);
                }
-       }
 
-       if (W_ERROR_V(result) == ERRnomoreitems) {
-               result = W_ERROR(ERRsuccess);
-       }
+       } while (W_ERROR_IS_OK(r.out.result));
 
 done:
        if (is_valid_policy_hnd(&hnd)) {