summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-11-16 09:00:52 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:05:52 -0500
commit8a18778286a16423d7d6e483fdb308a91e294efe (patch)
treeb1cf6a44c1cb4deccb04897ab426a724204b3f52 /source4/lib/ldb/ldb_tdb
parente81157c7379116d83b9906e27c9fd418c779d129 (diff)
downloadsamba-8a18778286a16423d7d6e483fdb308a91e294efe.tar.gz
samba-8a18778286a16423d7d6e483fdb308a91e294efe.tar.bz2
samba-8a18778286a16423d7d6e483fdb308a91e294efe.zip
r3783: - don't use make proto for ldb anymore
- split ldh.h out of samba's includes.h - make ldb_context and ldb_module private to the subsystem - use ltdb_ prefix for all ldb_tdb functions metze (This used to be commit f5ee40d6ce8224e280070975efc9911558fe675c)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c2
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c8
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_match.c43
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c13
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c40
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c12
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h69
7 files changed, 121 insertions, 66 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index cf175090e6..a8eb9ae916 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -33,6 +33,8 @@
*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
/*
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 93e358e4d2..b651aa38c1 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -33,6 +33,8 @@
*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
#include "ldb/include/ldb_parse.h"
@@ -523,7 +525,7 @@ static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tr
return -1;
}
- if (ldb_message_match(module, &msg, tree, base, scope) == 1) {
+ if (ltdb_message_match(module, &msg, tree, base, scope) == 1) {
ret = ltdb_add_attr_results(module, &msg, attrs, &count, res);
}
ltdb_search_dn1_free(module, &msg);
@@ -860,7 +862,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
return 0;
}
- ret = ltdb_unpack_data(module->ldb, &data, &msg);
+ ret = ltdb_unpack_data(module, &data, &msg);
if (ret != 0) {
return -1;
}
@@ -871,7 +873,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
ret = ltdb_index_add(module, &msg);
- ltdb_unpack_data_free(module->ldb, &msg);
+ ltdb_unpack_data_free(module, &msg);
return ret;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_match.c b/source4/lib/ldb/ldb_tdb/ldb_match.c
index 52e9f5afc7..4a51cfddf0 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_match.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_match.c
@@ -33,16 +33,17 @@
*/
#include "includes.h"
-#include <fnmatch.h>
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
#include "ldb/include/ldb_parse.h"
-
+#include <fnmatch.h>
/*
see if two ldb_val structures contain the same data as integers
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_integer(const struct ldb_val *v1, const struct ldb_val *v2)
+static int ltdb_val_equal_integer(const struct ldb_val *v1, const struct ldb_val *v2)
{
int i1, i2;
@@ -56,7 +57,7 @@ static int ldb_val_equal_integer(const struct ldb_val *v1, const struct ldb_val
see if two ldb_val structures contain the same data as case insensitive strings
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_case_insensitive(const struct ldb_val *v1,
+static int ltdb_val_equal_case_insensitive(const struct ldb_val *v1,
const struct ldb_val *v2)
{
if (v1->length != v2->length) {
@@ -73,10 +74,11 @@ static int ldb_val_equal_case_insensitive(const struct ldb_val *v1,
and case insensitive
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_wildcard_ci(struct ldb_context *ldb,
+static int ltdb_val_equal_wildcard_ci(struct ldb_module *module,
const struct ldb_val *v1,
const struct ldb_val *v2)
{
+ struct ldb_context *ldb = module->ldb;
char *s1, *s2;
int ret;
@@ -110,13 +112,13 @@ static int ldb_val_equal_wildcard_ci(struct ldb_context *ldb,
see if two ldb_val structures contain the same data with wildcards
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_wildcard(struct ldb_context *ldb,
+static int ltdb_val_equal_wildcard(struct ldb_module *module,
const struct ldb_val *v1,
const struct ldb_val *v2,
int flags)
{
if (flags & LTDB_FLAG_CASE_INSENSITIVE) {
- return ldb_val_equal_wildcard_ci(ldb, v1, v2);
+ return ltdb_val_equal_wildcard_ci(module, v1, v2);
}
if (!v1->data || !v2->data) {
return v1->data == v2->data;
@@ -137,13 +139,13 @@ static int ldb_val_equal_wildcard(struct ldb_context *ldb,
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_objectclass(struct ldb_module *module,
+static int ltdb_val_equal_objectclass(struct ldb_module *module,
const struct ldb_val *v1, const struct ldb_val *v2)
{
struct ltdb_private *ltdb = module->private_data;
unsigned int i;
- if (ldb_val_equal_case_insensitive(v1, v2) == 1) {
+ if (ltdb_val_equal_case_insensitive(v1, v2) == 1) {
return 1;
}
@@ -152,7 +154,7 @@ static int ldb_val_equal_objectclass(struct ldb_module *module,
if (ldb_attr_cmp(el->name, v2->data) == 0) {
unsigned int j;
for (j=0;j<el->num_values;j++) {
- if (ldb_val_equal_objectclass(module, v1, &el->values[j])) {
+ if (ltdb_val_equal_objectclass(module, v1, &el->values[j])) {
return 1;
}
}
@@ -171,27 +173,26 @@ static int ldb_val_equal_objectclass(struct ldb_module *module,
return 1 for a match, 0 for a mis-match
*/
-int ldb_val_equal(struct ldb_module *module,
+int ltdb_val_equal(struct ldb_module *module,
const char *attr_name,
const struct ldb_val *v1, const struct ldb_val *v2)
{
- struct ldb_context *ldb = module->ldb;
int flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_OBJECTCLASS) {
- return ldb_val_equal_objectclass(module, v1, v2);
+ return ltdb_val_equal_objectclass(module, v1, v2);
}
if (flags & LTDB_FLAG_INTEGER) {
- return ldb_val_equal_integer(v1, v2);
+ return ltdb_val_equal_integer(v1, v2);
}
if (flags & LTDB_FLAG_WILDCARD) {
- return ldb_val_equal_wildcard(ldb, v1, v2, flags);
+ return ltdb_val_equal_wildcard(module, v1, v2, flags);
}
if (flags & LTDB_FLAG_CASE_INSENSITIVE) {
- return ldb_val_equal_case_insensitive(v1, v2);
+ return ltdb_val_equal_case_insensitive(v1, v2);
}
if (v1->length != v2->length) return 0;
@@ -280,7 +281,7 @@ static int match_leaf(struct ldb_module *module,
return 1;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- if (ldb_val_equal(module, msg->elements[i].name,
+ if (ltdb_val_equal(module, msg->elements[i].name,
&msg->elements[i].values[j],
&tree->u.simple.value)) {
return 1;
@@ -300,7 +301,7 @@ static int match_leaf(struct ldb_module *module,
this is a recursive function, and does short-circuit evaluation
*/
-int ldb_message_match(struct ldb_module *module,
+int ltdb_message_match(struct ldb_module *module,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
const char *base,
@@ -314,11 +315,11 @@ int ldb_message_match(struct ldb_module *module,
break;
case LDB_OP_NOT:
- return ! ldb_message_match(module, msg, tree->u.not.child, base, scope);
+ return ! ltdb_message_match(module, msg, tree->u.not.child, base, scope);
case LDB_OP_AND:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_message_match(module, msg, tree->u.list.elements[i],
+ v = ltdb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (!v) return 0;
}
@@ -326,7 +327,7 @@ int ldb_message_match(struct ldb_module *module,
case LDB_OP_OR:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_message_match(module, msg, tree->u.list.elements[i],
+ v = ltdb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (v) return 1;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index ad856d2faf..9515beeaa7 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -33,6 +33,8 @@
*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
/* change this if the data format ever changes */
@@ -65,10 +67,11 @@ static unsigned int pull_uint32(uint8_t *p, int ofs)
caller frees the data buffer after use
*/
-int ltdb_pack_data(struct ldb_context *ldb,
+int ltdb_pack_data(struct ldb_module *module,
const struct ldb_message *message,
struct TDB_DATA *data)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i, j, real_elements=0;
size_t size;
char *p;
@@ -138,9 +141,10 @@ int ltdb_pack_data(struct ldb_context *ldb,
/*
free the memory allocated from a ltdb_unpack_data()
*/
-void ltdb_unpack_data_free(struct ldb_context *ldb,
+void ltdb_unpack_data_free(struct ldb_module *module,
struct ldb_message *message)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
for (i=0;i<message->num_elements;i++) {
@@ -160,10 +164,11 @@ void ltdb_unpack_data_free(struct ldb_context *ldb,
TDB_DATA data. This means the caller only has to free the elements
and values arrays. This can be done with ltdb_unpack_data_free()
*/
-int ltdb_unpack_data(struct ldb_context *ldb,
+int ltdb_unpack_data(struct ldb_module *module,
const struct TDB_DATA *data,
struct ldb_message *message)
{
+ struct ldb_context *ldb = module->ldb;
char *p;
unsigned int remaining;
unsigned int i, j;
@@ -274,7 +279,7 @@ int ltdb_unpack_data(struct ldb_context *ldb,
return 0;
failed:
- ltdb_unpack_data_free(ldb, message);
+ ltdb_unpack_data_free(module, message);
return -1;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index cb93483881..903c4cb802 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -33,6 +33,8 @@
*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
#include "ldb/include/ldb_parse.h"
@@ -56,34 +58,6 @@ static void msg_free_all_parts(struct ldb_context *ldb, struct ldb_message *msg)
/*
- duplicate a ldb_val structure
-*/
-struct ldb_val ldb_val_dup(struct ldb_context *ldb,
- const struct ldb_val *v)
-{
- struct ldb_val v2;
- v2.length = v->length;
- if (v->length == 0) {
- v2.data = NULL;
- return v2;
- }
-
- /* the +1 is to cope with buggy C library routines like strndup
- that look one byte beyond */
- v2.data = ldb_malloc(ldb, v->length+1);
- if (!v2.data) {
- v2.length = 0;
- return v2;
- }
-
- memcpy(v2.data, v->data, v->length);
- ((char *)v2.data)[v->length] = 0;
- return v2;
-}
-
-
-
-/*
add one element to a message
*/
static int msg_add_element(struct ldb_context *ldb,
@@ -319,7 +293,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag
msg->num_elements = 0;
msg->elements = NULL;
- ret = ltdb_unpack_data(ldb, &tdb_data2, msg);
+ ret = ltdb_unpack_data(module, &tdb_data2, msg);
if (ret == -1) {
ldb_free(ldb, tdb_data2.dptr);
return -1;
@@ -439,7 +413,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
}
/* unpack the record */
- ret = ltdb_unpack_data(sinfo->module->ldb, &data, &msg);
+ ret = ltdb_unpack_data(sinfo->module, &data, &msg);
if (ret == -1) {
sinfo->failures++;
return 0;
@@ -450,9 +424,9 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
}
/* see if it matches the given expression */
- if (!ldb_message_match(sinfo->module, &msg, sinfo->tree,
+ if (!ltdb_message_match(sinfo->module, &msg, sinfo->tree,
sinfo->base, sinfo->scope)) {
- ltdb_unpack_data_free(sinfo->module->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module, &msg);
return 0;
}
@@ -462,7 +436,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
sinfo->failures++;
}
- ltdb_unpack_data_free(sinfo->module->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module, &msg);
return ret;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index a2aa5a7aca..5f6af43f94 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -36,6 +36,8 @@
*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
/*
@@ -195,7 +197,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
return -1;
}
- ret = ltdb_pack_data(ldb, msg, &tdb_data);
+ ret = ltdb_pack_data(module, msg, &tdb_data);
if (ret == -1) {
ldb_free(ldb, tdb_key.dptr);
return -1;
@@ -439,7 +441,7 @@ static int msg_delete_element(struct ldb_module *module,
el = &msg->elements[found];
for (i=0;i<el->num_values;i++) {
- if (ldb_val_equal(module, msg->elements[i].name, &el->values[i], val)) {
+ if (ltdb_val_equal(module, msg->elements[i].name, &el->values[i], val)) {
if (i<el->num_values-1) {
memmove(&el->values[i], &el->values[i+1],
sizeof(el->values[i])*(el->num_values-(i+1)));
@@ -483,7 +485,7 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms
return -1;
}
- ret = ltdb_unpack_data(ldb, &tdb_data, &msg2);
+ ret = ltdb_unpack_data(module, &tdb_data, &msg2);
if (ret == -1) {
ldb_free(ldb, tdb_key.dptr);
free(tdb_data.dptr);
@@ -551,13 +553,13 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms
ldb_free(ldb, tdb_key.dptr);
free(tdb_data.dptr);
- ltdb_unpack_data_free(ldb, &msg2);
+ ltdb_unpack_data_free(module, &msg2);
return ret;
failed:
ldb_free(ldb, tdb_key.dptr);
free(tdb_data.dptr);
- ltdb_unpack_data_free(ldb, &msg2);
+ ltdb_unpack_data_free(module, &msg2);
return -1;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index b6660c5825..7b926e21a2 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -1,3 +1,8 @@
+
+#ifdef STANDALONE
+#include "tdb.h"
+#endif
+
/* this private structure is used by the ltdb backend in the
ldb_context */
struct ltdb_private {
@@ -43,3 +48,67 @@ struct ltdb_private {
#define LTDB_FLAG_WILDCARD (1<<2)
#define LTDB_FLAG_OBJECTCLASS (1<<3)
#define LTDB_FLAG_HIDDEN (1<<4)
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
+
+void ltdb_cache_free(struct ldb_module *module);
+int ltdb_cache_load(struct ldb_module *module);
+int ltdb_increase_sequence_number(struct ldb_module *module);
+int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name);
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
+
+struct ldb_parse_tree;
+
+int ltdb_search_indexed(struct ldb_module *module,
+ const char *base,
+ enum ldb_scope scope,
+ struct ldb_parse_tree *tree,
+ const char * const attrs[], struct ldb_message ***res);
+int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg);
+int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg);
+int ltdb_reindex(struct ldb_module *module);
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_pack.c */
+
+int ltdb_pack_data(struct ldb_module *module,
+ const struct ldb_message *message,
+ struct TDB_DATA *data);
+void ltdb_unpack_data_free(struct ldb_module *module,
+ struct ldb_message *message);
+int ltdb_unpack_data(struct ldb_module *module,
+ const struct TDB_DATA *data,
+ struct ldb_message *message);
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_search.c */
+
+int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
+ const struct ldb_val *val);
+void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
+int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg);
+int ltdb_search_dn(struct ldb_module *module, char *dn,
+ const char * const attrs[], struct ldb_message ***res);
+int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
+ const char * const attrs[],
+ unsigned 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);
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
+struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn);
+int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
+int ltdb_delete_noindex(struct ldb_module *module, const char *dn);
+int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg);
+
+/* The following definitions come from lib/ldb/ldb_tdb/ldb_match.c */
+int ltdb_val_equal(struct ldb_module *module,
+ const char *attr_name,
+ const struct ldb_val *v1, const struct ldb_val *v2);
+int ltdb_message_match(struct ldb_module *module,
+ struct ldb_message *msg,
+ struct ldb_parse_tree *tree,
+ const char *base,
+ enum ldb_scope scope);