summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-08-21 07:43:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:14 -0500
commitb7e1ea20dc873a753ff64653987130f03897a4e9 (patch)
tree67f37a1a19113c622dedf942f39b27ca994c1b05
parentb45f4ebbb880e41abf86abb54264123f3edbde05 (diff)
downloadsamba-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)
-rw-r--r--source4/include/cli_context.h10
-rw-r--r--source4/lib/talloc.c39
-rw-r--r--source4/libcli/cliconnect.c14
-rw-r--r--source4/libcli/raw/clisession.c13
-rw-r--r--source4/libcli/raw/clisocket.c23
-rw-r--r--source4/libcli/raw/clitransport.c15
-rw-r--r--source4/libcli/raw/clitree.c15
-rw-r--r--source4/libcli/raw/rawnegotiate.c10
-rw-r--r--source4/librpc/ndr/libndr.h9
-rw-r--r--source4/librpc/ndr/ndr.c109
-rw-r--r--source4/librpc/ndr/ndr_basic.c22
-rw-r--r--source4/librpc/ndr/ndr_sec.c2
-rw-r--r--source4/torture/basic/aliases.c10
-rw-r--r--source4/utils/ndrdump.c12
14 files changed, 148 insertions, 155 deletions
diff --git a/source4/include/cli_context.h b/source4/include/cli_context.h
index 9013d3d071..a2816e2cbb 100644
--- a/source4/include/cli_context.h
+++ b/source4/include/cli_context.h
@@ -63,8 +63,6 @@ struct smbcli_negotiate {
/* this is the context for a SMB socket associated with the socket itself */
struct smbcli_socket {
- TALLOC_CTX *mem_ctx; /* life of socket pool */
-
/* when the reference count reaches zero then the socket is destroyed */
int reference_count;
@@ -101,8 +99,6 @@ struct smbcli_options {
/* this is the context for the client transport layer */
struct smbcli_transport {
- TALLOC_CTX *mem_ctx;
-
/* when the reference count reaches zero then the transport is destroyed */
int reference_count;
@@ -188,8 +184,6 @@ struct smbcli_transport {
/* this is the context for the session layer */
struct smbcli_session {
- TALLOC_CTX *mem_ctx; /* life of session */
-
/* when the reference count reaches zero then the session is destroyed */
int reference_count;
@@ -213,9 +207,6 @@ struct smbcli_session {
smbcli_tree context: internal state for a tree connection.
*/
struct smbcli_tree {
- /* life of tree tree */
- TALLOC_CTX *mem_ctx;
-
/* when the reference count reaches zero then the tree is destroyed */
int reference_count;
@@ -296,7 +287,6 @@ struct smbcli_request {
i.e. a single session on a single socket.
*/
struct smbcli_state {
- TALLOC_CTX *mem_ctx; /* life of client pool */
struct smbcli_transport *transport;
struct smbcli_session *session;
struct smbcli_tree *tree;
diff --git a/source4/lib/talloc.c b/source4/lib/talloc.c
index 8a67f83a7f..b01bcb27c8 100644
--- a/source4/lib/talloc.c
+++ b/source4/lib/talloc.c
@@ -20,6 +20,10 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/*
+ inspired by http://swapped.cc/halloc/
+*/
+
#include "includes.h"
#define MAX_TALLOC_SIZE 0x10000000
@@ -81,24 +85,49 @@ void *talloc(void *context, size_t size)
/*
- create a named talloc pointer
+ add a name to an existing pointer - va_list version
+*/
+static void talloc_set_name_v(void *ptr, const char *fmt, va_list ap)
+{
+ struct talloc_chunk *tc;
+
+ tc = ((struct talloc_chunk *)ptr)-1;
+ if (tc->magic != TALLOC_MAGIC) {
+ return;
+ }
+
+ vasprintf(&tc->name, fmt, ap);
+}
+
+/*
+ add a name to an existing pointer
+*/
+void talloc_set_name(void *ptr, const char *fmt, ...) _PRINTF_ATTRIBUTE(2,3)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ talloc_set_name_v(ptr, fmt, ap);
+ va_end(ap);
+}
+
+/*
+ create a named talloc pointer. Any talloc pointer can be named, and
+ talloc_named() operates just like talloc() except that it allows you
+ to name the pointer.
*/
void *talloc_named(void *context, size_t size,
const char *fmt, ...) _PRINTF_ATTRIBUTE(3,4)
{
va_list ap;
void *ptr;
- struct talloc_chunk *tc;
ptr = talloc(context, size);
if (ptr == NULL) {
return NULL;
}
- tc = ((struct talloc_chunk *)ptr)-1;
-
va_start(ap, fmt);
- vasprintf(&tc->name, fmt, ap);
+ talloc_set_name_v(ptr, fmt, ap);
va_end(ap);
return ptr;
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c
index 14f7d5a1b3..d89925eda5 100644
--- a/source4/libcli/cliconnect.c
+++ b/source4/libcli/cliconnect.c
@@ -195,13 +195,11 @@ NTSTATUS smbcli_tdis(struct smbcli_state *cli)
struct smbcli_state *smbcli_state_init(void)
{
struct smbcli_state *cli;
- TALLOC_CTX *mem_ctx;
-
- mem_ctx = talloc_init("smbcli_state");
- if (!mem_ctx) return NULL;
- cli = talloc_zero(mem_ctx, sizeof(*cli));
- cli->mem_ctx = mem_ctx;
+ cli = talloc_named(NULL, sizeof(*cli), "smbcli_state");
+ if (cli) {
+ ZERO_STRUCTP(cli);
+ }
return cli;
}
@@ -216,7 +214,5 @@ void smbcli_shutdown(struct smbcli_state *cli)
cli->tree->reference_count++;
smbcli_tree_close(cli->tree);
}
- if (cli->mem_ctx) {
- talloc_destroy(cli->mem_ctx);
- }
+ talloc_free(cli);
}
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 */
diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h
index 68713cdae2..cea7290577 100644
--- a/source4/librpc/ndr/libndr.h
+++ b/source4/librpc/ndr/libndr.h
@@ -45,7 +45,6 @@ struct ndr_pull {
char *data;
uint32_t data_size;
uint32_t offset;
- TALLOC_CTX *mem_ctx;
struct ndr_token_list *relative_list;
@@ -66,7 +65,6 @@ struct ndr_push {
char *data;
uint32_t alloc_size;
uint32_t offset;
- TALLOC_CTX *mem_ctx;
struct ndr_token_list *relative_list;
@@ -83,7 +81,6 @@ struct ndr_push_save {
/* structure passed to functions that print IDL structures */
struct ndr_print {
uint32_t flags; /* LIBNDR_FLAG_* */
- TALLOC_CTX *mem_ctx;
uint32_t depth;
void (*print)(struct ndr_print *, const char *, ...);
void *private;
@@ -191,7 +188,7 @@ enum ndr_err_code {
#define NDR_ALLOC_SIZE(ndr, s, size) do { \
- (s) = talloc(ndr->mem_ctx, size); \
+ (s) = talloc(ndr, size); \
if ((size) && !(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, \
"Alloc %u failed\n", \
size); \
@@ -204,7 +201,7 @@ enum ndr_err_code {
if ((n) == 0) { \
(s) = NULL; \
} else { \
- (s) = talloc(ndr->mem_ctx, (n) * elsize); \
+ (s) = talloc(ndr, (n) * elsize); \
if (!(s)) return ndr_pull_error(ndr, \
NDR_ERR_ALLOC, \
"Alloc %u * %u failed\n", \
@@ -216,7 +213,7 @@ enum ndr_err_code {
#define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \
- (s) = talloc(ndr->mem_ctx, size); \
+ (s) = talloc(ndr, size); \
if ((size) && !(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, \
"push alloc %u failed\n",\
size); \
diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c
index cbb1046281..32836c9411 100644
--- a/source4/librpc/ndr/ndr.c
+++ b/source4/librpc/ndr/ndr.c
@@ -54,7 +54,6 @@ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
ndr->data = blob->data;
ndr->data_size = blob->length;
ndr->offset = 0;
- ndr->mem_ctx = mem_ctx;
ndr->ptr_count = 0;
ndr->relative_list = NULL;
@@ -130,10 +129,9 @@ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
return NULL;
}
- ndr->mem_ctx = mem_ctx;
ndr->flags = 0;
ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
- ndr->data = talloc(ndr->mem_ctx, ndr->alloc_size);
+ ndr->data = talloc(ndr, ndr->alloc_size);
if (!ndr->data) {
return NULL;
}
@@ -161,7 +159,7 @@ struct ndr_push *ndr_push_init(void)
/* free a ndr_push structure */
void ndr_push_free(struct ndr_push *ndr)
{
- talloc_destroy(ndr->mem_ctx);
+ talloc_destroy(ndr);
}
@@ -309,15 +307,15 @@ void ndr_print_debug(void (*fn)(struct ndr_print *, const char *, void *),
const char *name,
void *ptr)
{
- struct ndr_print ndr;
+ struct ndr_print *ndr;
- ndr.mem_ctx = talloc_init("ndr_print_debug");
- if (!ndr.mem_ctx) return;
- ndr.print = ndr_print_debug_helper;
- ndr.depth = 1;
- ndr.flags = 0;
- fn(&ndr, name, ptr);
- talloc_destroy(ndr.mem_ctx);
+ ndr = talloc_p(NULL, struct ndr_print);
+ if (!ndr) return;
+ ndr->print = ndr_print_debug_helper;
+ ndr->depth = 1;
+ ndr->flags = 0;
+ fn(ndr, name, ptr);
+ talloc_free(ndr);
}
@@ -329,15 +327,15 @@ void ndr_print_union_debug(void (*fn)(struct ndr_print *, const char *, uint32_t
uint32_t level,
void *ptr)
{
- struct ndr_print ndr;
+ struct ndr_print *ndr;
- ndr.mem_ctx = talloc_init("ndr_print_union");
- if (!ndr.mem_ctx) return;
- ndr.print = ndr_print_debug_helper;
- ndr.depth = 1;
- ndr.flags = 0;
- fn(&ndr, name, level, ptr);
- talloc_destroy(ndr.mem_ctx);
+ ndr = talloc_p(NULL, struct ndr_print);
+ if (!ndr) return;
+ ndr->print = ndr_print_debug_helper;
+ ndr->depth = 1;
+ ndr->flags = 0;
+ fn(ndr, name, level, ptr);
+ talloc_free(ndr);
}
/*
@@ -348,15 +346,15 @@ void ndr_print_function_debug(void (*fn)(struct ndr_print *, const char *, int ,
int flags,
void *ptr)
{
- struct ndr_print ndr;
+ struct ndr_print *ndr;
- ndr.mem_ctx = talloc_init("ndr_print_function");
- if (!ndr.mem_ctx) return;
- ndr.print = ndr_print_debug_helper;
- ndr.depth = 1;
- ndr.flags = 0;
- fn(&ndr, name, flags, ptr);
- talloc_destroy(ndr.mem_ctx);
+ ndr = talloc_p(NULL, struct ndr_print);
+ if (!ndr) return;
+ ndr->print = ndr_print_debug_helper;
+ ndr->depth = 1;
+ ndr->flags = 0;
+ fn(ndr, name, flags, ptr);
+ talloc_free(ndr);
}
@@ -460,14 +458,14 @@ NTSTATUS ndr_pull_subcontext_fn(struct ndr_pull *ndr,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, void *))
{
- struct ndr_pull ndr2;
-
- NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
- NDR_CHECK(fn(&ndr2, base));
+ struct ndr_pull *ndr2;
+ NDR_ALLOC(ndr, ndr2);
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
+ NDR_CHECK(fn(ndr2, base));
if (sub_size) {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
}
return NT_STATUS_OK;
}
@@ -478,14 +476,14 @@ NTSTATUS ndr_pull_subcontext_flags_fn(struct ndr_pull *ndr,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , void *))
{
- struct ndr_pull ndr2;
-
- NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
- NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, base));
+ struct ndr_pull *ndr2;
+ NDR_ALLOC(ndr, ndr2);
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
+ NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, base));
if (sub_size) {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
}
return NT_STATUS_OK;
}
@@ -496,14 +494,15 @@ NTSTATUS ndr_pull_subcontext_union_fn(struct ndr_pull *ndr,
void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , uint32_t , void *))
{
- struct ndr_pull ndr2;
+ struct ndr_pull *ndr2;
- NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2));
- NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, level, base));
+ NDR_ALLOC(ndr, ndr2);
+ NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
+ NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, level, base));
if (sub_size) {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else {
- NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset));
+ NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
}
return NT_STATUS_OK;
}
@@ -546,7 +545,7 @@ NTSTATUS ndr_push_subcontext_fn(struct ndr_push *ndr,
{
struct ndr_push *ndr2;
- ndr2 = ndr_push_init_ctx(ndr->mem_ctx);
+ ndr2 = ndr_push_init_ctx(ndr);
if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags;
@@ -566,7 +565,7 @@ NTSTATUS ndr_push_subcontext_flags_fn(struct ndr_push *ndr,
{
struct ndr_push *ndr2;
- ndr2 = ndr_push_init_ctx(ndr->mem_ctx);
+ ndr2 = ndr_push_init_ctx(ndr);
if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags;
@@ -587,7 +586,7 @@ NTSTATUS ndr_push_subcontext_union_fn(struct ndr_push *ndr,
{
struct ndr_push *ndr2;
- ndr2 = ndr_push_init_ctx(ndr->mem_ctx);
+ ndr2 = ndr_push_init_ctx(ndr);
if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags;
@@ -635,11 +634,12 @@ void ndr_push_struct_end(struct ndr_push *ndr)
NTSTATUS ndr_pull_relative(struct ndr_pull *ndr, const void **buf, size_t size,
NTSTATUS (*fn)(struct ndr_pull *, int ndr_flags, void *))
{
- struct ndr_pull ndr2;
+ struct ndr_pull *ndr2;
uint32_t ofs;
struct ndr_pull_save save;
void *p;
+ NDR_ALLOC(ndr, ndr2);
NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
if (ofs == 0) {
(*buf) = NULL;
@@ -651,16 +651,17 @@ NTSTATUS ndr_pull_relative(struct ndr_pull *ndr, const void **buf, size_t size,
but I am keeping the code around in case I missed a
critical use for it (tridge, august 2004) */
NDR_CHECK(ndr_pull_set_offset(ndr, ofs));
- NDR_CHECK(ndr_pull_subcontext(ndr, &ndr2, ndr->data_size - ndr->offset));
+ NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, ndr->data_size - ndr->offset));
/* strings must be allocated by the backend functions */
if (ndr->flags & LIBNDR_STRING_FLAGS) {
- NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, &p));
+ NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, &p));
} else {
NDR_ALLOC_SIZE(ndr, p, size);
- NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, p));
+ NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, p));
}
(*buf) = p;
ndr_pull_restore(ndr, &save);
+ talloc_free(ndr2);
return NT_STATUS_OK;
}
@@ -706,7 +707,7 @@ static uint32_t ndr_token_retrieve(struct ndr_token_list **list, const void *key
*/
NTSTATUS ndr_pull_relative1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
{
- return ndr_token_store(ndr->mem_ctx, &ndr->relative_list, p, rel_offset);
+ return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
}
/*
@@ -734,7 +735,7 @@ NTSTATUS ndr_push_relative1(struct ndr_push *ndr, const void *p)
return NT_STATUS_OK;
}
NDR_CHECK(ndr_push_align(ndr, 4));
- NDR_CHECK(ndr_token_store(ndr->mem_ctx, &ndr->relative_list, p, ndr->offset));
+ NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
return ndr_push_uint32(ndr, 0xFFFFFFFF);
}
diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c
index d495bf2946..43c469d4c5 100644
--- a/source4/librpc/ndr/ndr_basic.c
+++ b/source4/librpc/ndr/ndr_basic.c
@@ -443,11 +443,11 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
len1, ofs, len2);
}
if (len2 == 0) {
- *s = talloc_strdup(ndr->mem_ctx, "");
+ *s = talloc_strdup(ndr, "");
break;
}
NDR_PULL_NEED_BYTES(ndr, len2*2);
- ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX,
+ ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset,
len2*2,
(const void **)&as);
@@ -476,10 +476,10 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
NDR_CHECK(ndr_pull_uint32(ndr, &len1));
NDR_PULL_NEED_BYTES(ndr, len1*2);
if (len1 == 0) {
- *s = talloc_strdup(ndr->mem_ctx, "");
+ *s = talloc_strdup(ndr, "");
break;
}
- ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX,
+ ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset,
len1*2,
(const void **)&as);
@@ -507,10 +507,10 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
NDR_CHECK(ndr_pull_uint16(ndr, &len3));
NDR_PULL_NEED_BYTES(ndr, len3);
if (len3 == 0) {
- *s = talloc_strdup(ndr->mem_ctx, "");
+ *s = talloc_strdup(ndr, "");
break;
}
- ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX,
+ ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset,
len3,
(const void **)&as);
@@ -528,7 +528,7 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
if (len1*2+2 <= ndr->data_size - ndr->offset) {
len1++;
}
- ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX,
+ ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset,
len1*2,
(const void **)&as);
@@ -855,7 +855,7 @@ void ndr_print_string(struct ndr_print *ndr, const char *name, const char *s)
void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t)
{
- ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr->mem_ctx, t));
+ ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr, t));
}
void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
@@ -863,7 +863,7 @@ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t)
if (t == (time_t)-1 || t == 0) {
ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
} else {
- ndr->print(ndr, "%-25s: %s", name, timestring(ndr->mem_ctx, t));
+ ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t));
}
}
@@ -1007,7 +1007,7 @@ const char *GUID_string(TALLOC_CTX *mem_ctx, const struct GUID *guid)
void ndr_print_GUID(struct ndr_print *ndr, const char *name, const struct GUID *guid)
{
- ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr->mem_ctx, guid));
+ ndr->print(ndr, "%-25s: %s", name, GUID_string(ndr, guid));
}
void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r)
@@ -1065,7 +1065,7 @@ NTSTATUS ndr_pull_DATA_BLOB(struct ndr_pull *ndr, DATA_BLOB *blob)
NDR_CHECK(ndr_pull_uint32(ndr, &length));
}
NDR_PULL_NEED_BYTES(ndr, length);
- *blob = data_blob_talloc(ndr->mem_ctx, ndr->data+ndr->offset, length);
+ *blob = data_blob_talloc(ndr, ndr->data+ndr->offset, length);
ndr->offset += length;
return NT_STATUS_OK;
}
diff --git a/source4/librpc/ndr/ndr_sec.c b/source4/librpc/ndr/ndr_sec.c
index d1d84cd724..f9169536ae 100644
--- a/source4/librpc/ndr/ndr_sec.c
+++ b/source4/librpc/ndr/ndr_sec.c
@@ -88,7 +88,7 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
*/
void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, struct dom_sid *sid)
{
- ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr->mem_ctx, sid));
+ ndr->print(ndr, "%-25s: %s", name, dom_sid_string(ndr, sid));
}
void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, struct dom_sid2 *sid)
diff --git a/source4/torture/basic/aliases.c b/source4/torture/basic/aliases.c
index 5da8d2643b..1cc5b3f39b 100644
--- a/source4/torture/basic/aliases.c
+++ b/source4/torture/basic/aliases.c
@@ -119,7 +119,7 @@ static void qfileinfo_aliases(struct smbcli_state *cli)
t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname);
- fnum = create_complex_file(cli, cli->mem_ctx, fname);
+ fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
}
@@ -159,7 +159,7 @@ static void qpathinfo_aliases(struct smbcli_state *cli)
t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname);
- fnum = create_complex_file(cli, cli->mem_ctx, fname);
+ fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
}
@@ -203,7 +203,7 @@ static void findfirst_aliases(struct smbcli_state *cli)
t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname);
- fnum = create_complex_file(cli, cli->mem_ctx, fname);
+ fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
}
@@ -315,7 +315,7 @@ static void setfileinfo_aliases(struct smbcli_state *cli)
t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname);
- fnum = create_complex_file(cli, cli->mem_ctx, fname);
+ fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
}
@@ -356,7 +356,7 @@ static void setpathinfo_aliases(struct smbcli_state *cli)
smbcli_unlink(cli->tree, fname);
- fnum = create_complex_file(cli, cli->mem_ctx, fname);
+ fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
}
diff --git a/source4/utils/ndrdump.c b/source4/utils/ndrdump.c
index b47b068257..22310d7985 100644
--- a/source4/utils/ndrdump.c
+++ b/source4/utils/ndrdump.c
@@ -103,7 +103,7 @@ static void show_functions(const struct dcerpc_interface_table *p)
int flags;
NTSTATUS status;
void *st;
- struct ndr_print pr;
+ struct ndr_print *pr;
DEBUGLEVEL = 10;
@@ -172,10 +172,10 @@ static void show_functions(const struct dcerpc_interface_table *p)
dump_data(0, ndr->data+ndr->offset, ndr->data_size - ndr->offset);
}
- pr.mem_ctx = mem_ctx;
- pr.print = ndr_print_debug_helper;
- pr.depth = 1;
- f->ndr_print(&pr, function, flags, st);
+ pr = talloc_p(NULL, struct ndr_print);
+ pr->print = ndr_print_debug_helper;
+ pr->depth = 1;
+ f->ndr_print(pr, function, flags, st);
if (!NT_STATUS_IS_OK(status) ||
ndr->offset != ndr->data_size) {
@@ -184,6 +184,8 @@ static void show_functions(const struct dcerpc_interface_table *p)
}
printf("dump OK\n");
+
+ talloc_free(pr);
return 0;
}