mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
r3754: merge in ldb modules support from the tmp branch ldbPlugins
(This used to be commit 71323f424b
)
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
5b397619cc
commit
679e95db03
@ -75,7 +75,80 @@ static char *parse_slash(char *p, char *end) {
|
||||
} \
|
||||
} 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;
|
||||
|
@ -35,3 +35,7 @@ struct ldap_dn {
|
||||
int comp_num;
|
||||
struct dn_component **components;
|
||||
};
|
||||
|
||||
struct ldap_schema {
|
||||
int dummy;
|
||||
};
|
||||
|
@ -385,8 +385,8 @@ static NTSTATUS sldb_Modify(struct ldapsrv_partition *partition, struct ldapsrv_
|
||||
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);
|
||||
|
||||
@ -399,11 +399,6 @@ static NTSTATUS sldb_Modify(struct ldapsrv_partition *partition, struct ldapsrv_
|
||||
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 {
|
||||
|
@ -23,9 +23,11 @@ LDB_TDB_OBJ=ldb_tdb/ldb_match.o ldb_tdb/ldb_tdb.o \
|
||||
|
||||
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
|
||||
|
||||
@ -67,7 +69,7 @@ bin/ldbtest: tools/ldbtest.o $(LIBS)
|
||||
$(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]
|
||||
|
@ -47,20 +47,32 @@
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -68,8 +80,7 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -84,12 +95,7 @@ int ldb_search(struct ldb_context *ldb,
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -97,7 +103,7 @@ int ldb_search(struct ldb_context *ldb,
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -108,10 +114,7 @@ int ldb_search_free(struct ldb_context *ldb, struct ldb_message **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);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -120,11 +123,7 @@ int ldb_add(struct ldb_context *ldb,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -133,10 +132,7 @@ int ldb_modify(struct ldb_context *ldb,
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -144,10 +140,7 @@ int ldb_delete(struct ldb_context *ldb, const char *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);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -155,5 +148,6 @@ int ldb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
|
||||
*/
|
||||
const char *ldb_errstring(struct ldb_context *ldb)
|
||||
{
|
||||
return ldb->ops->errstring(ldb);
|
||||
return ldb->modules->ops->errstring(ldb->modules);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
################################################
|
||||
# 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]
|
||||
@ -38,7 +47,8 @@ ADD_OBJ_FILES = \
|
||||
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
|
||||
#
|
||||
|
@ -121,26 +121,39 @@ struct ldb_context;
|
||||
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
|
||||
@ -172,11 +185,8 @@ struct ldb_debug_ops {
|
||||
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;
|
||||
|
@ -68,10 +68,11 @@ static const char *lldb_option_find(const struct lldb_private *lldb, const char
|
||||
/*
|
||||
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;
|
||||
@ -94,9 +95,10 @@ static int lldb_close(struct ldb_context *ldb)
|
||||
/*
|
||||
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 = "";
|
||||
@ -129,9 +131,9 @@ static int lldb_rename(struct ldb_context *ldb, const char *olddn, const char *n
|
||||
/*
|
||||
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 */
|
||||
@ -171,8 +173,9 @@ static int lldb_msg_free(struct ldb_context *ldb, struct ldb_message *msg)
|
||||
/*
|
||||
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) {
|
||||
@ -243,11 +246,12 @@ static int lldb_add_msg_attr(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -335,7 +339,7 @@ static int lldb_search(struct ldb_context *ldb, const char *base,
|
||||
return msg_count;
|
||||
|
||||
failed:
|
||||
if (*res) lldb_search_free(ldb, *res);
|
||||
if (*res) lldb_search_free(module, *res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -434,9 +438,10 @@ failed:
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -461,9 +466,10 @@ static int lldb_add(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -488,14 +494,15 @@ static int lldb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
/*
|
||||
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,
|
||||
@ -544,8 +551,16 @@ struct ldb_context *lldb_connect(const char *url,
|
||||
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
|
||||
|
@ -38,9 +38,10 @@
|
||||
/*
|
||||
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;
|
||||
@ -77,7 +78,7 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb)
|
||||
}
|
||||
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);
|
||||
@ -89,17 +90,18 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb)
|
||||
/*
|
||||
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));
|
||||
@ -110,26 +112,27 @@ void ltdb_cache_free(struct ldb_context *ldb)
|
||||
/*
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -145,17 +148,17 @@ int ltdb_cache_load(struct ldb_context *ldb)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -172,9 +175,10 @@ 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;
|
||||
@ -197,7 +201,7 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb)
|
||||
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);
|
||||
@ -215,9 +219,10 @@ int ltdb_increase_sequence_number(struct ldb_context *ldb)
|
||||
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;
|
||||
|
@ -107,11 +107,12 @@ static int list_cmp(const char **s1, const char **s2)
|
||||
/*
|
||||
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;
|
||||
@ -123,7 +124,7 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
|
||||
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;
|
||||
@ -163,14 +164,14 @@ static int ltdb_index_dn_simple(struct ldb_context *ldb,
|
||||
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);
|
||||
|
||||
@ -184,12 +185,13 @@ static int list_union(struct ldb_context *, struct dn_list *, const struct dn_li
|
||||
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;
|
||||
@ -197,7 +199,7 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
|
||||
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];
|
||||
@ -212,7 +214,7 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
|
||||
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;
|
||||
@ -233,15 +235,15 @@ static int ltdb_index_dn_objectclass(struct ldb_context *ldb,
|
||||
/*
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -331,7 +333,7 @@ static int list_union(struct ldb_context *ldb,
|
||||
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);
|
||||
@ -340,11 +342,12 @@ static int ltdb_index_dn(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -355,7 +358,7 @@ static int ltdb_index_dn_or(struct ldb_context *ldb,
|
||||
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 */
|
||||
@ -395,7 +398,7 @@ static int ltdb_index_dn_or(struct ldb_context *ldb,
|
||||
/*
|
||||
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)
|
||||
@ -414,11 +417,12 @@ static int ltdb_index_dn_not(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -429,7 +433,7 @@ static int ltdb_index_dn_and(struct ldb_context *ldb,
|
||||
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 */
|
||||
@ -465,7 +469,7 @@ static int ltdb_index_dn_and(struct ldb_context *ldb,
|
||||
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)
|
||||
@ -474,19 +478,19 @@ static int ltdb_index_dn(struct ldb_context *ldb,
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -497,7 +501,7 @@ static int ltdb_index_dn(struct ldb_context *ldb,
|
||||
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,
|
||||
@ -508,7 +512,7 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
|
||||
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;
|
||||
@ -519,10 +523,10 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
|
||||
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;
|
||||
}
|
||||
@ -536,13 +540,14 @@ static int ldb_index_filter(struct ldb_context *ldb, struct ldb_parse_tree *tree
|
||||
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;
|
||||
|
||||
@ -551,12 +556,12 @@ int ltdb_search_indexed(struct ldb_context *ldb,
|
||||
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);
|
||||
}
|
||||
@ -638,9 +643,10 @@ static int ltdb_index_add1_add(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
@ -651,7 +657,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
|
||||
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;
|
||||
@ -686,7 +692,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = ltdb_store(ldb, &msg, TDB_REPLACE);
|
||||
ret = ltdb_store(module, &msg, TDB_REPLACE);
|
||||
}
|
||||
|
||||
if (added) {
|
||||
@ -696,7 +702,7 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
|
||||
ldb_free(ldb, msg.dn);
|
||||
}
|
||||
|
||||
ltdb_search_dn1_free(ldb, &msg);
|
||||
ltdb_search_dn1_free(module, &msg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -705,9 +711,9 @@ static int ltdb_index_add1(struct ldb_context *ldb, char *dn,
|
||||
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;
|
||||
|
||||
@ -723,7 +729,7 @@ int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
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;
|
||||
}
|
||||
@ -737,9 +743,10 @@ int ltdb_index_add(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
/*
|
||||
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;
|
||||
@ -750,7 +757,7 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
|
||||
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;
|
||||
@ -768,7 +775,7 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
|
||||
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;
|
||||
}
|
||||
@ -782,12 +789,12 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
|
||||
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;
|
||||
@ -797,9 +804,9 @@ static int ltdb_index_del1(struct ldb_context *ldb, const char *dn,
|
||||
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;
|
||||
|
||||
@ -816,7 +823,7 @@ int ltdb_index_del(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
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;
|
||||
}
|
||||
@ -844,7 +851,7 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -853,7 +860,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = ltdb_unpack_data(ldb, &data, &msg);
|
||||
ret = ltdb_unpack_data(module->ldb, &data, &msg);
|
||||
if (ret != 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -862,9 +869,9 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
|
||||
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;
|
||||
}
|
||||
@ -872,14 +879,14 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
@ -891,7 +898,7 @@ int ltdb_reindex(struct ldb_context *ldb)
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
@ -137,10 +137,10 @@ static int ldb_val_equal_wildcard(struct ldb_context *ldb,
|
||||
|
||||
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) {
|
||||
@ -152,7 +152,7 @@ static int ldb_val_equal_objectclass(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -171,14 +171,15 @@ static int ldb_val_equal_objectclass(struct ldb_context *ldb,
|
||||
|
||||
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) {
|
||||
@ -254,7 +255,7 @@ static int scope_match(const char *dn, const char *base, enum ldb_scope scope)
|
||||
/*
|
||||
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,
|
||||
@ -279,7 +280,7 @@ static int match_leaf(struct ldb_context *ldb,
|
||||
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;
|
||||
@ -299,7 +300,7 @@ static int match_leaf(struct ldb_context *ldb,
|
||||
|
||||
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,
|
||||
@ -313,11 +314,11 @@ int ldb_message_match(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
@ -325,12 +326,12 @@ int ldb_message_match(struct ldb_context *ldb,
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -131,12 +131,14 @@ static int msg_add_element(struct ldb_context *ldb,
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -152,10 +154,11 @@ static int msg_add_all_elements(struct ldb_context *ldb, struct ldb_message *ret
|
||||
/*
|
||||
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;
|
||||
|
||||
@ -175,7 +178,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
@ -186,7 +189,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
@ -237,7 +240,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_context *ldb,
|
||||
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;
|
||||
@ -251,7 +254,7 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
flags = ltdb_attribute_flags(ldb, attr_name);
|
||||
flags = ltdb_attribute_flags(module, attr_name);
|
||||
if (flags & LTDB_FLAG_WILDCARD) {
|
||||
return 1;
|
||||
}
|
||||
@ -263,8 +266,9 @@ int ltdb_has_wildcard(struct ldb_context *ldb, const char *attr_name,
|
||||
/*
|
||||
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++) {
|
||||
@ -281,16 +285,17 @@ void ltdb_search_dn1_free(struct ldb_context *ldb, struct ldb_message *msg)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -335,20 +340,21 @@ int ltdb_search_dn1(struct ldb_context *ldb, const char *dn, struct ldb_message
|
||||
/*
|
||||
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;
|
||||
@ -371,16 +377,17 @@ int ltdb_search_dn(struct ldb_context *ldb, char *dn,
|
||||
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;
|
||||
}
|
||||
@ -406,7 +413,7 @@ int ltdb_add_attr_results(struct ldb_context *ldb, struct ldb_message *msg,
|
||||
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;
|
||||
@ -432,7 +439,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
|
||||
}
|
||||
|
||||
/* 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;
|
||||
@ -443,19 +450,19 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
|
||||
}
|
||||
|
||||
/* 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;
|
||||
}
|
||||
@ -464,9 +471,10 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi
|
||||
/*
|
||||
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;
|
||||
@ -486,18 +494,18 @@ int ltdb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
|
||||
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;
|
||||
@ -508,7 +516,7 @@ static int ltdb_search_full(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -521,17 +529,18 @@ static int ltdb_search_full(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -546,13 +555,13 @@ int ltdb_search(struct ldb_context *ldb, const char *base,
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,9 @@
|
||||
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;
|
||||
@ -74,7 +75,7 @@ struct TDB_DATA ltdb_key(struct ldb_context *ldb, const char *dn)
|
||||
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);
|
||||
@ -119,13 +120,14 @@ failed:
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -140,12 +142,13 @@ static int ltdb_lock(struct ldb_context *ldb)
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -160,18 +163,18 @@ static void ltdb_unlock(struct ldb_context *ldb)
|
||||
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;
|
||||
@ -180,13 +183,14 @@ static int ltdb_modified(struct ldb_context *ldb, const char *dn)
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -202,7 +206,7 @@ int ltdb_store(struct ldb_context *ldb, const struct ldb_message *msg, int flgs)
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = ltdb_index_add(ldb, msg);
|
||||
ret = ltdb_index_add(module, msg);
|
||||
if (ret == -1) {
|
||||
tdb_delete(ltdb->tdb, tdb_key);
|
||||
}
|
||||
@ -218,29 +222,29 @@ done:
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
@ -249,13 +253,14 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
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;
|
||||
}
|
||||
@ -269,51 +274,51 @@ int ltdb_delete_noindex(struct ldb_context *ldb, const char *dn)
|
||||
/*
|
||||
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;
|
||||
}
|
||||
|
||||
@ -416,11 +421,12 @@ static int msg_delete_attribute(struct ldb_context *ldb,
|
||||
|
||||
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;
|
||||
@ -433,7 +439,7 @@ static int msg_delete_element(struct ldb_context *ldb,
|
||||
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)));
|
||||
@ -457,15 +463,16 @@ static int msg_delete_element(struct ldb_context *ldb,
|
||||
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;
|
||||
}
|
||||
@ -527,7 +534,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
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) {
|
||||
@ -540,7 +547,7 @@ int ltdb_modify_internal(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -557,29 +564,29 @@ failed:
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -587,22 +594,23 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
|
||||
/*
|
||||
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;
|
||||
@ -610,46 +618,47 @@ static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *n
|
||||
|
||||
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);
|
||||
@ -662,9 +671,9 @@ static int ltdb_close(struct ldb_context *ldb)
|
||||
/*
|
||||
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;
|
||||
}
|
||||
@ -672,7 +681,8 @@ static const char *ltdb_errstring(struct ldb_context *ldb)
|
||||
}
|
||||
|
||||
|
||||
static const struct ldb_backend_ops ltdb_ops = {
|
||||
static const struct ldb_module_ops ltdb_ops = {
|
||||
"tdb",
|
||||
ltdb_close,
|
||||
ltdb_search,
|
||||
ltdb_search_free,
|
||||
@ -743,8 +753,17 @@ struct ldb_context *ltdb_connect(const char *url,
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -83,16 +83,34 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
||||
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();
|
||||
@ -108,7 +126,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
|
@ -72,13 +72,16 @@ static void usage(void)
|
||||
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;
|
||||
@ -88,6 +91,21 @@ static void usage(void)
|
||||
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();
|
||||
@ -108,7 +126,7 @@ static void usage(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
exit(1);
|
||||
|
@ -304,6 +304,8 @@ static void usage(void)
|
||||
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;
|
||||
@ -321,7 +323,8 @@ static void usage(void)
|
||||
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;
|
||||
@ -353,6 +356,21 @@ static void usage(void)
|
||||
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();
|
||||
@ -381,7 +399,7 @@ static void usage(void)
|
||||
attrs = (const char * const *)argv;
|
||||
}
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
|
@ -85,16 +85,34 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
||||
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();
|
||||
@ -110,7 +128,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
|
@ -51,16 +51,34 @@ static void usage(void)
|
||||
{
|
||||
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();
|
||||
@ -76,7 +94,7 @@ static void usage(void)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
|
@ -89,13 +89,15 @@ static int do_search(struct ldb_context *ldb,
|
||||
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;
|
||||
@ -119,6 +121,21 @@ static int do_search(struct ldb_context *ldb,
|
||||
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();
|
||||
@ -143,7 +160,7 @@ static int do_search(struct ldb_context *ldb,
|
||||
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);
|
||||
|
@ -358,13 +358,16 @@ static void usage(void)
|
||||
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;
|
||||
@ -382,6 +385,21 @@ static void usage(void)
|
||||
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();
|
||||
@ -397,7 +415,7 @@ static void usage(void)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
ldb = ldb_connect(ldb_url, 0, NULL);
|
||||
ldb = ldb_connect(ldb_url, 0, options);
|
||||
|
||||
if (!ldb) {
|
||||
perror("ldb_connect");
|
||||
|
@ -18,6 +18,8 @@ ntPwdHash: HIDDEN
|
||||
ntPwdHistory: HIDDEN
|
||||
lmPwdHash: HIDDEN
|
||||
lmPwdHistory: HIDDEN
|
||||
createTimestamp: HIDDEN
|
||||
modifyTimestamp: HIDDEN
|
||||
|
||||
dn: @SUBCLASSES
|
||||
top: domain
|
||||
@ -31,6 +33,9 @@ user: computer
|
||||
template: userTemplate
|
||||
template: groupTemplate
|
||||
|
||||
dn: @MODULES
|
||||
@MODULE: timestamps
|
||||
|
||||
dn: ${BASEDN}
|
||||
objectClass: top
|
||||
objectClass: domain
|
||||
|
@ -1,9 +1,14 @@
|
||||
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}
|
||||
|
Reference in New Issue
Block a user