*/
ltdb->max_key_length = LDB_MDB_MAX_KEY_LENGTH;
- return init_store(ltdb, "ldb_mdb backend", ldb, options, _module);
+ return ldb_kv_init_store(
+ ltdb, "ldb_mdb backend", ldb, options, _module);
}
static const struct {
const char *name;
int value;
-} ltdb_valid_attr_flags[] = {
+} ldb_kv_valid_attr_flags[] = {
{ "CASE_INSENSITIVE", LTDB_FLAG_CASE_INSENSITIVE },
{ "INTEGER", LTDB_FLAG_INTEGER },
{ "HIDDEN", 0 },
{ NULL, 0 }
};
-
/*
de-register any special handlers for @ATTRIBUTES
*/
-static void ltdb_attributes_unload(struct ldb_module *module)
+static void ldb_kv_attributes_unload(struct ldb_module *module)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
/*
add up the attrib flags for a @ATTRIBUTES element
*/
-static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v)
+static int ldb_kv_attributes_flags(struct ldb_message_element *el, unsigned *v)
{
unsigned int i;
unsigned value = 0;
for (i=0;i<el->num_values;i++) {
unsigned int j;
- for (j=0;ltdb_valid_attr_flags[j].name;j++) {
- if (strcmp(ltdb_valid_attr_flags[j].name,
+ for (j = 0; ldb_kv_valid_attr_flags[j].name; j++) {
+ if (strcmp(ldb_kv_valid_attr_flags[j].name,
(char *)el->values[i].data) == 0) {
- value |= ltdb_valid_attr_flags[j].value;
+ value |= ldb_kv_valid_attr_flags[j].value;
break;
}
}
- if (ltdb_valid_attr_flags[j].name == NULL) {
+ if (ldb_kv_valid_attr_flags[j].name == NULL) {
return -1;
}
}
/*
register any special handlers from @ATTRIBUTES
*/
-static int ltdb_attributes_load(struct ldb_module *module)
+static int ldb_kv_attributes_load(struct ldb_module *module)
{
struct ldb_schema_attribute *attrs;
struct ldb_context *ldb;
dn = ldb_dn_new(module, ldb, LTDB_ATTRIBUTES);
if (dn == NULL) goto failed;
- r = ltdb_search_dn1(module, dn, attrs_msg,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC
- |LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC
- |LDB_UNPACK_DATA_FLAG_NO_DN);
+ r = ldb_kv_search_dn1(module,
+ dn,
+ attrs_msg,
+ LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_DN);
talloc_free(dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed;
continue;
}
- if (ltdb_attributes_flags(&attrs_msg->elements[i], &flags) != 0) {
+ if (ldb_kv_attributes_flags(&attrs_msg->elements[i], &flags) !=
+ 0) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Invalid @ATTRIBUTES element for '%s'",
attrs_msg->elements[i].name);
/*
register any index records we find for the DB
*/
-static int ltdb_index_load(struct ldb_module *module,
- struct ltdb_private *ltdb)
+static int ldb_kv_index_load(struct ldb_module *module,
+ struct ltdb_private *ltdb)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
struct ldb_dn *indexlist_dn;
return -1;
}
- r = ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist,
- LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC
- |LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC
- |LDB_UNPACK_DATA_FLAG_NO_DN);
+ r = ldb_kv_search_dn1(module,
+ indexlist_dn,
+ ltdb->cache->indexlist,
+ LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC |
+ LDB_UNPACK_DATA_FLAG_NO_DN);
TALLOC_FREE(indexlist_dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
/*
initialise the baseinfo record
*/
-static int ltdb_baseinfo_init(struct ldb_module *module)
+static int ldb_kv_baseinfo_init(struct ldb_module *module)
{
struct ldb_context *ldb;
void *data = ldb_module_get_private(module);
goto failed;
}
val.length = 1;
-
- ret = ltdb_store(module, msg, TDB_INSERT);
+
+ ret = ldb_kv_store(module, msg, TDB_INSERT);
talloc_free(msg);
/*
free any cache records
*/
-static void ltdb_cache_free(struct ldb_module *module)
+static void ldb_kv_cache_free(struct ldb_module *module)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
/*
force a cache reload
*/
-int ltdb_cache_reload(struct ldb_module *module)
+int ldb_kv_cache_reload(struct ldb_module *module)
{
- ltdb_attributes_unload(module);
- ltdb_cache_free(module);
- return ltdb_cache_load(module);
+ ldb_kv_attributes_unload(module);
+ ldb_kv_cache_free(module);
+ return ldb_kv_cache_load(module);
}
/*
load the cache records
*/
-int ltdb_cache_load(struct ldb_module *module)
+int ldb_kv_cache_load(struct ldb_module *module)
{
struct ldb_context *ldb;
void *data = ldb_module_get_private(module);
if (r != LDB_SUCCESS) {
goto failed;
}
- r= ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0);
+ r = ldb_kv_search_dn1(module, baseinfo_dn, baseinfo, 0);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed_and_unlock;
}
/* error handling for ltdb_baseinfo_init() is by
looking for the record again. */
- ltdb_baseinfo_init(module);
+ ldb_kv_baseinfo_init(module);
- if (ltdb_search_dn1(module, baseinfo_dn, baseinfo, 0) != LDB_SUCCESS) {
+ if (ldb_kv_search_dn1(module, baseinfo_dn, baseinfo, 0) !=
+ LDB_SUCCESS) {
goto failed_and_unlock;
}
options_dn = ldb_dn_new(options, ldb, LTDB_OPTIONS);
if (options_dn == NULL) goto failed_and_unlock;
- r= ltdb_search_dn1(module, options_dn, options, 0);
+ r = ldb_kv_search_dn1(module, options_dn, options, 0);
talloc_free(options_dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed_and_unlock;
* the handlers across all databases when used under Samba's
* partition module.
*/
- ltdb_attributes_unload(module);
+ ldb_kv_attributes_unload(module);
- if (ltdb_index_load(module, ltdb) == -1) {
+ if (ldb_kv_index_load(module, ltdb) == -1) {
goto failed_and_unlock;
}
* the handlers across all databases when used under Samba's
* partition module.
*/
- if (ltdb_attributes_load(module) == -1) {
+ if (ldb_kv_attributes_load(module) == -1) {
goto failed_and_unlock;
}
/*
increase the sequence number to indicate a database change
*/
-int ltdb_increase_sequence_number(struct ldb_module *module)
+int ldb_kv_increase_sequence_number(struct ldb_module *module)
{
struct ldb_context *ldb;
void *data = ldb_module_get_private(module);
val_time.data = (uint8_t *)s;
val_time.length = strlen(s);
- ret = ltdb_modify_internal(module, msg, NULL);
+ ret = ldb_kv_modify_internal(module, msg, NULL);
talloc_free(msg);
return ret;
}
-int ltdb_check_at_attributes_values(const struct ldb_val *value)
+int ldb_kv_check_at_attributes_values(const struct ldb_val *value)
{
unsigned int i;
- for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) {
- if ((strcmp(ltdb_valid_attr_flags[i].name, (char *)value->data) == 0)) {
+ for (i = 0; ldb_kv_valid_attr_flags[i].name != NULL; i++) {
+ if ((strcmp(ldb_kv_valid_attr_flags[i].name,
+ (char *)value->data) == 0)) {
return 0;
}
}
KEY_TRUNCATED,
};
-static int ltdb_write_index_dn_guid(struct ldb_module *module,
- const struct ldb_message *msg,
- int add);
-static int ltdb_index_dn_base_dn(struct ldb_module *module,
- struct ltdb_private *ltdb,
- struct ldb_dn *base_dn,
- struct dn_list *dn_list,
- enum key_truncation *truncation);
+static int ldb_kv_write_index_dn_guid(struct ldb_module *module,
+ const struct ldb_message *msg,
+ int add);
+static int ldb_kv_index_dn_base_dn(struct ldb_module *module,
+ struct ltdb_private *ltdb,
+ struct ldb_dn *base_dn,
+ struct dn_list *dn_list,
+ enum key_truncation *truncation);
-static void ltdb_dn_list_sort(struct ltdb_private *ltdb,
- struct dn_list *list);
+static void ldb_kv_dn_list_sort(struct ltdb_private *ltdb,
+ struct dn_list *list);
/* we put a @IDXVERSION attribute on index entries. This
allows us to tell if it was written by an older version
#define LTDB_GUID_INDEXING_VERSION 3
-static unsigned ltdb_max_key_length(struct ltdb_private *ltdb) {
+static unsigned ldb_kv_max_key_length(struct ltdb_private *ltdb)
+{
if (ltdb->max_key_length == 0){
return UINT_MAX;
}
}
/* enable the idxptr mode when transactions start */
-int ltdb_index_transaction_start(struct ldb_module *module)
+int ldb_kv_index_transaction_start(struct ldb_module *module)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
ltdb->idxptr = talloc_zero(ltdb, struct ltdb_idxptr);
This is therefore safe when the value is a GUID in the future
*/
-static int ltdb_dn_list_find_val(struct ltdb_private *ltdb,
- const struct dn_list *list,
- const struct ldb_val *v)
+static int ldb_kv_dn_list_find_val(struct ltdb_private *ltdb,
+ const struct dn_list *list,
+ const struct ldb_val *v)
{
unsigned int i;
struct ldb_val *exact = NULL, *next = NULL;
find a entry in a dn_list. Uses a case sensitive comparison with the dn
returns -1 if not found
*/
-static int ltdb_dn_list_find_msg(struct ltdb_private *ltdb,
- struct dn_list *list,
- const struct ldb_message *msg)
+static int ldb_kv_dn_list_find_msg(struct ltdb_private *ltdb,
+ struct dn_list *list,
+ const struct ldb_message *msg)
{
struct ldb_val v;
const struct ldb_val *key_val;
}
v = *key_val;
}
- return ltdb_dn_list_find_val(ltdb, list, &v);
+ return ldb_kv_dn_list_find_val(ltdb, list, &v);
}
/*
checks and also copes with CPUs that are fussy about pointer
alignment
*/
-static struct dn_list *ltdb_index_idxptr(struct ldb_module *module, TDB_DATA rec, bool check_parent)
+static struct dn_list *ldb_kv_index_idxptr(struct ldb_module *module, TDB_DATA rec, bool check_parent)
{
struct dn_list *list;
if (rec.dsize != sizeof(void *)) {
return the @IDX list in an index entry for a dn as a
struct dn_list
*/
-static int ltdb_dn_list_load(struct ldb_module *module,
+static int ldb_kv_dn_list_load(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_dn *dn, struct dn_list *list)
{
}
/* we've found an in-memory index entry */
- list2 = ltdb_index_idxptr(module, rec, true);
+ list2 = ldb_kv_index_idxptr(module, rec, true);
if (list2 == NULL) {
free(rec.dptr);
return LDB_ERR_OPERATIONS_ERROR;
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_search_dn1(module, dn, msg,
+ ret = ldb_kv_search_dn1(module, dn, msg,
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC
|LDB_UNPACK_DATA_FLAG_NO_DN);
if (ret != LDB_SUCCESS) {
return LDB_SUCCESS;
}
-int ltdb_key_dn_from_idx(struct ldb_module *module,
+int ldb_kv_key_dn_from_idx(struct ldb_module *module,
struct ltdb_private *ltdb,
TALLOC_CTX *mem_ctx,
struct ldb_dn *dn,
}
- ret = ltdb_index_dn_base_dn(module, ltdb, dn, list, &truncation);
+ ret = ldb_kv_index_dn_base_dn(module, ltdb, dn, list, &truncation);
if (ret != LDB_SUCCESS) {
TALLOC_FREE(list);
return ret;
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_idx_to_key(module, ltdb,
+ ret = ldb_kv_idx_to_key(module, ltdb,
ldb, &list->dn[i],
&key);
if (ret != LDB_SUCCESS) {
return ret;
}
- ret = ltdb_search_key(module, ltdb, key,
+ ret = ldb_kv_search_key(module, ltdb, key,
rec, flags);
if (key.dptr != guid_key) {
TALLOC_FREE(key.dptr);
}
/* The tdb_key memory is allocated by the caller */
- ret = ltdb_guid_to_key(module, ltdb,
+ ret = ldb_kv_guid_to_key(module, ltdb,
&list->dn[index], tdb_key);
TALLOC_FREE(list);
/*
save a dn_list into a full @IDX style record
*/
-static int ltdb_dn_list_store_full(struct ldb_module *module,
+static int ldb_kv_dn_list_store_full(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_dn *dn,
struct dn_list *list)
msg->dn = dn;
if (list->count == 0) {
- ret = ltdb_delete_noindex(module, msg);
+ ret = ldb_kv_delete_noindex(module, msg);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
ret = LDB_SUCCESS;
}
}
}
- ret = ltdb_store(module, msg, TDB_REPLACE);
+ ret = ldb_kv_store(module, msg, TDB_REPLACE);
talloc_free(msg);
return ret;
}
/*
save a dn_list into the database, in either @IDX or internal format
*/
-static int ltdb_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
+static int ldb_kv_dn_list_store(struct ldb_module *module, struct ldb_dn *dn,
struct dn_list *list)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
struct dn_list *list2;
if (ltdb->idxptr == NULL) {
- return ltdb_dn_list_store_full(module, ltdb,
+ return ldb_kv_dn_list_store_full(module, ltdb,
dn, list);
}
rec = tdb_fetch(ltdb->idxptr->itdb, key);
if (rec.dptr != NULL) {
- list2 = ltdb_index_idxptr(module, rec, false);
+ list2 = ldb_kv_index_idxptr(module, rec, false);
if (list2 == NULL) {
free(rec.dptr);
return LDB_ERR_OPERATIONS_ERROR;
/*
traverse function for storing the in-memory index entries on disk
*/
-static int ltdb_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
+static int ldb_kv_index_traverse_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
struct ldb_module *module = state;
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
struct ldb_val v;
struct dn_list *list;
- list = ltdb_index_idxptr(module, data, true);
+ list = ldb_kv_index_idxptr(module, data, true);
if (list == NULL) {
ltdb->idxptr->error = LDB_ERR_OPERATIONS_ERROR;
return -1;
return -1;
}
- ltdb->idxptr->error = ltdb_dn_list_store_full(module, ltdb,
+ ltdb->idxptr->error = ldb_kv_dn_list_store_full(module, ltdb,
dn, list);
talloc_free(dn);
if (ltdb->idxptr->error != 0) {
}
/* cleanup the idxptr mode when transaction commits */
-int ltdb_index_transaction_commit(struct ldb_module *module)
+int ldb_kv_index_transaction_commit(struct ldb_module *module)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
int ret;
ldb_reset_err_string(ldb);
if (ltdb->idxptr->itdb) {
- tdb_traverse(ltdb->idxptr->itdb, ltdb_index_traverse_store, module);
+ tdb_traverse(ltdb->idxptr->itdb, ldb_kv_index_traverse_store, module);
tdb_close(ltdb->idxptr->itdb);
}
}
/* cleanup the idxptr mode when transaction cancels */
-int ltdb_index_transaction_cancel(struct ldb_module *module)
+int ldb_kv_index_transaction_cancel(struct ldb_module *module)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
if (ltdb->idxptr && ltdb->idxptr->itdb) {
return the dn key to be used for an index
the caller is responsible for freeing
*/
-static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb,
+static struct ldb_dn *ldb_kv_index_key(struct ldb_context *ldb,
struct ltdb_private *ltdb,
const char *attr, const struct ldb_val *value,
const struct ldb_schema_attribute **ap,
int r;
bool should_b64_encode;
- unsigned int max_key_length = ltdb_max_key_length(ltdb);
+ unsigned int max_key_length = ldb_kv_max_key_length(ltdb);
size_t key_len = 0;
size_t attr_len = 0;
const size_t indx_len = sizeof(LTDB_INDEX) - 1;
/*
see if a attribute value is in the list of indexed attributes
*/
-static bool ltdb_is_indexed(struct ldb_module *module,
+static bool ldb_kv_is_indexed(struct ldb_module *module,
struct ltdb_private *ltdb,
const char *attr)
{
return a list of dn's that might match a simple indexed search (an
equality search only)
*/
-static int ltdb_index_dn_simple(struct ldb_module *module,
+static int ldb_kv_index_dn_simple(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
/* if the attribute isn't in the list of indexed attributes then
this node needs a full search */
- if (!ltdb_is_indexed(module, ltdb, tree->u.equality.attr)) {
+ if (!ldb_kv_is_indexed(module, ltdb, tree->u.equality.attr)) {
return LDB_ERR_OPERATIONS_ERROR;
}
/* the attribute is indexed. Pull the list of DNs that match the
search criterion */
- dn = ltdb_index_key(ldb, ltdb,
+ dn = ldb_kv_index_key(ldb, ltdb,
tree->u.equality.attr,
&tree->u.equality.value, NULL, &truncation);
/*
*/
if (!dn) return LDB_ERR_OPERATIONS_ERROR;
- ret = ltdb_dn_list_load(module, ltdb, dn, list);
+ ret = ldb_kv_dn_list_load(module, ltdb, dn, list);
talloc_free(dn);
return ret;
}
/*
return a list of dn's that might match a leaf indexed search
*/
-static int ltdb_index_dn_leaf(struct ldb_module *module,
+static int ldb_kv_index_dn_leaf(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
* We can't call TALLOC_FREE(dn) as this must belong
* to list for the memory to remain valid.
*/
- return ltdb_index_dn_base_dn(module, ltdb, dn, list,
+ return ldb_kv_index_dn_base_dn(module, ltdb, dn, list,
&truncation);
/*
* We ignore truncation here and allow multi-valued matches
return LDB_SUCCESS;
}
- return ltdb_index_dn_simple(module, ltdb, tree, list);
+ return ldb_kv_index_dn_simple(module, ltdb, tree, list);
}
for (i=0;i<short_list->count;i++) {
/* For the GUID index case, this is a binary search */
- if (ltdb_dn_list_find_val(ltdb, long_list,
+ if (ldb_kv_dn_list_find_val(ltdb, long_list,
&short_list->dn[i]) != -1) {
list3->dn[list3->count] = short_list->dn[i];
list3->count++;
* NOTE: This can sort the in-memory index values, as list or
* list2 might not be a copy!
*/
- ltdb_dn_list_sort(ltdb, list);
- ltdb_dn_list_sort(ltdb, list2);
+ ldb_kv_dn_list_sort(ltdb, list);
+ ldb_kv_dn_list_sort(ltdb, list2);
dn3 = talloc_array(list, struct ldb_val, list->count + list2->count);
if (!dn3) {
return true;
}
-static int ltdb_index_dn(struct ldb_module *module,
+static int ldb_kv_index_dn(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list);
/*
process an OR list (a union)
*/
-static int ltdb_index_dn_or(struct ldb_module *module,
+static int ldb_kv_index_dn_or(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_index_dn(module, ltdb,
+ ret = ldb_kv_index_dn(module, ltdb,
tree->u.list.elements[i], list2);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/*
NOT an index results
*/
-static int ltdb_index_dn_not(struct ldb_module *module,
+static int ldb_kv_index_dn_not(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
* These things are unique, so avoid a full scan if this is a search
* by GUID, DN or a unique attribute
*/
-static bool ltdb_index_unique(struct ldb_context *ldb,
+static bool ldb_kv_index_unique(struct ldb_context *ldb,
struct ltdb_private *ltdb,
const char *attr)
{
/*
process an AND expression (intersection)
*/
-static int ltdb_index_dn_and(struct ldb_module *module,
+static int ldb_kv_index_dn_and(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
int ret;
if (subtree->operation != LDB_OP_EQUALITY ||
- !ltdb_index_unique(ldb, ltdb,
+ !ldb_kv_index_unique(ldb, ltdb,
subtree->u.equality.attr)) {
continue;
}
- ret = ltdb_index_dn(module, ltdb, subtree, list);
+ ret = ldb_kv_index_dn(module, ltdb, subtree, list);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* 0 && X == 0 */
return LDB_ERR_NO_SUCH_OBJECT;
return ldb_module_oom(module);
}
- ret = ltdb_index_dn(module, ltdb, subtree, list2);
+ ret = ldb_kv_index_dn(module, ltdb, subtree, list2);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* X && 0 == 0 */
/*
return a list of matching objects using a one-level index
*/
-static int ltdb_index_dn_attr(struct ldb_module *module,
+static int ldb_kv_index_dn_attr(struct ldb_module *module,
struct ltdb_private *ltdb,
const char *attr,
struct ldb_dn *dn,
/* work out the index key from the parent DN */
val.data = (uint8_t *)((uintptr_t)ldb_dn_get_casefold(dn));
val.length = strlen((char *)val.data);
- key = ltdb_index_key(ldb, ltdb, attr, &val, NULL, truncation);
+ key = ldb_kv_index_key(ldb, ltdb, attr, &val, NULL, truncation);
if (!key) {
ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_dn_list_load(module, ltdb, key, list);
+ ret = ldb_kv_dn_list_load(module, ltdb, key, list);
talloc_free(key);
if (ret != LDB_SUCCESS) {
return ret;
/*
return a list of matching objects using a one-level index
*/
-static int ltdb_index_dn_one(struct ldb_module *module,
+static int ldb_kv_index_dn_one(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_dn *parent_dn,
struct dn_list *list,
{
/* Ensure we do not shortcut on intersection for this list */
list->strict = true;
- return ltdb_index_dn_attr(module, ltdb,
+ return ldb_kv_index_dn_attr(module, ltdb,
LTDB_IDXONE, parent_dn, list, truncation);
}
/*
return a list of matching objects using the DN index
*/
-static int ltdb_index_dn_base_dn(struct ldb_module *module,
+static int ldb_kv_index_dn_base_dn(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_dn *base_dn,
struct dn_list *dn_list,
return LDB_SUCCESS;
}
- return ltdb_index_dn_attr(module, ltdb,
+ return ldb_kv_index_dn_attr(module, ltdb,
LTDB_IDXDN, base_dn, dn_list, truncation);
}
return a list of dn's that might match a indexed search or
an error. return LDB_ERR_NO_SUCH_OBJECT for no matches, or LDB_SUCCESS for matches
*/
-static int ltdb_index_dn(struct ldb_module *module,
+static int ldb_kv_index_dn(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_parse_tree *tree,
struct dn_list *list)
switch (tree->operation) {
case LDB_OP_AND:
- ret = ltdb_index_dn_and(module, ltdb, tree, list);
+ ret = ldb_kv_index_dn_and(module, ltdb, tree, list);
break;
case LDB_OP_OR:
- ret = ltdb_index_dn_or(module, ltdb, tree, list);
+ ret = ldb_kv_index_dn_or(module, ltdb, tree, list);
break;
case LDB_OP_NOT:
- ret = ltdb_index_dn_not(module, ltdb, tree, list);
+ ret = ldb_kv_index_dn_not(module, ltdb, tree, list);
break;
case LDB_OP_EQUALITY:
- ret = ltdb_index_dn_leaf(module, ltdb, tree, list);
+ ret = ldb_kv_index_dn_leaf(module, ltdb, tree, list);
break;
case LDB_OP_SUBSTRING:
filter a candidate dn_list from an indexed search into a set of results
extracting just the given attributes
*/
-static int ltdb_index_filter(struct ltdb_private *ltdb,
+static int ldb_kv_index_filter(struct ltdb_private *ltdb,
const struct dn_list *dn_list,
struct ltdb_context *ac,
uint32_t *match_count,
for (i = 0; i < dn_list->count; i++) {
int ret;
- ret = ltdb_idx_to_key(ac->module,
+ ret = ldb_kv_idx_to_key(ac->module,
ltdb,
keys,
&dn_list->dn[i],
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_search_key(ac->module, ltdb,
+ ret = ldb_kv_search_key(ac->module, ltdb,
keys[i], msg,
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC|
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC);
}
/* filter the attributes that the user wants */
- ret = ltdb_filter_attrs(ac, msg, ac->attrs, &filtered_msg);
+ ret = ldb_kv_filter_attrs(ac, msg, ac->attrs, &filtered_msg);
talloc_free(msg);
/*
sort a DN list
*/
-static void ltdb_dn_list_sort(struct ltdb_private *ltdb,
+static void ldb_kv_dn_list_sort(struct ltdb_private *ltdb,
struct dn_list *list)
{
if (list->count < 2) {
returns -1 if an indexed search is not possible, in which
case the caller should call ltdb_search_full()
*/
-int ltdb_search_indexed(struct ltdb_context *ac, uint32_t *match_count)
+int ldb_kv_search_indexed(struct ltdb_context *ac, uint32_t *match_count)
{
struct ldb_context *ldb = ldb_module_get_ctx(ac->module);
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(ac->module), struct ltdb_private);
* the tree, we must ensure we strictly intersect with
* this list, as we trust the ONELEVEL index
*/
- ret = ltdb_index_dn_one(ac->module, ltdb, ac->base, dn_list,
+ ret = ldb_kv_index_dn_one(ac->module, ltdb, ac->base, dn_list,
&scope_one_truncation);
if (ret != LDB_SUCCESS) {
talloc_free(dn_list);
* index can't trim the result list down then
* the ONELEVEL index is still good enough.
*/
- ret = ltdb_index_dn(ac->module, ltdb, ac->tree,
+ ret = ldb_kv_index_dn(ac->module, ltdb, ac->tree,
idx_one_tree_list);
if (ret == LDB_SUCCESS) {
if (!list_intersect(ldb, ltdb,
* Here we load the index for the tree. We have no
* index for the subtree.
*/
- ret = ltdb_index_dn(ac->module, ltdb, ac->tree, dn_list);
+ ret = ldb_kv_index_dn(ac->module, ltdb, ac->tree, dn_list);
if (ret != LDB_SUCCESS) {
talloc_free(dn_list);
return ret;
* processing as the truncation here refers only to the
* SCOPE_ONELEVEL index.
*/
- ret = ltdb_index_filter(ltdb, dn_list, ac, match_count,
+ ret = ldb_kv_index_filter(ltdb, dn_list, ac, match_count,
scope_one_truncation);
talloc_free(dn_list);
return ret;
*
* @return An ldb error code
*/
-static int ltdb_index_add1(struct ldb_module *module,
+static int ldb_kv_index_add1(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el, int v_idx)
return LDB_ERR_OPERATIONS_ERROR;
}
- dn_key = ltdb_index_key(ldb, ltdb,
+ dn_key = ldb_kv_index_key(ldb, ltdb,
el->name, &el->values[v_idx], &a, &truncation);
if (!dn_key) {
talloc_free(list);
}
talloc_steal(list, dn_key);
- ret = ltdb_dn_list_load(module, ltdb, dn_key, list);
+ ret = ldb_kv_dn_list_load(module, ltdb, dn_key, list);
if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) {
talloc_free(list);
return ret;
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_idx_to_key(module, ltdb,
+ ret = ldb_kv_idx_to_key(module, ltdb,
ldb, &list->dn[i],
&key);
if (ret != LDB_SUCCESS) {
return ret;
}
- ret = ltdb_search_key(module, ltdb, key,
+ ret = ldb_kv_search_key(module, ltdb, key,
rec, flags);
if (key.dptr != guid_key) {
TALLOC_FREE(key.dptr);
}
list->count++;
- ret = ltdb_dn_list_store(module, dn_key, list);
+ ret = ldb_kv_dn_list_store(module, dn_key, list);
talloc_free(list);
/*
add index entries for one elements in a message
*/
-static int ltdb_index_add_el(struct ldb_module *module,
+static int ldb_kv_index_add_el(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el)
{
unsigned int i;
for (i = 0; i < el->num_values; i++) {
- int ret = ltdb_index_add1(module, ltdb,
+ int ret = ldb_kv_index_add1(module, ltdb,
msg, el, i);
if (ret != LDB_SUCCESS) {
return ret;
/*
add index entries for all elements in a message
*/
-static int ltdb_index_add_all(struct ldb_module *module,
+static int ldb_kv_index_add_all(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg)
{
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_write_index_dn_guid(module, msg, 1);
+ ret = ldb_kv_write_index_dn_guid(module, msg, 1);
if (ret != LDB_SUCCESS) {
return ret;
}
}
for (i = 0; i < msg->num_elements; i++) {
- if (!ltdb_is_indexed(module, ltdb, elements[i].name)) {
+ if (!ldb_kv_is_indexed(module, ltdb, elements[i].name)) {
continue;
}
- ret = ltdb_index_add_el(module, ltdb,
+ ret = ldb_kv_index_add_el(module, ltdb,
msg, &elements[i]);
if (ret != LDB_SUCCESS) {
struct ldb_context *ldb = ldb_module_get_ctx(module);
/*
insert a DN index for a message
*/
-static int ltdb_modify_index_dn(struct ldb_module *module,
+static int ldb_kv_modify_index_dn(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_dn *dn,
el.num_values = 1;
if (add) {
- ret = ltdb_index_add1(module, ltdb, msg, &el, 0);
+ ret = ldb_kv_index_add1(module, ltdb, msg, &el, 0);
} else { /* delete */
- ret = ltdb_index_del_value(module, ltdb, msg, &el, 0);
+ ret = ldb_kv_index_del_value(module, ltdb, msg, &el, 0);
}
if (ret != LDB_SUCCESS) {
/*
insert a one level index for a message
*/
-static int ltdb_index_onelevel(struct ldb_module *module,
+static int ldb_kv_index_onelevel(struct ldb_module *module,
const struct ldb_message *msg, int add)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module),
if (pdn == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_modify_index_dn(module, ltdb,
+ ret = ldb_kv_modify_index_dn(module, ltdb,
msg, pdn, LTDB_IDXONE, add);
talloc_free(pdn);
/*
insert a one level index for a message
*/
-static int ltdb_write_index_dn_guid(struct ldb_module *module,
+static int ldb_kv_write_index_dn_guid(struct ldb_module *module,
const struct ldb_message *msg,
int add)
{
return LDB_SUCCESS;
}
- ret = ltdb_modify_index_dn(module, ltdb, msg, msg->dn,
+ ret = ldb_kv_modify_index_dn(module, ltdb, msg, msg->dn,
LTDB_IDXDN, add);
if (ret == LDB_ERR_CONSTRAINT_VIOLATION) {
add the index entries for a new element in a record
The caller guarantees that these element values are not yet indexed
*/
-int ltdb_index_add_element(struct ldb_module *module,
+int ldb_kv_index_add_element(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el)
if (ldb_dn_is_special(msg->dn)) {
return LDB_SUCCESS;
}
- if (!ltdb_is_indexed(module, ltdb, el->name)) {
+ if (!ldb_kv_is_indexed(module, ltdb, el->name)) {
return LDB_SUCCESS;
}
- return ltdb_index_add_el(module, ltdb, msg, el);
+ return ldb_kv_index_add_el(module, ltdb, msg, el);
}
/*
add the index entries for a new record
*/
-int ltdb_index_add_new(struct ldb_module *module,
+int ldb_kv_index_add_new(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg)
{
return LDB_SUCCESS;
}
- ret = ltdb_index_add_all(module, ltdb, msg);
+ ret = ldb_kv_index_add_all(module, ltdb, msg);
if (ret != LDB_SUCCESS) {
/*
* Because we can't trust the caller to be doing
* cleanup
*/
- ltdb_index_delete(module, msg);
+ ldb_kv_index_delete(module, msg);
return ret;
}
- ret = ltdb_index_onelevel(module, msg, 1);
+ ret = ldb_kv_index_onelevel(module, msg, 1);
if (ret != LDB_SUCCESS) {
/*
* Because we can't trust the caller to be doing
* entry rather than relying on a transaction
* cleanup
*/
- ltdb_index_delete(module, msg);
+ ldb_kv_index_delete(module, msg);
return ret;
}
return ret;
/*
delete an index entry for one message element
*/
-int ltdb_index_del_value(struct ldb_module *module,
+int ldb_kv_index_del_value(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el, unsigned int v_idx)
return LDB_SUCCESS;
}
- dn_key = ltdb_index_key(ldb, ltdb,
+ dn_key = ldb_kv_index_key(ldb, ltdb,
el->name, &el->values[v_idx],
NULL, &truncation);
/*
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_dn_list_load(module, ltdb, dn_key, list);
+ ret = ldb_kv_dn_list_load(module, ltdb, dn_key, list);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* it wasn't indexed. Did we have an earlier error? If we did then
its gone now */
/*
* Find one of the values matching this message to remove
*/
- i = ltdb_dn_list_find_msg(ltdb, list, msg);
+ i = ldb_kv_dn_list_find_msg(ltdb, list, msg);
if (i == -1) {
/* nothing to delete */
talloc_free(dn_key);
list->dn = talloc_realloc(list, list->dn, struct ldb_val, list->count);
}
- ret = ltdb_dn_list_store(module, dn_key, list);
+ ret = ldb_kv_dn_list_store(module, dn_key, list);
talloc_free(dn_key);
delete the index entries for a element
return -1 on failure
*/
-int ltdb_index_del_element(struct ldb_module *module,
+int ldb_kv_index_del_element(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el)
return LDB_SUCCESS;
}
- if (!ltdb_is_indexed(module, ltdb, el->name)) {
+ if (!ldb_kv_is_indexed(module, ltdb, el->name)) {
return LDB_SUCCESS;
}
for (i = 0; i < el->num_values; i++) {
- ret = ltdb_index_del_value(module, ltdb, msg, el, i);
+ ret = ldb_kv_index_del_value(module, ltdb, msg, el, i);
if (ret != LDB_SUCCESS) {
return ret;
}
delete the index entries for a record
return -1 on failure
*/
-int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg)
+int ldb_kv_index_delete(struct ldb_module *module, const struct ldb_message *msg)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
int ret;
return LDB_SUCCESS;
}
- ret = ltdb_index_onelevel(module, msg, 0);
+ ret = ldb_kv_index_onelevel(module, msg, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
- ret = ltdb_write_index_dn_guid(module, msg, 0);
+ ret = ldb_kv_write_index_dn_guid(module, msg, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
}
for (i = 0; i < msg->num_elements; i++) {
- ret = ltdb_index_del_element(module, ltdb,
+ ret = ldb_kv_index_del_element(module, ltdb,
msg, &msg->elements[i]);
if (ret != LDB_SUCCESS) {
return ret;
* This does not actually touch the DB quite yet, just
* the in-memory index cache
*/
- ret = ltdb_dn_list_store(module, dn, &list);
+ ret = ldb_kv_dn_list_store(module, dn, &list);
if (ret != LDB_SUCCESS) {
ldb_asprintf_errstring(ldb_module_get_ctx(module),
"Unable to store null index for %s\n",
return 0;
}
- is_record = ltdb_key_is_record(key);
+ is_record = ldb_kv_key_is_record(key);
if (is_record == false) {
return 0;
}
/* check if the DN key has changed, perhaps due to the case
insensitivity of an element changing, or a change from DN
to GUID keys */
- key2 = ltdb_key_msg(module, msg, msg);
+ key2 = ldb_kv_key_msg(module, msg, msg);
if (key2.dptr == NULL) {
/* probably a corrupt record ... darn */
ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s",
return 0;
}
- is_record = ltdb_key_is_record(key);
+ is_record = ldb_kv_key_is_record(key);
if (is_record == false) {
return 0;
}
return -1;
}
- ret = ltdb_index_onelevel(module, msg, 1);
+ ret = ldb_kv_index_onelevel(module, msg, 1);
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Adding special ONE LEVEL index failed (%s)!",
return -1;
}
- ret = ltdb_index_add_all(module, ltdb, msg);
+ ret = ldb_kv_index_add_all(module, ltdb, msg);
if (ret != LDB_SUCCESS) {
ctx->error = ret;
/*
force a complete reindex of the database
*/
-int ltdb_reindex(struct ldb_module *module)
+int ldb_kv_reindex(struct ldb_module *module)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
int ret;
return LDB_ERR_UNWILLING_TO_PERFORM;
}
- if (ltdb_cache_reload(module) != 0) {
+ if (ldb_kv_cache_reload(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
* DB, no values stored so far are any use as we want to do a
* re-index
*/
- ltdb_index_transaction_cancel(module);
+ ldb_kv_index_transaction_cancel(module);
- ret = ltdb_index_transaction_start(module);
+ ret = ldb_kv_index_transaction_start(module);
if (ret != LDB_SUCCESS) {
return ret;
}
return LDB_ERR_NO_SUCH_OBJECT on record-not-found
and LDB_SUCCESS on success
*/
-int ltdb_search_base(struct ldb_module *module,
+int ldb_kv_search_base(struct ldb_module *module,
TALLOC_CTX *mem_ctx,
struct ldb_dn *dn,
struct ldb_dn **ret_dn)
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_search_dn1(module, dn,
+ ret = ldb_kv_search_dn1(module, dn,
msg,
LDB_UNPACK_DATA_FLAG_NO_ATTRS);
if (ret == LDB_SUCCESS) {
unsigned int unpack_flags;
};
-static int ltdb_parse_data_unpack(struct ldb_val key,
+static int ldb_kv_parse_data_unpack(struct ldb_val key,
struct ldb_val data,
void *private_data)
{
return LDB_ERR_NO_SUCH_OBJECT on record-not-found
and LDB_SUCCESS on success
*/
-int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
+int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
const struct TDB_DATA tdb_key,
struct ldb_message *msg,
unsigned int unpack_flags)
msg->elements = NULL;
ret = ltdb->kv_ops->fetch_and_parse(ltdb, ldb_key,
- ltdb_parse_data_unpack, &ctx);
+ ldb_kv_parse_data_unpack, &ctx);
if (ret == -1) {
ret = ltdb->kv_ops->error(ltdb);
return LDB_ERR_NO_SUCH_OBJECT on record-not-found
and LDB_SUCCESS on success
*/
-int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
+int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
unsigned int unpack_flags)
{
void *data = ldb_module_get_private(module);
}
/* form the key */
- tdb_key = ltdb_key_dn(module, tdb_key_ctx, dn);
+ tdb_key = ldb_kv_key_dn(module, tdb_key_ctx, dn);
if (!tdb_key.dptr) {
TALLOC_FREE(tdb_key_ctx);
return LDB_ERR_OPERATIONS_ERROR;
* used for internal memory.
*
*/
- ret = ltdb_key_dn_from_idx(module, ltdb,
+ ret = ldb_kv_key_dn_from_idx(module, ltdb,
msg,
dn, &tdb_key);
if (ret != LDB_SUCCESS) {
}
}
- ret = ltdb_search_key(module, ltdb, tdb_key, msg, unpack_flags);
+ ret = ldb_kv_search_key(module, ltdb, tdb_key, msg, unpack_flags);
TALLOC_FREE(tdb_key_ctx);
individually allocated, which is what our callers expect.
*/
-int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
+int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg, const char * const *attrs,
struct ldb_message **filtered_msg)
{
ac = talloc_get_type(state, struct ltdb_context);
ldb = ldb_module_get_ctx(ac->module);
- if (ltdb_key_is_record(tdb_key) == false) {
+ if (ldb_kv_key_is_record(tdb_key) == false) {
return 0;
}
}
/* filter the attributes that the user wants */
- ret = ltdb_filter_attrs(ac, msg, ac->attrs, &filtered_msg);
+ ret = ldb_kv_filter_attrs(ac, msg, ac->attrs, &filtered_msg);
talloc_free(msg);
if (ret == -1) {
search the database with a LDAP-like expression.
this is the "full search" non-indexed variant
*/
-static int ltdb_search_full(struct ltdb_context *ctx)
+static int ldb_kv_search_full(struct ltdb_context *ctx)
{
void *data = ldb_module_get_private(ctx->module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
return ctx->error;
}
-static int ltdb_search_and_return_base(struct ltdb_private *ltdb,
+static int ldb_kv_search_and_return_base(struct ltdb_private *ltdb,
struct ltdb_context *ctx)
{
struct ldb_message *msg, *filtered_msg;
if (!msg) {
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_search_dn1(ctx->module, ctx->base, msg,
+ ret = ldb_kv_search_dn1(ctx->module, ctx->base, msg,
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC|
LDB_UNPACK_DATA_FLAG_NO_VALUES_ALLOC);
* This copies msg->dn including the casefolding, so the above
* assignment is safe
*/
- ret = ltdb_filter_attrs(ctx, msg, ctx->attrs, &filtered_msg);
+ ret = ldb_kv_filter_attrs(ctx, msg, ctx->attrs, &filtered_msg);
/*
* Remove any extended components possibly copied in from
search the database with a LDAP-like expression.
choses a search method
*/
-int ltdb_search(struct ltdb_context *ctx)
+int ldb_kv_search(struct ltdb_context *ctx)
{
struct ldb_context *ldb;
struct ldb_module *module = ctx->module;
return LDB_ERR_OPERATIONS_ERROR;
}
- if (ltdb_cache_load(module) != 0) {
+ if (ldb_kv_cache_load(module) != 0) {
ltdb->kv_ops->unlock_read(module);
return LDB_ERR_OPERATIONS_ERROR;
}
* will try to look up an index record for a special
* record (which doesn't exist).
*/
- ret = ltdb_search_and_return_base(ltdb, ctx);
+ ret = ldb_kv_search_and_return_base(ltdb, ctx);
ltdb->kv_ops->unlock_read(module);
* dn. Also optimise the subsequent filter by filling
* in the ctx->base to be exactly case correct
*/
- ret = ltdb_search_base(module, ctx,
+ ret = ldb_kv_search_base(module, ctx,
req->op.search.base,
&ctx->base);
if (ret == LDB_SUCCESS) {
uint32_t match_count = 0;
- ret = ltdb_search_indexed(ctx, &match_count);
+ ret = ldb_kv_search_indexed(ctx, &match_count);
if (ret == LDB_ERR_NO_SUCH_OBJECT) {
/* Not in the index, therefore OK! */
ret = LDB_SUCCESS;
return LDB_ERR_INAPPROPRIATE_MATCHING;
}
- ret = ltdb_search_full(ctx);
+ ret = ldb_kv_search_full(ctx);
if (ret != LDB_SUCCESS) {
ldb_set_errstring(ldb, "Indexed and full searches both failed!\n");
}
* Determine if this key could hold a record. We allow the new GUID
* index, the old DN index and a possible future ID=
*/
-bool ltdb_key_is_record(TDB_DATA key)
+bool ldb_kv_key_is_record(TDB_DATA key)
{
if (key.dsize < 4) {
return false;
note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
-TDB_DATA ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
+TDB_DATA ldb_kv_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
struct ldb_dn *dn)
{
TDB_DATA key;
}
/* The caller is to provide a correctly sized key */
-int ltdb_guid_to_key(struct ldb_module *module,
+int ldb_kv_guid_to_key(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_val *GUID_val,
TDB_DATA *key)
* The caller is to provide a correctly sized key, used only in
* the GUID index mode
*/
-int ltdb_idx_to_key(struct ldb_module *module,
+int ldb_kv_idx_to_key(struct ldb_module *module,
struct ltdb_private *ltdb,
TALLOC_CTX *mem_ctx,
const struct ldb_val *idx_val,
struct ldb_dn *dn;
if (ltdb->cache->GUID_index_attribute != NULL) {
- return ltdb_guid_to_key(module, ltdb,
+ return ldb_kv_guid_to_key(module, ltdb,
idx_val, key);
}
return LDB_ERR_OPERATIONS_ERROR;
}
/* form the key */
- *key = ltdb_key_dn(module, mem_ctx, dn);
+ *key = ldb_kv_key_dn(module, mem_ctx, dn);
TALLOC_FREE(dn);
if (!key->dptr) {
return ldb_module_oom(module);
note that the key for a record can depend on whether a
GUID index is in use, or the DN is used as the key
*/
-TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
+TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
const struct ldb_message *msg)
{
void *data = ldb_module_get_private(module);
int ret;
if (ltdb->cache->GUID_index_attribute == NULL) {
- return ltdb_key_dn(module, mem_ctx, msg->dn);
+ return ldb_kv_key_dn(module, mem_ctx, msg->dn);
}
if (ldb_dn_is_special(msg->dn)) {
- return ltdb_key_dn(module, mem_ctx, msg->dn);
+ return ldb_kv_key_dn(module, mem_ctx, msg->dn);
}
guid_val = ldb_msg_find_ldb_val(msg,
}
key.dsize = talloc_get_size(key.dptr);
- ret = ltdb_guid_to_key(module, ltdb, guid_val, &key);
+ ret = ldb_kv_guid_to_key(module, ltdb, guid_val, &key);
if (ret != LDB_SUCCESS) {
errno = EINVAL;
check special dn's have valid attributes
currently only @ATTRIBUTES is checked
*/
-static int ltdb_check_special_dn(struct ldb_module *module,
+static int ldb_kv_check_special_dn(struct ldb_module *module,
const struct ldb_message *msg)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
if (ldb_attr_cmp(msg->elements[i].name, "distinguishedName") == 0) continue;
for (j = 0; j < msg->elements[i].num_values; j++) {
- if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) {
+ if (ldb_kv_check_at_attributes_values(&msg->elements[i].values[j]) != 0) {
ldb_set_errstring(ldb, "Invalid attribute value in an @ATTRIBUTES entry");
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
we've made a modification to a dn - possibly reindex and
update sequence number
*/
-static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn)
+static int ldb_kv_modified(struct ldb_module *module, struct ldb_dn *dn)
{
int ret = LDB_SUCCESS;
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module), struct ltdb_private);
LDB_DEBUG_ERROR, "Reindexing %s due to modification on %s",
ltdb->kv_ops->name(ltdb), ldb_dn_get_linearized(dn));
}
- ret = ltdb_reindex(module);
+ ret = ldb_kv_reindex(module);
}
/* If the modify was to a normal record, or any special except @BASEINFO, update the seq number */
if (ret == LDB_SUCCESS &&
!(ldb_dn_is_special(dn) &&
ldb_dn_check_special(dn, LTDB_BASEINFO)) ) {
- ret = ltdb_increase_sequence_number(module);
+ ret = ldb_kv_increase_sequence_number(module);
}
/* If the modify was to @OPTIONS, reload the cache */
if (ret == LDB_SUCCESS &&
ldb_dn_is_special(dn) &&
(ldb_dn_check_special(dn, LTDB_OPTIONS)) ) {
- ret = ltdb_cache_reload(module);
+ ret = ldb_kv_cache_reload(module);
}
if (ret != LDB_SUCCESS) {
return ret;
}
-static int ltdb_tdb_store(struct ltdb_private *ltdb, struct ldb_val ldb_key,
+static int ltdb_store(struct ltdb_private *ltdb, struct ldb_val ldb_key,
struct ldb_val ldb_data, int flags)
{
TDB_DATA key = {
/*
store a record into the db
*/
-int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs)
+int ldb_kv_store(
+ struct ldb_module *module,
+ const struct ldb_message *msg,
+ int flgs)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
- tdb_key = ltdb_key_msg(module, tdb_key_ctx, msg);
+ tdb_key = ldb_kv_key_msg(module, tdb_key_ctx, msg);
if (tdb_key.dptr == NULL) {
TALLOC_FREE(tdb_key_ctx);
return LDB_ERR_OTHER;
/*
check if a attribute is a single valued, for a given element
*/
-static bool ldb_tdb_single_valued(const struct ldb_schema_attribute *a,
+static bool ldb_kv_single_valued(const struct ldb_schema_attribute *a,
struct ldb_message_element *el)
{
if (!a) return false;
return false;
}
-static int ltdb_add_internal(struct ldb_module *module,
+static int ldb_kv_add_internal(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
bool check_single_value)
}
if (check_single_value &&
el->num_values > 1 &&
- ldb_tdb_single_valued(a, el)) {
+ ldb_kv_single_valued(a, el)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg->dn));
return LDB_ERR_CONSTRAINT_VIOLATION;
}
}
- ret = ltdb_store(module, msg, TDB_INSERT);
+ ret = ldb_kv_store(module, msg, TDB_INSERT);
if (ret != LDB_SUCCESS) {
/*
* Try really hard to get the right error code for
if (mem_ctx == NULL) {
return ldb_module_operr(module);
}
- ret2 = ltdb_search_base(module, mem_ctx,
+ ret2 = ldb_kv_search_base(module, mem_ctx,
msg->dn, &dn2);
TALLOC_FREE(mem_ctx);
if (ret2 == LDB_SUCCESS) {
return ret;
}
- ret = ltdb_index_add_new(module, ltdb, msg);
+ ret = ldb_kv_index_add_new(module, ltdb, msg);
if (ret != LDB_SUCCESS) {
/*
* If we failed to index, delete the message again.
* Note that the caller may not cancel the transation
* and this means the above add might really show up!
*/
- ltdb_delete_noindex(module, msg);
+ ldb_kv_delete_noindex(module, msg);
return ret;
}
- ret = ltdb_modified(module, msg->dn);
+ ret = ldb_kv_modified(module, msg->dn);
return ret;
}
/*
add a record to the database
*/
-static int ltdb_add(struct ltdb_context *ctx)
+static int ldb_kv_add(struct ltdb_context *ctx)
{
struct ldb_module *module = ctx->module;
struct ldb_request *req = ctx->req;
return LDB_ERR_UNWILLING_TO_PERFORM;
}
- ret = ltdb_check_special_dn(module, req->op.add.message);
+ ret = ldb_kv_check_special_dn(module, req->op.add.message);
if (ret != LDB_SUCCESS) {
return ret;
}
ldb_request_set_state(req, LDB_ASYNC_PENDING);
- if (ltdb_cache_load(module) != 0) {
+ if (ldb_kv_cache_load(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_add_internal(module, ltdb,
+ ret = ldb_kv_add_internal(module, ltdb,
req->op.add.message, true);
return ret;
}
-static int ltdb_tdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key)
+static int ltdb_delete(struct ltdb_private *ltdb, struct ldb_val ldb_key)
{
TDB_DATA tdb_key = {
.dptr = ldb_key.data,
delete a record from the database, not updating indexes (used for deleting
index records)
*/
-int ltdb_delete_noindex(struct ldb_module *module,
+int ldb_kv_delete_noindex(struct ldb_module *module,
const struct ldb_message *msg)
{
void *data = ldb_module_get_private(module);
return LDB_ERR_UNWILLING_TO_PERFORM;
}
- tdb_key = ltdb_key_msg(module, tdb_key_ctx, msg);
+ tdb_key = ldb_kv_key_msg(module, tdb_key_ctx, msg);
if (!tdb_key.dptr) {
TALLOC_FREE(tdb_key_ctx);
return LDB_ERR_OTHER;
return ret;
}
-static int ltdb_delete_internal(struct ldb_module *module, struct ldb_dn *dn)
+static int ldb_kv_delete_internal(struct ldb_module *module, struct ldb_dn *dn)
{
struct ldb_message *msg;
int ret = LDB_SUCCESS;
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ltdb_search_dn1(module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
+ ret = ldb_kv_search_dn1(module, dn, msg, LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
if (ret != LDB_SUCCESS) {
/* not finding the old record is an error */
goto done;
}
- ret = ltdb_delete_noindex(module, msg);
+ ret = ldb_kv_delete_noindex(module, msg);
if (ret != LDB_SUCCESS) {
goto done;
}
/* remove any indexed attributes */
- ret = ltdb_index_delete(module, msg);
+ ret = ldb_kv_index_delete(module, msg);
if (ret != LDB_SUCCESS) {
goto done;
}
- ret = ltdb_modified(module, dn);
+ ret = ldb_kv_modified(module, dn);
if (ret != LDB_SUCCESS) {
goto done;
}
/*
delete a record from the database
*/
-static int ltdb_delete(struct ltdb_context *ctx)
+static int ldb_kv_delete(struct ltdb_context *ctx)
{
struct ldb_module *module = ctx->module;
struct ldb_request *req = ctx->req;
ldb_request_set_state(req, LDB_ASYNC_PENDING);
- if (ltdb_cache_load(module) != 0) {
+ if (ldb_kv_cache_load(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_delete_internal(module, req->op.del.dn);
+ ret = ldb_kv_delete_internal(module, req->op.del.dn);
return ret;
}
return the index of the first matching element if found, otherwise -1
*/
-static int find_element(const struct ldb_message *msg, const char *name)
+static int ldb_kv_find_element(const struct ldb_message *msg, const char *name)
{
unsigned int i;
for (i=0;i<msg->num_elements;i++) {
returns 0 on success, -1 on failure (and sets errno)
*/
-static int ltdb_msg_add_element(struct ldb_message *msg,
+static int ldb_kv_msg_add_element(struct ldb_message *msg,
struct ldb_message_element *el)
{
struct ldb_message_element *e2;
/*
delete all elements having a specified attribute name
*/
-static int msg_delete_attribute(struct ldb_module *module,
+static int ldb_kv_msg_delete_attribute(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_message *msg, const char *name)
{
}
i = el - msg->elements;
- ret = ltdb_index_del_element(module, ltdb, msg, el);
+ ret = ldb_kv_index_del_element(module, ltdb, msg, el);
if (ret != LDB_SUCCESS) {
return ret;
}
return LDB Error on failure
*/
-static int msg_delete_element(struct ldb_module *module,
+static int ldb_kv_msg_delete_element(struct ldb_module *module,
struct ltdb_private *ltdb,
struct ldb_message *msg,
const char *name,
struct ldb_message_element *el;
const struct ldb_schema_attribute *a;
- found = find_element(msg, name);
+ found = ldb_kv_find_element(msg, name);
if (found == -1) {
return LDB_ERR_NO_SUCH_ATTRIBUTE;
}
}
if (matched) {
if (el->num_values == 1) {
- return msg_delete_attribute(module,
+ return ldb_kv_msg_delete_attribute(module,
ltdb, msg, name);
}
- ret = ltdb_index_del_value(module, ltdb, msg, el, i);
+ ret = ldb_kv_index_del_value(module, ltdb, msg, el, i);
if (ret != LDB_SUCCESS) {
return ret;
}
'req' is optional, and is used to specify controls if supplied
*/
-int ltdb_modify_internal(struct ldb_module *module,
+int ldb_kv_modify_internal(struct ldb_module *module,
const struct ldb_message *msg,
struct ldb_request *req)
{
goto done;
}
- ret = ltdb_search_dn1(module, msg->dn,
+ ret = ldb_kv_search_dn1(module, msg->dn,
msg2,
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
if (ret != LDB_SUCCESS) {
}
}
- if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) {
+ if (el->num_values > 1 && ldb_kv_single_valued(a, el)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
}
/* Checks if element already exists */
- idx = find_element(msg2, el->name);
+ idx = ldb_kv_find_element(msg2, el->name);
if (idx == -1) {
- if (ltdb_msg_add_element(msg2, el) != 0) {
+ if (ldb_kv_msg_add_element(msg2, el) != 0) {
ret = LDB_ERR_OTHER;
goto done;
}
- ret = ltdb_index_add_element(module, ltdb,
+ ret = ldb_kv_index_add_element(module, ltdb,
msg2,
el);
if (ret != LDB_SUCCESS) {
/* We cannot add another value on a existing one
if the attribute is single-valued */
- if (ldb_tdb_single_valued(a, el)) {
+ if (ldb_kv_single_valued(a, el)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
el2->values = vals;
el2->num_values += el->num_values;
- ret = ltdb_index_add_element(module, ltdb,
+ ret = ldb_kv_index_add_element(module, ltdb,
msg2, el);
if (ret != LDB_SUCCESS) {
goto done;
case LDB_FLAG_MOD_REPLACE:
- if (el->num_values > 1 && ldb_tdb_single_valued(a, el)) {
+ if (el->num_values > 1 && ldb_kv_single_valued(a, el)) {
ldb_asprintf_errstring(ldb, "SINGLE-VALUE attribute %s on %s specified more than once",
el->name, ldb_dn_get_linearized(msg2->dn));
ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS;
}
/* Checks if element already exists */
- idx = find_element(msg2, el->name);
+ idx = ldb_kv_find_element(msg2, el->name);
if (idx != -1) {
j = (unsigned int) idx;
el2 = &(msg2->elements[j]);
}
/* Delete the attribute if it exists in the DB */
- if (msg_delete_attribute(module, ltdb,
+ if (ldb_kv_msg_delete_attribute(module, ltdb,
msg2,
el->name) != 0) {
ret = LDB_ERR_OTHER;
}
/* Recreate it with the new values */
- if (ltdb_msg_add_element(msg2, el) != 0) {
+ if (ldb_kv_msg_add_element(msg2, el) != 0) {
ret = LDB_ERR_OTHER;
goto done;
}
- ret = ltdb_index_add_element(module, ltdb,
+ ret = ldb_kv_index_add_element(module, ltdb,
msg2, el);
if (ret != LDB_SUCCESS) {
goto done;
if (msg->elements[i].num_values == 0) {
/* Delete the whole attribute */
- ret = msg_delete_attribute(module,
+ ret = ldb_kv_msg_delete_attribute(module,
ltdb,
msg2,
msg->elements[i].name);
} else {
/* Delete specified values from an attribute */
for (j=0; j < msg->elements[i].num_values; j++) {
- ret = msg_delete_element(module,
+ ret = ldb_kv_msg_delete_element(module,
ltdb,
msg2,
msg->elements[i].name,
}
}
- ret = ltdb_store(module, msg2, TDB_MODIFY);
+ ret = ldb_kv_store(module, msg2, TDB_MODIFY);
if (ret != LDB_SUCCESS) {
goto done;
}
- ret = ltdb_modified(module, msg2->dn);
+ ret = ldb_kv_modified(module, msg2->dn);
if (ret != LDB_SUCCESS) {
goto done;
}
/*
modify a record
*/
-static int ltdb_modify(struct ltdb_context *ctx)
+static int ldb_kv_modify(struct ltdb_context *ctx)
{
struct ldb_module *module = ctx->module;
struct ldb_request *req = ctx->req;
int ret = LDB_SUCCESS;
- ret = ltdb_check_special_dn(module, req->op.mod.message);
+ ret = ldb_kv_check_special_dn(module, req->op.mod.message);
if (ret != LDB_SUCCESS) {
return ret;
}
ldb_request_set_state(req, LDB_ASYNC_PENDING);
- if (ltdb_cache_load(module) != 0) {
+ if (ldb_kv_cache_load(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_modify_internal(module, req->op.mod.message, req);
+ ret = ldb_kv_modify_internal(module, req->op.mod.message, req);
return ret;
}
/*
rename a record
*/
-static int ltdb_rename(struct ltdb_context *ctx)
+static int ldb_kv_rename(struct ltdb_context *ctx)
{
struct ldb_module *module = ctx->module;
void *data = ldb_module_get_private(module);
ldb_request_set_state(req, LDB_ASYNC_PENDING);
- if (ltdb_cache_load(ctx->module) != 0) {
+ if (ldb_kv_cache_load(ctx->module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
}
/* we need to fetch the old record to re-add under the new name */
- ret = ltdb_search_dn1(module, req->op.rename.olddn, msg,
+ ret = ldb_kv_search_dn1(module, req->op.rename.olddn, msg,
LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC);
if (ret != LDB_SUCCESS) {
/* not finding the old record is an error */
* Even in GUID index mode we use ltdb_key_dn() as we are
* trying to figure out if this is just a case rename
*/
- tdb_key = ltdb_key_dn(module, msg, req->op.rename.newdn);
+ tdb_key = ldb_kv_key_dn(module, msg, req->op.rename.newdn);
if (!tdb_key.dptr) {
talloc_free(msg);
return LDB_ERR_OPERATIONS_ERROR;
}
- tdb_key_old = ltdb_key_dn(module, msg, req->op.rename.olddn);
+ tdb_key_old = ldb_kv_key_dn(module, msg, req->op.rename.olddn);
if (!tdb_key_old.dptr) {
talloc_free(msg);
talloc_free(tdb_key.dptr);
*/
if (tdb_key_old.dsize != tdb_key.dsize
|| memcmp(tdb_key.dptr, tdb_key_old.dptr, tdb_key.dsize) != 0) {
- ret = ltdb_search_base(module, msg,
+ ret = ldb_kv_search_base(module, msg,
req->op.rename.newdn,
&db_dn);
if (ret == LDB_SUCCESS) {
* unique indexes. We rely on the transaction to make this
* atomic
*/
- ret = ltdb_delete_internal(module, msg->dn);
+ ret = ldb_kv_delete_internal(module, msg->dn);
if (ret != LDB_SUCCESS) {
talloc_free(msg);
return ret;
* deleted attributes. We could go through all elements but that's
* maybe not the most efficient way
*/
- ret = ltdb_add_internal(module, ltdb, msg, false);
+ ret = ldb_kv_add_internal(module, ltdb, msg, false);
talloc_free(msg);
return ret;
}
-static int ltdb_tdb_transaction_start(struct ltdb_private *ltdb)
+static int ltdb_transaction_start(struct ltdb_private *ltdb)
{
pid_t pid = getpid();
return tdb_transaction_start(ltdb->tdb);
}
-static int ltdb_tdb_transaction_cancel(struct ltdb_private *ltdb)
+static int ltdb_transaction_cancel(struct ltdb_private *ltdb)
{
pid_t pid = getpid();
return tdb_transaction_cancel(ltdb->tdb);
}
-static int ltdb_tdb_transaction_prepare_commit(struct ltdb_private *ltdb)
+static int ltdb_transaction_prepare_commit(struct ltdb_private *ltdb)
{
pid_t pid = getpid();
return tdb_transaction_prepare_commit(ltdb->tdb);
}
-static int ltdb_tdb_transaction_commit(struct ltdb_private *ltdb)
+static int ltdb_transaction_commit(struct ltdb_private *ltdb)
{
pid_t pid = getpid();
return tdb_transaction_commit(ltdb->tdb);
}
-static int ltdb_start_trans(struct ldb_module *module)
+static int ldb_kv_start_trans(struct ldb_module *module)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
}
- ltdb_index_transaction_start(module);
+ ldb_kv_index_transaction_start(module);
ltdb->reindex_failed = false;
* Forward declaration to allow prepare_commit to in fact abort the
* transaction
*/
-static int ltdb_del_trans(struct ldb_module *module);
+static int ldb_kv_del_trans(struct ldb_module *module);
-static int ltdb_prepare_commit(struct ldb_module *module)
+static int ldb_kv_prepare_commit(struct ldb_module *module)
{
int ret;
void *data = ldb_module_get_private(module);
* We must instead abort the transaction so we get the
* old values and old index back
*/
- ltdb_del_trans(module);
+ ldb_kv_del_trans(module);
ldb_set_errstring(ldb_module_get_ctx(module),
"Failure during re-index, so "
"transaction must be aborted.");
return LDB_ERR_OPERATIONS_ERROR;
}
- ret = ltdb_index_transaction_commit(module);
+ ret = ldb_kv_index_transaction_commit(module);
if (ret != LDB_SUCCESS) {
ltdb->kv_ops->abort_write(ltdb);
return ret;
return LDB_SUCCESS;
}
-static int ltdb_end_trans(struct ldb_module *module)
+static int ldb_kv_end_trans(struct ldb_module *module)
{
int ret;
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
if (!ltdb->prepared_commit) {
- ret = ltdb_prepare_commit(module);
+ ret = ldb_kv_prepare_commit(module);
if (ret != LDB_SUCCESS) {
return ret;
}
return LDB_SUCCESS;
}
-static int ltdb_del_trans(struct ldb_module *module)
+static int ldb_kv_del_trans(struct ldb_module *module)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
- if (ltdb_index_transaction_cancel(module) != 0) {
+ if (ldb_kv_index_transaction_cancel(module) != 0) {
ltdb->kv_ops->abort_write(ltdb);
return ltdb->kv_ops->error(ltdb);
}
/*
return sequenceNumber from @BASEINFO
*/
-static int ltdb_sequence_number(struct ltdb_context *ctx,
+static int ldb_kv_sequence_number(struct ltdb_context *ctx,
struct ldb_extended **ext)
{
struct ldb_context *ldb;
goto done;
}
- ret = ltdb_search_dn1(module, dn, msg, 0);
+ ret = ldb_kv_search_dn1(module, dn, msg, 0);
if (ret != LDB_SUCCESS) {
goto done;
}
return ret;
}
-static void ltdb_request_done(struct ltdb_context *ctx, int error)
+static void ldb_kv_request_done(struct ltdb_context *ctx, int error)
{
struct ldb_context *ldb;
struct ldb_request *req;
req->callback(req, ares);
}
-static void ltdb_timeout(struct tevent_context *ev,
+static void ldb_kv_timeout(struct tevent_context *ev,
struct tevent_timer *te,
struct timeval t,
void *private_data)
if (!ctx->request_terminated) {
/* request is done now */
- ltdb_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED);
+ ldb_kv_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED);
}
if (ctx->spy) {
talloc_free(ctx);
}
-static void ltdb_request_extended_done(struct ltdb_context *ctx,
+static void ldb_kv_request_extended_done(struct ltdb_context *ctx,
struct ldb_extended *ext,
int error)
{
req->callback(req, ares);
}
-static void ltdb_handle_extended(struct ltdb_context *ctx)
+static void ldb_kv_handle_extended(struct ltdb_context *ctx)
{
struct ldb_extended *ext = NULL;
int ret;
if (strcmp(ctx->req->op.extended.oid,
LDB_EXTENDED_SEQUENCE_NUMBER) == 0) {
/* get sequence number */
- ret = ltdb_sequence_number(ctx, &ext);
+ ret = ldb_kv_sequence_number(ctx, &ext);
} else {
/* not recognized */
ret = LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
- ltdb_request_extended_done(ctx, ext, ret);
+ ldb_kv_request_extended_done(ctx, ext, ret);
}
struct kv_ctx {
void *private_data);
};
-static int ldb_tdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key, TDB_DATA tdb_data, void *ctx)
+static int ltdb_traverse_fn_wrapper(struct tdb_context *tdb, TDB_DATA tdb_key, TDB_DATA tdb_data, void *ctx)
{
struct kv_ctx *kv_ctx = ctx;
struct ldb_val key = {
return kv_ctx->kv_traverse_fn(kv_ctx->ltdb, key, data, kv_ctx->ctx);
}
-static int ltdb_tdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx)
+static int ltdb_traverse_fn(struct ltdb_private *ltdb, ldb_kv_traverse_fn fn, void *ctx)
{
struct kv_ctx kv_ctx = {
.kv_traverse_fn = fn,
.ltdb = ltdb
};
if (tdb_transaction_active(ltdb->tdb)) {
- return tdb_traverse(ltdb->tdb, ldb_tdb_traverse_fn_wrapper, &kv_ctx);
+ return tdb_traverse(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx);
} else {
- return tdb_traverse_read(ltdb->tdb, ldb_tdb_traverse_fn_wrapper, &kv_ctx);
+ return tdb_traverse_read(ltdb->tdb, ltdb_traverse_fn_wrapper, &kv_ctx);
}
}
-static int ltdb_tdb_update_in_iterate(struct ltdb_private *ltdb,
+static int ltdb_update_in_iterate(struct ltdb_private *ltdb,
struct ldb_val ldb_key,
struct ldb_val ldb_key2,
struct ldb_val ldb_data, void *state)
return tdb_ret;
}
-static int ltdb_tdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data,
+static int ltdb_parse_record_wrapper(TDB_DATA tdb_key, TDB_DATA tdb_data,
void *ctx)
{
struct kv_ctx *kv_ctx = ctx;
return kv_ctx->parser(key, data, kv_ctx->ctx);
}
-static int ltdb_tdb_parse_record(struct ltdb_private *ltdb,
+static int ltdb_parse_record(struct ltdb_private *ltdb,
struct ldb_val ldb_key,
int (*parser)(struct ldb_val key,
struct ldb_val data,
return LDB_ERR_PROTOCOL_ERROR;
}
- ret = tdb_parse_record(ltdb->tdb, key, ltdb_tdb_parse_record_wrapper,
+ ret = tdb_parse_record(ltdb->tdb, key, ltdb_parse_record_wrapper,
&kv_ctx);
if (ret == 0) {
return LDB_SUCCESS;
return ltdb_err_map(tdb_error(ltdb->tdb));
}
-static const char * ltdb_tdb_name(struct ltdb_private *ltdb)
+static const char * ltdb_name(struct ltdb_private *ltdb)
{
return tdb_name(ltdb->tdb);
}
-static bool ltdb_tdb_changed(struct ltdb_private *ltdb)
+static bool ltdb_changed(struct ltdb_private *ltdb)
{
int seq = tdb_get_seqnum(ltdb->tdb);
bool has_changed = (seq != ltdb->tdb_seqnum);
}
static const struct kv_db_ops key_value_ops = {
- .store = ltdb_tdb_store,
- .delete = ltdb_tdb_delete,
- .iterate = ltdb_tdb_traverse_fn,
- .update_in_iterate = ltdb_tdb_update_in_iterate,
- .fetch_and_parse = ltdb_tdb_parse_record,
+ .store = ltdb_store,
+ .delete = ltdb_delete,
+ .iterate = ltdb_traverse_fn,
+ .update_in_iterate = ltdb_update_in_iterate,
+ .fetch_and_parse = ltdb_parse_record,
.lock_read = ltdb_lock_read,
.unlock_read = ltdb_unlock_read,
- .begin_write = ltdb_tdb_transaction_start,
- .prepare_write = ltdb_tdb_transaction_prepare_commit,
- .finish_write = ltdb_tdb_transaction_commit,
- .abort_write = ltdb_tdb_transaction_cancel,
+ .begin_write = ltdb_transaction_start,
+ .prepare_write = ltdb_transaction_prepare_commit,
+ .finish_write = ltdb_transaction_commit,
+ .abort_write = ltdb_transaction_cancel,
.error = ltdb_error,
.errorstr = ltdb_errorstr,
- .name = ltdb_tdb_name,
- .has_changed = ltdb_tdb_changed,
+ .name = ltdb_name,
+ .has_changed = ltdb_changed,
.transaction_active = ltdb_transaction_active,
};
-static void ltdb_callback(struct tevent_context *ev,
+static void ldb_kv_callback(struct tevent_context *ev,
struct tevent_timer *te,
struct timeval t,
void *private_data)
switch (ctx->req->operation) {
case LDB_SEARCH:
- ret = ltdb_search(ctx);
+ ret = ldb_kv_search(ctx);
break;
case LDB_ADD:
- ret = ltdb_add(ctx);
+ ret = ldb_kv_add(ctx);
break;
case LDB_MODIFY:
- ret = ltdb_modify(ctx);
+ ret = ldb_kv_modify(ctx);
break;
case LDB_DELETE:
- ret = ltdb_delete(ctx);
+ ret = ldb_kv_delete(ctx);
break;
case LDB_RENAME:
- ret = ltdb_rename(ctx);
+ ret = ldb_kv_rename(ctx);
break;
case LDB_EXTENDED:
- ltdb_handle_extended(ctx);
+ ldb_kv_handle_extended(ctx);
goto done;
default:
/* no other op supported */
if (!ctx->request_terminated) {
/* request is done now */
- ltdb_request_done(ctx, ret);
+ ldb_kv_request_done(ctx, ret);
}
done:
talloc_free(ctx);
}
-static int ltdb_request_destructor(void *ptr)
+static int ldb_kv_request_destructor(void *ptr)
{
struct ltdb_req_spy *spy = talloc_get_type(ptr, struct ltdb_req_spy);
return 0;
}
-static int ltdb_handle_request(struct ldb_module *module,
+static int ldb_kv_handle_request(struct ldb_module *module,
struct ldb_request *req)
{
struct ldb_control *control_permissive;
tv.tv_sec = 0;
tv.tv_usec = 0;
- te = tevent_add_timer(ev, ac, tv, ltdb_callback, ac);
+ te = tevent_add_timer(ev, ac, tv, ldb_kv_callback, ac);
if (NULL == te) {
talloc_free(ac);
return LDB_ERR_OPERATIONS_ERROR;
tv.tv_sec = req->starttime + req->timeout;
tv.tv_usec = 0;
ac->timeout_event = tevent_add_timer(ev, ac, tv,
- ltdb_timeout, ac);
+ ldb_kv_timeout, ac);
if (NULL == ac->timeout_event) {
talloc_free(ac);
return LDB_ERR_OPERATIONS_ERROR;
}
ac->spy->ctx = ac;
- talloc_set_destructor((TALLOC_CTX *)ac->spy, ltdb_request_destructor);
+ talloc_set_destructor((TALLOC_CTX *)ac->spy, ldb_kv_request_destructor);
return LDB_SUCCESS;
}
-static int ltdb_init_rootdse(struct ldb_module *module)
+static int ldb_kv_init_rootdse(struct ldb_module *module)
{
/* ignore errors on this - we expect it for non-sam databases */
ldb_mod_register_control(module, LDB_CONTROL_PERMISSIVE_MODIFY_OID);
}
-static int generic_lock_read(struct ldb_module *module)
+static int ldb_kv_lock_read(struct ldb_module *module)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
return ltdb->kv_ops->lock_read(module);
}
-static int generic_unlock_read(struct ldb_module *module)
+static int ldb_kv_unlock_read(struct ldb_module *module)
{
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
return ltdb->kv_ops->unlock_read(module);
}
-static const struct ldb_module_ops ltdb_ops = {
+static const struct ldb_module_ops ldb_kv_ops = {
.name = "tdb",
- .init_context = ltdb_init_rootdse,
- .search = ltdb_handle_request,
- .add = ltdb_handle_request,
- .modify = ltdb_handle_request,
- .del = ltdb_handle_request,
- .rename = ltdb_handle_request,
- .extended = ltdb_handle_request,
- .start_transaction = ltdb_start_trans,
- .end_transaction = ltdb_end_trans,
- .prepare_commit = ltdb_prepare_commit,
- .del_transaction = ltdb_del_trans,
- .read_lock = generic_lock_read,
- .read_unlock = generic_unlock_read,
+ .init_context = ldb_kv_init_rootdse,
+ .search = ldb_kv_handle_request,
+ .add = ldb_kv_handle_request,
+ .modify = ldb_kv_handle_request,
+ .del = ldb_kv_handle_request,
+ .rename = ldb_kv_handle_request,
+ .extended = ldb_kv_handle_request,
+ .start_transaction = ldb_kv_start_trans,
+ .end_transaction = ldb_kv_end_trans,
+ .prepare_commit = ldb_kv_prepare_commit,
+ .del_transaction = ldb_kv_del_trans,
+ .read_lock = ldb_kv_lock_read,
+ .read_unlock = ldb_kv_unlock_read,
};
-int init_store(struct ltdb_private *ltdb,
+int ldb_kv_init_store(struct ltdb_private *ltdb,
const char *name,
struct ldb_context *ldb,
const char *options[],
ltdb->pid = getpid();
- ltdb->module = ldb_module_new(ldb, ldb, name, <db_ops);
+ ltdb->module = ldb_module_new(ldb, ldb, name, &ldb_kv_ops);
if (!ltdb->module) {
ldb_oom(ldb);
talloc_free(ltdb);
ldb_module_set_private(ltdb->module, ltdb);
talloc_steal(ltdb->module, ltdb);
- if (ltdb_cache_load(ltdb->module) != 0) {
+ if (ldb_kv_cache_load(ltdb->module) != 0) {
ldb_asprintf_errstring(ldb, "Unable to load ltdb cache "
"records for backend '%s'", name);
talloc_free(ltdb->module);
return LDB_ERR_OPERATIONS_ERROR;
}
- return init_store(ltdb, "ldb_tdb backend", ldb, options, _module);
+ return ldb_kv_init_store(
+ ltdb, "ldb_tdb backend", ldb, options, _module);
}
/* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c */
-int ltdb_cache_reload(struct ldb_module *module);
-int ltdb_cache_load(struct ldb_module *module);
-int ltdb_increase_sequence_number(struct ldb_module *module);
-int ltdb_check_at_attributes_values(const struct ldb_val *value);
+int ldb_kv_cache_reload(struct ldb_module *module);
+int ldb_kv_cache_load(struct ldb_module *module);
+int ldb_kv_increase_sequence_number(struct ldb_module *module);
+int ldb_kv_check_at_attributes_values(const struct ldb_val *value);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c */
struct ldb_parse_tree;
-int ltdb_search_indexed(struct ltdb_context *ctx, uint32_t *);
-int ltdb_index_add_new(struct ldb_module *module,
+int ldb_kv_search_indexed(struct ltdb_context *ctx, uint32_t *);
+int ldb_kv_index_add_new(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg);
-int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg);
-int ltdb_index_del_element(struct ldb_module *module,
+int ldb_kv_index_delete(struct ldb_module *module, const struct ldb_message *msg);
+int ldb_kv_index_del_element(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el);
-int ltdb_index_add_element(struct ldb_module *module,
+int ldb_kv_index_add_element(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el);
-int ltdb_index_del_value(struct ldb_module *module,
+int ldb_kv_index_del_value(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_message *msg,
struct ldb_message_element *el, unsigned int v_idx);
-int ltdb_reindex(struct ldb_module *module);
-int ltdb_index_transaction_start(struct ldb_module *module);
-int ltdb_index_transaction_commit(struct ldb_module *module);
-int ltdb_index_transaction_cancel(struct ldb_module *module);
-int ltdb_key_dn_from_idx(struct ldb_module *module,
+int ldb_kv_reindex(struct ldb_module *module);
+int ldb_kv_index_transaction_start(struct ldb_module *module);
+int ldb_kv_index_transaction_commit(struct ldb_module *module);
+int ldb_kv_index_transaction_cancel(struct ldb_module *module);
+int ldb_kv_key_dn_from_idx(struct ldb_module *module,
struct ltdb_private *ltdb,
TALLOC_CTX *mem_ctx,
struct ldb_dn *dn,
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, struct ldb_dn *dn, struct ldb_message *msg,
+int ldb_kv_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg,
unsigned int unpack_flags);
-int ltdb_search_base(struct ldb_module *module,
+int ldb_kv_search_base(struct ldb_module *module,
TALLOC_CTX *mem_ctx,
struct ldb_dn *dn,
struct ldb_dn **ret_dn);
-int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
+int ldb_kv_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
struct TDB_DATA tdb_key,
struct ldb_message *msg,
unsigned int unpack_flags);
-int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
+int ldb_kv_filter_attrs(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg, const char * const *attrs,
struct ldb_message **filtered_msg);
-int ltdb_search(struct ltdb_context *ctx);
+int ldb_kv_search(struct ltdb_context *ctx);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */
/*
* Determine if this key could hold a record. We allow the new GUID
* index, the old DN index and a possible future ID=
*/
-bool ltdb_key_is_record(TDB_DATA key);
-TDB_DATA ltdb_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
+bool ldb_kv_key_is_record(TDB_DATA key);
+TDB_DATA ldb_kv_key_dn(struct ldb_module *module, TALLOC_CTX *mem_ctx,
struct ldb_dn *dn);
-TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
+TDB_DATA ldb_kv_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
const struct ldb_message *msg);
-int ltdb_guid_to_key(struct ldb_module *module,
+int ldb_kv_guid_to_key(struct ldb_module *module,
struct ltdb_private *ltdb,
const struct ldb_val *GUID_val,
TDB_DATA *key);
-int ltdb_idx_to_key(struct ldb_module *module,
+int ldb_kv_idx_to_key(struct ldb_module *module,
struct ltdb_private *ltdb,
TALLOC_CTX *mem_ctx,
const struct ldb_val *idx_val,
TDB_DATA *key);
TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
-int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
-int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
-int ltdb_delete_noindex(struct ldb_module *module,
+int ldb_kv_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
+int ldb_kv_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req);
+int ldb_kv_delete_noindex(struct ldb_module *module,
const struct ldb_message *msg);
int ltdb_err_map(enum TDB_ERROR tdb_code);
const char *path, int hash_size, int tdb_flags,
int open_flags, mode_t mode,
struct ldb_context *ldb);
-int init_store(struct ltdb_private *ltdb, const char *name,
- struct ldb_context *ldb, const char *options[],
- struct ldb_module **_module);
+int ldb_kv_init_store(struct ltdb_private *ltdb, const char *name,
+ struct ldb_context *ldb, const char *options[],
+ struct ldb_module **_module);
int ltdb_connect(struct ldb_context *ldb, const char *url,
unsigned int flags, const char *options[],