summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-02-27 11:35:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:10:55 -0500
commitb1b14817eaa6e6579596d54166e17bc8d5605c01 (patch)
treeb1af59838a0337dd52b510374b048255397dfe24 /source4/lib/ldb
parentd2dc86994e7075490f95faa1cc85008feb38f04a (diff)
downloadsamba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.gz
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.bz2
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.zip
r5585: LDB interfaces change:
changes: - ldb_wrap disappears from code and become a private structure of db_wrap.c thanks to our move to talloc in ldb code, we do not need to expose it anymore - removal of ldb_close() function form the code thanks to our move to talloc in ldb code, we do not need it anymore use talloc_free() to close and free an ldb database - some minor updates to ldb modules code to cope with the change and fix some bugs I found out during the process (This used to be commit d58be9e74b786a11a57e89df36081d55730dfe0a)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb.c11
-rw-r--r--source4/lib/ldb/common/ldb_modules.c103
-rw-r--r--source4/lib/ldb/include/ldb.h6
-rw-r--r--source4/lib/ldb/include/ldb_private.h8
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c11
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c11
-rw-r--r--source4/lib/ldb/man/man3/ldb.yo2
-rw-r--r--source4/lib/ldb/modules/schema.c40
-rw-r--r--source4/lib/ldb/modules/skel.c16
-rw-r--r--source4/lib/ldb/modules/timestamps.c134
-rw-r--r--source4/lib/ldb/tools/ldbadd.c2
-rw-r--r--source4/lib/ldb/tools/ldbdel.c2
-rw-r--r--source4/lib/ldb/tools/ldbedit.c2
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c2
-rw-r--r--source4/lib/ldb/tools/ldbrename.c2
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c2
-rw-r--r--source4/lib/ldb/tools/ldbtest.c6
17 files changed, 187 insertions, 173 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 0fb371011f..40616c5963 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -69,7 +69,7 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
}
if (ldb_load_modules(ldb_ctx, options) != 0) {
- ldb_close(ldb_ctx);
+ talloc_free(ldb_ctx);
errno = EINVAL;
return NULL;
}
@@ -78,15 +78,6 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
}
/*
- close the connection to the database
-*/
-int ldb_close(struct ldb_context *ldb)
-{
- return ldb->modules->ops->close(ldb->modules);
-}
-
-
-/*
search the database given a LDAP-like search expression
return the number of records found, or -1 on error
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 22d1ce112e..f8162aee8c 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -41,6 +41,10 @@
#include <sys/stat.h>
#include <unistd.h>
+#ifdef HAVE_DLOPEN_DISABLED
+#include <dlfcn.h>
+#endif
+
#define LDB_MODULE_PREFIX "modules"
#define LDB_MODULE_PREFIX_LEN 7
#define LDB_MODULE_SEP ':'
@@ -49,14 +53,15 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *current;
char **modules;
- char *p, *q;
- int pn, i;
+ int mnum, i;
/* find out which modules we are requested to activate */
modules = NULL;
- pn = 0;
+ mnum = 0;
if (options) {
+ char *q, *p;
+
for (i = 0; options[i] != NULL; i++) {
if (strncmp(options[i], LDB_MODULE_PREFIX,
LDB_MODULE_PREFIX_LEN) == 0) {
@@ -68,13 +73,13 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
do {
*p = '\0';
q = p + 1;
- pn++;
- modules = talloc_realloc(ldb, modules, char *, pn);
+ mnum++;
+ modules = talloc_realloc(ldb, modules, char *, mnum);
if (!modules) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in register_modules()\n");
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_load_modules()\n");
return -1;
}
- modules[pn - 1] = q;
+ modules[mnum - 1] = q;
} while ((p = strchr(q, LDB_MODULE_SEP)));
}
}
@@ -83,9 +88,10 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
if (!modules && strcmp("ldap", ldb->modules->ops->name)) {
/* no modules in the options, look for @MODULES in the
db (not for ldap) */
- int ret, j, k;
- const char * const attrs[] = { "@MODULE" , NULL};
+ int ret;
+ const char * const attrs[] = { "@LIST" , NULL};
struct ldb_message **msg = NULL;
+ char *modstr, *c, *p;
ret = ldb_search(ldb, "", LDB_SCOPE_BASE, "dn=@MODULES", attrs, &msg);
if (ret == 0) {
@@ -100,6 +106,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
return -1;
}
+/*
for (j = 0; j < msg[0]->num_elements; j++) {
for (k = 0; k < msg[0]->elements[j].num_values; k++) {
pn++;
@@ -115,12 +122,58 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
}
}
+*/
+ modstr = msg[0]->elements[0].values[0].data;
+ for (c = modstr, mnum = 0; c != NULL; mnum++) {
+ c = strchr(c, ',');
+ if (c != NULL) {
+ c++;
+ if (*c == '\0') { /* avoid failing if the modules string lasts with ',' */
+ break;
+ }
+ }
+ }
+
+
+ modules = talloc_array(ldb, char *, mnum);
+ if ( ! modules ) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_load_modules()\n");
+ return -1;
+ }
+
+ for (p = c = modstr, i = 0; mnum > i; i++) {
+ c = strchr(p, ',');
+ if (c) {
+ *c = '\0';
+ }
+ /* modules are seeked in inverse order. Lets place them as an admin would think the right order is */
+ modules[mnum - i - 1] = talloc_strdup(modules, p);
+ p = c + 1;
+ }
}
talloc_free(msg);
}
if (modules) {
- for (i = 0; i < pn; i++) {
+ for (i = 0; i < mnum; i++) {
+#ifdef HAVE_DLOPEN_DISABLED
+ void *handle;
+ ldb_module_init_function init;
+ struct stat st;
+ char *filename;
+ const char *errstr;
+#endif
+
+ if (strcmp(modules[i], "schema") == 0) {
+ current = schema_module_init(ldb, options);
+ if (!current) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
+ return -1;
+ }
+ DLIST_ADD(ldb->modules, current);
+ continue;
+ }
+
if (strcmp(modules[i], "timestamps") == 0) {
current = timestamps_module_init(ldb, options);
if (!current) {
@@ -131,8 +184,8 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
continue;
}
- if (strcmp(modules[i], "schema") == 0) {
- current = schema_module_init(ldb, options);
+ if (strcmp(modules[i], "samldb") == 0) {
+ current = samldb_module_init(ldb, options);
if (!current) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
return -1;
@@ -142,18 +195,18 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
#ifdef HAVE_DLOPEN_DISABLED
- {
- void *handle;
- ldb_module_init_function init;
- struct stat st;
- const char *errstr;
+ filename = talloc_asprintf(ldb, "%s.so", modules[i]);
+ if (!filename) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Talloc failed!\n");
+ return -1;
+ }
- if (stat(modules[i], &st) < 0) {
+ if (stat(filename, &st) < 0) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
return -1;
}
- handle = dlopen(modules[i], RTLD_LAZY);
+ handle = dlopen(filename, RTLD_LAZY);
if (!handle) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Error loading module %s [%s]\n", modules[i], dlerror());
@@ -174,10 +227,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
return -1;
}
DLIST_ADD(ldb->modules, current);
- }
#else
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
- return -1;
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
+ return -1;
#endif
}
}
@@ -188,13 +240,6 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
/*
helper functions to call the next module in chain
*/
-int ldb_next_close(struct ldb_module *module)
-{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->close(module->next);
-}
int ldb_next_search(struct ldb_module *module,
const char *base,
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 09b4cbf84a..0eb661d7ce 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -159,12 +159,6 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
const char *options[]);
/*
- close the connection to the database
-*/
-int ldb_close(struct ldb_context *ldb);
-
-
-/*
search the database given a LDAP-like search expression
return the number of records found, or -1 on error
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 426da5ccae..a370a80299 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -55,7 +55,6 @@ struct ldb_module {
*/
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_module *, struct ldb_message **);
@@ -68,9 +67,6 @@ struct ldb_module_ops {
const char * (*errstring)(struct ldb_module *);
};
-/* the modules init function */
-typedef struct ldb_module *(*ldb_module_init_function)(void);
-
/*
every ldb connection is started by establishing a ldb_context
*/
@@ -82,10 +78,12 @@ struct ldb_context {
struct ldb_debug_ops debug_ops;
};
+/* the modules init function */
+typedef struct ldb_module *(*ldb_module_init_function)(struct ldb_context *ldb, const char *options[]);
+
/* The following definitions come from lib/ldb/common/ldb_modules.c */
int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
-int ldb_next_close(struct ldb_module *module);
int ldb_next_search(struct ldb_module *module,
const char *base,
enum ldb_scope scope,
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 46ea1a9e33..dc392dd56b 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -68,16 +68,6 @@ static const char *lldb_option_find(const struct lldb_private *lldb, const char
#endif
/*
- close/free the connection
-*/
-static int lldb_close(struct ldb_module *module)
-{
- struct ldb_context *ldb = module->ldb;
- talloc_free(ldb);
- return 0;
-}
-
-/*
rename a record
*/
static int lldb_rename(struct ldb_module *module, const char *olddn, const char *newdn)
@@ -468,7 +458,6 @@ static const char *lldb_errstring(struct ldb_module *module)
static const struct ldb_module_ops lldb_ops = {
"ldap",
- lldb_close,
lldb_search,
lldb_search_free,
lldb_add,
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 07a9fa8866..204eaf9d3c 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -780,16 +780,6 @@ failed:
return -1;
}
-/*
- close database
-*/
-static int ltdb_close(struct ldb_module *module)
-{
- struct ldb_context *ldb = module->ldb;
- talloc_free(ldb);
- return 0;
-}
-
/*
return extended error information
@@ -806,7 +796,6 @@ static const char *ltdb_errstring(struct ldb_module *module)
static const struct ldb_module_ops ltdb_ops = {
"tdb",
- ltdb_close,
ltdb_search,
ltdb_search_free,
ltdb_add,
diff --git a/source4/lib/ldb/man/man3/ldb.yo b/source4/lib/ldb/man/man3/ldb.yo
index ce8a590fbc..8d7a60ccf2 100644
--- a/source4/lib/ldb/man/man3/ldb.yo
+++ b/source4/lib/ldb/man/man3/ldb.yo
@@ -64,8 +64,6 @@ formatted input
dit(bf(ldb_connect(3))) connect to a ldb backend
-dit(bf(ldb_close(3))) close a connection to a ldb backend
-
dit(bf(ldb_search(3))) perform a database search
dit(bf(ldb_search_free(3))) free the results of a ldb_search
diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c
index 2921bdc68b..ef766b55ee 100644
--- a/source4/lib/ldb/modules/schema.c
+++ b/source4/lib/ldb/modules/schema.c
@@ -297,12 +297,6 @@ static int get_attr_list_recursive(struct ldb_module *module, struct schema_stru
return 0;
}
-/* close */
-static int schema_close(struct ldb_module *module)
-{
- return ldb_next_close(module);
-}
-
/* search */
static int schema_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
@@ -371,18 +365,6 @@ static int schema_add_record(struct ldb_module *module, const struct ldb_message
return -1;
}
- /* check we are not trying to delete a required attribute */
- /* TODO: consider multivalued attrs */
- if ((attr->flags & SCHEMA_FLAG_MOD_DELETE) != 0) {
- ldb_debug(module->ldb, LDB_DEBUG_ERROR,
- "Trying to delete the required attribute %s.\n",
- attr->name);
-
- data->error_string = "Objectclass violation, a required attribute cannot be removed";
- talloc_free(entry_structs);
- return -1;
- }
-
/* mark the attribute as checked */
attr->flags = SCHEMA_FLAG_CHECKED;
}
@@ -477,6 +459,18 @@ static int schema_modify_record(struct ldb_module *module, const struct ldb_mess
return -1;
}
+ /* check we are not trying to delete a required attribute */
+ /* TODO: consider multivalued attrs */
+ if ((attr->flags & SCHEMA_FLAG_MOD_DELETE) != 0) {
+ ldb_debug(module->ldb, LDB_DEBUG_ERROR,
+ "Trying to delete the required attribute %s.\n",
+ attr->name);
+
+ data->error_string = "Objectclass violation, a required attribute cannot be removed";
+ talloc_free(entry_structs);
+ return -1;
+ }
+
/* mark the attribute as checked */
attr->flags = SCHEMA_FLAG_CHECKED;
}
@@ -544,9 +538,15 @@ static const char *schema_errstring(struct ldb_module *module)
return ldb_next_errstring(module);
}
+static int schema_destructor(void *module_ctx)
+{
+ struct ldb_module *ctx = module_ctx;
+ /* put your clean-up functions here */
+ return 0;
+}
+
static const struct ldb_module_ops schema_ops = {
"schema",
- schema_close,
schema_search,
schema_search_free,
schema_add_record,
@@ -584,5 +584,7 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio
ctx->prev = ctx->next = NULL;
ctx->ops = &schema_ops;
+ talloc_set_destructor (ctx, schema_destructor);
+
return ctx;
}
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index afafe1bbd9..882a776819 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -36,12 +36,6 @@
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_private.h"
-/* close */
-static int skel_close(struct ldb_module *module)
-{
- return ldb_next_close(module);
-}
-
/* search */
static int skel_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
@@ -98,9 +92,15 @@ static const char *skel_errstring(struct ldb_module *module)
return ldb_next_errstring(module);
}
+static int skel_destructor(void *module_ctx)
+{
+ struct ldb_module *ctx = module_ctx;
+ /* put your clean-up functions here */
+ return 0;
+}
+
static const struct ldb_module_ops skel_ops = {
"skel",
- skel_close,
skel_search,
skel_search_free,
skel_add_record,
@@ -129,5 +129,7 @@ struct ldb_module *skel_plugin_init(struct ldb_context *ldb, const char *options
ctx->private_data = NULL;
ctx->ops = &skel_ops;
+ talloc_set_destructor (ctx, skel_destructor);
+
return ctx;
}
diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c
index 1deeeb218b..dec564bf66 100644
--- a/source4/lib/ldb/modules/timestamps.c
+++ b/source4/lib/ldb/modules/timestamps.c
@@ -41,12 +41,6 @@ struct private_data {
const char *error_string;
};
-static int timestamps_close(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_close\n");
- return ldb_next_close(module);
-}
-
static int timestamps_search(struct ldb_module *module, const char *base,
enum ldb_scope scope, const char *expression,
const char * const *attrs, struct ldb_message ***res)
@@ -106,41 +100,43 @@ static int timestamps_add_record(struct ldb_module *module, const struct ldb_mes
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_add_record\n");
- if (msg->dn[0] != '@') { /* do not manipulate our control entries */
- timeval = time(NULL);
- tm = gmtime(&timeval);
- if (!tm) {
- return -1;
- }
+ if (msg->dn[0] == '@') { /* do not manipulate our control entries */
+ return ldb_next_add_record(module, msg);
+ }
- msg2 = talloc(module, struct ldb_message);
- if (!msg2) {
- return -1;
- }
+ timeval = time(NULL);
+ tm = gmtime(&timeval);
+ if (!tm) {
+ return -1;
+ }
- /* formatted like: 20040408072012.0Z */
- timestr = talloc_asprintf(msg2, "%04u%02u%02u%02u%02u%02u.0Z",
- tm->tm_year+1900, tm->tm_mon+1,
- tm->tm_mday, tm->tm_hour, tm->tm_min,
- tm->tm_sec);
- if (!timestr) {
- return -1;
- }
+ msg2 = talloc(module, struct ldb_message);
+ if (!msg2) {
+ return -1;
+ }
- msg2->dn = msg->dn;
- msg2->num_elements = msg->num_elements;
- msg2->private_data = msg->private_data;
- msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements);
- for (i = 0; i < msg2->num_elements; i++) {
- msg2->elements[i] = msg->elements[i];
- }
+ /* formatted like: 20040408072012.0Z */
+ timestr = talloc_asprintf(msg2, "%04u%02u%02u%02u%02u%02u.0Z",
+ tm->tm_year+1900, tm->tm_mon+1,
+ tm->tm_mday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec);
+ if (!timestr) {
+ return -1;
+ }
- add_time_element(module, msg2, "createTimestamp", timestr, LDB_FLAG_MOD_ADD);
- add_time_element(module, msg2, "modifyTimestamp", timestr, LDB_FLAG_MOD_ADD);
- add_time_element(module, msg2, "whenCreated", timestr, LDB_FLAG_MOD_ADD);
- add_time_element(module, msg2, "whenChanged", timestr, LDB_FLAG_MOD_ADD);
+ msg2->dn = msg->dn;
+ msg2->num_elements = msg->num_elements;
+ msg2->private_data = msg->private_data;
+ msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements);
+ for (i = 0; i < msg2->num_elements; i++) {
+ msg2->elements[i] = msg->elements[i];
}
+ add_time_element(module, msg2, "createTimestamp", timestr, LDB_FLAG_MOD_ADD);
+ add_time_element(module, msg2, "modifyTimestamp", timestr, LDB_FLAG_MOD_ADD);
+ add_time_element(module, msg2, "whenCreated", timestr, LDB_FLAG_MOD_ADD);
+ add_time_element(module, msg2, "whenChanged", timestr, LDB_FLAG_MOD_ADD);
+
if (msg2) {
ret = ldb_next_add_record(module, msg2);
talloc_free(msg2);
@@ -162,40 +158,42 @@ static int timestamps_modify_record(struct ldb_module *module, const struct ldb_
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_modify_record\n");
- if (msg->dn[0] != '@') { /* do not manipulate our control entries */
- timeval = time(NULL);
- tm = gmtime(&timeval);
- if (!tm) {
- return -1;
- }
+ if (msg->dn[0] == '@') { /* do not manipulate our control entries */
+ return ldb_next_modify_record(module, msg);
+ }
- msg2 = talloc(module, struct ldb_message);
- if (!msg2) {
- return -1;
- }
+ timeval = time(NULL);
+ tm = gmtime(&timeval);
+ if (!tm) {
+ return -1;
+ }
- /* formatted like: 20040408072012.0Z */
- timestr = talloc_asprintf(msg2,
- "%04u%02u%02u%02u%02u%02u.0Z",
- tm->tm_year+1900, tm->tm_mon+1,
- tm->tm_mday, tm->tm_hour, tm->tm_min,
- tm->tm_sec);
- if (!timestr) {
- return -1;
- }
+ msg2 = talloc(module, struct ldb_message);
+ if (!msg2) {
+ return -1;
+ }
- msg2->dn = msg->dn;
- msg2->num_elements = msg->num_elements;
- msg2->private_data = msg->private_data;
- msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements);
- for (i = 0; i < msg2->num_elements; i++) {
- msg2->elements[i] = msg->elements[i];
- }
+ /* formatted like: 20040408072012.0Z */
+ timestr = talloc_asprintf(msg2,
+ "%04u%02u%02u%02u%02u%02u.0Z",
+ tm->tm_year+1900, tm->tm_mon+1,
+ tm->tm_mday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec);
+ if (!timestr) {
+ return -1;
+ }
- add_time_element(module, msg2, "modifyTimestamp", timestr, LDB_FLAG_MOD_REPLACE);
- add_time_element(module, msg2, "whenChanged", timestr, LDB_FLAG_MOD_REPLACE);
+ msg2->dn = msg->dn;
+ msg2->num_elements = msg->num_elements;
+ msg2->private_data = msg->private_data;
+ msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements);
+ for (i = 0; i < msg2->num_elements; i++) {
+ msg2->elements[i] = msg->elements[i];
}
+ add_time_element(module, msg2, "modifyTimestamp", timestr, LDB_FLAG_MOD_REPLACE);
+ add_time_element(module, msg2, "whenChanged", timestr, LDB_FLAG_MOD_REPLACE);
+
if (msg2) {
ret = ldb_next_modify_record(module, msg2);
talloc_free(msg2);
@@ -247,9 +245,15 @@ static const char *timestamps_errstring(struct ldb_module *module)
return ldb_next_errstring(module);
}
+static int timestamps_destructor(void *module_ctx)
+{
+ struct ldb_module *ctx = module_ctx;
+ /* put your clean-up functions here */
+ return 0;
+}
+
static const struct ldb_module_ops timestamps_ops = {
"timestamps",
- timestamps_close,
timestamps_search,
timestamps_search_free,
timestamps_add_record,
@@ -288,5 +292,7 @@ struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *o
ctx->prev = ctx->next = NULL;
ctx->ops = &timestamps_ops;
+ talloc_set_destructor (ctx, timestamps_destructor);
+
return ctx;
}
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index 927debc65e..41273a08da 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -153,7 +153,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
}
}
- ldb_close(ldb);
+ talloc_free(ldb);
printf("Added %d records with %d failures\n", count, failures);
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index 2241a0b823..72540db07a 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -146,7 +146,7 @@ static void usage(void)
}
}
- ldb_close(ldb);
+ talloc_free(ldb);
return 0;
}
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 20cb7da810..b9f82c282a 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -434,6 +434,6 @@ static void usage(void)
}
}
- ldb_close(ldb);
+ talloc_free(ldb);
return 0;
}
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index 97dec1050e..78baa0e36c 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -156,7 +156,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
}
}
- ldb_close(ldb);
+ talloc_free(ldb);
printf("Modified %d records with %d failures\n", count, failures);
diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c
index ba870b0a45..273c792584 100644
--- a/source4/lib/ldb/tools/ldbrename.c
+++ b/source4/lib/ldb/tools/ldbrename.c
@@ -112,7 +112,7 @@ static void usage(void)
argv[0], argv[1], ldb_errstring(ldb));
}
- ldb_close(ldb);
+ talloc_free(ldb);
return ret;
}
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index f764b28557..8d435e7661 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -176,6 +176,6 @@ static int do_search(struct ldb_context *ldb,
ret = do_search(ldb, basedn, scope, argv[0], attrs);
}
- ldb_close(ldb);
+ talloc_free(ldb);
return ret;
}
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index a166447aae..86f39d4606 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -323,8 +323,8 @@ static void start_test_index(struct ldb_context **ldb)
exit(1);
}
- if (ldb_close(*ldb) != 0) {
- printf("ldb_close failed - %s\n", ldb_errstring(*ldb));
+ if (talloc_free(*ldb) != 0) {
+ printf("failed to free/close ldb database");
exit(1);
}
@@ -427,7 +427,7 @@ static void usage(void)
start_test_index(&ldb);
- ldb_close(ldb);
+ talloc_free(ldb);
return 0;
}