*/
static void ltdb_attributes_unload(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;
- unsigned int i;
-
- ldb = ldb_module_get_ctx(module);
+ struct ldb_context *ldb = ldb_module_get_ctx(module);
- if (ltdb->cache->attributes == NULL) {
- /* no previously loaded attributes */
- return;
- }
+ ldb_schema_attribute_remove_flagged(ldb, LDB_ATTR_FLAG_FROM_DB);
- msg = ltdb->cache->attributes;
- for (i=0;i<msg->num_elements;i++) {
- ldb_schema_attribute_remove(ldb, msg->elements[i].name);
- }
-
- talloc_free(ltdb->cache->attributes);
- ltdb->cache->attributes = NULL;
}
/*
static int ltdb_attributes_load(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 = ltdb->cache->attributes;
+ struct ldb_message *attrs_msg = NULL;
struct ldb_dn *dn;
unsigned int i;
int r;
return 0;
}
+ attrs_msg = ldb_msg_new(module);
+ if (attrs_msg == NULL) {
+ goto failed;
+ }
+
dn = ldb_dn_new(module, ldb, LTDB_ATTRIBUTES);
if (dn == NULL) goto failed;
- r = ltdb_search_dn1(module, dn, msg, 0);
+ r = ltdb_search_dn1(module, dn, attrs_msg, 0);
talloc_free(dn);
if (r != LDB_SUCCESS && r != LDB_ERR_NO_SUCH_OBJECT) {
goto failed;
}
/* mapping these flags onto ldap 'syntaxes' isn't strictly correct,
but its close enough for now */
- for (i=0;i<msg->num_elements;i++) {
+ for (i=0;i<attrs_msg->num_elements;i++) {
unsigned flags;
const char *syntax;
const struct ldb_schema_syntax *s;
- if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'", msg->elements[i].name);
+ if (ltdb_attributes_flags(&attrs_msg->elements[i], &flags) != 0) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Invalid @ATTRIBUTES element for '%s'",
+ attrs_msg->elements[i].name);
goto failed;
}
switch (flags & ~LTDB_FLAG_HIDDEN) {
default:
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Invalid flag combination 0x%x for '%s' in @ATTRIBUTES",
- flags, msg->elements[i].name);
+ flags, attrs_msg->elements[i].name);
goto failed;
}
if (s == NULL) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
"Invalid attribute syntax '%s' for '%s' in @ATTRIBUTES",
- syntax, msg->elements[i].name);
+ syntax, attrs_msg->elements[i].name);
goto failed;
}
- flags |= LDB_ATTR_FLAG_ALLOCATED;
- if (ldb_schema_attribute_add_with_syntax(ldb, msg->elements[i].name, flags, s) != 0) {
+ flags |= LDB_ATTR_FLAG_ALLOCATED | LDB_ATTR_FLAG_FROM_DB;
+ if (ldb_schema_attribute_add_with_syntax(ldb,
+ attrs_msg->elements[i].name,
+ flags, s) != 0) {
goto failed;
}
}
+ TALLOC_FREE(attrs_msg);
return 0;
failed:
+ TALLOC_FREE(attrs_msg);
return -1;
}
ltdb->cache = talloc_zero(ltdb, struct ltdb_cache);
if (ltdb->cache == NULL) goto failed;
ltdb->cache->indexlist = ldb_msg_new(ltdb->cache);
- ltdb->cache->attributes = ldb_msg_new(ltdb->cache);
- if (ltdb->cache->indexlist == NULL ||
- ltdb->cache->attributes == NULL) {
+ if (ltdb->cache->indexlist == NULL) {
goto failed;
}
}
ltdb_attributes_unload(module); /* calls internally "talloc_free" */
ltdb->cache->indexlist = ldb_msg_new(ltdb->cache);
- ltdb->cache->attributes = ldb_msg_new(ltdb->cache);
- if (ltdb->cache->indexlist == NULL ||
- ltdb->cache->attributes == NULL) {
+ if (ltdb->cache->indexlist == NULL) {
goto failed;
}
ltdb->cache->one_level_indexes = false;