From 8888f95947b67371696acfa9f76a61b55302d312 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 23 Nov 2023 14:51:48 +0100 Subject: [PATCH] s3:libsmb: Pass a memory context to cli_start_connection() Signed-off-by: Andreas Schneider Reviewed-by: Volker Lendecke --- source3/client/smbspool.c | 10 ++++++++-- source3/libsmb/cliconnect.c | 7 ++++--- source3/libsmb/proto.h | 3 ++- source3/torture/torture.c | 10 ++++++++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c index b3da87556d2..363f14a085f 100644 --- a/source3/client/smbspool.c +++ b/source3/client/smbspool.c @@ -544,8 +544,14 @@ smb_complete_connection(struct cli_state **output_cli, struct cli_credentials *creds = NULL; /* Start the SMB connection */ - nt_status = cli_start_connection(&cli, myname, server, NULL, port, - SMB_SIGNING_DEFAULT, 0); + nt_status = cli_start_connection(talloc_tos(), + &cli, + myname, + server, + NULL, + port, + SMB_SIGNING_DEFAULT, + 0); if (!NT_STATUS_IS_OK(nt_status)) { fprintf(stderr, "ERROR: Connection failed: %s\n", nt_errstr(nt_status)); return nt_status; diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 327848bbdef..8ac22ba2ae8 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -2961,7 +2961,8 @@ static NTSTATUS cli_start_connection_recv(struct tevent_req *req, return NT_STATUS_OK; } -NTSTATUS cli_start_connection(struct cli_state **output_cli, +NTSTATUS cli_start_connection(TALLOC_CTX *mem_ctx, + struct cli_state **output_cli, const char *my_name, const char *dest_host, const struct sockaddr_storage *dest_ss, int port, @@ -2971,7 +2972,7 @@ NTSTATUS cli_start_connection(struct cli_state **output_cli, struct tevent_req *req; NTSTATUS status = NT_STATUS_NO_MEMORY; - ev = samba_tevent_context_init(talloc_tos()); + ev = samba_tevent_context_init(mem_ctx); if (ev == NULL) { goto fail; } @@ -2983,7 +2984,7 @@ NTSTATUS cli_start_connection(struct cli_state **output_cli, if (!tevent_req_poll_ntstatus(req, ev, &status)) { goto fail; } - status = cli_start_connection_recv(req, NULL, output_cli); + status = cli_start_connection_recv(req, mem_ctx, output_cli); fail: TALLOC_FREE(ev); return status; diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index ec24f411a4c..2f67cbfd074 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -91,7 +91,8 @@ NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx, enum smb_signing_setting signing_state, int flags, struct cli_state **pcli); -NTSTATUS cli_start_connection(struct cli_state **output_cli, +NTSTATUS cli_start_connection(TALLOC_CTX *mem_ctx, + struct cli_state **output_cli, const char *my_name, const char *dest_host, const struct sockaddr_storage *dest_ss, int port, diff --git a/source3/torture/torture.c b/source3/torture/torture.c index ca66a6db5fc..a154b528681 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -10644,8 +10644,14 @@ static bool run_chain2(int dummy) int flags = CLI_FULL_CONNECTION_FORCE_SMB1; printf("starting chain2 test\n"); - status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL, - port_to_use, SMB_SIGNING_DEFAULT, flags); + status = cli_start_connection(talloc_tos(), + &cli1, + lp_netbios_name(), + host, + NULL, + port_to_use, + SMB_SIGNING_DEFAULT, + flags); if (!NT_STATUS_IS_OK(status)) { return False; } -- 2.34.1