From e3880fa759cfa03222262327854fe7bbe585fe01 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 11:30:20 +0000 Subject: r2660: - converted the libcli/raw/ library to use talloc_increase_ref_count() rather than manual reference counts - properly support SMBexit in the cifs and posix backends - added a logoff method to all backends With these changes the RAW-CONTEXT test now passes against the posix backend (This used to be commit c315d6ac1cc40546fde1474702a6d66d07ee13c8) --- source4/libcli/raw/clitree.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'source4/libcli/raw/clitree.c') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index e3a1a6d341..e0072a31b1 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -26,6 +26,15 @@ if (!req) return NULL; \ } while (0) +/* + destroy a smbcli_tree +*/ +static int tree_destructor(void *ptr) +{ + struct smbcli_tree *tree = ptr; + talloc_free(tree->session); + return 0; +} /**************************************************************************** Initialize the tree context @@ -41,24 +50,11 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) ZERO_STRUCTP(tree); tree->session = session; - tree->session->reference_count++; + talloc_set_destructor(tree, tree_destructor); return tree; } -/**************************************************************************** -reduce reference count on a tree and destroy if <= 0 -****************************************************************************/ -void smbcli_tree_close(struct smbcli_tree *tree) -{ - if (!tree) return; - tree->reference_count--; - if (tree->reference_count <= 0) { - smbcli_session_close(tree->session); - } -} - - /**************************************************************************** Send a tconX (async send) ****************************************************************************/ @@ -202,7 +198,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, transport = smbcli_transport_init(sock); if (!transport) { - smbcli_sock_close(sock); + talloc_free(sock); return NT_STATUS_NO_MEMORY; } @@ -211,7 +207,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, choose_called_name(&called, dest_host, 0x20); if (!smbcli_transport_connect(transport, &calling, &called)) { - smbcli_transport_close(transport); + talloc_free(transport); return NT_STATUS_UNSUCCESSFUL; } @@ -219,13 +215,13 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, /* negotiate protocol options with the server */ status = smb_raw_negotiate(transport); if (!NT_STATUS_IS_OK(status)) { - smbcli_transport_close(transport); + talloc_free(transport); return status; } session = smbcli_session_init(transport); if (!session) { - smbcli_transport_close(transport); + talloc_free(transport); return NT_STATUS_NO_MEMORY; } @@ -251,7 +247,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, status = smb_raw_session_setup(session, mem_ctx, &setup); if (!NT_STATUS_IS_OK(status)) { - smbcli_session_close(session); + talloc_free(session); talloc_free(mem_ctx); return status; } @@ -260,7 +256,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree = smbcli_tree_init(session); if (!tree) { - smbcli_session_close(session); + talloc_free(session); talloc_free(mem_ctx); return NT_STATUS_NO_MEMORY; } @@ -284,7 +280,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, SAFE_FREE(in_path); if (!NT_STATUS_IS_OK(status)) { - smbcli_tree_close(tree); + talloc_free(tree); talloc_free(mem_ctx); return status; } -- cgit