1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

r2792: got rid of talloc_ldb_alloc() and instead created talloc_realloc_fn(),

so talloc now doesn't contain any ldb specific functions.

allow NULL to be passed to a couple more talloc() functions
(This used to be commit 1246f80d80)
This commit is contained in:
Andrew Tridgell 2004-10-03 06:39:19 +00:00 committed by Gerald (Jerry) Carter
parent 15b9736ed3
commit 1429ed54f1
8 changed files with 44 additions and 31 deletions

View File

@ -141,7 +141,7 @@ static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_
attrs[i] = NULL;
}
ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
count = ldb_search(ldb, basedn, scope, r->filter, attrs, &res);
for (i=0; i < count; i++) {
@ -284,7 +284,7 @@ invalid_input:
add_result->dn = talloc_steal(add_reply, dn);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_add(ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
@ -330,7 +330,7 @@ static NTSTATUS sldb_Del(struct ldapsrv_partition *partition, struct ldapsrv_cal
DEBUG(10, ("sldb_Del: dn: [%s]\n", dn));
ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_delete(ldb, dn);
del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);
@ -449,7 +449,7 @@ invalid_input:
modify_result->dn = talloc_steal(modify_reply, dn);
if (result == LDAP_SUCCESS) {
ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
ldb_ret = ldb_modify(ldb, msg);
if (ldb_ret == 0) {
result = LDAP_SUCCESS;
@ -503,7 +503,7 @@ static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv
attrs[0] = NULL;
ldb_set_alloc(ldb, talloc_ldb_alloc, samdb);
ldb_set_alloc(ldb, talloc_realloc_fn, samdb);
count = ldb_search(ldb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);

View File

@ -39,7 +39,7 @@
this allows the user to choose their own allocation function
*/
int ldb_set_alloc(struct ldb_context *ldb,
void *(*alloc)(void *context, void *ptr, size_t size),
void *(*alloc)(const void *context, void *ptr, size_t size),
void *context)
{
ldb->alloc_ops.alloc = alloc;
@ -50,7 +50,7 @@ int ldb_set_alloc(struct ldb_context *ldb,
/*
this is the default memory allocation function
*/
static void *ldb_default_alloc(void *context, void *ptr, size_t size)
static void *ldb_default_alloc(const void *context, void *ptr, size_t size)
{
/* by setting LDB_ALLOC_OFS to non-zero the test suite can
catch any places where we incorrectly use the libc alloc

View File

@ -145,7 +145,7 @@ struct ldb_backend_ops {
for pool allocators
*/
struct ldb_alloc_ops {
void *(*alloc)(void *context, void *ptr, size_t size);
void *(*alloc)(const void *context, void *ptr, size_t size);
void *context;
};
@ -320,7 +320,7 @@ const char *ldb_msg_find_string(const struct ldb_message *msg,
which often take a context argument
*/
int ldb_set_alloc(struct ldb_context *ldb,
void *(*alloc)(void *context, void *ptr, size_t size),
void *(*alloc)(const void *context, void *ptr, size_t size),
void *context);
/*

View File

@ -273,6 +273,10 @@ int talloc_unlink(const void *context, void *ptr)
struct talloc_chunk *tc_p, *new_p;
void *new_parent;
if (context == NULL) {
context = null_context;
}
if (talloc_unreference(context, ptr) == 0) {
return 0;
}
@ -561,6 +565,10 @@ void *talloc_steal(const void *new_ctx, const void *ptr)
return NULL;
}
if (new_ctx == NULL) {
new_ctx = null_context;
}
tc = talloc_chunk_from_ptr(ptr);
if (new_ctx == NULL) {
@ -948,16 +956,11 @@ void *talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned
}
/*
a alloc function for ldb that uses talloc
a function version of talloc_realloc(), so it can be passed as a function pointer
to libraries that want a realloc function (a realloc function encapsulates
all the basic capabilities of an allocation library, which is why this is useful)
*/
void *talloc_ldb_alloc(void *context, void *ptr, size_t size)
void *talloc_realloc_fn(const void *context, void *ptr, size_t size)
{
if (ptr == NULL) {
return talloc(context, size);
}
if (size == 0) {
talloc_free(ptr);
return NULL;
}
return talloc_realloc(context, ptr, size);
return _talloc_realloc(context, ptr, size, NULL);
}

View File

@ -42,7 +42,7 @@ int gendb_search_v(struct ldb_context *ldb,
return -1;
}
ldb_set_alloc(ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx);
count = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, attrs, res);

View File

@ -43,7 +43,7 @@ static struct ldb_context *schannel_db_connect(TALLOC_CTX *mem_ctx)
return NULL;
}
ldb_set_alloc(ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(ldb, talloc_realloc_fn, mem_ctx);
return ldb;
}

View File

@ -119,7 +119,7 @@ int samdb_search_free(void *ctx,
TALLOC_CTX *mem_ctx, struct ldb_message **res)
{
struct samdb_context *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_search_free(sam_ctx->ldb, res);
}
@ -746,7 +746,7 @@ int samdb_msg_add_string(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
if (s == NULL || a == NULL) {
return -1;
}
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_string(sam_ctx->ldb, msg, a, s);
}
@ -761,7 +761,7 @@ int samdb_msg_add_delete(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
if (a == NULL) {
return -1;
}
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
/* we use an empty replace rather than a delete, as it allows for
samdb_replace() to be used everywhere */
return ldb_msg_add_empty(sam_ctx->ldb, msg, a, LDB_FLAG_MOD_REPLACE);
@ -811,7 +811,7 @@ int samdb_msg_add_hash(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg,
return -1;
}
memcpy(val.data, hash.hash, 16);
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -832,7 +832,7 @@ int samdb_msg_add_hashes(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
for (i=0;i<count;i++) {
memcpy(i*16 + (char *)val.data, hashes[i].hash, 16);
}
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -855,7 +855,7 @@ int samdb_msg_add_logon_hours(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message
struct ldb_val val;
val.length = hours.units_per_week / 8;
val.data = hours.bitmap;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_msg_add_value(sam_ctx->ldb, msg, attr_name, &val);
}
@ -868,7 +868,7 @@ int samdb_msg_set_string(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg
struct samdb_context *sam_ctx = ctx;
struct ldb_message_element *el;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
el = ldb_msg_find_element(msg, attr_name);
if (el) {
@ -897,7 +897,7 @@ int samdb_add(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg)
{
struct samdb_context *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_add(sam_ctx->ldb, msg);
}
@ -908,7 +908,7 @@ int samdb_delete(void *ctx, TALLOC_CTX *mem_ctx, const char *dn)
{
struct samdb_context *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_delete(sam_ctx->ldb, dn);
}
@ -919,7 +919,7 @@ int samdb_modify(void *ctx, TALLOC_CTX *mem_ctx, struct ldb_message *msg)
{
struct samdb_context *sam_ctx = ctx;
ldb_set_alloc(sam_ctx->ldb, talloc_ldb_alloc, mem_ctx);
ldb_set_alloc(sam_ctx->ldb, talloc_realloc_fn, mem_ctx);
return ldb_modify(sam_ctx->ldb, msg);
}

View File

@ -458,3 +458,13 @@ The talloc_realloc_p() macro is equivalent to:
except that it provides integer overflow protection for the multiply,
returning NULL if the multiply overflows.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
void *talloc_realloc_fn(const void *ctx, void *ptr, size_t size);
This is a non-macro version of talloc_realloc(), which is useful
as libraries sometimes want a ralloc function pointer. A realloc()
implementation encapsulates the functionality of malloc(), free() and
realloc() in one call, which is why it is useful to be able to pass
around a single function pointer.