From: Stefan Metzmacher Date: Mon, 16 Sep 2024 19:56:50 +0000 (+0200) Subject: s3:rpc_client: add struct rpc_client_{association,connection} and helpers X-Git-Tag: samba-4.21.7~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dc83405eeb3d693288299f4eb70735e25c77075;p=thirdparty%2Fsamba.git s3:rpc_client: add struct rpc_client_{association,connection} and helpers They will be every useful for NCACN_NP and NCACN_IP_TCP, so that we can support alter_context or more than one connection per association group. We mark the helpers as _UNUSED_ for now in order to compile... Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit 327fe920d07e5bcbcaa0f09f276aad2b99d68235) --- diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index 86e437754f9..f2b64eaba03 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -50,6 +50,157 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_CLI +struct rpc_client_association { + struct dcerpc_binding *binding; + + struct samba_sockaddr addr; +}; + +_UNUSED_ +static NTSTATUS rpc_client_association_create(TALLOC_CTX *mem_ctx, + const char *target_hostname, + enum dcerpc_transport_t transport, + const struct samba_sockaddr *addr, + const char *endpoint, + struct rpc_client_association **passoc) +{ + struct rpc_client_association *assoc = NULL; + struct dcerpc_binding *bd = NULL; + NTSTATUS status; + + assoc = talloc_zero(mem_ctx, struct rpc_client_association); + if (assoc == NULL) { + return NT_STATUS_NO_MEMORY; + } + + status = dcerpc_parse_binding(assoc, "", &bd); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(assoc); + return status; + } + status = dcerpc_binding_set_transport(bd, transport); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(assoc); + return status; + } + status = dcerpc_binding_set_string_option(bd, + "host", + target_hostname); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(assoc); + return status; + } + status = dcerpc_binding_set_string_option(bd, + "target_hostname", + target_hostname); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(assoc); + return status; + } + status = dcerpc_binding_set_string_option(bd, + "endpoint", + endpoint); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(assoc); + return status; + } + + assoc->binding = bd; + assoc->addr = *addr; + + *passoc = assoc; + return NT_STATUS_OK; +} + +struct rpc_client_connection { + DATA_BLOB transport_session_key; + struct rpc_cli_transport *transport; +}; + +_UNUSED_ +static NTSTATUS rpc_client_connection_create(TALLOC_CTX *mem_ctx, + struct rpc_client_connection **pconn) +{ + struct rpc_client_connection *conn = NULL; + + conn = talloc_zero(mem_ctx, struct rpc_client_connection); + if (conn == NULL) { + return NT_STATUS_NO_MEMORY; + } + + *pconn = conn; + return NT_STATUS_OK; +} + +static int rpc_pipe_client_wrap_destructor(struct rpc_pipe_client *p) +{ + if (p->np_cli != NULL) { + DLIST_REMOVE(p->np_cli->pipe_list, p); + p->np_cli = NULL; + } + + return 0; +} + +_UNUSED_ +static NTSTATUS rpc_pipe_wrap_create( + const struct ndr_interface_table *table, + struct cli_state *np_cli, + struct rpc_client_association **passoc, + struct rpc_client_connection **pconn, + TALLOC_CTX *mem_ctx, + struct rpc_pipe_client **presult) +{ + struct rpc_pipe_client *result = NULL; + const char *hostname = NULL; + + result = talloc_zero(mem_ctx, struct rpc_pipe_client); + if (result == NULL) { + return NT_STATUS_NO_MEMORY; + } + talloc_set_destructor(result, rpc_pipe_client_wrap_destructor); + + result->assoc = talloc_move(result, passoc); + result->conn = talloc_move(result, pconn); + + result->transport_session_key = result->conn->transport_session_key; + result->transport = result->conn->transport; + + result->abstract_syntax = table->syntax_id; + result->transfer_syntax = ndr_transfer_syntax_ndr; + + hostname = dcerpc_binding_get_string_option(result->assoc->binding, + "target_hostname"); + result->desthost = talloc_strdup(result, hostname); + if (result->desthost == NULL) { + TALLOC_FREE(result); + return NT_STATUS_NO_MEMORY; + } + + result->srv_name_slash = talloc_asprintf_strupper_m( + result, "\\\\%s", result->desthost); + if (result->srv_name_slash == NULL) { + TALLOC_FREE(result); + return NT_STATUS_NO_MEMORY; + } + + result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN; + + result->binding_handle = rpccli_bh_create(result, NULL, table); + if (result->binding_handle == NULL) { + TALLOC_FREE(result); + return NT_STATUS_NO_MEMORY; + } + + if (np_cli != NULL) { + result->np_cli = np_cli; + DLIST_ADD_END(np_cli->pipe_list, result); + } + + *presult = result; + return NT_STATUS_OK; +} + /******************************************************************** Pipe description for a DEBUG ********************************************************************/ diff --git a/source3/rpc_client/rpc_client.h b/source3/rpc_client/rpc_client.h index 84422188a49..4cc037d567c 100644 --- a/source3/rpc_client/rpc_client.h +++ b/source3/rpc_client/rpc_client.h @@ -39,6 +39,9 @@ struct dcerpc_binding_handle; +struct rpc_client_association; +struct rpc_client_connection; + struct rpc_pipe_client { struct rpc_pipe_client *prev, *next; @@ -50,6 +53,12 @@ struct rpc_pipe_client { SOURCE3_LIBRPC_INTERNALS_BEGIN + struct cli_state *np_cli; + + struct rpc_client_association *assoc; + struct rpc_client_connection *conn; + struct pipe_auth_data *auth; + DATA_BLOB transport_session_key; struct rpc_cli_transport *transport; @@ -72,8 +81,6 @@ struct rpc_pipe_client { uint16_t max_xmit_frag; - struct pipe_auth_data *auth; - SOURCE3_LIBRPC_INTERNALS_END; };