s3:rpc_client: pass object and table to rpccli_bh_create()
[mat/samba.git] / source3 / rpc_server / rpc_ncacn_np.c
index 25ad8570a2864af64a601fcf021ada2993a655b0..c58f97dec9879fe5131c6d792df993c0a82f5b10 100644 (file)
@@ -36,6 +36,7 @@
 #include "../lib/util/tevent_ntstatus.h"
 #include "rpc_contexts.h"
 #include "rpc_server/rpc_config.h"
+#include "librpc/ndr/ndr_table.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -54,8 +55,15 @@ struct pipes_struct *make_internal_rpc_pipe_p(TALLOC_CTX *mem_ctx,
        struct pipe_rpc_fns *context_fns;
        const char *pipe_name;
        int ret;
+       const struct ndr_interface_table *table;
 
-       pipe_name = get_pipe_name_from_syntax(talloc_tos(), syntax);
+       table = ndr_table_by_uuid(&syntax->uuid);
+       if (table == NULL) {
+               DEBUG(0,("unknown interface\n"));
+               return NULL;
+       }
+
+       pipe_name = dcerpc_default_transport_endpoint(mem_ctx, NCACN_NP, table);
 
        DEBUG(4,("Create pipe requested %s\n", pipe_name));
 
@@ -553,7 +561,7 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
                GLOBAL_SECTION_SNUM, "external_rpc_pipe", "socket_dir",
                lp_ncalrpc_dir());
        if (socket_dir == NULL) {
-               DEBUG(0, ("externan_rpc_pipe:socket_dir not set\n"));
+               DEBUG(0, ("external_rpc_pipe:socket_dir not set\n"));
                goto fail;
        }
        socket_np_dir = talloc_asprintf(talloc_tos(), "%s/np", socket_dir);
@@ -632,7 +640,7 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
 
 static NTSTATUS rpc_pipe_open_external(TALLOC_CTX *mem_ctx,
                                const char *pipe_name,
-                               const struct ndr_syntax_id *abstract_syntax,
+                               const struct ndr_interface_table *table,
                                const struct auth_session_info *session_info,
                                struct rpc_pipe_client **_result)
 {
@@ -667,7 +675,7 @@ static NTSTATUS rpc_pipe_open_external(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result->abstract_syntax = *abstract_syntax;
+       result->abstract_syntax = table->syntax_id;
        result->transfer_syntax = ndr_transfer_syntax_ndr;
 
        result->desthost = get_myname(result);
@@ -688,7 +696,7 @@ static NTSTATUS rpc_pipe_open_external(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       result->binding_handle = rpccli_bh_create(result);
+       result->binding_handle = rpccli_bh_create(result, NULL, table);
        if (result->binding_handle == NULL) {
                status = NT_STATUS_NO_MEMORY;
                DEBUG(0, ("Failed to create binding handle.\n"));
@@ -758,7 +766,7 @@ done:
  */
 
 NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
-                                const struct ndr_syntax_id *syntax,
+                                const struct ndr_interface_table *table,
                                 const struct auth_session_info *session_info,
                                 const struct tsocket_address *remote_address,
                                 struct messaging_context *msg_ctx,
@@ -770,10 +778,12 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx;
 
-       if (cli_pipe && rpccli_is_connected(*cli_pipe)) {
-               return NT_STATUS_OK;
-       } else {
-               TALLOC_FREE(*cli_pipe);
+       if (cli_pipe != NULL) {
+               if (rpccli_is_connected(*cli_pipe)) {
+                       return NT_STATUS_OK;
+               } else {
+                       TALLOC_FREE(*cli_pipe);
+               }
        }
 
        tmp_ctx = talloc_stackframe();
@@ -781,7 +791,7 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       pipe_name = get_pipe_name_from_syntax(tmp_ctx, syntax);
+       pipe_name = dcerpc_default_transport_endpoint(mem_ctx, NCACN_NP, table);
        if (pipe_name == NULL) {
                status = NT_STATUS_INVALID_PARAMETER;
                goto done;
@@ -798,7 +808,7 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
        switch (pipe_mode) {
        case RPC_SERVICE_MODE_EMBEDDED:
                status = rpc_pipe_open_internal(tmp_ctx,
-                                               syntax, session_info,
+                                               &table->syntax_id, session_info,
                                                remote_address, msg_ctx,
                                                &cli);
                if (!NT_STATUS_IS_OK(status)) {
@@ -811,7 +821,7 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
                 * to spoolssd. */
 
                status = rpc_pipe_open_external(tmp_ctx,
-                                               pipe_name, syntax,
+                                               pipe_name, table,
                                                session_info,
                                                &cli);
                if (!NT_STATUS_IS_OK(status)) {
@@ -827,7 +837,7 @@ NTSTATUS rpc_pipe_open_interface(TALLOC_CTX *mem_ctx,
 
        status = NT_STATUS_OK;
 done:
-       if (NT_STATUS_IS_OK(status)) {
+       if (NT_STATUS_IS_OK(status) && cli_pipe != NULL) {
                *cli_pipe = talloc_move(mem_ctx, &cli);
        }
        TALLOC_FREE(tmp_ctx);