1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

r1985: take advantage of the new talloc in a few more places

(This used to be commit 6ffdfd779936ce8c5ca49c5f444e8da2bbeee0a8)
This commit is contained in:
Andrew Tridgell 2004-08-21 07:43:29 +00:00 committed by Gerald (Jerry) Carter
parent b45f4ebbb8
commit b7e1ea20dc
14 changed files with 148 additions and 155 deletions

View File

@ -63,8 +63,6 @@ struct smbcli_negotiate {
/* this is the context for a SMB socket associated with the socket itself */ /* this is the context for a SMB socket associated with the socket itself */
struct smbcli_socket { struct smbcli_socket {
TALLOC_CTX *mem_ctx; /* life of socket pool */
/* when the reference count reaches zero then the socket is destroyed */ /* when the reference count reaches zero then the socket is destroyed */
int reference_count; int reference_count;
@ -101,8 +99,6 @@ struct smbcli_options {
/* this is the context for the client transport layer */ /* this is the context for the client transport layer */
struct smbcli_transport { struct smbcli_transport {
TALLOC_CTX *mem_ctx;
/* when the reference count reaches zero then the transport is destroyed */ /* when the reference count reaches zero then the transport is destroyed */
int reference_count; int reference_count;
@ -188,8 +184,6 @@ struct smbcli_transport {
/* this is the context for the session layer */ /* this is the context for the session layer */
struct smbcli_session { struct smbcli_session {
TALLOC_CTX *mem_ctx; /* life of session */
/* when the reference count reaches zero then the session is destroyed */ /* when the reference count reaches zero then the session is destroyed */
int reference_count; int reference_count;
@ -213,9 +207,6 @@ struct smbcli_session {
smbcli_tree context: internal state for a tree connection. smbcli_tree context: internal state for a tree connection.
*/ */
struct smbcli_tree { struct smbcli_tree {
/* life of tree tree */
TALLOC_CTX *mem_ctx;
/* when the reference count reaches zero then the tree is destroyed */ /* when the reference count reaches zero then the tree is destroyed */
int reference_count; int reference_count;
@ -296,7 +287,6 @@ struct smbcli_request {
i.e. a single session on a single socket. i.e. a single session on a single socket.
*/ */
struct smbcli_state { struct smbcli_state {
TALLOC_CTX *mem_ctx; /* life of client pool */
struct smbcli_transport *transport; struct smbcli_transport *transport;
struct smbcli_session *session; struct smbcli_session *session;
struct smbcli_tree *tree; struct smbcli_tree *tree;

View File

@ -20,6 +20,10 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/*
inspired by http://swapped.cc/halloc/
*/
#include "includes.h" #include "includes.h"
#define MAX_TALLOC_SIZE 0x10000000 #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, void *talloc_named(void *context, size_t size,
const char *fmt, ...) _PRINTF_ATTRIBUTE(3,4) const char *fmt, ...) _PRINTF_ATTRIBUTE(3,4)
{ {
va_list ap; va_list ap;
void *ptr; void *ptr;
struct talloc_chunk *tc;
ptr = talloc(context, size); ptr = talloc(context, size);
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} }
tc = ((struct talloc_chunk *)ptr)-1;
va_start(ap, fmt); va_start(ap, fmt);
vasprintf(&tc->name, fmt, ap); talloc_set_name_v(ptr, fmt, ap);
va_end(ap); va_end(ap);
return ptr; return ptr;

View File

@ -195,13 +195,11 @@ NTSTATUS smbcli_tdis(struct smbcli_state *cli)
struct smbcli_state *smbcli_state_init(void) struct smbcli_state *smbcli_state_init(void)
{ {
struct smbcli_state *cli; struct smbcli_state *cli;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("smbcli_state"); cli = talloc_named(NULL, sizeof(*cli), "smbcli_state");
if (!mem_ctx) return NULL; if (cli) {
ZERO_STRUCTP(cli);
cli = talloc_zero(mem_ctx, sizeof(*cli)); }
cli->mem_ctx = mem_ctx;
return cli; return cli;
} }
@ -216,7 +214,5 @@ void smbcli_shutdown(struct smbcli_state *cli)
cli->tree->reference_count++; cli->tree->reference_count++;
smbcli_tree_close(cli->tree); smbcli_tree_close(cli->tree);
} }
if (cli->mem_ctx) { talloc_free(cli);
talloc_destroy(cli->mem_ctx);
}
} }

View File

@ -32,18 +32,13 @@
struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport)
{ {
struct smbcli_session *session; 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) { if (!session) {
talloc_destroy(mem_ctx);
return NULL; return NULL;
} }
session->mem_ctx = mem_ctx; ZERO_STRUCTP(session);
session->transport = transport; session->transport = transport;
session->pid = (uint16_t)getpid(); session->pid = (uint16_t)getpid();
session->vuid = UID_FIELD_INVALID; session->vuid = UID_FIELD_INVALID;
@ -60,7 +55,7 @@ void smbcli_session_close(struct smbcli_session *session)
session->reference_count--; session->reference_count--;
if (session->reference_count <= 0) { if (session->reference_count <= 0) {
smbcli_transport_close(session->transport); 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, void smbcli_session_set_user_session_key(struct smbcli_session *session,
const DATA_BLOB *session_key) 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->data,
session_key->length); session_key->length);
} }

View File

@ -28,18 +28,13 @@
struct smbcli_socket *smbcli_sock_init(void) struct smbcli_socket *smbcli_sock_init(void)
{ {
struct smbcli_socket *sock; struct smbcli_socket *sock;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_init("smbcli_socket"); sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket");
if (!mem_ctx) return NULL;
sock = talloc_zero(mem_ctx, sizeof(*sock));
if (!sock) { if (!sock) {
talloc_destroy(mem_ctx);
return NULL; return NULL;
} }
sock->mem_ctx = mem_ctx; ZERO_STRUCTP(sock);
sock->fd = -1; sock->fd = -1;
sock->port = 0; sock->port = 0;
/* 20 second default timeout */ /* 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; int name_type = 0x20;
struct in_addr ip; struct in_addr ip;
TALLOC_CTX *mem_ctx;
char *name, *p; char *name, *p;
BOOL ret; BOOL ret;
@ -162,10 +156,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in
return sock->fd != -1; return sock->fd != -1;
} }
mem_ctx = talloc_init("smbcli_sock_connect_byname"); name = talloc_strdup(sock, host);
if (!mem_ctx) return False;
name = talloc_strdup(mem_ctx, host);
/* allow hostnames of the form NAME#xx and do a netbios lookup */ /* allow hostnames of the form NAME#xx and do a netbios lookup */
if ((p = strchr(name, '#'))) { if ((p = strchr(name, '#'))) {
@ -173,18 +164,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in
*p = 0; *p = 0;
} }
if (!resolve_name(mem_ctx, name, &ip, name_type)) { if (!resolve_name(name, name, &ip, name_type)) {
talloc_destroy(mem_ctx); talloc_free(name);
return False; return False;
} }
ret = smbcli_sock_connect(sock, &ip, port); ret = smbcli_sock_connect(sock, &ip, port);
if (ret) { 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; return ret;
} }

View File

@ -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) struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock)
{ {
TALLOC_CTX *mem_ctx;
struct smbcli_transport *transport; struct smbcli_transport *transport;
struct fd_event fde; struct fd_event fde;
mem_ctx = talloc_init("smbcli_transport"); transport = talloc_named(NULL, sizeof(*transport), "smbcli_transport");
if (!mem_ctx) return NULL;
transport = talloc_zero(mem_ctx, sizeof(*transport));
if (!transport) return NULL; if (!transport) return NULL;
ZERO_STRUCTP(transport);
transport->event.ctx = event_context_init(); transport->event.ctx = event_context_init();
if (transport->event.ctx == NULL) { if (transport->event.ctx == NULL) {
talloc_destroy(mem_ctx); talloc_destroy(transport);
return NULL; return NULL;
} }
transport->mem_ctx = mem_ctx;
transport->socket = sock; transport->socket = sock;
transport->negotiate.protocol = PROTOCOL_NT1; transport->negotiate.protocol = PROTOCOL_NT1;
transport->options.use_spnego = lp_use_spnego(); 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_fd(transport->event.ctx, transport->event.fde);
event_remove_timed(transport->event.ctx, transport->event.te); event_remove_timed(transport->event.ctx, transport->event.te);
event_context_destroy(transport->event.ctx); 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) { if (transport->recv_buffer.received == NBT_HDR_SIZE) {
/* we've got a full header */ /* we've got a full header */
transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; 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); NBT_HDR_SIZE+transport->recv_buffer.req_size);
if (transport->recv_buffer.buffer == NULL) { if (transport->recv_buffer.buffer == NULL) {
smbcli_transport_dead(transport); smbcli_transport_dead(transport);

View File

@ -33,18 +33,13 @@
struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session)
{ {
struct smbcli_tree *tree; 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) { if (!tree) {
talloc_destroy(mem_ctx);
return NULL; return NULL;
} }
tree->mem_ctx = mem_ctx; ZERO_STRUCTP(tree);
tree->session = session; tree->session = session;
tree->session->reference_count++; tree->session->reference_count++;
@ -60,7 +55,7 @@ void smbcli_tree_close(struct smbcli_tree *tree)
tree->reference_count--; tree->reference_count--;
if (tree->reference_count <= 0) { if (tree->reference_count <= 0) {
smbcli_session_close(tree->session); 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; tree->tid = tcon.tconx.out.cnum;
if (tcon.tconx.out.dev_type) { 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) { 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); talloc_destroy(mem_ctx);

View File

@ -130,14 +130,14 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport)
if (req->in.data_size < 16) { if (req->in.data_size < 16) {
goto failed; goto failed;
} }
transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport, 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.secblob = smbcli_req_pull_blob(req, transport, req->in.data + 16, req->in.data_size - 16);
} else { } else {
if (req->in.data_size < (transport->negotiate.key_len)) { if (req->in.data_size < (transport->negotiate.key_len)) {
goto failed; goto failed;
} }
transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, transport->negotiate.key_len);
smbcli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, smbcli_req_pull_string(req, transport, &transport->negotiate.server_domain,
req->in.data+transport->negotiate.key_len, req->in.data+transport->negotiate.key_len,
req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN);
/* here comes the server name */ /* 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)) { if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) {
transport->negotiate.writebraw_supported = 1; 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); req->in.data, req->in.data_size);
} else { } else {
/* the old core protocol */ /* the old core protocol */

View File

@ -45,7 +45,6 @@ struct ndr_pull {
char *data; char *data;
uint32_t data_size; uint32_t data_size;
uint32_t offset; uint32_t offset;
TALLOC_CTX *mem_ctx;
struct ndr_token_list *relative_list; struct ndr_token_list *relative_list;
@ -66,7 +65,6 @@ struct ndr_push {
char *data; char *data;
uint32_t alloc_size; uint32_t alloc_size;
uint32_t offset; uint32_t offset;
TALLOC_CTX *mem_ctx;
struct ndr_token_list *relative_list; struct ndr_token_list *relative_list;
@ -83,7 +81,6 @@ struct ndr_push_save {
/* structure passed to functions that print IDL structures */ /* structure passed to functions that print IDL structures */
struct ndr_print { struct ndr_print {
uint32_t flags; /* LIBNDR_FLAG_* */ uint32_t flags; /* LIBNDR_FLAG_* */
TALLOC_CTX *mem_ctx;
uint32_t depth; uint32_t depth;
void (*print)(struct ndr_print *, const char *, ...); void (*print)(struct ndr_print *, const char *, ...);
void *private; void *private;
@ -191,7 +188,7 @@ enum ndr_err_code {
#define NDR_ALLOC_SIZE(ndr, s, size) do { \ #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, \ if ((size) && !(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, \
"Alloc %u failed\n", \ "Alloc %u failed\n", \
size); \ size); \
@ -204,7 +201,7 @@ enum ndr_err_code {
if ((n) == 0) { \ if ((n) == 0) { \
(s) = NULL; \ (s) = NULL; \
} else { \ } else { \
(s) = talloc(ndr->mem_ctx, (n) * elsize); \ (s) = talloc(ndr, (n) * elsize); \
if (!(s)) return ndr_pull_error(ndr, \ if (!(s)) return ndr_pull_error(ndr, \
NDR_ERR_ALLOC, \ NDR_ERR_ALLOC, \
"Alloc %u * %u failed\n", \ "Alloc %u * %u failed\n", \
@ -216,7 +213,7 @@ enum ndr_err_code {
#define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \ #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, \ if ((size) && !(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, \
"push alloc %u failed\n",\ "push alloc %u failed\n",\
size); \ size); \

View File

@ -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 = blob->data;
ndr->data_size = blob->length; ndr->data_size = blob->length;
ndr->offset = 0; ndr->offset = 0;
ndr->mem_ctx = mem_ctx;
ndr->ptr_count = 0; ndr->ptr_count = 0;
ndr->relative_list = NULL; ndr->relative_list = NULL;
@ -130,10 +129,9 @@ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
return NULL; return NULL;
} }
ndr->mem_ctx = mem_ctx;
ndr->flags = 0; ndr->flags = 0;
ndr->alloc_size = NDR_BASE_MARSHALL_SIZE; 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) { if (!ndr->data) {
return NULL; return NULL;
} }
@ -161,7 +159,7 @@ struct ndr_push *ndr_push_init(void)
/* free a ndr_push structure */ /* free a ndr_push structure */
void ndr_push_free(struct ndr_push *ndr) 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, const char *name,
void *ptr) void *ptr)
{ {
struct ndr_print ndr; struct ndr_print *ndr;
ndr.mem_ctx = talloc_init("ndr_print_debug"); ndr = talloc_p(NULL, struct ndr_print);
if (!ndr.mem_ctx) return; if (!ndr) return;
ndr.print = ndr_print_debug_helper; ndr->print = ndr_print_debug_helper;
ndr.depth = 1; ndr->depth = 1;
ndr.flags = 0; ndr->flags = 0;
fn(&ndr, name, ptr); fn(ndr, name, ptr);
talloc_destroy(ndr.mem_ctx); talloc_free(ndr);
} }
@ -329,15 +327,15 @@ void ndr_print_union_debug(void (*fn)(struct ndr_print *, const char *, uint32_t
uint32_t level, uint32_t level,
void *ptr) void *ptr)
{ {
struct ndr_print ndr; struct ndr_print *ndr;
ndr.mem_ctx = talloc_init("ndr_print_union"); ndr = talloc_p(NULL, struct ndr_print);
if (!ndr.mem_ctx) return; if (!ndr) return;
ndr.print = ndr_print_debug_helper; ndr->print = ndr_print_debug_helper;
ndr.depth = 1; ndr->depth = 1;
ndr.flags = 0; ndr->flags = 0;
fn(&ndr, name, level, ptr); fn(ndr, name, level, ptr);
talloc_destroy(ndr.mem_ctx); talloc_free(ndr);
} }
/* /*
@ -348,15 +346,15 @@ void ndr_print_function_debug(void (*fn)(struct ndr_print *, const char *, int ,
int flags, int flags,
void *ptr) void *ptr)
{ {
struct ndr_print ndr; struct ndr_print *ndr;
ndr.mem_ctx = talloc_init("ndr_print_function"); ndr = talloc_p(NULL, struct ndr_print);
if (!ndr.mem_ctx) return; if (!ndr) return;
ndr.print = ndr_print_debug_helper; ndr->print = ndr_print_debug_helper;
ndr.depth = 1; ndr->depth = 1;
ndr.flags = 0; ndr->flags = 0;
fn(&ndr, name, flags, ptr); fn(ndr, name, flags, ptr);
talloc_destroy(ndr.mem_ctx); talloc_free(ndr);
} }
@ -460,14 +458,14 @@ NTSTATUS ndr_pull_subcontext_fn(struct ndr_pull *ndr,
void *base, void *base,
NTSTATUS (*fn)(struct ndr_pull *, void *)) NTSTATUS (*fn)(struct ndr_pull *, void *))
{ {
struct ndr_pull ndr2; struct ndr_pull *ndr2;
NDR_ALLOC(ndr, ndr2);
NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2)); NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
NDR_CHECK(fn(&ndr2, base)); NDR_CHECK(fn(ndr2, base));
if (sub_size) { if (sub_size) {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else { } else {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
} }
return NT_STATUS_OK; return NT_STATUS_OK;
} }
@ -478,14 +476,14 @@ NTSTATUS ndr_pull_subcontext_flags_fn(struct ndr_pull *ndr,
void *base, void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , void *)) NTSTATUS (*fn)(struct ndr_pull *, int , void *))
{ {
struct ndr_pull ndr2; struct ndr_pull *ndr2;
NDR_ALLOC(ndr, ndr2);
NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, &ndr2)); NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, base)); NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, base));
if (sub_size) { if (sub_size) {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else { } else {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
} }
return NT_STATUS_OK; return NT_STATUS_OK;
} }
@ -496,14 +494,15 @@ NTSTATUS ndr_pull_subcontext_union_fn(struct ndr_pull *ndr,
void *base, void *base,
NTSTATUS (*fn)(struct ndr_pull *, int , uint32_t , void *)) 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_ALLOC(ndr, ndr2);
NDR_CHECK(fn(&ndr2, NDR_SCALARS|NDR_BUFFERS, level, base)); NDR_CHECK(ndr_pull_subcontext_header(ndr, sub_size, ndr2));
NDR_CHECK(fn(ndr2, NDR_SCALARS|NDR_BUFFERS, level, base));
if (sub_size) { if (sub_size) {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.data_size)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->data_size));
} else { } else {
NDR_CHECK(ndr_pull_advance(ndr, ndr2.offset)); NDR_CHECK(ndr_pull_advance(ndr, ndr2->offset));
} }
return NT_STATUS_OK; return NT_STATUS_OK;
} }
@ -546,7 +545,7 @@ NTSTATUS ndr_push_subcontext_fn(struct ndr_push *ndr,
{ {
struct ndr_push *ndr2; 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; if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags; ndr2->flags = ndr->flags;
@ -566,7 +565,7 @@ NTSTATUS ndr_push_subcontext_flags_fn(struct ndr_push *ndr,
{ {
struct ndr_push *ndr2; 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; if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags; ndr2->flags = ndr->flags;
@ -587,7 +586,7 @@ NTSTATUS ndr_push_subcontext_union_fn(struct ndr_push *ndr,
{ {
struct ndr_push *ndr2; 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; if (!ndr2) return NT_STATUS_NO_MEMORY;
ndr2->flags = ndr->flags; 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 ndr_pull_relative(struct ndr_pull *ndr, const void **buf, size_t size,
NTSTATUS (*fn)(struct ndr_pull *, int ndr_flags, void *)) NTSTATUS (*fn)(struct ndr_pull *, int ndr_flags, void *))
{ {
struct ndr_pull ndr2; struct ndr_pull *ndr2;
uint32_t ofs; uint32_t ofs;
struct ndr_pull_save save; struct ndr_pull_save save;
void *p; void *p;
NDR_ALLOC(ndr, ndr2);
NDR_CHECK(ndr_pull_uint32(ndr, &ofs)); NDR_CHECK(ndr_pull_uint32(ndr, &ofs));
if (ofs == 0) { if (ofs == 0) {
(*buf) = NULL; (*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 but I am keeping the code around in case I missed a
critical use for it (tridge, august 2004) */ critical use for it (tridge, august 2004) */
NDR_CHECK(ndr_pull_set_offset(ndr, ofs)); 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 */ /* strings must be allocated by the backend functions */
if (ndr->flags & LIBNDR_STRING_FLAGS) { 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 { } else {
NDR_ALLOC_SIZE(ndr, p, size); 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; (*buf) = p;
ndr_pull_restore(ndr, &save); ndr_pull_restore(ndr, &save);
talloc_free(ndr2);
return NT_STATUS_OK; 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) 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; return NT_STATUS_OK;
} }
NDR_CHECK(ndr_push_align(ndr, 4)); 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); return ndr_push_uint32(ndr, 0xFFFFFFFF);
} }

View File

@ -443,11 +443,11 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
len1, ofs, len2); len1, ofs, len2);
} }
if (len2 == 0) { if (len2 == 0) {
*s = talloc_strdup(ndr->mem_ctx, ""); *s = talloc_strdup(ndr, "");
break; break;
} }
NDR_PULL_NEED_BYTES(ndr, len2*2); 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, ndr->data+ndr->offset,
len2*2, len2*2,
(const void **)&as); (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_CHECK(ndr_pull_uint32(ndr, &len1));
NDR_PULL_NEED_BYTES(ndr, len1*2); NDR_PULL_NEED_BYTES(ndr, len1*2);
if (len1 == 0) { if (len1 == 0) {
*s = talloc_strdup(ndr->mem_ctx, ""); *s = talloc_strdup(ndr, "");
break; break;
} }
ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset, ndr->data+ndr->offset,
len1*2, len1*2,
(const void **)&as); (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_CHECK(ndr_pull_uint16(ndr, &len3));
NDR_PULL_NEED_BYTES(ndr, len3); NDR_PULL_NEED_BYTES(ndr, len3);
if (len3 == 0) { if (len3 == 0) {
*s = talloc_strdup(ndr->mem_ctx, ""); *s = talloc_strdup(ndr, "");
break; break;
} }
ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset, ndr->data+ndr->offset,
len3, len3,
(const void **)&as); (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) { if (len1*2+2 <= ndr->data_size - ndr->offset) {
len1++; len1++;
} }
ret = convert_string_talloc(ndr->mem_ctx, chset, CH_UNIX, ret = convert_string_talloc(ndr, chset, CH_UNIX,
ndr->data+ndr->offset, ndr->data+ndr->offset,
len1*2, len1*2,
(const void **)&as); (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) 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) 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) { if (t == (time_t)-1 || t == 0) {
ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t); ndr->print(ndr, "%-25s: (time_t)%d", name, (int)t);
} else { } 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) 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) 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_CHECK(ndr_pull_uint32(ndr, &length));
} }
NDR_PULL_NEED_BYTES(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; ndr->offset += length;
return NT_STATUS_OK; return NT_STATUS_OK;
} }

View File

@ -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) 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) void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, struct dom_sid2 *sid)

View File

@ -119,7 +119,7 @@ static void qfileinfo_aliases(struct smbcli_state *cli)
t2.in.data = data_blob(NULL, 0); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli->mem_ctx, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); 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); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli->mem_ctx, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); 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); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli->mem_ctx, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); 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); t2.in.data = data_blob(NULL, 0);
smbcli_unlink(cli->tree, fname); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli->mem_ctx, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); 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); smbcli_unlink(cli->tree, fname);
fnum = create_complex_file(cli, cli->mem_ctx, fname); fnum = create_complex_file(cli, cli, fname);
if (fnum == -1) { if (fnum == -1) {
printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree)); printf("ERROR: open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
} }

View File

@ -103,7 +103,7 @@ static void show_functions(const struct dcerpc_interface_table *p)
int flags; int flags;
NTSTATUS status; NTSTATUS status;
void *st; void *st;
struct ndr_print pr; struct ndr_print *pr;
DEBUGLEVEL = 10; 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); dump_data(0, ndr->data+ndr->offset, ndr->data_size - ndr->offset);
} }
pr.mem_ctx = mem_ctx; pr = talloc_p(NULL, struct ndr_print);
pr.print = ndr_print_debug_helper; pr->print = ndr_print_debug_helper;
pr.depth = 1; pr->depth = 1;
f->ndr_print(&pr, function, flags, st); f->ndr_print(pr, function, flags, st);
if (!NT_STATUS_IS_OK(status) || if (!NT_STATUS_IS_OK(status) ||
ndr->offset != ndr->data_size) { ndr->offset != ndr->data_size) {
@ -184,6 +184,8 @@ static void show_functions(const struct dcerpc_interface_table *p)
} }
printf("dump OK\n"); printf("dump OK\n");
talloc_free(pr);
return 0; return 0;
} }