* Author: Andrew Tridgell
*/
-#include "ldb_includes.h"
-
#include "ldb_tdb.h"
/*
*/
static int ltdb_idxptr_add(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
ltdb->idxptr->dn_list = talloc_realloc(ltdb->idxptr, ltdb->idxptr->dn_list,
const char *, ltdb->idxptr->num_dns+1);
if (ltdb->idxptr->dn_list == NULL) {
struct ldb_index_pointer *ptr, *tmp;
int i;
struct ldb_val *val2;
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
ptr = NULL;
/* enable the idxptr mode when transactions start */
int ltdb_index_transaction_start(struct ldb_module *module)
{
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
ltdb->idxptr = talloc_zero(module, struct ltdb_idxptr);
return LDB_SUCCESS;
}
*/
static int ltdb_idxptr_fix_dn(struct ldb_module *module, const char *strdn)
{
+ struct ldb_context *ldb;
struct ldb_dn *dn;
struct ldb_message *msg = ldb_msg_new(module);
int ret;
- dn = ldb_dn_new(msg, module->ldb, strdn);
+ ldb = ldb_module_get_ctx(module);
+
+ dn = ldb_dn_new(msg, ldb, strdn);
if (ltdb_search_dn1_index(module, dn, msg) == LDB_SUCCESS) {
ret = ltdb_store(module, msg, TDB_REPLACE);
}
int ltdb_index_transaction_commit(struct ldb_module *module)
{
int i;
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
/* fix all the DNs that we have modified */
if (ltdb->idxptr) {
/* cleanup the idxptr mode when transaction cancels */
int ltdb_index_transaction_cancel(struct ldb_module *module)
{
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
talloc_free(ltdb->idxptr);
ltdb->idxptr = NULL;
return LDB_SUCCESS;
*/
int ltdb_store_idxptr(struct ldb_module *module, const struct ldb_message *msg, int flgs)
{
- struct ltdb_private *ltdb =
- talloc_get_type(module->private_data, struct ltdb_private);
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
int ret;
if (ltdb->idxptr) {
const struct ldb_message *index_list,
struct dn_list *list)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
struct ldb_dn *dn;
int ret;
unsigned int i, j;
struct ldb_message *msg;
+ ldb = ldb_module_get_ctx(module);
+
list->count = 0;
list->dn = NULL;
const struct ldb_message *index_list,
struct dn_list *list)
{
+ struct ldb_context *ldb;
+ ldb = ldb_module_get_ctx(module);
+
if (ldb_attr_dn(tree->u.equality.attr) == 0) {
list->dn = talloc_array(list, char *, 1);
if (list->dn == NULL) {
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
list->dn[0] = talloc_strdup(list->dn, (char *)tree->u.equality.value.data);
if (list->dn[0] == NULL) {
- ldb_oom(module->ldb);
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
list->count = 1;
const struct ldb_message *index_list,
struct dn_list *list)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
unsigned int i;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
ret = LDB_ERR_OPERATIONS_ERROR;
list->dn = NULL;
list->count = 0;
const struct ldb_message *index_list,
struct dn_list *list)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
unsigned int i;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
ret = LDB_ERR_OPERATIONS_ERROR;
list->dn = NULL;
list->count = 0;
struct ldb_dn *parent_dn,
struct dn_list *list)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
struct dn_list *list2;
struct ldb_message *msg;
struct ldb_dn *key;
unsigned int i, j;
int ret;
+ ldb = ldb_module_get_ctx(module);
+
list2 = talloc_zero(module, struct dn_list);
if (list2 == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
static int ltdb_index_filter(const struct dn_list *dn_list,
struct ltdb_context *ac)
{
+ struct ldb_context *ldb;
struct ldb_message *msg;
unsigned int i;
+ ldb = ldb_module_get_ctx(ac->module);
+
for (i = 0; i < dn_list->count; i++) {
struct ldb_dn *dn;
int ret;
return LDB_ERR_OPERATIONS_ERROR;
}
- dn = ldb_dn_new(msg, ac->module->ldb, dn_list->dn[i]);
+ dn = ldb_dn_new(msg, ldb, dn_list->dn[i]);
if (dn == NULL) {
talloc_free(msg);
return LDB_ERR_OPERATIONS_ERROR;
return LDB_ERR_OPERATIONS_ERROR;
}
- if (!ldb_match_msg(ac->module->ldb, msg,
+ if (!ldb_match_msg(ldb, msg,
ac->tree, ac->base, ac->scope)) {
talloc_free(msg);
continue;
*/
int ltdb_search_indexed(struct ltdb_context *ac)
{
- struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private);
+ struct ldb_context *ldb;
+ void *data = ldb_module_get_private(ac->module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
struct dn_list *dn_list;
int ret, idxattr, idxone;
+ ldb = ldb_module_get_ctx(ac->module);
+
idxattr = idxone = 0;
ret = ldb_msg_find_idx(ltdb->cache->indexlist, NULL, NULL, LTDB_IDXATTR);
if (ret == 0 ) {
/* with BASE searches only one DN can match */
dn_list->dn = talloc_array(dn_list, char *, 1);
if (dn_list->dn == NULL) {
- ldb_oom(ac->module->ldb);
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
dn_list->dn[0] = ldb_dn_alloc_linearized(dn_list, ac->base);
if (dn_list->dn[0] == NULL) {
- ldb_oom(ac->module->ldb);
+ ldb_oom(ldb);
return LDB_ERR_OPERATIONS_ERROR;
}
dn_list->count = 1;
static int ltdb_index_add1(struct ldb_module *module, const char *dn,
struct ldb_message_element *el, int v_idx)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
struct ldb_message *msg;
struct ldb_dn *dn_key;
int ret;
unsigned int i;
+ ldb = ldb_module_get_ctx(module);
+
msg = talloc(module, struct ldb_message);
if (msg == NULL) {
errno = ENOMEM;
static int ltdb_index_add0(struct ldb_module *module, const char *dn,
struct ldb_message_element *elements, int num_el)
{
- struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
int ret;
unsigned int i, j;
int ltdb_index_del_value(struct ldb_module *module, const char *dn,
struct ldb_message_element *el, int v_idx)
{
- struct ldb_context *ldb = module->ldb;
+ struct ldb_context *ldb;
struct ldb_message *msg;
struct ldb_dn *dn_key;
int ret, i;
unsigned int j;
+ ldb = ldb_module_get_ctx(module);
+
if (dn[0] == '@') {
return LDB_SUCCESS;
}
ldb_dn_get_linearized(dn_key));
ldif.changetype = LDB_CHANGETYPE_NONE;
ldif.msg = msg;
- ldb_ldif_write_file(module->ldb, stdout, &ldif);
+ ldb_ldif_write_file(ldb, stdout, &ldif);
sleep(100);
/* it ain't there. hmmm */
talloc_free(dn_key);
*/
int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg)
{
- struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
int ret;
const char *dn;
unsigned int i, j;
*/
int ltdb_index_one(struct ldb_module *module, const struct ldb_message *msg, int add)
{
- struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
struct ldb_message_element el;
struct ldb_val val;
struct ldb_dn *pdn;
*/
static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
+ struct ldb_context *ldb;
struct ldb_module *module = (struct ldb_module *)state;
struct ldb_message *msg;
const char *dn = NULL;
int ret;
TDB_DATA key2;
+ ldb = ldb_module_get_ctx(module);
+
if (strncmp((char *)key.dptr, "DN=@", 4) == 0 ||
strncmp((char *)key.dptr, "DN=", 3) != 0) {
return 0;
key2 = ltdb_key(module, msg->dn);
if (key2.dptr == NULL) {
/* probably a corrupt record ... darn */
- ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n",
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n",
ldb_dn_get_linearized(msg->dn));
talloc_free(msg);
return 0;
if (ret == LDB_SUCCESS) {
ret = ltdb_index_add0(module, dn, msg->elements, msg->num_elements);
} else {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR,
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
"Adding special ONE LEVEL index failed (%s)!\n",
ldb_dn_get_linearized(msg->dn));
}
*/
int ltdb_reindex(struct ldb_module *module)
{
- struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ void *data = ldb_module_get_private(module);
+ struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
int ret;
if (ltdb_cache_reload(module) != 0) {