summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-05 04:27:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:45 -0500
commit232bc1503fc0e3f85b4711f077d2566dc0f0c823 (patch)
tree14e4a2736ab44368bdb27296ddbe5fb3a05fd5fc /source4/lib/ldb/ldb_tdb
parentaf66c31e44bcb052f35f9b1de8e997149fddac89 (diff)
downloadsamba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.tar.gz
samba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.tar.bz2
samba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.zip
r490: - expanded the test suite to test modify and delete operations
- made yet another attempt to make ldb const clean. - "make test" now runs both the tdb and ldap backend tests, and run the ldbtest utility with and without indexing - added prototypes in ldb.h for ldb_msg_*() public functions (This used to be commit 01e87406768cb5a98ac8530a2f361a4987a36cd3)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c36
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c22
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c12
3 files changed, 53 insertions, 17 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index 5d61fd35b3..3c6ce63c2b 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -44,20 +44,42 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb)
struct ldb_message msg;
struct ldb_message_element el;
struct ldb_val val;
+ int ret;
ltdb->sequence_number = 0;
msg.num_elements = 1;
msg.elements = &el;
- msg.dn = LTDB_BASEINFO;
- el.name = LTDB_SEQUENCE_NUMBER;
+ msg.dn = strdup(LTDB_BASEINFO);
+ if (!msg.dn) {
+ errno = ENOMEM;
+ return -1;
+ }
+ el.name = strdup(LTDB_SEQUENCE_NUMBER);
+ if (!el.name) {
+ free(msg.dn);
+ errno = ENOMEM;
+ return -1;
+ }
el.values = &val;
el.num_values = 1;
el.flags = 0;
- val.data = "0";
+ val.data = strdup("0");
+ if (!val.data) {
+ free(el.name);
+ free(msg.dn);
+ errno = ENOMEM;
+ return -1;
+ }
val.length = 1;
- return ltdb_store(ldb, &msg, TDB_INSERT);
+ ret = ltdb_store(ldb, &msg, TDB_INSERT);
+
+ free(msg.dn);
+ free(el.name);
+ free(val.data);
+
+ return ret;
}
/*
@@ -150,8 +172,8 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb)
msg.num_elements = 1;
msg.elements = &el;
- msg.dn = LTDB_BASEINFO;
- el.name = LTDB_SEQUENCE_NUMBER;
+ msg.dn = strdup(LTDB_BASEINFO);
+ el.name = strdup(LTDB_SEQUENCE_NUMBER);
el.values = &val;
el.num_values = 1;
el.flags = LDB_FLAG_MOD_REPLACE;
@@ -161,6 +183,8 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb)
ret = ltdb_modify_internal(ldb, &msg);
free(s);
+ free(msg.dn);
+ free(el.name);
if (ret == 0) {
ltdb->sequence_number += 1;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index d250bc10be..0b9581e52f 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -202,7 +202,10 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
struct ldb_parse_tree tree2;
struct dn_list list2;
tree2.operation = LDB_OP_SIMPLE;
- tree2.u.simple.attr = LTDB_OBJECTCLASS;
+ tree2.u.simple.attr = strdup(LTDB_OBJECTCLASS);
+ if (!tree2.u.simple.attr) {
+ return -1;
+ }
tree2.u.simple.value = el->values[j];
if (ltdb_index_dn_objectclass(ldb, &tree2,
index_list, &list2) == 1) {
@@ -214,6 +217,7 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
dn_list_free(&list2);
}
}
+ free(tree2.u.simple.attr);
}
}
}
@@ -488,7 +492,7 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
const char *base,
enum ldb_scope scope,
const struct dn_list *dn_list,
- const char * const attrs[], struct ldb_message ***res)
+ char * const attrs[], struct ldb_message ***res)
{
int i;
unsigned int count = 0;
@@ -528,7 +532,7 @@ int ltdb_search_indexed(struct ldb_context *ldb,
const char *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res)
+ char * const attrs[], struct ldb_message ***res)
{
struct ltdb_private *ltdb = ldb->private_data;
struct dn_list dn_list;
@@ -569,7 +573,10 @@ static int ltdb_index_add1_new(struct ldb_context *ldb,
}
msg->elements = el2;
- msg->elements[msg->num_elements].name = LTDB_IDX;
+ msg->elements[msg->num_elements].name = strdup(LTDB_IDX);
+ if (!msg->elements[msg->num_elements].name) {
+ return -1;
+ }
msg->elements[msg->num_elements].num_values = 0;
msg->elements[msg->num_elements].values = malloc_p(struct ldb_val);
if (!msg->elements[msg->num_elements].values) {
@@ -627,7 +634,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
{
struct ldb_message msg;
char *dn_key;
- int ret, i;
+ int ret, i, added=0;
dn_key = ldb_dn_key(el->name, &el->values[v_idx]);
if (!dn_key) {
@@ -661,6 +668,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
}
if (i == msg.num_elements) {
+ added = 1;
ret = ltdb_index_add1_new(ldb, &msg, el, dn);
} else {
ret = ltdb_index_add1_add(ldb, &msg, el, i, dn);
@@ -670,6 +678,10 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
ret = ltdb_store(ldb, &msg, TDB_REPLACE);
}
+ if (added) {
+ free(msg.elements[i].name);
+ }
+
ltdb_search_dn1_free(ldb, &msg);
return ret;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index cce865e052..1dce8f83a2 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -148,7 +148,7 @@ static int msg_add_all_elements(struct ldb_message *ret,
*/
static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
const struct ldb_message *msg,
- const char * const *attrs)
+ char * const *attrs)
{
struct ldb_message *ret;
int i;
@@ -294,7 +294,7 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message
search the database for a single simple dn
*/
int ltdb_search_dn(struct ldb_context *ldb, char *dn,
- const char * const attrs[], struct ldb_message ***res)
+ char * const attrs[], struct ldb_message ***res)
{
int ret;
struct ldb_message msg, *msg2;
@@ -330,7 +330,7 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn,
return 0 on success, -1 on failure
*/
int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg,
- const char * const attrs[],
+ char * const attrs[],
unsigned int *count,
struct ldb_message ***res)
{
@@ -368,7 +368,7 @@ struct ltdb_search_info {
struct ldb_parse_tree *tree;
const char *base;
enum ldb_scope scope;
- const char * const *attrs;
+ char * const *attrs;
struct ldb_message **msgs;
int failures;
int count;
@@ -445,7 +445,7 @@ static int ltdb_search_full(struct ldb_context *ldb,
const char *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
- const char * const attrs[], struct ldb_message ***res)
+ char * const attrs[], struct ldb_message ***res)
{
struct ltdb_private *ltdb = ldb->private_data;
int ret;
@@ -478,7 +478,7 @@ static int ltdb_search_full(struct ldb_context *ldb,
*/
int ltdb_search(struct ldb_context *ldb, const char *base,
enum ldb_scope scope, const char *expression,
- const char * const attrs[], struct ldb_message ***res)
+ char * const attrs[], struct ldb_message ***res)
{
struct ldb_parse_tree *tree;
int ret;