mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
r2680: switched the libcli/raw/ code over to use talloc_reference(), which simplifies things quite a bit
This commit is contained in:
parent
9087fab0ad
commit
c82a9cf750
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user