s3-rpc_client: Migrate to dcerpc_winreg_enumvals() function.
authorVicentiu Ciorbaru <cvicentiu@gmail.com>
Tue, 12 Jul 2011 16:42:15 +0000 (19:42 +0300)
committerAndreas Schneider <asn@samba.org>
Wed, 13 Jul 2011 09:30:55 +0000 (11:30 +0200)
The functions that called winreg_printer_enumvalues() function now use
dcerpc_winreg_enumvals().

Signed-off-by: Andreas Schneider <asn@samba.org>
source3/rpc_client/cli_winreg_spoolss.c

index f742a47759d65334988bb14abee0c8ef7e567861..a7e2cdb9b9dfb1cf0b483b86ce46b8b85c5db661 100644 (file)
@@ -1608,7 +1608,7 @@ WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
        struct spoolss_PrinterInfo2 *info2;
        uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        struct policy_handle hive_hnd, key_hnd;
-       struct spoolss_PrinterEnumValues *enum_values = NULL;
+       struct spoolss_PrinterEnumValues enum_value;
        struct spoolss_PrinterEnumValues *v = NULL;
        enum ndr_err_code ndr_err;
        DATA_BLOB blob;
@@ -1618,6 +1618,9 @@ WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
        char *path;
        NTSTATUS status;
        WERROR result = WERR_OK;
+       const char **enum_names = NULL;
+       enum winreg_Type *enum_types = NULL;
+       DATA_BLOB *enum_data_blobs = NULL;
        TALLOC_CTX *tmp_ctx;
 
        tmp_ctx = talloc_stackframe();
@@ -1645,11 +1648,18 @@ WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result = winreg_printer_enumvalues(tmp_ctx,
-                                          winreg_handle,
-                                          &key_hnd,
-                                          &num_values,
-                                          &enum_values);
+       status = dcerpc_winreg_enumvals(tmp_ctx,
+                                       winreg_handle,
+                                       &key_hnd,
+                                       &num_values,
+                                       &enum_names,
+                                       &enum_types,
+                                       &enum_data_blobs,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)){
+               result = ntstatus_to_werror(status);
+       }
+
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_get_printer: Could not enumerate values in %s: %s\n",
                          path, win_errstr(result)));
@@ -1675,7 +1685,15 @@ WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
        FILL_STRING(info2, EMPTY_STRING, info2->parameters);
 
        for (i = 0; i < num_values; i++) {
-               v = &enum_values[i];
+               enum_value.value_name = enum_names[i];
+               enum_value.value_name_len = 2*strlen_m_term(enum_names[i]);
+               enum_value.type = enum_types[i];
+               enum_value.data_length = enum_data_blobs[i].length;
+               enum_value.data = NULL;
+               if (enum_value.data_length != 0){
+                       enum_value.data = &enum_data_blobs[i];
+               }
+               v = &enum_value;
 
                result = winreg_enumval_to_sz(info2,
                                              v,
@@ -2343,6 +2361,7 @@ WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
                                  uint32_t *pnum_values,
                                  struct spoolss_PrinterEnumValues **penum_values)
 {
+       uint32_t i;
        uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        struct policy_handle hive_hnd, key_hnd;
 
@@ -2350,6 +2369,10 @@ WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
        uint32_t num_values = 0;
        char *path;
        WERROR result = WERR_OK;
+       NTSTATUS status;
+       const char **enum_names = NULL;
+       enum winreg_Type *enum_types = NULL;
+       DATA_BLOB *enum_data_blobs = NULL;
 
        TALLOC_CTX *tmp_ctx;
 
@@ -2378,17 +2401,48 @@ WERROR winreg_enum_printer_dataex(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result = winreg_printer_enumvalues(tmp_ctx,
-                                          winreg_handle,
-                                          &key_hnd,
-                                          &num_values,
-                                          &enum_values);
+       status = dcerpc_winreg_enumvals(tmp_ctx,
+                                       winreg_handle,
+                                       &key_hnd,
+                                       &num_values,
+                                       &enum_names,
+                                       &enum_types,
+                                       &enum_data_blobs,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)){
+               result = ntstatus_to_werror(status);
+       }
+
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
                          key, win_errstr(result)));
                goto done;
        }
 
+       enum_values = talloc_array(tmp_ctx, struct spoolss_PrinterEnumValues, num_values);
+       if (enum_values == NULL){
+               result = WERR_NOMEM;
+               DEBUG(0, ("winreg_enum_printer_dataex: Could not enumerate values in %s: %s\n",
+                         key, win_errstr(result)));
+               goto done;
+       }
+
+       for (i = 0; i < num_values; i++){
+               enum_values[i].value_name = enum_names[i];
+               enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
+               enum_values[i].type = enum_types[i];
+               enum_values[i].data_length = enum_data_blobs[i].length;
+               enum_values[i].data = NULL;
+
+               if (enum_values[i].data_length != 0){
+                       enum_values[i].data = &enum_data_blobs[i];
+               }
+       }
+
+       enum_names = talloc_move(mem_ctx, &enum_names);
+       enum_types = talloc_move(mem_ctx, &enum_types);
+       enum_data_blobs = talloc_move(mem_ctx, &enum_data_blobs);
+
        *pnum_values = num_values;
        if (penum_values) {
                *penum_values = talloc_move(mem_ctx, &enum_values);
@@ -2917,6 +2971,10 @@ WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
        uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
        uint32_t i;
        WERROR result;
+       NTSTATUS status;
+       const char **enum_names = NULL;
+       enum winreg_Type *enum_types = NULL;
+       DATA_BLOB *enum_data_blobs = NULL;
        TALLOC_CTX *tmp_ctx;
 
        tmp_ctx = talloc_stackframe();
@@ -2947,11 +3005,43 @@ WERROR winreg_printer_enumforms1(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result = winreg_printer_enumvalues(tmp_ctx,
-                                          winreg_handle,
-                                          &key_hnd,
-                                          &num_values,
-                                          &enum_values);
+       status = dcerpc_winreg_enumvals(tmp_ctx,
+                                       winreg_handle,
+                                       &key_hnd,
+                                       &num_values,
+                                       &enum_names,
+                                       &enum_types,
+                                       &enum_data_blobs,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)){
+               result = ntstatus_to_werror(status);
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
+                         TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
+               goto done;
+       }
+
+       enum_values = talloc_zero_array(tmp_ctx,
+                                       struct spoolss_PrinterEnumValues,
+                                       num_values);
+       if (enum_values == NULL){
+               result = WERR_NOMEM;
+               goto done;
+       }
+
+       for (i = 0; i < num_values; i++){
+               enum_values[i].value_name = enum_names[i];
+               enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
+               enum_values[i].type = enum_types[i];
+               enum_values[i].data_length = enum_data_blobs[i].length;
+               enum_values[i].data = NULL;
+               if (enum_values[i].data_length != 0){
+                       enum_values[i].data = &enum_data_blobs[i];
+               }
+       }
+
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_printer_enumforms1: Could not enumerate values in %s: %s\n",
                          TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
@@ -3678,7 +3768,11 @@ WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
        uint32_t num_values = 0;
        TALLOC_CTX *tmp_ctx;
        WERROR result;
+       NTSTATUS status;
        uint32_t i;
+       const char **enum_names = NULL;
+       enum winreg_Type *enum_types = NULL;
+       DATA_BLOB *enum_data_blobs = NULL;
 
        ZERO_STRUCT(hive_hnd);
        ZERO_STRUCT(key_hnd);
@@ -3728,11 +3822,18 @@ WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result = winreg_printer_enumvalues(tmp_ctx,
-                                          winreg_handle,
-                                          &key_hnd,
-                                          &num_values,
-                                          &enum_values);
+       status = dcerpc_winreg_enumvals(tmp_ctx,
+                                       winreg_handle,
+                                       &key_hnd,
+                                       &num_values,
+                                       &enum_names,
+                                       &enum_types,
+                                       &enum_data_blobs,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)){
+               result = ntstatus_to_werror(status);
+       }
+
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_get_driver: "
                          "Could not enumerate values for (%s,%s,%d): %s\n",
@@ -3741,6 +3842,25 @@ WERROR winreg_get_driver(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
+       enum_values = talloc_zero_array(tmp_ctx,
+                                       struct spoolss_PrinterEnumValues,
+                                       num_values);
+       if (enum_values == NULL){
+               result = WERR_NOMEM;
+               goto done;
+       }
+
+       for (i = 0; i < num_values; i++){
+               enum_values[i].value_name = enum_names[i];
+               enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
+               enum_values[i].type = enum_types[i];
+               enum_values[i].data_length = enum_data_blobs[i].length;
+               enum_values[i].data = NULL;
+               if (enum_values[i].data_length != 0){
+                       enum_values[i].data = &enum_data_blobs[i];
+               }
+       }
+
        info8 = talloc_zero(tmp_ctx, struct spoolss_DriverInfo8);
        if (info8 == NULL) {
                result = WERR_NOMEM;