From: Stefan Metzmacher Date: Mon, 16 Sep 2024 20:01:06 +0000 (+0200) Subject: s3:rpc_client: convert rpc_pipe_open_local_np() to rpc_client_{association,connection} X-Git-Tag: samba-4.21.7~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f81ee3b6d0fd8e5d06c1c800e2e41f7b7fe999b2;p=thirdparty%2Fsamba.git s3:rpc_client: convert rpc_pipe_open_local_np() to rpc_client_{association,connection} For rpc_pipe_open_local_np() it's not really important to abstract these out, but we want to have these for all... Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme (cherry picked from commit 338dd71cc39195fcf25977b40b9772775972bc9f) --- diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c index ce3cc2ad815..d89e2b2b11c 100644 --- a/source3/rpc_client/cli_pipe.c +++ b/source3/rpc_client/cli_pipe.c @@ -3349,42 +3349,59 @@ NTSTATUS rpc_pipe_open_local_np( const struct auth_session_info *session_info, struct rpc_pipe_client **presult) { + TALLOC_CTX *frame = talloc_stackframe(); + struct rpc_client_association *assoc = NULL; + struct rpc_client_connection *conn = NULL; struct rpc_pipe_client *result = NULL; struct pipe_auth_data *auth = NULL; + struct samba_sockaddr saddr = { .sa_socklen = 0, }; const char *pipe_name = NULL; struct tstream_context *npa_stream = NULL; NTSTATUS status = NT_STATUS_NO_MEMORY; int ret; - result = talloc_zero(mem_ctx, struct rpc_pipe_client); - if (result == NULL) { - goto fail; - } - result->abstract_syntax = table->syntax_id; - result->transfer_syntax = ndr_transfer_syntax_ndr; - result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN; - - pipe_name = dcerpc_default_transport_endpoint( - result, NCACN_NP, table); + pipe_name = dcerpc_default_transport_endpoint(frame, + NCACN_NP, + table); if (pipe_name == NULL) { DBG_DEBUG("dcerpc_default_transport_endpoint failed\n"); - status = NT_STATUS_OBJECT_NAME_NOT_FOUND; - goto fail; + TALLOC_FREE(frame); + return NT_STATUS_OBJECT_NAME_NOT_FOUND; } if (local_server_name == NULL) { - result->desthost = get_myname(result); - } else { - result->desthost = talloc_strdup(result, local_server_name); + local_server_name = get_myname(result); } - if (result->desthost == NULL) { - goto fail; + + if (local_server_addr != NULL) { + saddr.sa_socklen = tsocket_address_bsd_sockaddr(local_server_addr, + &saddr.u.sa, + sizeof(saddr.u.ss)); + if (saddr.sa_socklen == -1) { + status = map_nt_error_from_unix(errno); + TALLOC_FREE(frame); + return status; + } } - result->srv_name_slash = talloc_asprintf_strupper_m( - result, "\\\\%s", result->desthost); - if (result->srv_name_slash == NULL) { - goto fail; + + status = rpc_client_association_create(mem_ctx, + local_server_name, + NCACN_NP, + &saddr, + pipe_name, + &assoc); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(frame); + return status; + } + talloc_steal(frame, assoc); + + status = rpc_client_connection_create(mem_ctx, &conn); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(frame); + return status; } + talloc_steal(frame, conn); ret = local_np_connect( pipe_name, @@ -3395,7 +3412,7 @@ NTSTATUS rpc_pipe_open_local_np( local_server_addr, session_info, true, - result, + conn, &npa_stream); if (ret != 0) { DBG_DEBUG("local_np_connect for %s and " @@ -3405,43 +3422,51 @@ NTSTATUS rpc_pipe_open_local_np( session_info->info->account_name, strerror(ret)); status = map_nt_error_from_unix(ret); - goto fail; + TALLOC_FREE(frame); + return status; } - status = rpc_transport_tstream_init( - result, &npa_stream, &result->transport); + status = rpc_transport_tstream_init(conn, + &npa_stream, + &conn->transport); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("rpc_transport_tstream_init failed: %s\n", nt_errstr(status)); - goto fail; + TALLOC_FREE(frame); + return status; } + conn->transport->transport = NCACN_NP; - result->binding_handle = rpccli_bh_create(result, NULL, table); - if (result->binding_handle == NULL) { - status = NT_STATUS_NO_MEMORY; - DBG_DEBUG("Failed to create binding handle.\n"); - goto fail; + status = rpc_pipe_wrap_create(table, + NULL, + &assoc, + &conn, + mem_ctx, + &result); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(frame); + return status; } + talloc_steal(frame, result); status = rpccli_anon_bind_data(result, &auth); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("rpccli_anon_bind_data failed: %s\n", nt_errstr(status)); - goto fail; + TALLOC_FREE(frame); + return status; } status = rpc_pipe_bind(result, auth); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("rpc_pipe_bind failed: %s\n", nt_errstr(status)); - goto fail; + TALLOC_FREE(frame); + return status; } - *presult = result; + *presult = talloc_move(mem_ctx, &result); + TALLOC_FREE(frame); return NT_STATUS_OK; - -fail: - TALLOC_FREE(result); - return status; } struct rpc_pipe_client_np_ref {