The branch, master has been updated
       via  32e9577 s3-spoolss: Move spoolss winreg to new dcerpc client 
funtions.
      from  2226347 s3: Simplify cm_connect_sam a bit

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 32e95772f9e6e6538da7eefa388e015be17af0e8
Author: Andreas Schneider <[email protected]>
Date:   Wed Sep 1 18:00:44 2010 +0200

    s3-spoolss: Move spoolss winreg to new dcerpc client funtions.

-----------------------------------------------------------------------

Summary of changes:
 source3/rpc_server/srv_spoolss_util.c |  736 +++++++++++++++++----------------
 1 files changed, 389 insertions(+), 347 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/rpc_server/srv_spoolss_util.c 
b/source3/rpc_server/srv_spoolss_util.c
index 927bb5e..8179012 100644
--- a/source3/rpc_server/srv_spoolss_util.c
+++ b/source3/rpc_server/srv_spoolss_util.c
@@ -223,7 +223,7 @@ static uint32_t winreg_printer_rev_changeid(void)
  *
  * @param[in]  server_info   The supplied server info.
  *
- * @param[out] winreg_pipe   A pointer for the winreg rpc client pipe.
+ * @param[out] binding_handle A pointer for the winreg dcerpc binding handle.
  *
  * @param[in]  path          The path to the key to open.
  *
@@ -244,7 +244,7 @@ static uint32_t winreg_printer_rev_changeid(void)
 static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                              struct auth_serversupplied_info *server_info,
                              struct messaging_context *msg_ctx,
-                             struct rpc_pipe_client **winreg_pipe,
+                             struct dcerpc_binding_handle 
**winreg_binding_handle,
                              const char *path,
                              const char *key,
                              bool create_key,
@@ -252,26 +252,29 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                              struct policy_handle *hive_handle,
                              struct policy_handle *key_handle)
 {
-       struct rpc_pipe_client *pipe_handle;
+       static struct client_address client_id;
+       struct dcerpc_binding_handle *binding_handle;
        struct winreg_String wkey, wkeyclass;
        char *keyname;
        NTSTATUS status;
        WERROR result = WERR_OK;
 
-       /* create winreg connection */
-       status = rpc_pipe_open_internal(mem_ctx,
-                                       &ndr_table_winreg.syntax_id,
-                                       server_info,
-                                       NULL,
-                                       msg_ctx,
-                                       &pipe_handle);
+       strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
+       client_id.name = "127.0.0.1";
+
+       status = rpcint_binding_handle(mem_ctx,
+                                      &ndr_table_winreg,
+                                      &client_id,
+                                      server_info,
+                                      msg_ctx,
+                                      &binding_handle);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("winreg_printer_openkey: Could not connect to 
winreg_pipe: %s\n",
+               DEBUG(0, ("winreg_printer_openkey: Could not connect to winreg 
pipe: %s\n",
                          nt_errstr(status)));
                return ntstatus_to_werror(status);
        }
 
-       status = rpccli_winreg_OpenHKLM(pipe_handle,
+       status = dcerpc_winreg_OpenHKLM(binding_handle,
                                        mem_ctx,
                                        NULL,
                                        access_mask,
@@ -280,12 +283,15 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: 
%s\n",
                          nt_errstr(status)));
-               talloc_free(pipe_handle);
-               if (!W_ERROR_IS_OK(result)) {
-                       return result;
-               }
+               talloc_free(binding_handle);
                return ntstatus_to_werror(status);
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_printer_openkey: Could not open HKLM hive: 
%s\n",
+                         win_errstr(result)));
+               talloc_free(binding_handle);
+               return result;
+       }
 
        if (key && *key) {
                keyname = talloc_asprintf(mem_ctx, "%s\\%s", path, key);
@@ -293,7 +299,7 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                keyname = talloc_strdup(mem_ctx, path);
        }
        if (keyname == NULL) {
-               talloc_free(pipe_handle);
+               talloc_free(binding_handle);
                return WERR_NOMEM;
        }
 
@@ -306,7 +312,7 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                ZERO_STRUCT(wkeyclass);
                wkeyclass.name = "";
 
-               status = rpccli_winreg_CreateKey(pipe_handle,
+               status = dcerpc_winreg_CreateKey(binding_handle,
                                                 mem_ctx,
                                                 hive_handle,
                                                 wkey,
@@ -329,7 +335,7 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                                break;
                }
        } else {
-               status = rpccli_winreg_OpenKey(pipe_handle,
+               status = dcerpc_winreg_OpenKey(binding_handle,
                                               mem_ctx,
                                               hive_handle,
                                               wkey,
@@ -339,14 +345,15 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
                                               &result);
        }
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(pipe_handle);
-               if (!W_ERROR_IS_OK(result)) {
-                       return result;
-               }
+               talloc_free(binding_handle);
                return ntstatus_to_werror(status);
        }
+       if (!W_ERROR_IS_OK(result)) {
+               talloc_free(binding_handle);
+               return result;
+       }
 
-       *winreg_pipe = pipe_handle;
+       *winreg_binding_handle = binding_handle;
 
        return WERR_OK;
 }
@@ -371,7 +378,7 @@ static char *winreg_printer_data_keyname(TALLOC_CTX 
*mem_ctx, const char *printe
  *
  * @param[in]  mem_ctx  The memory context to use.
  *
- * @param[in]  pipe_handle The pipe handle for the rpc connection.
+ * @param[in]  winreg_handle The binding handle for the rpc connection.
  *
  * @param[in]  key_hnd  The opened key handle.
  *
@@ -383,7 +390,7 @@ static char *winreg_printer_data_keyname(TALLOC_CTX 
*mem_ctx, const char *printe
  *                           code if something gone wrong.
  */
 static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
-                                       struct rpc_pipe_client *pipe_handle,
+                                       struct dcerpc_binding_handle 
*winreg_handle,
                                        struct policy_handle *key_hnd,
                                        uint32_t *pnum_values,
                                        struct spoolss_PrinterEnumValues 
**penum_values)
@@ -408,7 +415,7 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(classname);
 
-       status = rpccli_winreg_QueryInfoKey(pipe_handle,
+       status = dcerpc_winreg_QueryInfoKey(winreg_handle,
                                            tmp_ctx,
                                            key_hnd,
                                            &classname,
@@ -424,12 +431,14 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX 
*mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("winreg_printer_enumvalues: Could not query info: 
%s\n",
                          nt_errstr(status)));
-               if (!W_ERROR_IS_OK(result)) {
-                       goto error;
-               }
                result = ntstatus_to_werror(status);
                goto error;
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_printer_enumvalues: Could not query info: 
%s\n",
+                         win_errstr(result)));
+               goto error;
+       }
 
        if (num_values == 0) {
                *pnum_values = 0;
@@ -463,7 +472,7 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
                }
                length = 0;
 
-               status = rpccli_winreg_EnumValue(pipe_handle,
+               status = dcerpc_winreg_EnumValue(winreg_handle,
                                                 tmp_ctx,
                                                 key_hnd,
                                                 i,
@@ -482,12 +491,14 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX 
*mem_ctx,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("winreg_printer_enumvalues: Could not 
enumerate values: %s\n",
                                  nt_errstr(status)));
-                       if (!W_ERROR_IS_OK(result)) {
-                               goto error;
-                       }
                        result = ntstatus_to_werror(status);
                        goto error;
                }
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("winreg_printer_enumvalues: Could not 
enumerate values: %s\n",
+                                 win_errstr(result)));
+                       goto error;
+               }
 
                if (name_buf.name == NULL) {
                        result = WERR_INVALID_PARAMETER;
@@ -535,7 +546,7 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
  *
  * @param[in]  mem_ctx  The memory context to use.
  *
- * @param[in]  pipe_handle The pipe handle for the rpc connection.
+ * @param[in]  winreg_handle The binding handle for the rpc connection.
  *
  * @param[in]  key_hnd  The opened key handle.
  *
@@ -548,7 +559,7 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
  *                           code if something gone wrong.
  */
 static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
-                                     struct rpc_pipe_client *pipe_handle,
+                                     struct dcerpc_binding_handle 
*winreg_handle,
                                      struct policy_handle *key_hnd,
                                      uint32_t *pnum_subkeys,
                                      const char ***psubkeys)
@@ -571,7 +582,7 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(classname);
 
-       status = rpccli_winreg_QueryInfoKey(pipe_handle,
+       status = dcerpc_winreg_QueryInfoKey(winreg_handle,
                                            tmp_ctx,
                                            key_hnd,
                                            &classname,
@@ -587,12 +598,14 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
                          nt_errstr(status)));
-               if (!W_ERROR_IS_OK(result)) {
-                       goto error;
-               }
                result = ntstatus_to_werror(status);
                goto error;
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
+                         win_errstr(result)));
+               goto error;
+       }
 
        subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
        if (subkeys == NULL) {
@@ -633,7 +646,7 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
 
                ZERO_STRUCT(modtime);
 
-               status = rpccli_winreg_EnumKey(pipe_handle,
+               status = dcerpc_winreg_EnumKey(winreg_handle,
                                               tmp_ctx,
                                               key_hnd,
                                               i,
@@ -650,12 +663,14 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate 
keys: %s\n",
                                  nt_errstr(status)));
-                       if (!W_ERROR_IS_OK(result)) {
-                               goto error;
-                       }
                        result = ntstatus_to_werror(status);
                        goto error;
                }
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate 
keys: %s\n",
+                                 win_errstr(result)));
+                       goto error;
+               }
 
                if (name_buf.name == NULL) {
                        result = WERR_INVALID_PARAMETER;
@@ -688,7 +703,7 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
  *
  * @param[in]  mem_ctx  The memory context to use.
  *
- * @param[in]  pipe_handle The pipe handle for the rpc connection.
+ * @param[in]  winreg_handle The binding handle for the rpc connection.
  *
  * @param[in]  hive_handle A opened hive handle to the key.
  *
@@ -700,7 +715,7 @@ static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
  *                      code if something gone wrong.
  */
 static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
-                                           struct rpc_pipe_client *pipe_handle,
+                                           struct dcerpc_binding_handle 
*winreg_handle,
                                            struct policy_handle *hive_handle,
                                            uint32_t access_mask,
                                            const char *key)
@@ -718,7 +733,7 @@ static WERROR winreg_printer_delete_subkeys(TALLOC_CTX 
*mem_ctx,
 
        DEBUG(2, ("winreg_printer_delete_subkeys: delete key %s\n", key));
        /* open the key */
-       status = rpccli_winreg_OpenKey(pipe_handle,
+       status = dcerpc_winreg_OpenKey(winreg_handle,
                                       mem_ctx,
                                       hive_handle,
                                       wkey,
@@ -729,14 +744,16 @@ static WERROR winreg_printer_delete_subkeys(TALLOC_CTX 
*mem_ctx,
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key 
%s: %s\n",
                          wkey.name, nt_errstr(status)));
-               if (!W_ERROR_IS_OK(result)) {
-                       return result;
-               }
                return ntstatus_to_werror(status);
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_printer_delete_subkeys: Could not open key 
%s: %s\n",
+                         wkey.name, win_errstr(result)));
+               return result;
+       }
 
        result = winreg_printer_enumkeys(mem_ctx,
-                                        pipe_handle,
+                                        winreg_handle,
                                         &key_hnd,
                                         &num_subkeys,
                                         &subkeys);
@@ -753,7 +770,7 @@ static WERROR winreg_printer_delete_subkeys(TALLOC_CTX 
*mem_ctx,
 
                DEBUG(2, ("winreg_printer_delete_subkeys: delete subkey %s\n", 
subkey));
                result = winreg_printer_delete_subkeys(mem_ctx,
-                                                      pipe_handle,
+                                                      winreg_handle,
                                                       hive_handle,
                                                       access_mask,
                                                       subkey);
@@ -763,27 +780,33 @@ static WERROR winreg_printer_delete_subkeys(TALLOC_CTX 
*mem_ctx,
        }
 
        if (is_valid_policy_hnd(&key_hnd)) {
-               rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
+               WERROR ignore;
+               dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, 
&ignore);
        }
 
        wkey.name = key;
 
-       status = rpccli_winreg_DeleteKey(pipe_handle,
+       status = dcerpc_winreg_DeleteKey(winreg_handle,
                                         mem_ctx,
                                         hive_handle,
                                         wkey,
                                         &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
 
 done:
        if (is_valid_policy_hnd(&key_hnd)) {
-               rpccli_winreg_CloseKey(pipe_handle, mem_ctx, &key_hnd, NULL);
+               WERROR ignore;
+
+               dcerpc_winreg_CloseKey(winreg_handle, mem_ctx, &key_hnd, 
&ignore);
        }
 
        return result;
 }
 
 static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
-                                     struct rpc_pipe_client *pipe_handle,
+                                     struct dcerpc_binding_handle 
*winreg_handle,
                                      struct policy_handle *key_handle,
                                      const char *value,
                                      const char *data)
@@ -803,7 +826,7 @@ static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
                        return WERR_NOMEM;
                }
        }
-       status = rpccli_winreg_SetValue(pipe_handle,
+       status = dcerpc_winreg_SetValue(winreg_handle,
                                        mem_ctx,
                                        key_handle,
                                        wvalue,
@@ -812,18 +835,18 @@ static WERROR winreg_printer_write_sz(TALLOC_CTX *mem_ctx,
                                        blob.length,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_printer_write_sz: Could not set value %s: 
%s\n",
                        wvalue.name, win_errstr(result)));
-               if (!W_ERROR_IS_OK(result)) {
-                       result = ntstatus_to_werror(status);
-               }
        }
 
        return result;
 }
 
 static WERROR winreg_printer_write_dword(TALLOC_CTX *mem_ctx,
-                                        struct rpc_pipe_client *pipe_handle,
+                                        struct dcerpc_binding_handle 
*winreg_handle,
                                         struct policy_handle *key_handle,
                                         const char *value,
                                         uint32_t data)
@@ -837,7 +860,7 @@ static WERROR winreg_printer_write_dword(TALLOC_CTX 
*mem_ctx,
        blob = data_blob_talloc(mem_ctx, NULL, 4);
        SIVAL(blob.data, 0, data);
 
-       status = rpccli_winreg_SetValue(pipe_handle,
+       status = dcerpc_winreg_SetValue(winreg_handle,
                                        mem_ctx,
                                        key_handle,
                                        wvalue,
@@ -846,18 +869,18 @@ static WERROR winreg_printer_write_dword(TALLOC_CTX 
*mem_ctx,
                                        blob.length,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_printer_write_dword: Could not set value %s: 
%s\n",
                        wvalue.name, win_errstr(result)));
-               if (!W_ERROR_IS_OK(result)) {
-                       result = ntstatus_to_werror(status);
-               }
        }
 
        return result;
 }
 
 static WERROR winreg_printer_write_binary(TALLOC_CTX *mem_ctx,
-                                         struct rpc_pipe_client *pipe_handle,
+                                         struct dcerpc_binding_handle 
*winreg_handle,
                                          struct policy_handle *key_handle,
                                          const char *value,
                                          DATA_BLOB blob)
@@ -867,7 +890,7 @@ static WERROR winreg_printer_write_binary(TALLOC_CTX 
*mem_ctx,
        NTSTATUS status;
 
        wvalue.name = value;
-       status = rpccli_winreg_SetValue(pipe_handle,
+       status = dcerpc_winreg_SetValue(winreg_handle,
                                        mem_ctx,
                                        key_handle,
                                        wvalue,
@@ -876,18 +899,18 @@ static WERROR winreg_printer_write_binary(TALLOC_CTX 
*mem_ctx,
                                        blob.length,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("winreg_printer_write_binary: Could not set value %s: 
%s\n",
                        wvalue.name, win_errstr(result)));
-               if (!W_ERROR_IS_OK(result)) {
-                       result = ntstatus_to_werror(status);
-               }
        }
 
        return result;
 }
 
 static WERROR winreg_printer_query_binary(TALLOC_CTX *mem_ctx,
-                                         struct rpc_pipe_client *pipe_handle,
+                                         struct dcerpc_binding_handle 
*winreg_handle,
                                          struct policy_handle *key_handle,
                                          const char *value,
                                          DATA_BLOB *data)
@@ -901,7 +924,7 @@ static WERROR winreg_printer_query_binary(TALLOC_CTX 
*mem_ctx,
        DATA_BLOB blob;
 
        wvalue.name = value;
-       status = rpccli_winreg_QueryValue(pipe_handle,
+       status = dcerpc_winreg_QueryValue(winreg_handle,
                                          mem_ctx,
                                          key_handle,
                                          &wvalue,
@@ -911,12 +934,11 @@ static WERROR winreg_printer_query_binary(TALLOC_CTX 
*mem_ctx,
                                          &value_len,
                                          &result);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(2, ("winreg_printer_query_binary: Could not query value 
%s: %s\n",
-                         wvalue.name, nt_errstr(status)));
-               if (!W_ERROR_IS_OK(result)) {
-                       goto done;
-               }
                result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("winreg_printer_query_binary: Could not query value 
%s: %s\n",
+                         wvalue.name, win_errstr(result)));
                goto done;
        }
 
@@ -931,7 +953,7 @@ static WERROR winreg_printer_query_binary(TALLOC_CTX 
*mem_ctx,
        }
        value_len = 0;
 
-       status = rpccli_winreg_QueryValue(pipe_handle,
+       status = dcerpc_winreg_QueryValue(winreg_handle,
                                          mem_ctx,
                                          key_handle,
                                          &wvalue,


-- 
Samba Shared Repository

Reply via email to