]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:rpc_client: add struct rpc_client_{association,connection} and helpers
authorStefan Metzmacher <metze@samba.org>
Mon, 16 Sep 2024 19:56:50 +0000 (21:56 +0200)
committerJule Anger <janger@samba.org>
Thu, 12 Jun 2025 11:27:15 +0000 (11:27 +0000)
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 <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 327fe920d07e5bcbcaa0f09f276aad2b99d68235)

source3/rpc_client/cli_pipe.c
source3/rpc_client/rpc_client.h

index 86e437754f9ec07c07fa31145f43d6b23e258820..f2b64eaba0307b1d8e275a4a2b92f46de2fcd45e 100644 (file)
 #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
  ********************************************************************/
index 84422188a498444d1667e45eb247b131575c0e90..4cc037d567cb9dbaf2fdcd6a41115aaabca04f73 100644 (file)
@@ -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;
 };