summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-27 08:41:39 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:21 -0500
commitaa12305945df5f1578250b56ae2f3653b051736f (patch)
tree30e072fca46873f0d59d736d65b96096326eec2a
parent3aa3428bc93e6c8741b52eaa65d43f3a5abcee2e (diff)
downloadsamba-aa12305945df5f1578250b56ae2f3653b051736f.tar.gz
samba-aa12305945df5f1578250b56ae2f3653b051736f.tar.bz2
samba-aa12305945df5f1578250b56ae2f3653b051736f.zip
r2680: switched the libcli/raw/ code over to use talloc_reference(), which simplifies things quite a bit
(This used to be commit c82a9cf750829c4f6982ca3133295c8599023c4e)
-rw-r--r--source4/libcli/cliconnect.c15
-rw-r--r--source4/libcli/raw/clisession.c14
-rw-r--r--source4/libcli/raw/clitransport.c3
-rw-r--r--source4/libcli/raw/clitree.c22
-rw-r--r--source4/librpc/rpc/dcerpc_smb.c22
-rw-r--r--source4/rpc_server/samr/samdb.c3
-rw-r--r--source4/torture/basic/secleak.c7
-rw-r--r--source4/torture/raw/context.c5
-rw-r--r--source4/torture/rpc/echo.c2
9 files changed, 26 insertions, 67 deletions
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index f772070305..aa6aec4a1e 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -36,8 +36,8 @@ BOOL smbcli_socket_connect(struct smbcli_state *cli, const char *server)
}
cli->transport = smbcli_transport_init(sock);
+ talloc_free(sock);
if (!cli->transport) {
- talloc_free(sock);
return False;
}
@@ -60,9 +60,9 @@ NTSTATUS smbcli_negprot(struct smbcli_state *cli)
/* wrapper around smb_raw_session_setup() */
NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
- const char *user,
- const char *password,
- const char *domain)
+ const char *user,
+ const char *password,
+ const char *domain)
{
union smb_sesssetup setup;
NTSTATUS status;
@@ -70,6 +70,7 @@ NTSTATUS smbcli_session_setup(struct smbcli_state *cli,
cli->session = smbcli_session_init(cli->transport);
if (!cli->session) return NT_STATUS_UNSUCCESSFUL;
+ talloc_free(cli->transport);
mem_ctx = talloc_init("smbcli_session_setup");
if (!mem_ctx) return NT_STATUS_NO_MEMORY;
@@ -110,6 +111,7 @@ NTSTATUS smbcli_send_tconX(struct smbcli_state *cli, const char *sharename,
NTSTATUS status;
cli->tree = smbcli_tree_init(cli->session);
+ talloc_free(cli->session);
if (!cli->tree) return NT_STATUS_UNSUCCESSFUL;
mem_ctx = talloc_init("tcon");
@@ -183,7 +185,8 @@ NTSTATUS smbcli_full_connection(struct smbcli_state **ret_cli,
(*ret_cli) = smbcli_state_init();
- (*ret_cli)->tree = tree;
+ (*ret_cli)->tree = talloc_reference(*ret_cli, tree);
+ talloc_free(tree);
(*ret_cli)->session = tree->session;
(*ret_cli)->transport = tree->session->transport;
@@ -221,7 +224,5 @@ struct smbcli_state *smbcli_state_init(void)
****************************************************************************/
void smbcli_shutdown(struct smbcli_state *cli)
{
- if (!cli) return;
- talloc_free(cli->tree);
talloc_free(cli);
}
diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c
index 0c6c80d94c..431d225021 100644
--- a/source4/libcli/raw/clisession.c
+++ b/source4/libcli/raw/clisession.c
@@ -27,16 +27,6 @@
} while (0)
-/*
- destroy a smbcli_session
-*/
-static int session_destroy(void *ptr)
-{
- struct smbcli_session *session = ptr;
- talloc_free(session->transport);
- return 0;
-}
-
/****************************************************************************
Initialize the session context
****************************************************************************/
@@ -50,12 +40,10 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport)
}
ZERO_STRUCTP(session);
- session->transport = transport;
+ session->transport = talloc_reference(session, transport);
session->pid = (uint16_t)getpid();
session->vuid = UID_FIELD_INVALID;
- talloc_set_destructor(session, session_destroy);
-
return session;
}
diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c
index eb1d3631ee..f06f2c57ff 100644
--- a/source4/libcli/raw/clitransport.c
+++ b/source4/libcli/raw/clitransport.c
@@ -52,7 +52,6 @@ static int transport_destructor(void *ptr)
event_remove_fd(transport->event.ctx, transport->event.fde);
event_remove_timed(transport->event.ctx, transport->event.te);
event_context_destroy(transport->event.ctx);
- talloc_free(transport->socket);
return 0;
}
@@ -75,7 +74,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock)
return NULL;
}
- transport->socket = sock;
+ transport->socket = talloc_reference(transport, sock);
transport->negotiate.protocol = PROTOCOL_NT1;
transport->options.use_spnego = lp_use_spnego();
transport->negotiate.max_xmit = ~0;
diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c
index e0072a31b1..f19cbf8e28 100644
--- a/source4/libcli/raw/clitree.c
+++ b/source4/libcli/raw/clitree.c
@@ -26,16 +26,6 @@
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
****************************************************************************/
@@ -49,8 +39,7 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session)
}
ZERO_STRUCTP(tree);
- tree->session = session;
- talloc_set_destructor(tree, tree_destructor);
+ tree->session = talloc_reference(tree, session);
return tree;
}
@@ -188,17 +177,16 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
return NT_STATUS_NO_MEMORY;
}
- talloc_set_name_const(sock, "smbcli_tree_full_connection");
-
/* open a TCP socket to the server */
if (!smbcli_sock_connect_byname(sock, dest_host, port)) {
+ talloc_free(sock);
DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno)));
return NT_STATUS_UNSUCCESSFUL;
}
transport = smbcli_transport_init(sock);
+ talloc_free(sock);
if (!transport) {
- talloc_free(sock);
return NT_STATUS_NO_MEMORY;
}
@@ -220,8 +208,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
}
session = smbcli_session_init(transport);
+ talloc_free(transport);
if (!session) {
- talloc_free(transport);
return NT_STATUS_NO_MEMORY;
}
@@ -255,8 +243,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree,
session->vuid = setup.generic.out.vuid;
tree = smbcli_tree_init(session);
+ talloc_free(session);
if (!tree) {
- talloc_free(session);
talloc_free(mem_ctx);
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/librpc/rpc/dcerpc_smb.c b/source4/librpc/rpc/dcerpc_smb.c
index 7000bcd20d..893093c050 100644
--- a/source4/librpc/rpc/dcerpc_smb.c
+++ b/source4/librpc/rpc/dcerpc_smb.c
@@ -334,7 +334,7 @@ static NTSTATUS smb_shutdown_pipe(struct dcerpc_pipe *p)
c.close.in.fnum = smb->fnum;
c.close.in.write_time = 0;
smb_raw_close(smb->tree, &c);
- talloc_free(smb->tree);
+ talloc_free(smb);
return NT_STATUS_OK;
}
@@ -371,15 +371,14 @@ NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe **p,
{
struct smb_private *smb;
NTSTATUS status;
- char *name = NULL;
+ char *name;
union smb_open io;
- TALLOC_CTX *mem_ctx;
- asprintf(&name, "\\%s", pipe_name);
+ name = talloc_asprintf(tree, "\\%s", pipe_name);
if (!name) {
return NT_STATUS_NO_MEMORY;
}
-
+
io.ntcreatex.level = RAW_OPEN_NTCREATEX;
io.ntcreatex.in.flags = 0;
io.ntcreatex.in.root_fid = 0;
@@ -400,14 +399,8 @@ NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe **p,
io.ntcreatex.in.security_flags = 0;
io.ntcreatex.in.fname = name;
- mem_ctx = talloc_init("torture_rpc_connection");
- if (!mem_ctx) {
- free(name);
- return NT_STATUS_NO_MEMORY;
- }
- status = smb_raw_open(tree, mem_ctx, &io);
- free(name);
- talloc_free(mem_ctx);
+ status = smb_raw_open(tree, name, &io);
+ talloc_free(name);
if (!NT_STATUS_IS_OK(status)) {
return status;
@@ -440,10 +433,9 @@ NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe **p,
}
smb->fnum = io.ntcreatex.out.fnum;
- smb->tree = tree;
+ smb->tree = talloc_reference(smb, tree);
(*p)->transport.private = smb;
- talloc_increase_ref_count(tree);
return NT_STATUS_OK;
}
diff --git a/source4/rpc_server/samr/samdb.c b/source4/rpc_server/samr/samdb.c
index 33c4eec86a..4160ef78fc 100644
--- a/source4/rpc_server/samr/samdb.c
+++ b/source4/rpc_server/samr/samdb.c
@@ -68,8 +68,7 @@ void *samdb_connect(TALLOC_CTX *mem_ctx)
second open due to the broken nature of unix locking.
*/
if (ctx != NULL) {
- talloc_increase_ref_count(ctx);
- return ctx;
+ return talloc_reference(mem_ctx, ctx);
}
ctx = talloc_p(mem_ctx, struct samdb_context);
diff --git a/source4/torture/basic/secleak.c b/source4/torture/basic/secleak.c
index 54fa3ecee6..998faec54e 100644
--- a/source4/torture/basic/secleak.c
+++ b/source4/torture/basic/secleak.c
@@ -27,7 +27,6 @@ static BOOL try_failed_login(struct smbcli_state *cli)
NTSTATUS status;
union smb_sesssetup setup;
struct smbcli_session *session;
- TALLOC_CTX *mem_ctx = talloc_init("failed_login");
session = smbcli_session_init(cli->transport);
setup.generic.level = RAW_SESSSETUP_GENERIC;
@@ -37,15 +36,13 @@ static BOOL try_failed_login(struct smbcli_state *cli)
setup.generic.in.user = "INVALID-USERNAME";
setup.generic.in.domain = "INVALID-DOMAIN";
- status = smb_raw_session_setup(session, mem_ctx, &setup);
+ status = smb_raw_session_setup(session, session, &setup);
+ talloc_free(session);
if (NT_STATUS_IS_OK(status)) {
printf("Allowed session setup with invalid credentials?!\n");
return False;
}
- talloc_free(session);
- talloc_free(mem_ctx);
-
return True;
}
diff --git a/source4/torture/raw/context.c b/source4/torture/raw/context.c
index 194d2de93b..b5f439b5e9 100644
--- a/source4/torture/raw/context.c
+++ b/source4/torture/raw/context.c
@@ -81,7 +81,6 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("create a second security context on the same transport\n");
session = smbcli_session_init(cli->transport);
- talloc_increase_ref_count(cli->transport);
setup.generic.level = RAW_SESSSETUP_GENERIC;
setup.generic.in.sesskey = cli->transport->negotiate.sesskey;
@@ -97,7 +96,6 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("create a third security context on the same transport, with vuid set\n");
session2 = smbcli_session_init(cli->transport);
- talloc_increase_ref_count(cli->transport);
session2->vuid = session->vuid;
setup.generic.level = RAW_SESSSETUP_GENERIC;
@@ -119,7 +117,6 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
if (cli->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) {
printf("create a fourth security context on the same transport, without extended security\n");
session3 = smbcli_session_init(cli->transport);
- talloc_increase_ref_count(cli->transport);
session3->vuid = session->vuid;
setup.generic.level = RAW_SESSSETUP_GENERIC;
@@ -137,7 +134,6 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("use the same tree as the existing connection\n");
tree = smbcli_tree_init(session);
- talloc_increase_ref_count(session);
tree->tid = cli->tree->tid;
printf("create a file using the new vuid\n");
@@ -228,7 +224,6 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("create a second tree context on the same session\n");
tree = smbcli_tree_init(cli->session);
- talloc_increase_ref_count(cli->session);
tcon.generic.level = RAW_TCON_TCONX;
tcon.tconx.in.flags = 0;
diff --git a/source4/torture/rpc/echo.c b/source4/torture/rpc/echo.c
index 707b0d0313..7d12c1b7f3 100644
--- a/source4/torture/rpc/echo.c
+++ b/source4/torture/rpc/echo.c
@@ -308,7 +308,7 @@ BOOL torture_rpc_echo(int dummy)
*/
printf("\n");
- talloc_destroy(mem_ctx);
+ talloc_free(mem_ctx);
torture_rpc_close(p);
return ret;