1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

ldb_tdb: Add/remove a GUID index of the DN during ltdb_index_add_all()/ltdb_index_delete()

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
This commit is contained in:
Andrew Bartlett 2017-08-11 12:25:42 +12:00
parent 98e82113ed
commit ec30439c43
2 changed files with 38 additions and 4 deletions

View File

@ -44,6 +44,10 @@ struct ltdb_idxptr {
int error; int error;
}; };
static int ltdb_write_index_dn_guid(struct ldb_module *module,
const struct ldb_message *msg,
int add);
/* we put a @IDXVERSION attribute on index entries. This /* we put a @IDXVERSION attribute on index entries. This
allows us to tell if it was written by an older version allows us to tell if it was written by an older version
*/ */
@ -1387,23 +1391,28 @@ static int ltdb_index_add_all(struct ldb_module *module,
struct ldb_message_element *elements = msg->elements; struct ldb_message_element *elements = msg->elements;
unsigned int i; unsigned int i;
const char *dn_str; const char *dn_str;
int ret;
if (ldb_dn_is_special(msg->dn)) { if (ldb_dn_is_special(msg->dn)) {
return LDB_SUCCESS; return LDB_SUCCESS;
} }
dn_str = ldb_dn_get_linearized(msg->dn); dn_str = ldb_dn_get_linearized(msg->dn);
if (dn_str == NULL) { if (dn_str == NULL) {
return LDB_ERR_OPERATIONS_ERROR; return LDB_ERR_OPERATIONS_ERROR;
} }
ret = ltdb_write_index_dn_guid(module, msg, 1);
if (ret != LDB_SUCCESS) {
return ret;
}
if (!ltdb->cache->attribute_indexes) { if (!ltdb->cache->attribute_indexes) {
/* no indexed fields */ /* no indexed fields */
return LDB_SUCCESS; return LDB_SUCCESS;
} }
for (i = 0; i < msg->num_elements; i++) { for (i = 0; i < msg->num_elements; i++) {
int ret;
if (!ltdb_is_indexed(module, ltdb, elements[i].name)) { if (!ltdb_is_indexed(module, ltdb, elements[i].name)) {
continue; continue;
} }
@ -1495,6 +1504,25 @@ static int ltdb_index_onelevel(struct ldb_module *module,
return ret; return ret;
} }
/*
insert a one level index for a message
*/
static int ltdb_write_index_dn_guid(struct ldb_module *module,
const struct ldb_message *msg,
int add)
{
struct ltdb_private *ltdb = talloc_get_type(ldb_module_get_private(module),
struct ltdb_private);
/* We index for DN only if using a GUID index */
if (ltdb->cache->GUID_index_attribute == NULL) {
return LDB_SUCCESS;
}
return ltdb_modify_index_dn(module, ltdb, msg, msg->dn,
LTDB_IDXDN, add);
}
/* /*
add the index entries for a new element in a record add the index entries for a new element in a record
The caller guarantees that these element values are not yet indexed The caller guarantees that these element values are not yet indexed
@ -1671,6 +1699,11 @@ int ltdb_index_delete(struct ldb_module *module, const struct ldb_message *msg)
return ret; return ret;
} }
ret = ltdb_write_index_dn_guid(module, msg, 0);
if (ret != LDB_SUCCESS) {
return ret;
}
if (!ltdb->cache->attribute_indexes) { if (!ltdb->cache->attribute_indexes) {
/* no indexed fields */ /* no indexed fields */
return LDB_SUCCESS; return LDB_SUCCESS;

View File

@ -62,6 +62,7 @@ struct ltdb_context {
#define LTDB_IDXVERSION "@IDXVERSION" #define LTDB_IDXVERSION "@IDXVERSION"
#define LTDB_IDXATTR "@IDXATTR" #define LTDB_IDXATTR "@IDXATTR"
#define LTDB_IDXONE "@IDXONE" #define LTDB_IDXONE "@IDXONE"
#define LTDB_IDXDN "@IDXDN"
#define LTDB_BASEINFO "@BASEINFO" #define LTDB_BASEINFO "@BASEINFO"
#define LTDB_OPTIONS "@OPTIONS" #define LTDB_OPTIONS "@OPTIONS"
#define LTDB_ATTRIBUTES "@ATTRIBUTES" #define LTDB_ATTRIBUTES "@ATTRIBUTES"