diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-08-21 07:43:29 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:58:14 -0500 |
commit | b7e1ea20dc873a753ff64653987130f03897a4e9 (patch) | |
tree | 67f37a1a19113c622dedf942f39b27ca994c1b05 /source4/libcli/raw | |
parent | b45f4ebbb880e41abf86abb54264123f3edbde05 (diff) | |
download | samba-b7e1ea20dc873a753ff64653987130f03897a4e9.tar.gz samba-b7e1ea20dc873a753ff64653987130f03897a4e9.tar.bz2 samba-b7e1ea20dc873a753ff64653987130f03897a4e9.zip |
r1985: take advantage of the new talloc in a few more places
(This used to be commit 6ffdfd779936ce8c5ca49c5f444e8da2bbeee0a8)
Diffstat (limited to 'source4/libcli/raw')
-rw-r--r-- | source4/libcli/raw/clisession.c | 13 | ||||
-rw-r--r-- | source4/libcli/raw/clisocket.c | 23 | ||||
-rw-r--r-- | source4/libcli/raw/clitransport.c | 15 | ||||
-rw-r--r-- | source4/libcli/raw/clitree.c | 15 | ||||
-rw-r--r-- | source4/libcli/raw/rawnegotiate.c | 10 |
5 files changed, 27 insertions, 49 deletions
diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 0ee631a549..af8a63328c 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -32,18 +32,13 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) { struct smbcli_session *session; - TALLOC_CTX *mem_ctx = talloc_init("smbcli_session"); - if (mem_ctx == NULL) { - return NULL; - } - session = talloc_zero(mem_ctx, sizeof(*session)); + session = talloc_named(NULL, sizeof(*session), "smbcli_session"); if (!session) { - talloc_destroy(mem_ctx); return NULL; } - session->mem_ctx = mem_ctx; + ZERO_STRUCTP(session); session->transport = transport; session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; @@ -60,7 +55,7 @@ void smbcli_session_close(struct smbcli_session *session) session->reference_count--; if (session->reference_count <= 0) { smbcli_transport_close(session->transport); - talloc_destroy(session->mem_ctx); + talloc_free(session); } } @@ -242,7 +237,7 @@ static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) void smbcli_session_set_user_session_key(struct smbcli_session *session, const DATA_BLOB *session_key) { - session->user_session_key = data_blob_talloc(session->mem_ctx, + session->user_session_key = data_blob_talloc(session, session_key->data, session_key->length); } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 2bb50d200f..94bb447f47 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -28,18 +28,13 @@ struct smbcli_socket *smbcli_sock_init(void) { struct smbcli_socket *sock; - TALLOC_CTX *mem_ctx; - mem_ctx = talloc_init("smbcli_socket"); - if (!mem_ctx) return NULL; - - sock = talloc_zero(mem_ctx, sizeof(*sock)); + sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket"); if (!sock) { - talloc_destroy(mem_ctx); return NULL; } - sock->mem_ctx = mem_ctx; + ZERO_STRUCTP(sock); sock->fd = -1; sock->port = 0; /* 20 second default timeout */ @@ -153,7 +148,6 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in { int name_type = 0x20; struct in_addr ip; - TALLOC_CTX *mem_ctx; char *name, *p; BOOL ret; @@ -162,10 +156,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in return sock->fd != -1; } - mem_ctx = talloc_init("smbcli_sock_connect_byname"); - if (!mem_ctx) return False; - - name = talloc_strdup(mem_ctx, host); + name = talloc_strdup(sock, host); /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { @@ -173,18 +164,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(mem_ctx, name, &ip, name_type)) { - talloc_destroy(mem_ctx); + if (!resolve_name(name, name, &ip, name_type)) { + talloc_free(name); return False; } ret = smbcli_sock_connect(sock, &ip, port); if (ret) { - sock->hostname = talloc_steal(sock->mem_ctx, name); + sock->hostname = talloc_steal(sock, name); } - talloc_destroy(mem_ctx); + talloc_destroy(name); return ret; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 5766fde03a..cae8e2a3be 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -37,23 +37,20 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_e */ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) { - TALLOC_CTX *mem_ctx; struct smbcli_transport *transport; struct fd_event fde; - mem_ctx = talloc_init("smbcli_transport"); - if (!mem_ctx) return NULL; - - transport = talloc_zero(mem_ctx, sizeof(*transport)); + transport = talloc_named(NULL, sizeof(*transport), "smbcli_transport"); if (!transport) return NULL; + ZERO_STRUCTP(transport); + transport->event.ctx = event_context_init(); if (transport->event.ctx == NULL) { - talloc_destroy(mem_ctx); + talloc_destroy(transport); return NULL; } - transport->mem_ctx = mem_ctx; transport->socket = sock; transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); @@ -88,7 +85,7 @@ void smbcli_transport_close(struct smbcli_transport *transport) 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_destroy(transport->mem_ctx); + talloc_free(transport); } } @@ -456,7 +453,7 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) if (transport->recv_buffer.received == NBT_HDR_SIZE) { /* we've got a full header */ transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; - transport->recv_buffer.buffer = talloc(transport->mem_ctx, + transport->recv_buffer.buffer = talloc(transport, NBT_HDR_SIZE+transport->recv_buffer.req_size); if (transport->recv_buffer.buffer == NULL) { smbcli_transport_dead(transport); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 57e322da32..2d642a9a8c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -33,18 +33,13 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) { struct smbcli_tree *tree; - TALLOC_CTX *mem_ctx = talloc_init("smbcli_tree"); - if (mem_ctx == NULL) { - return NULL; - } - tree = talloc_zero(mem_ctx, sizeof(*tree)); + tree = talloc_named(NULL, sizeof(*tree), "smbcli_tree"); if (!tree) { - talloc_destroy(mem_ctx); return NULL; } - tree->mem_ctx = mem_ctx; + ZERO_STRUCTP(tree); tree->session = session; tree->session->reference_count++; @@ -60,7 +55,7 @@ void smbcli_tree_close(struct smbcli_tree *tree) tree->reference_count--; if (tree->reference_count <= 0) { smbcli_session_close(tree->session); - talloc_destroy(tree->mem_ctx); + talloc_free(tree); } } @@ -295,10 +290,10 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree->tid = tcon.tconx.out.cnum; if (tcon.tconx.out.dev_type) { - tree->device = talloc_strdup(tree->mem_ctx, tcon.tconx.out.dev_type); + tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type); } if (tcon.tconx.out.fs_type) { - tree->fs_type = talloc_strdup(tree->mem_ctx, tcon.tconx.out.fs_type); + tree->fs_type = talloc_strdup(tree, tcon.tconx.out.fs_type); } talloc_destroy(mem_ctx); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 5ec827eebb..fdc1d0eb60 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -130,14 +130,14 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) if (req->in.data_size < 16) { goto failed; } - transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data + 16, req->in.data_size - 16); + transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport, req->in.data, 16); + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data + 16, req->in.data_size - 16); } else { if (req->in.data_size < (transport->negotiate.key_len)) { goto failed; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); - smbcli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, transport->negotiate.key_len); + smbcli_req_pull_string(req, transport, &transport->negotiate.server_domain, req->in.data+transport->negotiate.key_len, req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); /* here comes the server name */ @@ -163,7 +163,7 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) { transport->negotiate.writebraw_supported = 1; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, req->in.data_size); } else { /* the old core protocol */ |