} \
} while(0)
-struct ldap_dn *ldap_parse_dn(TALLOC_CTX *mem_ctx, const char *orig_dn)
+#if 0
+static void ldap_parse_attributetypedescription(struct ldap_schema *schema, DATA_BLOB *data)
+{
+ char *desc;
+
+ desc = (char *)talloc(schema, data->lenght + 1);
+ memcpy(desc, data->data, data->lenght);
+ desc[data->lenght] = '\0';
+
+}
+
+static void ldap_parse_objectclassdescription(struct ldap_schema *schema, DATA_BLOB *data)
+{
+ char *desc;
+
+ desc = (char *)talloc(schema, data->lenght + 1);
+ memcpy(desc, data->data, data->lenght);
+ desc[data->lenght] = '\0';
+
+}
+
+static struct ldap_schema *ldap_get_schema(void *mem_ctx, struct ldap_schema *schema, struct ldb_context *ldb)
+{
+ NTSTATUS status;
+ struct ldap_schema *local_schema;
+ struct ldb_message **res;
+ const char *errstr;
+ const char *schema_dn = "cn=schema";
+ const char *attr_filter = "attributeTypeDescription=*";
+ const char *class_filter = "objectClassDescription=*";
+ const char *attrs = "attributeTypeDescription";
+ const char *classes = "objectClassDescription";
+ enum ldb_scope scope = LDAP_SCOPE_SUBTREE;
+ int count, i, j, k;
+
+ local_schema = schema;
+ if (local_schema == NULL) {
+ local_schema = talloc_p(mem_ctx, struct ldap_schema);
+ ALLOC_CHECK(local_schema);
+ }
+
+ count = ldb_search(ldb, schema_dn, scope, attr_filter, attrs, &res);
+
+ for (i = 0; i < count; i++) {
+ if (res[i]->num_elements == 0) {
+ goto attr_done;
+ }
+ for (j = 0; j < res[i]->num_elements; j++) {
+ for (k = 0; res[i]->elements[j].num_values; k++) {
+ ldap_parse_attributetypedescription(local_schema, &(res[i]->elements[j].values[k]));
+ }
+ }
+attr_done:
+ }
+
+ count = ldb_search(ldb, schema_dn, scope, class_filter, classes, &res);
+
+ for (i = 0; i < count; i++) {
+ if (res[i]->num_elements == 0) {
+ goto class_done;
+ }
+ for (j = 0; j < res[i]->num_elements; j++) {
+ for (k = 0; res[i]->elements[j].num_values; k++) {
+ ldap_parse_objectclassdescription(local_schema, &(res[i]->elements[j].values[k]));
+ }
+ }
+class_done:
+ }
+
+ return local_schema;
+}
+#endif
+
+struct ldap_dn *ldap_parse_dn(void *mem_ctx, const char *orig_dn)
{
struct ldap_dn *dn;
struct dn_component *component;
int comp_num;
struct dn_component **components;
};
+
+struct ldap_schema {
+ int dummy;
+};
break;
}
- if (r->mods[i].attrib.num_values > 0) {
- msg->elements[i].num_values = r->mods[i].attrib.num_values;
+ msg->elements[i].num_values = r->mods[i].attrib.num_values;
+ if (msg->elements[i].num_values > 0) {
msg->elements[i].values = talloc_array_p(msg, struct ldb_val, msg->elements[i].num_values);
ALLOC_CHECK(msg->elements[i].values);
msg->elements[i].values[j].length = r->mods[i].attrib.values[j].length;
msg->elements[i].values[j].data = r->mods[i].attrib.values[j].data;
}
- } else {
- /* TODO: test what we should do here
- *
- * LDAP_MODIFY_DELETE is ok to pass here
- */
}
}
} else {
COMMON_OBJ=common/ldb.o common/ldb_ldif.o common/util.o \
common/ldb_parse.o common/ldb_msg.o common/ldb_utf8.o \
- common/ldb_alloc.o common/ldb_debug.o
+ common/ldb_alloc.o common/ldb_debug.o common/ldb_modules.o
-OBJS = $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(LDB_LDAP_OBJ)
+MODULES_OBJ=modules/timestamps.o
+
+OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(LDB_LDAP_OBJ)
LDB_LIB = lib/libldb.a
$(CC) -o bin/ldbtest tools/ldbtest.o $(LIB_FLAGS)
manpages:
- man/build_manpages.sh
+ -man/build_manpages.sh
clean:
rm -f */*.o *~ */*~ $(BINS) $(LDB_LIB) man/man?/*.[13]
struct ldb_context *ldb_connect(const char *url, unsigned int flags,
const char *options[])
{
+ struct ldb_context *ldb_ctx = NULL;
if (strncmp(url, "tdb:", 4) == 0 ||
strchr(url, ':') == NULL) {
- return ltdb_connect(url, flags, options);
+ ldb_ctx = ltdb_connect(url, flags, options);
}
#if HAVE_LDAP
if (strncmp(url, "ldap", 4) == 0) {
- return lldb_connect(url, flags, options);
+ ldb_ctx = lldb_connect(url, flags, options);
}
#endif
- errno = EINVAL;
- return NULL;
+
+ if (!ldb_ctx) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ if (ldb_load_modules(ldb_ctx, options) != 0) {
+ ldb_close(ldb_ctx);
+ errno = EINVAL;
+ return NULL;
+ }
+
+ return ldb_ctx;
}
/*
*/
int ldb_close(struct ldb_context *ldb)
{
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_close");
- return ldb->ops->close(ldb);
+ return ldb->modules->ops->close(ldb->modules);
}
const char *expression,
const char * const *attrs, struct ldb_message ***res)
{
- int ret;
- ret = ldb->ops->search(ldb, base, scope, expression, attrs, res);
-
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_search(%s) -> %d records\n",
- expression, ret);
- return ret;
+ return ldb->modules->ops->search(ldb->modules, base, scope, expression, attrs, res);
}
/*
*/
int ldb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
{
- return ldb->ops->search_free(ldb, msgs);
+ return ldb->modules->ops->search_free(ldb->modules, msgs);
}
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
- int ret;
- ret = ldb->ops->add_record(ldb, message);
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_add(%s) -> %d\n", message->dn, ret);
- return ret;
+ return ldb->modules->ops->add_record(ldb->modules, message);
}
/*
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
- int ret;
- ret = ldb->ops->modify_record(ldb, message);
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_modify(%s) -> %d\n",
- message->dn, ret);
- return ret;
+ return ldb->modules->ops->modify_record(ldb->modules, message);
}
*/
int ldb_delete(struct ldb_context *ldb, const char *dn)
{
- int ret;
- ret = ldb->ops->delete_record(ldb, dn);
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_delete(%s) -> %d\n", dn, ret);
- return ret;
+ return ldb->modules->ops->delete_record(ldb->modules, dn);
}
/*
*/
int ldb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
{
- int ret;
- ret = ldb->ops->rename_record(ldb, olddn, newdn);
- ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_rename(%s,%s) -> %d\n", olddn, newdn);
- return ret;
+ return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
}
/*
*/
const char *ldb_errstring(struct ldb_context *ldb)
{
- return ldb->ops->errstring(ldb);
+ return ldb->modules->ops->errstring(ldb->modules);
}
+
+################################################
+# Start MODULE libldb_timestamps
+[MODULE::libldb_timestamps]
+SUBSYSTEM = LIBLDB
+INIT_OBJ_FILES = \
+ lib/ldb/modules/timestamps.o
+# End MODULE libldb_timestamps
+################################################
+
################################################
# Start MODULE libldb_ldap
[MODULE::libldb_ldap]
lib/ldb/common/util.o \
lib/ldb/common/ldb_utf8.o \
lib/ldb/common/ldb_alloc.o \
- lib/ldb/common/ldb_debug.o
+ lib/ldb/common/ldb_debug.o \
+ lib/ldb/common/ldb_modules.o
REQUIRED_SUBSYSTEMS = \
LIBREPLACE
#
typedef int (*ldb_traverse_fn)(struct ldb_context *, const struct ldb_message *);
+struct ldb_module_ops;
+
+/* basic module structure */
+struct ldb_module {
+ struct ldb_module *prev, *next;
+ struct ldb_context *ldb;
+ void *private_data;
+ const struct ldb_module_ops *ops;
+};
+
/*
- these function pointers define the operations that a ldb backend must perform
+ these function pointers define the operations that a ldb module must perform
they correspond exactly to the ldb_*() interface
*/
-struct ldb_backend_ops {
- int (*close)(struct ldb_context *);
- int (*search)(struct ldb_context *, const char *, enum ldb_scope,
+struct ldb_module_ops {
+ const char *name;
+ int (*close)(struct ldb_module *);
+ int (*search)(struct ldb_module *, const char *, enum ldb_scope,
const char *, const char * const [], struct ldb_message ***);
- int (*search_free)(struct ldb_context *, struct ldb_message **);
- int (*add_record)(struct ldb_context *, const struct ldb_message *);
- int (*modify_record)(struct ldb_context *, const struct ldb_message *);
- int (*delete_record)(struct ldb_context *, const char *);
- int (*rename_record)(struct ldb_context *, const char *olddn, const char *newdn);
- const char * (*errstring)(struct ldb_context *);
+ int (*search_free)(struct ldb_module *, struct ldb_message **);
+ int (*add_record)(struct ldb_module *, const struct ldb_message *);
+ int (*modify_record)(struct ldb_module *, const struct ldb_message *);
+ int (*delete_record)(struct ldb_module *, const char *);
+ int (*rename_record)(struct ldb_module *, const char *, const char *);
+ const char * (*errstring)(struct ldb_module *);
/* this is called when the alloc ops changes to ensure we
don't have any old allocated data in the context */
- void (*cache_free)(struct ldb_context *);
+ void (*cache_free)(struct ldb_module *);
};
+/* the modules init function */
+typedef struct ldb_module *(*init_ldb_module_function)(void);
/*
the user can optionally supply a allocator function. It is presumed
every ldb connection is started by establishing a ldb_context
*/
struct ldb_context {
- /* a private pointer for the backend to use */
- void *private_data;
-
/* the operations provided by the backend */
- const struct ldb_backend_ops *ops;
+ struct ldb_module *modules;
/* memory allocation info */
struct ldb_alloc_ops alloc_ops;
/*
close/free the connection
*/
-static int lldb_close(struct ldb_context *ldb)
+static int lldb_close(struct ldb_module *module)
{
int i, ret = 0;
- struct lldb_private *lldb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
if (ldap_unbind(lldb->ldap) != LDAP_SUCCESS) {
ret = -1;
/*
rename a record
*/
-static int lldb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
+static int lldb_rename(struct ldb_module *module, const char *olddn, const char *newdn)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
int ret = 0;
char *newrdn, *p;
const char *parentdn = "";
/*
delete a record
*/
-static int lldb_delete(struct ldb_context *ldb, const char *dn)
+static int lldb_delete(struct ldb_module *module, const char *dn)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct lldb_private *lldb = module->private_data;
int ret = 0;
/* ignore ltdb specials */
/*
free a search result
*/
-static int lldb_search_free(struct ldb_context *ldb, struct ldb_message **res)
+static int lldb_search_free(struct ldb_module *module, struct ldb_message **res)
{
+ struct ldb_context *ldb = module->ldb;
int i;
for (i=0;res[i];i++) {
if (lldb_msg_free(ldb, res[i]) != 0) {
/*
search for matching records
*/
-static int lldb_search(struct ldb_context *ldb, const char *base,
+static int lldb_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
const char * const *attrs, struct ldb_message ***res)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
int count, msg_count;
LDAPMessage *ldapres, *msg;
return msg_count;
failed:
- if (*res) lldb_search_free(ldb, *res);
+ if (*res) lldb_search_free(module, *res);
return -1;
}
/*
add a record
*/
-static int lldb_add(struct ldb_context *ldb, const struct ldb_message *msg)
+static int lldb_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
LDAPMod **mods;
int ret = 0;
/*
modify a record
*/
-static int lldb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
+static int lldb_modify(struct ldb_module *module, const struct ldb_message *msg)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct lldb_private *lldb = module->private_data;
LDAPMod **mods;
int ret = 0;
/*
return extended error information
*/
-static const char *lldb_errstring(struct ldb_context *ldb)
+static const char *lldb_errstring(struct ldb_module *module)
{
- struct lldb_private *lldb = ldb->private_data;
+ struct lldb_private *lldb = module->private_data;
return ldap_err2string(lldb->last_rc);
}
-static const struct ldb_backend_ops lldb_ops = {
+static const struct ldb_module_ops lldb_ops = {
+ "ldap",
lldb_close,
lldb_search,
lldb_search_free,
goto failed;
}
- ldb->ops = &lldb_ops;
- ldb->private_data = lldb;
+ ldb->modules = ldb_malloc_p(ldb, struct ldb_module);
+ if (!ldb->modules) {
+ ldb_free(ldb, ldb);
+ errno = ENOMEM;
+ goto failed;
+ }
+ ldb->modules->ldb = ldb;
+ ldb->modules->prev = ldb->modules->next = NULL;
+ ldb->modules->private_data = lldb;
+ ldb->modules->ops = &lldb_ops;
if (options) {
/* take a copy of the options array, so we don't have to rely
/*
initialise the baseinfo record
*/
-static int ltdb_baseinfo_init(struct ldb_context *ldb)
+static int ltdb_baseinfo_init(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct ldb_message msg;
struct ldb_message_element el;
struct ldb_val val;
}
val.length = 1;
- ret = ltdb_store(ldb, &msg, TDB_INSERT);
+ ret = ltdb_store(module, &msg, TDB_INSERT);
ldb_free(ldb, msg.dn);
ldb_free(ldb, el.name);
/*
free any cache records
*/
-void ltdb_cache_free(struct ldb_context *ldb)
+void ltdb_cache_free(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct ldb_alloc_ops alloc = ldb->alloc_ops;
ldb->alloc_ops.alloc = NULL;
ltdb->sequence_number = 0;
- ltdb_search_dn1_free(ldb, <db->cache.baseinfo);
- ltdb_search_dn1_free(ldb, <db->cache.indexlist);
- ltdb_search_dn1_free(ldb, <db->cache.subclasses);
- ltdb_search_dn1_free(ldb, <db->cache.attributes);
+ ltdb_search_dn1_free(module, <db->cache.baseinfo);
+ ltdb_search_dn1_free(module, <db->cache.indexlist);
+ ltdb_search_dn1_free(module, <db->cache.subclasses);
+ ltdb_search_dn1_free(module, <db->cache.attributes);
ldb_free(ldb, ltdb->cache.last_attribute.name);
memset(<db->cache, 0, sizeof(ltdb->cache));
/*
load the cache records
*/
-int ltdb_cache_load(struct ldb_context *ldb)
+int ltdb_cache_load(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
double seq;
struct ldb_alloc_ops alloc = ldb->alloc_ops;
ldb->alloc_ops.alloc = NULL;
- ltdb_search_dn1_free(ldb, <db->cache.baseinfo);
+ ltdb_search_dn1_free(module, <db->cache.baseinfo);
- if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) == -1) {
+ if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) == -1) {
goto failed;
}
/* possibly initialise the baseinfo */
if (!ltdb->cache.baseinfo.dn) {
- if (ltdb_baseinfo_init(ldb) != 0) {
+ if (ltdb_baseinfo_init(module) != 0) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_BASEINFO, <db->cache.baseinfo) != 1) {
+ if (ltdb_search_dn1(module, LTDB_BASEINFO, <db->cache.baseinfo) != 1) {
goto failed;
}
}
ldb_free(ldb, ltdb->cache.last_attribute.name);
memset(<db->cache.last_attribute, 0, sizeof(ltdb->cache.last_attribute));
- ltdb_search_dn1_free(ldb, <db->cache.indexlist);
- ltdb_search_dn1_free(ldb, <db->cache.subclasses);
- ltdb_search_dn1_free(ldb, <db->cache.attributes);
+ ltdb_search_dn1_free(module, <db->cache.indexlist);
+ ltdb_search_dn1_free(module, <db->cache.subclasses);
+ ltdb_search_dn1_free(module, <db->cache.attributes);
- if (ltdb_search_dn1(ldb, LTDB_INDEXLIST, <db->cache.indexlist) == -1) {
+ if (ltdb_search_dn1(module, LTDB_INDEXLIST, <db->cache.indexlist) == -1) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) {
+ if (ltdb_search_dn1(module, LTDB_SUBCLASSES, <db->cache.subclasses) == -1) {
goto failed;
}
- if (ltdb_search_dn1(ldb, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) {
+ if (ltdb_search_dn1(module, LTDB_ATTRIBUTES, <db->cache.attributes) == -1) {
goto failed;
}
/*
increase the sequence number to indicate a database change
*/
-int ltdb_increase_sequence_number(struct ldb_context *ldb)
+int ltdb_increase_sequence_number(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct ldb_message msg;
struct ldb_message_element el;
struct ldb_val val;
val.data = s;
val.length = strlen(s);
- ret = ltdb_modify_internal(ldb, &msg);
+ ret = ltdb_modify_internal(module, &msg);
ldb_free(ldb, s);
ldb_free(ldb, msg.dn);
return the attribute flags from the @ATTRIBUTES record
for the given attribute
*/
-int ltdb_attribute_flags(struct ldb_context *ldb, const char *attr_name)
+int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
const char *attrs;
const struct {
const char *name;
/*
return a list of dn's that might match a simple indexed search or
*/
-static int ltdb_index_dn_simple(struct ldb_context *ldb,
+static int ltdb_index_dn_simple(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
char *dn = NULL;
int ret;
unsigned int i, j;
/*
if the value is a wildcard then we can't do a match via indexing
*/
- if (ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) {
+ if (ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) {
return -1;
}
dn = ldb_dn_key(ldb, tree->u.simple.attr, &tree->u.simple.value);
if (!dn) return -1;
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
ldb_free(ldb, dn);
if (ret == 0 || ret == -1) {
return ret;
ldb_strdup(ldb, (char *)el->values[j].data);
if (!list->dn[list->count]) {
dn_list_free(ldb, list);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
return -1;
}
list->count++;
}
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
qsort(list->dn, list->count, sizeof(char *), (comparison_fn_t) list_cmp);
return a list of dn's that might match a simple indexed search on
the special objectclass attribute
*/
-static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
+static int ltdb_index_dn_objectclass(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
unsigned int i;
int ret;
const char *target = tree->u.simple.value.data;
list->count = 0;
list->dn = NULL;
- ret = ltdb_index_dn_simple(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_simple(module, tree, index_list, list);
for (i=0;i<ltdb->cache.subclasses.num_elements;i++) {
struct ldb_message_element *el = <db->cache.subclasses.elements[i];
return -1;
}
tree2.u.simple.value = el->values[j];
- if (ltdb_index_dn_objectclass(ldb, &tree2,
+ if (ltdb_index_dn_objectclass(module, &tree2,
index_list, &list2) == 1) {
if (list->count == 0) {
*list = list2;
/*
return a list of dn's that might match a leaf indexed search
*/
-static int ltdb_index_dn_leaf(struct ldb_context *ldb,
+static int ltdb_index_dn_leaf(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
if (ldb_attr_cmp(tree->u.simple.attr, LTDB_OBJECTCLASS) == 0) {
- return ltdb_index_dn_objectclass(ldb, tree, index_list, list);
+ return ltdb_index_dn_objectclass(module, tree, index_list, list);
}
- return ltdb_index_dn_simple(ldb, tree, index_list, list);
+ return ltdb_index_dn_simple(module, tree, index_list, list);
}
return 0;
}
-static int ltdb_index_dn(struct ldb_context *ldb,
+static int ltdb_index_dn(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list);
/*
OR two index results
*/
-static int ltdb_index_dn_or(struct ldb_context *ldb,
+static int ltdb_index_dn_or(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int ret;
for (i=0;i<tree->u.list.num_elements;i++) {
struct dn_list list2;
int v;
- v = ltdb_index_dn(ldb, tree->u.list.elements[i], index_list, &list2);
+ v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, &list2);
if (v == 0) {
/* 0 || X == X */
/*
NOT an index results
*/
-static int ltdb_index_dn_not(struct ldb_context *ldb,
+static int ltdb_index_dn_not(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
/*
AND two index results
*/
-static int ltdb_index_dn_and(struct ldb_context *ldb,
+static int ltdb_index_dn_and(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int ret;
for (i=0;i<tree->u.list.num_elements;i++) {
struct dn_list list2;
int v;
- v = ltdb_index_dn(ldb, tree->u.list.elements[i], index_list, &list2);
+ v = ltdb_index_dn(module, tree->u.list.elements[i], index_list, &list2);
if (v == 0) {
/* 0 && X == 0 */
return a list of dn's that might match a indexed search or
-1 if an error. return 0 for no matches, or 1 for matches
*/
-static int ltdb_index_dn(struct ldb_context *ldb,
+static int ltdb_index_dn(struct ldb_module *module,
struct ldb_parse_tree *tree,
const struct ldb_message *index_list,
struct dn_list *list)
switch (tree->operation) {
case LDB_OP_SIMPLE:
- ret = ltdb_index_dn_leaf(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_leaf(module, tree, index_list, list);
break;
case LDB_OP_AND:
- ret = ltdb_index_dn_and(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_and(module, tree, index_list, list);
break;
case LDB_OP_OR:
- ret = ltdb_index_dn_or(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_or(module, tree, index_list, list);
break;
case LDB_OP_NOT:
- ret = ltdb_index_dn_not(ldb, tree, index_list, list);
+ ret = ltdb_index_dn_not(module, tree, index_list, list);
break;
}
filter a candidate dn_list from an indexed search into a set of results
extracting just the given attributes
*/
-static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree,
+static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tree,
const char *base,
enum ldb_scope scope,
const struct dn_list *dn_list,
for (i=0;i<dn_list->count;i++) {
struct ldb_message msg;
int ret;
- ret = ltdb_search_dn1(ldb, dn_list->dn[i], &msg);
+ ret = ltdb_search_dn1(module, dn_list->dn[i], &msg);
if (ret == 0) {
/* the record has disappeared? yes, this can happen */
continue;
return -1;
}
- if (ldb_message_match(ldb, &msg, tree, base, scope) == 1) {
- ret = ltdb_add_attr_results(ldb, &msg, attrs, &count, res);
+ if (ldb_message_match(module, &msg, tree, base, scope) == 1) {
+ ret = ltdb_add_attr_results(module, &msg, attrs, &count, res);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (ret != 0) {
return -1;
}
returns -1 if an indexed search is not possible, in which
case the caller should call ltdb_search_full()
*/
-int ltdb_search_indexed(struct ldb_context *ldb,
+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)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct dn_list dn_list;
int ret;
return -1;
}
- ret = ltdb_index_dn(ldb, tree, <db->cache.indexlist, &dn_list);
+ ret = ltdb_index_dn(module, tree, <db->cache.indexlist, &dn_list);
if (ret == 1) {
/* we've got a candidate list - now filter by the full tree
and extract the needed attributes */
- ret = ldb_index_filter(ldb, tree, base, scope, &dn_list,
+ ret = ldb_index_filter(module, tree, base, scope, &dn_list,
attrs, res);
dn_list_free(ldb, &dn_list);
}
/*
add an index entry for one message element
*/
-static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
+static int ltdb_index_add1(struct ldb_module *module, char *dn,
struct ldb_message_element *el, int v_idx)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message msg;
char *dn_key;
int ret, added=0, added_dn=0;
return -1;
}
- ret = ltdb_search_dn1(ldb, dn_key, &msg);
+ ret = ltdb_search_dn1(module, dn_key, &msg);
if (ret == -1) {
ldb_free(ldb, dn_key);
return -1;
}
if (ret == 0) {
- ret = ltdb_store(ldb, &msg, TDB_REPLACE);
+ ret = ltdb_store(module, &msg, TDB_REPLACE);
}
if (added) {
ldb_free(ldb, msg.dn);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
return ret;
}
add the index entries for a new record
return -1 on failure
*/
-int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
unsigned int i, j;
continue;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- ret = ltdb_index_add1(ldb, msg->dn, &msg->elements[i], j);
+ ret = ltdb_index_add1(module, msg->dn, &msg->elements[i], j);
if (ret == -1) {
return -1;
}
/*
delete an index entry for one message element
*/
-static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
+static int ltdb_index_del1(struct ldb_module *module, const char *dn,
struct ldb_message_element *el, int v_idx)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message msg;
char *dn_key;
int ret, i;
return -1;
}
- ret = ltdb_search_dn1(ldb, dn_key, &msg);
+ ret = ltdb_search_dn1(module, dn_key, &msg);
if (ret == -1) {
ldb_free(ldb, dn_key);
return -1;
if (i == -1) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: dn %s not found in %s\n", dn, dn_key);
/* it ain't there. hmmm */
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
ldb_free(ldb, dn_key);
return 0;
}
msg.elements[i].num_values--;
if (msg.elements[i].num_values == 0) {
- ret = ltdb_delete_noindex(ldb, dn_key);
+ ret = ltdb_delete_noindex(module, dn_key);
} else {
- ret = ltdb_store(ldb, &msg, TDB_REPLACE);
+ ret = ltdb_store(module, &msg, TDB_REPLACE);
}
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
ldb_free(ldb, dn_key);
return ret;
delete the index entries for a record
return -1 on failure
*/
-int ltdb_index_del(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
unsigned int i, j;
continue;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- ret = ltdb_index_del1(ldb, msg->dn, &msg->elements[i], j);
+ ret = ltdb_index_del1(module, msg->dn, &msg->elements[i], j);
if (ret == -1) {
return -1;
}
*/
static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
- struct ldb_context *ldb = state;
+ struct ldb_module *module = state;
struct ldb_message msg;
int ret;
return 0;
}
- ret = ltdb_unpack_data(ldb, &data, &msg);
+ ret = ltdb_unpack_data(module->ldb, &data, &msg);
if (ret != 0) {
return -1;
}
msg.dn = key.dptr+3;
}
- ret = ltdb_index_add(ldb, &msg);
+ ret = ltdb_index_add(module, &msg);
- ltdb_unpack_data_free(ldb, &msg);
+ ltdb_unpack_data_free(module->ldb, &msg);
return ret;
}
/*
force a complete reindex of the database
*/
-int ltdb_reindex(struct ldb_context *ldb)
+int ltdb_reindex(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
- ltdb_cache_free(ldb);
+ ltdb_cache_free(module);
- if (ltdb_cache_load(ldb) != 0) {
+ if (ltdb_cache_load(module) != 0) {
return -1;
}
}
/* now traverse adding any indexes for normal LDB records */
- ret = tdb_traverse(ltdb->tdb, re_index, ldb);
+ ret = tdb_traverse(ltdb->tdb, re_index, module);
if (ret == -1) {
errno = EIO;
return -1;
return 1 for a match, 0 for a mis-match
*/
-static int ldb_val_equal_objectclass(struct ldb_context *ldb,
+static int ldb_val_equal_objectclass(struct ldb_module *module,
const struct ldb_val *v1, const struct ldb_val *v2)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
unsigned int i;
if (ldb_val_equal_case_insensitive(v1, v2) == 1) {
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(ldb, v1, &el->values[j])) {
+ if (ldb_val_equal_objectclass(module, v1, &el->values[j])) {
return 1;
}
}
return 1 for a match, 0 for a mis-match
*/
-int ldb_val_equal(struct ldb_context *ldb,
+int ldb_val_equal(struct ldb_module *module,
const char *attr_name,
const struct ldb_val *v1, const struct ldb_val *v2)
{
- int flags = ltdb_attribute_flags(ldb, attr_name);
+ struct ldb_context *ldb = module->ldb;
+ int flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_OBJECTCLASS) {
- return ldb_val_equal_objectclass(ldb, v1, v2);
+ return ldb_val_equal_objectclass(module, v1, v2);
}
if (flags & LTDB_FLAG_INTEGER) {
/*
match a leaf node
*/
-static int match_leaf(struct ldb_context *ldb,
+static int match_leaf(struct ldb_module *module,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
const char *base,
return 1;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- if (ldb_val_equal(ldb, msg->elements[i].name,
+ if (ldb_val_equal(module, msg->elements[i].name,
&msg->elements[i].values[j],
&tree->u.simple.value)) {
return 1;
this is a recursive function, and does short-circuit evaluation
*/
-int ldb_message_match(struct ldb_context *ldb,
+int ldb_message_match(struct ldb_module *module,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
const char *base,
break;
case LDB_OP_NOT:
- return ! ldb_message_match(ldb, msg, tree->u.not.child, base, scope);
+ return ! ldb_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(ldb, msg, tree->u.list.elements[i],
+ v = ldb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (!v) return 0;
}
case LDB_OP_OR:
for (i=0;i<tree->u.list.num_elements;i++) {
- v = ldb_message_match(ldb, msg, tree->u.list.elements[i],
+ v = ldb_message_match(module, msg, tree->u.list.elements[i],
base, scope);
if (v) return 1;
}
return 0;
}
- return match_leaf(ldb, msg, tree, base, scope);
+ return match_leaf(module, msg, tree, base, scope);
}
/*
add all elements from one message into another
*/
-static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret,
+static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *ret,
const struct ldb_message *msg)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
+
for (i=0;i<msg->num_elements;i++) {
- int flags = ltdb_attribute_flags(ldb, msg->elements[i].name);
+ int flags = ltdb_attribute_flags(module, msg->elements[i].name);
if ((msg->dn[0] != '@') && (flags & LTDB_FLAG_HIDDEN)) {
continue;
}
/*
pull the specified list of attributes from a message
*/
-static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
+static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module,
const struct ldb_message *msg,
const char * const *attrs)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message *ret;
int i;
ret->private_data = NULL;
if (!attrs) {
- if (msg_add_all_elements(ldb, ret, msg) != 0) {
+ if (msg_add_all_elements(module, ret, msg) != 0) {
msg_free_all_parts(ldb, ret);
return NULL;
}
struct ldb_message_element *el;
if (strcmp(attrs[i], "*") == 0) {
- if (msg_add_all_elements(ldb, ret, msg) != 0) {
+ if (msg_add_all_elements(module, ret, msg) != 0) {
msg_free_all_parts(ldb, ret);
return NULL;
}
see if a ldb_val is a wildcard
return 1 if yes, 0 if no
*/
-int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
+int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name,
const struct ldb_val *val)
{
int flags;
return 0;
}
- flags = ltdb_attribute_flags(ldb, attr_name);
+ flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_WILDCARD) {
return 1;
}
/*
free the results of a ltdb_search_dn1 search
*/
-void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg)
+void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
ldb_free(ldb, msg->private_data);
for (i=0;i<msg->num_elements;i++) {
return 1 on success, 0 on record-not-found and -1 on error
*/
-int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message *msg)
+int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
TDB_DATA tdb_key, tdb_data, tdb_data2;
memset(msg, 0, sizeof(*msg));
/* form the key */
- tdb_key = ltdb_key(ldb, dn);
+ tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
return -1;
}
/*
search the database for a single simple dn
*/
-int ltdb_search_dn(struct ldb_context *ldb, char *dn,
+int ltdb_search_dn(struct ldb_module *module, char *dn,
const char * const attrs[], struct ldb_message ***res)
{
+ struct ldb_context *ldb = module->ldb;
int ret;
struct ldb_message msg, *msg2;
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
if (ret != 1) {
return ret;
}
- msg2 = ltdb_pull_attrs(ldb, &msg, attrs);
+ msg2 = ltdb_pull_attrs(module, &msg, attrs);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (!msg2) {
return -1;
add a set of attributes from a record to a set of results
return 0 on success, -1 on failure
*/
-int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg,
+int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
unsigned int *count,
struct ldb_message ***res)
{
+ struct ldb_context *ldb = module->ldb;
struct ldb_message *msg2;
struct ldb_message **res2;
/* pull the attributes that the user wants */
- msg2 = ltdb_pull_attrs(ldb, msg, attrs);
+ msg2 = ltdb_pull_attrs(module, msg, attrs);
if (!msg2) {
return -1;
}
internal search state during a full db search
*/
struct ltdb_search_info {
- struct ldb_context *ldb;
+ struct ldb_module *module;
struct ldb_parse_tree *tree;
const char *base;
enum ldb_scope scope;
}
/* unpack the record */
- ret = ltdb_unpack_data(sinfo->ldb, &data, &msg);
+ ret = ltdb_unpack_data(sinfo->module->ldb, &data, &msg);
if (ret == -1) {
sinfo->failures++;
return 0;
}
/* see if it matches the given expression */
- if (!ldb_message_match(sinfo->ldb, &msg, sinfo->tree,
+ if (!ldb_message_match(sinfo->module, &msg, sinfo->tree,
sinfo->base, sinfo->scope)) {
- ltdb_unpack_data_free(sinfo->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module->ldb, &msg);
return 0;
}
- ret = ltdb_add_attr_results(sinfo->ldb, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs);
+ ret = ltdb_add_attr_results(sinfo->module, &msg, sinfo->attrs, &sinfo->count, &sinfo->msgs);
if (ret == -1) {
sinfo->failures++;
}
- ltdb_unpack_data_free(sinfo->ldb, &msg);
+ ltdb_unpack_data_free(sinfo->module->ldb, &msg);
return ret;
}
/*
free a set of search results
*/
-int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
+int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int i;
ltdb->last_err_string = NULL;
search the database with a LDAP-like expression.
this is the "full search" non-indexed variant
*/
-static int ltdb_search_full(struct ldb_context *ldb,
+static int ltdb_search_full(struct ldb_module *module,
const char *base,
enum ldb_scope scope,
struct ldb_parse_tree *tree,
const char * const attrs[], struct ldb_message ***res)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ltdb_search_info sinfo;
sinfo.tree = tree;
- sinfo.ldb = ldb;
+ sinfo.module = module;
sinfo.scope = scope;
sinfo.base = base;
sinfo.attrs = attrs;
ret = tdb_traverse(ltdb->tdb, search_func, &sinfo);
if (ret == -1) {
- ltdb_search_free(ldb, sinfo.msgs);
+ ltdb_search_free(module, sinfo.msgs);
return -1;
}
search the database with a LDAP-like expression.
choses a search method
*/
-int ltdb_search(struct ldb_context *ldb, const char *base,
+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)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
struct ldb_parse_tree *tree;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_cache_load(ldb) != 0) {
+ if (ltdb_cache_load(module) != 0) {
return -1;
}
if (tree->operation == LDB_OP_SIMPLE &&
ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 &&
- !ltdb_has_wildcard(ldb, tree->u.simple.attr, &tree->u.simple.value)) {
+ !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) {
/* yay! its a nice simple one */
- ret = ltdb_search_dn(ldb, tree->u.simple.value.data, attrs, res);
+ ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res);
} else {
- ret = ltdb_search_indexed(ldb, base, scope, tree, attrs, res);
+ ret = ltdb_search_indexed(module, base, scope, tree, attrs, res);
if (ret == -1) {
- ret = ltdb_search_full(ldb, base, scope, tree, attrs, res);
+ ret = ltdb_search_full(module, base, scope, tree, attrs, res);
}
}
note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
-struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn)
+struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn)
{
+ struct ldb_context *ldb = module->ldb;
TDB_DATA key;
char *key_str = NULL;
char *dn_folded = NULL;
if (!attr_name) {
goto failed;
}
- flags = ltdb_attribute_flags(ldb, attr_name);
+ flags = ltdb_attribute_flags(module, attr_name);
if (flags & LTDB_FLAG_CASE_INSENSITIVE) {
dn_folded = ldb_casefold(ldb, dn);
/*
lock the database for write - currently a single lock is used
*/
-static int ltdb_lock(struct ldb_context *ldb)
+static int ltdb_lock(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
int ret;
- key = ltdb_key(ldb, "LDBLOCK");
+ key = ltdb_key(module, "LDBLOCK");
if (!key.dptr) {
return -1;
}
/*
unlock the database after a ltdb_lock()
*/
-static void ltdb_unlock(struct ldb_context *ldb)
+static void ltdb_unlock(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA key;
- key = ltdb_key(ldb, "LDBLOCK");
+ key = ltdb_key(module, "LDBLOCK");
if (!key.dptr) {
return;
}
we've made a modification to a dn - possibly reindex and
update sequence number
*/
-static int ltdb_modified(struct ldb_context *ldb, const char *dn)
+static int ltdb_modified(struct ldb_module *module, const char *dn)
{
int ret = 0;
if (strcmp(dn, LTDB_INDEXLIST) == 0 ||
strcmp(dn, LTDB_ATTRIBUTES) == 0) {
- ret = ltdb_reindex(ldb);
+ ret = ltdb_reindex(module);
}
if (ret == 0 &&
strcmp(dn, LTDB_BASEINFO) != 0) {
- ret = ltdb_increase_sequence_number(ldb);
+ ret = ltdb_increase_sequence_number(module);
}
return ret;
/*
store a record into the db
*/
-int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs)
+int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key, tdb_data;
int ret;
- tdb_key = ltdb_key(ldb, msg->dn);
+ tdb_key = ltdb_key(module, msg->dn);
if (!tdb_key.dptr) {
return -1;
}
goto done;
}
- ret = ltdb_index_add(ldb, msg);
+ ret = ltdb_index_add(module, msg);
if (ret == -1) {
tdb_delete(ltdb->tdb, tdb_key);
}
/*
add a record to the database
*/
-static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg)
+static int ltdb_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
- ret = ltdb_store(ldb, msg, TDB_INSERT);
+ ret = ltdb_store(module, msg, TDB_INSERT);
if (ret == 0) {
- ltdb_modified(ldb, msg->dn);
+ ltdb_modified(module, msg->dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
}
delete a record from the database, not updating indexes (used for deleting
index records)
*/
-int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn)
+int ltdb_delete_noindex(struct ldb_module *module, const char *dn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key;
int ret;
- tdb_key = ltdb_key(ldb, dn);
+ tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
return -1;
}
/*
delete a record from the database
*/
-static int ltdb_delete(struct ldb_context *ldb, const char *dn)
+static int ltdb_delete(struct ldb_module *module, const char *dn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ldb_message msg;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ltdb_search_dn1(ldb, dn, &msg);
+ ret = ltdb_search_dn1(module, dn, &msg);
if (ret != 1) {
/* not finding the old record is an error */
goto failed;
}
- ret = ltdb_delete_noindex(ldb, dn);
+ ret = ltdb_delete_noindex(module, dn);
if (ret == -1) {
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
/* remove any indexed attributes */
- ret = ltdb_index_del(ldb, &msg);
+ ret = ltdb_index_del(module, &msg);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
if (ret == 0) {
- ltdb_modified(ldb, dn);
+ ltdb_modified(module, dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
failed:
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return -1;
}
return 0 on success, -1 on failure
*/
-static int msg_delete_element(struct ldb_context *ldb,
+static int msg_delete_element(struct ldb_module *module,
struct ldb_message *msg,
const char *name,
const struct ldb_val *val)
{
+ struct ldb_context *ldb = module->ldb;
unsigned int i;
int found;
struct ldb_message_element *el;
el = &msg->elements[found];
for (i=0;i<el->num_values;i++) {
- if (ldb_val_equal(ldb, msg->elements[i].name, &el->values[i], val)) {
+ if (ldb_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)));
get away with it, but if we ever have really large attribute lists
then we'll need to look at this again
*/
-int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
+int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
TDB_DATA tdb_key, tdb_data;
struct ldb_message msg2;
unsigned i, j;
int ret;
- tdb_key = ltdb_key(ldb, msg->dn);
+ tdb_key = ltdb_key(module, msg->dn);
if (!tdb_key.dptr) {
return -1;
}
break;
}
for (j=0;j<msg->elements[i].num_values;j++) {
- if (msg_delete_element(ldb,
+ if (msg_delete_element(module,
&msg2,
msg->elements[i].name,
&msg->elements[i].values[j]) != 0) {
}
/* we've made all the mods - save the modified record back into the database */
- ret = ltdb_store(ldb, &msg2, TDB_MODIFY);
+ ret = ltdb_store(module, &msg2, TDB_MODIFY);
ldb_free(ldb, tdb_key.dptr);
free(tdb_data.dptr);
/*
modify a record
*/
-static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
+static int ltdb_modify(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
- if (ltdb_cache_load(ldb) != 0) {
- ltdb_unlock(ldb);
+ if (ltdb_cache_load(module) != 0) {
+ ltdb_unlock(module);
return -1;
}
- ret = ltdb_modify_internal(ldb, msg);
+ ret = ltdb_modify_internal(module, msg);
if (ret == 0) {
- ltdb_modified(ldb, msg->dn);
+ ltdb_modified(module, msg->dn);
}
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
}
/*
rename a record
*/
-static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
+static int ltdb_rename(struct ldb_module *module, const char *olddn, const char *newdn)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
struct ldb_message msg;
const char *error_str;
ltdb->last_err_string = NULL;
- if (ltdb_lock(ldb) != 0) {
+ if (ltdb_lock(module) != 0) {
return -1;
}
/* in case any attribute of the message was indexed, we need
to fetch the old record */
- ret = ltdb_search_dn1(ldb, olddn, &msg);
+ ret = ltdb_search_dn1(module, olddn, &msg);
if (ret != 1) {
/* not finding the old record is an error */
goto failed;
msg.dn = ldb_strdup(ldb,newdn);
if (!msg.dn) {
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
- ret = ltdb_add(ldb, &msg);
+ ret = ltdb_add(module, &msg);
if (ret == -1) {
ldb_free(ldb, msg.dn);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
goto failed;
}
ldb_free(ldb, msg.dn);
- ltdb_search_dn1_free(ldb, &msg);
+ ltdb_search_dn1_free(module, &msg);
- ret = ltdb_delete(ldb, olddn);
+ ret = ltdb_delete(module, olddn);
error_str = ltdb->last_err_string;
if (ret == -1) {
- ltdb_delete(ldb, newdn);
+ ltdb_delete(module, newdn);
}
ltdb->last_err_string = error_str;
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return ret;
failed:
- ltdb_unlock(ldb);
+ ltdb_unlock(module);
return -1;
}
/*
close database
*/
-static int ltdb_close(struct ldb_context *ldb)
+static int ltdb_close(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ldb_context *ldb = module->ldb;
+ struct ltdb_private *ltdb = module->private_data;
int ret;
ltdb->last_err_string = NULL;
- ltdb_cache_free(ldb);
+ ltdb_cache_free(module);
ldb_set_alloc(ldb, NULL, NULL);
ret = tdb_close(ltdb->tdb);
/*
return extended error information
*/
-static const char *ltdb_errstring(struct ldb_context *ldb)
+static const char *ltdb_errstring(struct ldb_module *module)
{
- struct ltdb_private *ltdb = ldb->private_data;
+ struct ltdb_private *ltdb = module->private_data;
if (ltdb->last_err_string) {
return ltdb->last_err_string;
}
}
-static const struct ldb_backend_ops ltdb_ops = {
+static const struct ldb_module_ops ltdb_ops = {
+ "tdb",
ltdb_close,
ltdb_search,
ltdb_search_free,
memset(<db->cache, 0, sizeof(ltdb->cache));
- ldb->private_data = ltdb;
- ldb->ops = <db_ops;
+ ldb->modules = ldb_malloc_p(ldb, struct ldb_module);
+ if (!ldb->modules) {
+ tdb_close(tdb);
+ free(ldb);
+ errno = ENOMEM;
+ return NULL;
+ }
+ ldb->modules->ldb = ldb;
+ ldb->modules->prev = ldb->modules->next = NULL;
+ ldb->modules->private_data = ltdb;
+ ldb->modules->ops = <db_ops;
return ldb;
}
struct ldb_context *ldb;
int count=0;
const char *ldb_url;
+ const char **options = NULL;
+ int ldbopts;
int opt, i;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "hH:")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hH:o:")) != EOF) {
switch (opt) {
case 'H':
ldb_url = optarg;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
argc -= optind;
argv += optind;
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
int main(int argc, char * const argv[])
{
struct ldb_context *ldb;
+ const char **options = NULL;
+ int ldbopts;
int ret, i;
const char *ldb_url;
int opt, recursive=0;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "hH:r")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hH:ro:")) != EOF) {
switch (opt) {
case 'H':
ldb_url = optarg;
recursive=1;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
exit(1);
}
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
exit(1);
const char *expression = NULL;
const char *ldb_url;
const char *basedn = NULL;
+ const char **options = NULL;
+ int ldbopts;
int opt;
enum ldb_scope scope = LDB_SCOPE_SUBTREE;
const char *editor;
editor = "vi";
}
- while ((opt = getopt(argc, argv, "hab:e:H:s:v")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hab:e:H:s:vo:")) != EOF) {
switch (opt) {
case 'b':
basedn = optarg;
verbose++;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
attrs = (const char * const *)argv;
}
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
struct ldb_context *ldb;
int count=0;
const char *ldb_url;
+ const char **options = NULL;
+ int ldbopts;
int opt, i;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "hH:")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hH:o:")) != EOF) {
switch (opt) {
case 'H':
ldb_url = optarg;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
argc -= optind;
argv += optind;
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
{
struct ldb_context *ldb;
const char *ldb_url;
+ const char **options = NULL;
+ int ldbopts;
int opt, ret;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "hH:")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hH:o:")) != EOF) {
switch (opt) {
case 'H':
ldb_url = optarg;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
argc -= optind;
argv += optind;
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
const char * const * attrs = NULL;
const char *ldb_url;
const char *basedn = NULL;
- int opt;
+ const char **options = NULL;
+ int opt, ldbopts;
enum ldb_scope scope = LDB_SCOPE_SUBTREE;
int interactive = 0, ret=0;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "b:H:s:hi")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "b:H:s:o:hi")) != EOF) {
switch (opt) {
case 'b':
basedn = optarg;
interactive = 1;
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
attrs = (const char * const *)(argv+1);
}
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
exit(1);
int main(int argc, char * const argv[])
{
struct ldb_context *ldb;
+ const char **options = NULL;
+ int ldbopts;
int opt;
int nrecords = 5000;
int nsearches = 2000;
ldb_url = getenv("LDB_URL");
- while ((opt = getopt(argc, argv, "hH:r:s:b:")) != EOF) {
+ ldbopts = 0;
+ while ((opt = getopt(argc, argv, "hH:r:s:b:o:")) != EOF) {
switch (opt) {
case 'H':
ldb_url = optarg;
nsearches = atoi(optarg);
break;
+ case 'o':
+ ldbopts++;
+ if (options == NULL) {
+ options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
+ } else {
+ options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(-1);
+ }
+ }
+ options[ldbopts - 1] = optarg;
+ options[ldbopts] = NULL;
+ break;
+
case 'h':
default:
usage();
argc -= optind;
argv += optind;
- ldb = ldb_connect(ldb_url, 0, NULL);
+ ldb = ldb_connect(ldb_url, 0, options);
if (!ldb) {
perror("ldb_connect");
ntPwdHistory: HIDDEN
lmPwdHash: HIDDEN
lmPwdHistory: HIDDEN
+createTimestamp: HIDDEN
+modifyTimestamp: HIDDEN
dn: @SUBCLASSES
top: domain
template: userTemplate
template: groupTemplate
+dn: @MODULES
+@MODULE: timestamps
+
dn: ${BASEDN}
objectClass: top
objectClass: domain
dn: @INDEXLIST
dn: @ATTRIBUTES
+createTimestamp: HIDDEN
+modifyTimestamp: HIDDEN
dn: @SUBCLASSES
+dn: @MODULES
+@MODULE: timestamps
+
dn: cn=rootDSE
currentTime: _DYNAMIC_
subschemaSubentry: CN=Aggregate,CN=Schema,CN=Configuration,${BASEDN}