Just use talloc_free() to release the memory after an ldb_search().
return ldb_next_search(module, base, scope, expression, attrs, res);
}
-static int samldb_search_free(struct ldb_module *module, struct ldb_message **res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_search_free\n");
- return ldb_next_search_free(module, res);
-}
-
/*
allocate a new id, attempting to do it atomically
return 0 on failure, the id on success
ret = ldb_search(ldb, dn, LDB_SCOPE_BASE, "nextRid=*", attrs, &res);
if (ret != 1) {
- if (res) ldb_search_free(ldb, res);
+ if (res) talloc_free(res);
return -1;
}
str = ldb_msg_find_string(res[0], "nextRid", NULL);
if (str == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "attribute nextRid not found in %s\n", dn);
- ldb_search_free(ldb, res);
+ talloc_free(res);
return -1;
}
if ((*id)+1 == 0) {
/* out of IDs ! */
ldb_debug(ldb, LDB_DEBUG_FATAL, "Are we out of valid IDs ?\n");
- ldb_search_free(ldb, res);
+ talloc_free(res);
return -1;
}
- ldb_search_free(ldb, res);
+ talloc_free(res);
/* we do a delete and add as a single operation. That prevents
a race */
sdn++;
ret = ldb_search(module->ldb, sdn, LDB_SCOPE_BASE, "objectClass=domain", NULL, &res);
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
if (ret == 1)
break;
ret = ldb_search(module->ldb, dom_dn, LDB_SCOPE_BASE, "objectSid=*", attrs, &res);
if (ret != 1) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
- if (res) ldb_search_free(module->ldb, res);
+ if (res) talloc_free(res);
return NULL;
}
dom_sid = ldb_msg_find_string(res[0], "objectSid", NULL);
if (dom_sid == NULL) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_get_new_sid: error retrieving domain sid!\n");
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
return NULL;
}
}
if (ret != 0) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "Failed to increment nextRid of %s\n", dom_dn);
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
return NULL;
}
obj_sid = talloc_asprintf(mem_ctx, "%s-%u", dom_sid, rid);
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
+
return obj_sid;
}
NULL,
(char *)el->values[j].data)) {
ldb_debug(module->ldb, LDB_DEBUG_FATAL, "Attribute adding failed...\n");
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
return -1;
}
}
}
- ldb_search_free(module->ldb, res);
+ talloc_free(res);
return 0;
}
static const struct ldb_module_ops samldb_ops = {
"samldb",
samldb_search,
- samldb_search_free,
samldb_add_record,
samldb_modify_record,
samldb_delete_record,
return count;
}
-/*
- free up a search result
-*/
-int samdb_search_free(struct ldb_context *sam_ldb,
- TALLOC_CTX *mem_ctx, struct ldb_message **res)
-{
- return ldb_search_free(sam_ldb, res);
-}
-
/*
search the sam for a single string attribute in exactly 1 record
*/
attr_name, format, count));
}
if (count != 1) {
- samdb_search_free(sam_ldb, mem_ctx, res);
+ talloc_free(res);
return NULL;
}
if (res[i]->num_elements != 1) {
DEBUG(1,("samdb: search for %s %s not single valued\n",
attr_name, format));
- samdb_search_free(sam_ldb, mem_ctx, res);
+ talloc_free(res);
return -1;
}
}
*strs = talloc_array(mem_ctx, const char *, count+1);
if (! *strs) {
- samdb_search_free(sam_ldb, mem_ctx, res);
+ talloc_free(res);
return -1;
}
search the database given a LDAP-like search expression
return the number of records found, or -1 on error
+
+ Use talloc_free to free the ldb_message returned in 'res'
+
*/
int ldb_search(struct ldb_context *ldb,
const char *base,
return ldb->modules->ops->search(ldb->modules, base, scope, expression, attrs, res);
}
-/*
- free a set of messages returned by ldb_search
-*/
-int ldb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
-{
- return ldb->modules->ops->search_free(ldb->modules, msgs);
-}
-
-
/*
add a record to the database. Will fail if a record with the given class and key
already exists
return module->next->ops->search(module->next, base, scope, expression, attrs, res);
}
-int ldb_next_search_free(struct ldb_module *module, struct ldb_message **msg)
-{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->search_free(module->next, msg);
-}
-
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message)
{
if (!module->next) {
search the database given a LDAP-like search expression
return the number of records found, or -1 on error
+
+ use talloc_free to free the ldb_message returned
*/
int ldb_search(struct ldb_context *ldb,
const char *base,
const char *expression,
const char * const *attrs, struct ldb_message ***res);
-/*
- free a set of messages returned by ldb_search
-*/
-int ldb_search_free(struct ldb_context *ldb, struct ldb_message **msgs);
-
-
/*
add a record to the database. Will fail if a record with the given class and key
already exists
const char *name;
int (*search)(struct ldb_module *, const char *, enum ldb_scope,
const char *, const char * const [], struct ldb_message ***);
- int (*search_free)(struct ldb_module *, struct ldb_message **);
int (*add_record)(struct ldb_module *, const struct ldb_message *);
int (*modify_record)(struct ldb_module *, const struct ldb_message *);
int (*delete_record)(struct ldb_module *, const char *);
enum ldb_scope scope,
const char *expression,
const char * const *attrs, struct ldb_message ***res);
-int ldb_next_search_free(struct ldb_module *module, struct ldb_message **msg);
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message);
int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message);
int ldb_next_delete_record(struct ldb_module *module, const char *dn);
return ret;
}
-/*
- free a search result
-*/
-static int lldb_search_free(struct ldb_module *module, struct ldb_message **res)
-{
- talloc_free(res);
- return 0;
-}
-
-
/*
add a single set of ldap message values to a ldb_message
*/
return msg_count;
failed:
- if (*res) lldb_search_free(module, *res);
+ if (*res) talloc_free(*res);
return -1;
}
static const struct ldb_module_ops lldb_ops = {
"ldap",
lldb_search,
- lldb_search_free,
lldb_add,
lldb_modify,
lldb_delete,
}
-/*
- free a set of search results
-*/
-int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs)
-{
- struct ltdb_private *ltdb = module->private_data;
-
- ltdb->last_err_string = NULL;
-
- talloc_free(msgs);
-
- return 0;
-}
-
/*
search the database with a LDAP-like expression.
this is the "full search" non-indexed variant
static const struct ldb_module_ops ltdb_ops = {
"tdb",
ltdb_search,
- ltdb_search_free,
ltdb_add,
ltdb_modify,
ltdb_delete,
const char * const attrs[],
int *count,
struct ldb_message ***res);
-int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs);
int ltdb_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
const char * const attrs[], struct ldb_message ***res);
dit(bf(ldb_search(3))) perform a database search
-dit(bf(ldb_search_free(3))) free the results of a ldb_search
-
dit(bf(ldb_add(3))) add a record to the database
dit(bf(ldb_delete(3))) delete a record from the database
/* set flags to 0 as flags on search have undefined values */
ret = get_msg_attributes(ss, *srch, 0);
if (ret != 0) {
- ldb_search_free(ldb, srch);
+ talloc_free(srch);
return ret;
}
return ldb_next_search(module, base, scope, expression, attrs, res);
}
-/* search_free */
-static int schema_search_free(struct ldb_module *module, struct ldb_message **res)
-{
- return ldb_next_search_free(module, res);
-}
-
/* add_record */
static int schema_add_record(struct ldb_module *module, const struct ldb_message *msg)
{
static const struct ldb_module_ops schema_ops = {
"schema",
schema_search,
- schema_search_free,
schema_add_record,
schema_modify_record,
schema_delete_record,
return ldb_next_search(module, base, scope, expression, attrs, res);
}
-/* search_free */
-static int skel_search_free(struct ldb_module *module, struct ldb_message **res)
-{
- return ldb_next_search_free(module, res);
-}
-
/* add_record */
static int skel_add_record(struct ldb_module *module, const struct ldb_message *msg)
{
static const struct ldb_module_ops skel_ops = {
"skel",
skel_search,
- skel_search_free,
skel_add_record,
skel_modify_record,
skel_delete_record,
return ldb_next_search(module, base, scope, expression, attrs, res);
}
-static int timestamps_search_free(struct ldb_module *module, struct ldb_message **res)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_search_free\n");
- return ldb_next_search_free(module, res);
-}
-
static int add_time_element(struct ldb_module *module, struct ldb_message *msg,
const char *attr_name, const char *time_string, unsigned int flags)
{
static const struct ldb_module_ops timestamps_ops = {
"timestamps",
timestamps_search,
- timestamps_search_free,
timestamps_add_record,
timestamps_modify_record,
timestamps_delete_record,
}
}
- ldb_search_free(ldb, res);
+ talloc_free(res);
if (total == 0) {
return -1;
do_edit(ldb, msgs, ret, editor);
if (ret > 0) {
- ret = ldb_search_free(ldb, msgs);
+ ret = talloc_free(msgs);
if (ret == -1) {
- fprintf(stderr, "search_free failed - %s\n", ldb_errstring(ldb));
+ fprintf(stderr, "talloc_free failed\n");
exit(1);
}
}
}
if (ret > 0) {
- ret = ldb_search_free(ldb, msgs);
+ ret = talloc_free(msgs);
if (ret == -1) {
- fprintf(stderr, "search_free failed\n");
+ fprintf(stderr, "talloc_free failed\n");
exit(1);
}
}
}
if (ret > 0) {
- ldb_search_free(ldb, res);
+ talloc_free(res);
}
printf("testing uid %d/%d - %d \r", i, uid, ret);
struct ldb_context *c = key->hive->backend_data;
if (kd->subkeys) {
- ldb_search_free(c, kd->subkeys);
+ talloc_free(kd->subkeys);
kd->subkeys = NULL;
}
if (kd->values) {
- ldb_search_free(c, kd->values);
+ talloc_free(kd->values);
kd->values = NULL;
}
return 0;
(*key)->backend_data = newkd = talloc_zero(*key, struct ldb_key_data);
newkd->dn = talloc_strdup(mem_ctx, msg[0]->dn);
- ldb_search_free(c, msg);
+ talloc_free(msg);
return WERR_OK;
}
return NT_STATUS_NO_SUCH_DOMAIN;
}
if (ret > 1) {
- samdb_search_free(sam_ctx, mem_ctx, msgs);
+ talloc_free(msgs);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
r->out.info.min_password_length = samdb_result_uint(msgs[0], "minPwdLength", 0);
r->out.info.password_properties = samdb_result_uint(msgs[0], "pwdProperties", 1);
- samdb_search_free(sam_ctx, mem_ctx, msgs);
+ talloc_free(msgs);
talloc_free(sam_ctx);
return NT_STATUS_OK;