summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-05 04:27:29 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:45 -0500
commit232bc1503fc0e3f85b4711f077d2566dc0f0c823 (patch)
tree14e4a2736ab44368bdb27296ddbe5fb3a05fd5fc /source4/lib/ldb/tools
parentaf66c31e44bcb052f35f9b1de8e997149fddac89 (diff)
downloadsamba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.tar.gz
samba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.tar.bz2
samba-232bc1503fc0e3f85b4711f077d2566dc0f0c823.zip
r490: - expanded the test suite to test modify and delete operations
- made yet another attempt to make ldb const clean. - "make test" now runs both the tdb and ldap backend tests, and run the ldbtest utility with and without indexing - added prototypes in ldb.h for ldb_msg_*() public functions (This used to be commit 01e87406768cb5a98ac8530a2f361a4987a36cd3)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c4
-rw-r--r--source4/lib/ldb/tools/ldbtest.c98
2 files changed, 92 insertions, 10 deletions
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index e8275e87c1..541024dd2d 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -49,7 +49,7 @@ static void do_search(struct ldb_context *ldb,
const char *basedn,
int scope,
const char *expression,
- const char * const *attrs)
+ char * const *attrs)
{
int ret, i;
struct ldb_message **msgs;
@@ -84,7 +84,7 @@ static void do_search(struct ldb_context *ldb,
int main(int argc, char * const argv[])
{
struct ldb_context *ldb;
- const char * const * attrs = NULL;
+ char * const * attrs = NULL;
const char *ldb_url;
const char *basedn = NULL;
int opt;
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index b7d1d22db8..bcb8bdcb16 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -36,12 +36,12 @@
static struct timeval tp1,tp2;
-static void start_timer()
+static void start_timer(void)
{
gettimeofday(&tp1,NULL);
}
-static double end_timer()
+static double end_timer(void)
{
gettimeofday(&tp2,NULL);
return((tp2.tv_sec - tp1.tv_sec) +
@@ -108,6 +108,8 @@ static void add_records(struct ldb_context *ldb,
vals[5][0].data = name;
vals[5][0].length = strlen(vals[5][0].data);
+ ldb_delete(ldb, msg.dn);
+
if (ldb_add(ldb, &msg) != 0) {
printf("Add of %s failed - %s\n", name, ldb_errstring(ldb));
exit(1);
@@ -126,6 +128,83 @@ static void add_records(struct ldb_context *ldb,
printf("\n");
}
+static void modify_records(struct ldb_context *ldb,
+ const char *basedn,
+ int count)
+{
+ struct ldb_message msg;
+ int i;
+
+ for (i=0;i<count;i++) {
+ struct ldb_message_element el[3];
+ struct ldb_val vals[3];
+ char *name;
+
+ asprintf(&name, "Test%d", i);
+ asprintf(&msg.dn, "cn=%s,%s", name, basedn);
+
+ msg.num_elements = 3;
+ msg.elements = el;
+
+ el[0].flags = LDB_FLAG_MOD_DELETE;
+ el[0].name = "mail";
+ el[0].num_values = 0;
+
+ el[1].flags = LDB_FLAG_MOD_ADD;
+ el[1].name = "mail";
+ el[1].num_values = 1;
+ el[1].values = &vals[1];
+ asprintf((char **)&vals[1].data, "%s@other.example.com", name);
+ vals[1].length = strlen(vals[1].data);
+
+ el[2].flags = LDB_FLAG_MOD_REPLACE;
+ el[2].name = "mail";
+ el[2].num_values = 1;
+ el[2].values = &vals[2];
+ asprintf((char **)&vals[2].data, "%s@other2.example.com", name);
+ vals[2].length = strlen(vals[2].data);
+
+ if (ldb_modify(ldb, &msg) != 0) {
+ printf("Modify of %s failed - %s\n", name, ldb_errstring(ldb));
+ exit(1);
+ }
+
+ printf("Modifying uid %s\r", name);
+ fflush(stdout);
+
+ free(name);
+ free(msg.dn);
+ free(vals[1].data);
+ free(vals[2].data);
+ }
+
+ printf("\n");
+}
+
+
+static void delete_records(struct ldb_context *ldb,
+ const char *basedn,
+ int count)
+{
+ int i;
+
+ for (i=0;i<count;i++) {
+ char *dn;
+ asprintf(&dn, "cn=Test%d,%s", i, basedn);
+
+ printf("Deleting uid Test%d\r", i);
+ fflush(stdout);
+
+ if (ldb_delete(ldb, dn) != 0) {
+ printf("Delete of %s failed - %s\n", dn, ldb_errstring(ldb));
+ exit(1);
+ }
+ free(dn);
+ }
+
+ printf("\n");
+}
+
static void search_uid(struct ldb_context *ldb, int nrecords, int nsearches)
{
int i;
@@ -164,18 +243,21 @@ static void search_uid(struct ldb_context *ldb, int nrecords, int nsearches)
static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
{
- printf("Adding %d records\n", nrecords);
+ const char *base = "ou=Ldb Test,ou=People,o=University of Michigan,c=US";
- add_records(ldb, "ou=Ldb Test,ou=People,o=University of Michigan,c=US",
- nrecords);
+ printf("Adding %d records\n", nrecords);
+ add_records(ldb, base, nrecords);
printf("Starting search on uid\n");
-
start_timer();
-
search_uid(ldb, nrecords, nsearches);
-
printf("uid search took %.2f seconds\n", end_timer());
+
+ printf("Modifying records\n");
+ modify_records(ldb, base, nrecords);
+
+ printf("Deleting records\n");
+ delete_records(ldb, base, nrecords);
}