summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb/ldb_cache.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-09-22 21:11:41 -0700
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>2009-10-02 12:45:03 +0200
commit14c9070322d089dd96b389e8087c4f4bf1a6c7cc (patch)
treeff9834b314ad1842632152f8d6ebd7424e9cf504 /source4/lib/ldb/ldb_tdb/ldb_cache.c
parentbcbf0ae1e707c2355824800dc213d364070f070a (diff)
downloadsamba-14c9070322d089dd96b389e8087c4f4bf1a6c7cc.tar.gz
samba-14c9070322d089dd96b389e8087c4f4bf1a6c7cc.tar.bz2
samba-14c9070322d089dd96b389e8087c4f4bf1a6c7cc.zip
s4-ldb: merged with master
Diffstat (limited to 'source4/lib/ldb/ldb_tdb/ldb_cache.c')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_cache.c84
1 files changed, 64 insertions, 20 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c
index 2c399686ea..f853023509 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_cache.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c
@@ -190,8 +190,6 @@ static int ltdb_baseinfo_init(struct ldb_module *module)
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
struct ldb_message *msg;
- struct ldb_message_element el;
- struct ldb_val val;
int ret;
/* the initial sequence number must be different from the one
set in ltdb_cache_free(). Thanks to Jon for pointing this
@@ -202,31 +200,21 @@ static int ltdb_baseinfo_init(struct ldb_module *module)
ltdb->sequence_number = atof(initial_sequence_number);
- msg = talloc(ltdb, struct ldb_message);
- if (msg == NULL) {
- goto failed;
- }
-
- msg->num_elements = 1;
- msg->elements = &el;
+ msg = ldb_msg_new(ltdb);
msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO);
if (!msg->dn) {
goto failed;
}
- el.name = talloc_strdup(msg, LTDB_SEQUENCE_NUMBER);
- if (!el.name) {
+
+ if (ldb_msg_add_string(msg, LTDB_SEQUENCE_NUMBER, initial_sequence_number) != 0) {
goto failed;
}
- el.values = &val;
- el.num_values = 1;
- el.flags = 0;
- val.data = (uint8_t *)talloc_strdup(msg, initial_sequence_number);
- if (!val.data) {
+
+ if (ldb_msg_add_string(msg, LTDB_INDEX_VERSION, "1") != 0) {
goto failed;
}
- val.length = 1;
-
- ret = ltdb_store(module, msg, TDB_INSERT);
+
+ ret = ltdb_store(module, msg, msg, TDB_INSERT);
talloc_free(msg);
@@ -325,6 +313,16 @@ int ltdb_cache_load(struct ldb_module *module)
}
ltdb->sequence_number = seq;
+ /* Determine what index format we are in (updated on reindex) */
+ ltdb->index_version = ldb_msg_find_attr_as_uint64(baseinfo, LTDB_INDEX_VERSION, 0);
+
+ if (ltdb->index_version > 1) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Invalid index version %d on database. This ldb supports only index version 0 and 1",
+ ltdb->index_version);
+ goto failed;
+ }
+
/* Read an interpret database options */
options = talloc(ltdb->cache, struct ldb_message);
if (options == NULL) goto failed;
@@ -448,13 +446,15 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
s = ldb_timestring(msg, t);
if (s == NULL) {
+ talloc_free(msg);
+ errno = ENOMEM;
return LDB_ERR_OPERATIONS_ERROR;
}
val_time.data = (uint8_t *)s;
val_time.length = strlen(s);
- ret = ltdb_modify_internal(module, msg);
+ ret = ltdb_modify_internal(module, msg, msg);
talloc_free(msg);
@@ -469,6 +469,50 @@ int ltdb_increase_sequence_number(struct ldb_module *module)
return ret;
}
+/*
+ increase the index version number to indicate a database change
+*/
+int ltdb_set_casefold_index(struct ldb_module *module)
+{
+ struct ldb_context *ldb;
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+ struct ldb_message *msg;
+ struct ldb_message_element *el;
+
+ int ret;
+
+ ldb = ldb_module_get_ctx(module);
+
+ msg = ldb_msg_new(ltdb);
+ if (msg == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO);
+ if (msg->dn == NULL) {
+ talloc_free(msg);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ if (ldb_msg_add_string(msg, LTDB_INDEX_VERSION, "1") != 0) {
+ talloc_free(msg);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ el = ldb_msg_find_element(msg, LTDB_INDEX_VERSION);
+ if (!el) {
+ talloc_free(msg);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ el->flags = LDB_FLAG_MOD_REPLACE;
+
+ ret = ltdb_modify_internal(module, msg, msg);
+
+ talloc_free(msg);
+
+ return ret;
+}
+
int ltdb_check_at_attributes_values(const struct ldb_val *value)
{
int i;