summaryrefslogtreecommitdiff
path: root/source3/lib/ldb/common
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/ldb/common')
-rw-r--r--source3/lib/ldb/common/ldb.c32
-rw-r--r--source3/lib/ldb/common/ldb_dn.c119
-rw-r--r--source3/lib/ldb/common/ldb_match.c2
-rw-r--r--source3/lib/ldb/common/ldb_modules.c16
-rw-r--r--source3/lib/ldb/common/ldb_msg.c8
5 files changed, 123 insertions, 54 deletions
diff --git a/source3/lib/ldb/common/ldb.c b/source3/lib/ldb/common/ldb.c
index 7648abf795..9e0ee6ebca 100644
--- a/source3/lib/ldb/common/ldb.c
+++ b/source3/lib/ldb/common/ldb.c
@@ -522,7 +522,7 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
Use talloc_free to free the ldb_message returned in 'res', if successful
*/
-static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
{
struct ldb_result *res;
int n;
@@ -532,12 +532,13 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld
return LDB_ERR_OPERATIONS_ERROR;
}
- res = *((struct ldb_result **)context);
+ res = talloc_get_type(context, struct ldb_result);
if (!res || !ares) {
+ ldb_set_errstring(ldb, "NULL res or ares in callback");
goto error;
}
-
+
switch (ares->type) {
case LDB_REPLY_ENTRY:
res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);
@@ -564,19 +565,17 @@ static int ldb_search_callback(struct ldb_context *ldb, void *context, struct ld
res->refs[n] = talloc_move(res->refs, &ares->referral);
res->refs[n + 1] = NULL;
+ case LDB_REPLY_EXTENDED:
case LDB_REPLY_DONE:
- /* Should do something here to detect if this never
- * happens */
+ /* TODO: we should really support controls on entries and referrals too! */
+ res->controls = talloc_move(res, &ares->controls);
break;
}
- talloc_steal(res, ares->controls);
talloc_free(ares);
return LDB_SUCCESS;
error:
talloc_free(ares);
- talloc_free(res);
- *((struct ldb_result **)context) = NULL;
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -752,16 +751,19 @@ int ldb_search(struct ldb_context *ldb,
enum ldb_scope scope,
const char *expression,
const char * const *attrs,
- struct ldb_result **res)
+ struct ldb_result **_res)
{
struct ldb_request *req;
int ret;
+ struct ldb_result *res;
+
+ *_res = NULL;
- *res = talloc_zero(ldb, struct ldb_result);
- if (! *res) {
+ res = talloc_zero(ldb, struct ldb_result);
+ if (!res) {
return LDB_ERR_OPERATIONS_ERROR;
}
-
+
ret = ldb_build_search_req(&req, ldb, ldb,
base?base:ldb_get_default_basedn(ldb),
scope,
@@ -769,7 +771,7 @@ int ldb_search(struct ldb_context *ldb,
attrs,
NULL,
res,
- ldb_search_callback);
+ ldb_search_default_callback);
if (ret != LDB_SUCCESS) goto done;
@@ -785,10 +787,10 @@ int ldb_search(struct ldb_context *ldb,
done:
if (ret != LDB_SUCCESS) {
- talloc_free(*res);
- *res = NULL;
+ talloc_free(res);
}
+ *_res = res;
return ret;
}
diff --git a/source3/lib/ldb/common/ldb_dn.c b/source3/lib/ldb/common/ldb_dn.c
index e937a2b7fc..48f471bf6f 100644
--- a/source3/lib/ldb/common/ldb_dn.c
+++ b/source3/lib/ldb/common/ldb_dn.c
@@ -41,6 +41,19 @@
#define LDB_SPECIAL "@SPECIAL"
+/**
+ internal ldb exploded dn structures
+*/
+struct ldb_dn_component {
+ char *name;
+ struct ldb_val value;
+};
+
+struct ldb_dn {
+ int comp_num;
+ struct ldb_dn_component *components;
+};
+
int ldb_dn_is_special(const struct ldb_dn *dn)
{
if (dn == NULL || dn->comp_num != 1) return 0;
@@ -688,6 +701,26 @@ static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_d
return dst;
}
+/* Copy a DN but replace the old with the new base DN. */
+struct ldb_dn *ldb_dn_copy_rebase(void *mem_ctx, const struct ldb_dn *old, const struct ldb_dn *old_base, const struct ldb_dn *new_base)
+{
+ struct ldb_dn *new_dn;
+ int i, offset;
+
+ /* Perhaps we don't need to rebase at all? */
+ if (!old_base || !new_base) {
+ return ldb_dn_copy(mem_ctx, old);
+ }
+
+ offset = old->comp_num - old_base->comp_num;
+ new_dn = ldb_dn_copy_partial(mem_ctx, new_base, offset + new_base->comp_num);
+ for (i = 0; i < offset; i++) {
+ new_dn->components[i] = ldb_dn_copy_component(new_dn->components, &(old->components[i]));
+ }
+
+ return new_dn;
+}
+
/* copy specified number of elements of a dn into a new one
element are copied from top level up to the unique rdn
num_el may be greater than dn->comp_num (see ldb_dn_make_child)
@@ -799,15 +832,6 @@ failed:
}
-struct ldb_dn *ldb_dn_make_child(void *mem_ctx, const struct ldb_dn_component *component,
- const struct ldb_dn *base)
-{
- if (component == NULL) return NULL;
-
- return ldb_dn_build_child(mem_ctx, component->name,
- (char *)component->value.data, base);
-}
-
struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2)
{
int i;
@@ -872,28 +896,6 @@ struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, c
return dn;
}
-struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn)
-{
- struct ldb_dn_component *rdn;
-
- if (dn == NULL) return NULL;
-
- if (dn->comp_num < 1) {
- return NULL;
- }
-
- rdn = talloc(mem_ctx, struct ldb_dn_component);
- if (rdn == NULL) return NULL;
-
- *rdn = ldb_dn_copy_component(mem_ctx, &dn->components[0]);
- if (rdn->name == NULL) {
- talloc_free(rdn);
- return NULL;
- }
-
- return rdn;
-}
-
/* Create a 'canonical name' string from a DN:
ie dc=samba,dc=org -> samba.org/
@@ -962,3 +964,58 @@ char *ldb_dn_canonical_string(void *mem_ctx, const struct ldb_dn *dn) {
char *ldb_dn_canonical_ex_string(void *mem_ctx, const struct ldb_dn *dn) {
return ldb_dn_canonical(mem_ctx, dn, 1);
}
+
+int ldb_dn_get_comp_num(const struct ldb_dn *dn)
+{
+ return dn->comp_num;
+}
+
+const char *ldb_dn_get_component_name(const struct ldb_dn *dn, unsigned int num)
+{
+ if (num >= dn->comp_num) return NULL;
+ return dn->components[num].name;
+}
+
+const struct ldb_val *ldb_dn_get_component_val(const struct ldb_dn *dn, unsigned int num)
+{
+ if (num >= dn->comp_num) return NULL;
+ return &dn->components[num].value;
+}
+
+const char *ldb_dn_get_rdn_name(const struct ldb_dn *dn) {
+ if (dn->comp_num == 0) return NULL;
+ return dn->components[0].name;
+}
+
+const struct ldb_val *ldb_dn_get_rdn_val(const struct ldb_dn *dn) {
+ if (dn->comp_num == 0) return NULL;
+ return &dn->components[0].value;
+}
+
+int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val)
+{
+ char *n;
+ struct ldb_val v;
+
+ if (num >= dn->comp_num) {
+ return LDB_ERR_OTHER;
+ }
+
+ n = talloc_strdup(dn, name);
+ if ( ! n) {
+ return LDB_ERR_OTHER;
+ }
+
+ v.length = val.length;
+ v.data = (uint8_t *)talloc_memdup(dn, val.data, v.length+1);
+ if ( ! v.data) {
+ return LDB_ERR_OTHER;
+ }
+
+ talloc_free(dn->components[num].name);
+ talloc_free(dn->components[num].value.data);
+ dn->components[num].name = n;
+ dn->components[num].value = v;
+
+ return LDB_SUCCESS;
+}
diff --git a/source3/lib/ldb/common/ldb_match.c b/source3/lib/ldb/common/ldb_match.c
index 1fd12da7f3..0cd220ad60 100644
--- a/source3/lib/ldb/common/ldb_match.c
+++ b/source3/lib/ldb/common/ldb_match.c
@@ -58,7 +58,7 @@ static int ldb_match_scope(struct ldb_context *ldb,
break;
case LDB_SCOPE_ONELEVEL:
- if (dn->comp_num == (base->comp_num + 1)) {
+ if (ldb_dn_get_comp_num(dn) == (ldb_dn_get_comp_num(base) + 1)) {
if (ldb_dn_compare_base(ldb, base, dn) == 0) {
ret = 1;
}
diff --git a/source3/lib/ldb/common/ldb_modules.c b/source3/lib/ldb/common/ldb_modules.c
index 8bcafa36a8..a6997b324a 100644
--- a/source3/lib/ldb/common/ldb_modules.c
+++ b/source3/lib/ldb/common/ldb_modules.c
@@ -159,6 +159,7 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
ldb_objectclass_init, \
ldb_paged_results_init, \
ldb_sort_init, \
+ ldb_asq_init, \
NULL \
}
#endif
@@ -205,17 +206,26 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
char *path;
void *handle;
int (*init_fn) (void);
+ char *modulesdir;
#ifdef HAVE_DLOPEN
+ if (getenv("LD_LDB_MODULE_PATH") != NULL) {
+ modulesdir = talloc_strdup(ldb, getenv("LD_LDB_MODULE_PATH"));
+ } else {
#ifdef _SAMBA_BUILD_
- path = talloc_asprintf(ldb, "%s/ldb/%s.%s", dyn_MODULESDIR, name, dyn_SHLIBEXT);
+ modulesdir = talloc_asprintf(ldb, "%s/ldb", dyn_MODULESDIR);
#else
- path = talloc_asprintf(ldb, "%s/%s.%s", MODULESDIR, name, SHLIBEXT);
+ modulesdir = talloc_strdup(ldb, MODULESDIR);
#endif
+ }
+
+ path = talloc_asprintf(ldb, "%s/%s.%s", modulesdir, name, SHLIBEXT);
+
+ talloc_free(modulesdir);
ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path);
- handle = dlopen(path, 0);
+ handle = dlopen(path, RTLD_NOW);
if (handle == NULL) {
ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror());
return -1;
diff --git a/source3/lib/ldb/common/ldb_msg.c b/source3/lib/ldb/common/ldb_msg.c
index 46ab721e2e..9cb4cf5ed0 100644
--- a/source3/lib/ldb/common/ldb_msg.c
+++ b/source3/lib/ldb/common/ldb_msg.c
@@ -119,10 +119,10 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v)
/*
add an empty element to a message
*/
-int ldb_msg_add_empty(struct ldb_message *msg,
- const char *attr_name,
- int flags,
- struct ldb_message_element **return_el)
+int ldb_msg_add_empty( struct ldb_message *msg,
+ const char *attr_name,
+ int flags,
+ struct ldb_message_element **return_el)
{
struct ldb_message_element *els;