summaryrefslogtreecommitdiff
path: root/source4/librpc
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 /source4/librpc
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)
Diffstat (limited to 'source4/librpc')
-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
4 files changed, 70 insertions, 72 deletions
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)