summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-05-07 23:54:41 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:47 -0500
commit265023fafa463c742f89510879acb2a830de8ab9 (patch)
tree1614be24e20bd5c0bfc9f4a5d657a2b574df2c63 /source4/lib/ldb/tools
parentdee25d910e5ed3d07a240cebe8600f4a95c94159 (diff)
downloadsamba-265023fafa463c742f89510879acb2a830de8ab9.tar.gz
samba-265023fafa463c742f89510879acb2a830de8ab9.tar.bz2
samba-265023fafa463c742f89510879acb2a830de8ab9.zip
r574: - another attempt at const cleanliness in ldb
- fixed a problem with searching for values containing an '=' sign - fixed the semantics of attempting an attribute deletion on an attribute that doesn't exist. - added some more ldb_msg_*() utilities (This used to be commit 62b4ec367d170330d837b0f1fe5cd13205a53b59)
Diffstat (limited to 'source4/lib/ldb/tools')
-rw-r--r--source4/lib/ldb/tools/ldbedit.c2
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c4
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c6
-rw-r--r--source4/lib/ldb/tools/ldbtest.c31
4 files changed, 28 insertions, 15 deletions
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 739c3b6301..debe06c231 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -218,7 +218,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun
fclose(f);
- ldb_asprintf(ldb, &cmd, "%s %s", editor, template);
+ asprintf(&cmd, "%s %s", editor, template);
if (!cmd) {
unlink(template);
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index 9f7cbe4527..828b7d4865 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -144,6 +144,10 @@ static int process_file(struct ldb_context *ldb, FILE *f)
ldb_close(ldb);
printf("Modified %d records with %d failures\n", count, failures);
+
+ if (failures != 0) {
+ return -1;
+ }
return 0;
}
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index f80f81b50e..478601ec7e 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -49,7 +49,7 @@ static int do_search(struct ldb_context *ldb,
const char *basedn,
int scope,
const char *expression,
- char * const *attrs)
+ const char * const *attrs)
{
int ret, i;
struct ldb_message **msgs;
@@ -86,7 +86,7 @@ static int do_search(struct ldb_context *ldb,
int main(int argc, char * const argv[])
{
struct ldb_context *ldb;
- char * const * attrs = NULL;
+ const char * const * attrs = NULL;
const char *ldb_url;
const char *basedn = NULL;
int opt;
@@ -140,7 +140,7 @@ static int do_search(struct ldb_context *ldb,
}
if (argc > 1) {
- attrs = argv+1;
+ attrs = (const char * const *)(argv+1);
}
ldb = ldb_connect(ldb_url, 0, NULL);
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index fc224115f5..d7b4023895 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -59,7 +59,8 @@ static void add_records(struct ldb_context *ldb,
struct ldb_message_element el[6];
struct ldb_val vals[6][1];
char *name;
-
+ int j;
+
asprintf(&name, "Test%d", i);
asprintf(&msg.dn, "cn=%s,%s", name, basedn);
@@ -67,42 +68,42 @@ static void add_records(struct ldb_context *ldb,
msg.elements = el;
el[0].flags = 0;
- el[0].name = "cn";
+ el[0].name = strdup("cn");
el[0].num_values = 1;
el[0].values = vals[0];
vals[0][0].data = name;
vals[0][0].length = strlen(name);
el[1].flags = 0;
- el[1].name = "title";
+ el[1].name = strdup("title");
el[1].num_values = 1;
el[1].values = vals[1];
asprintf((char **)&vals[1][0].data, "The title of %s", name);
vals[1][0].length = strlen(vals[1][0].data);
el[2].flags = 0;
- el[2].name = "uid";
+ el[2].name = strdup("uid");
el[2].num_values = 1;
el[2].values = vals[2];
vals[2][0].data = ldb_casefold(ldb, name);
vals[2][0].length = strlen(vals[2][0].data);
el[3].flags = 0;
- el[3].name = "mail";
+ el[3].name = strdup("mail");
el[3].num_values = 1;
el[3].values = vals[3];
asprintf((char **)&vals[3][0].data, "%s@example.com", name);
vals[3][0].length = strlen(vals[3][0].data);
el[4].flags = 0;
- el[4].name = "objectClass";
+ el[4].name = strdup("objectClass");
el[4].num_values = 1;
el[4].values = vals[4];
- vals[4][0].data = "OpenLDAPperson";
+ vals[4][0].data = strdup("OpenLDAPperson");
vals[4][0].length = strlen(vals[4][0].data);
el[5].flags = 0;
- el[5].name = "sn";
+ el[5].name = strdup("sn");
el[5].num_values = 1;
el[5].values = vals[5];
vals[5][0].data = name;
@@ -118,11 +119,15 @@ static void add_records(struct ldb_context *ldb,
printf("adding uid %s\r", name);
fflush(stdout);
+ for (j=0;j<msg.num_elements;j++) {
+ free(el[j].name);
+ }
free(name);
free(msg.dn);
free(vals[1][0].data);
ldb_free(ldb, vals[2][0].data);
free(vals[3][0].data);
+ free(vals[4][0].data);
}
printf("\n");
@@ -139,6 +144,7 @@ static void modify_records(struct ldb_context *ldb,
struct ldb_message_element el[3];
struct ldb_val vals[3];
char *name;
+ int j;
asprintf(&name, "Test%d", i);
asprintf(&msg.dn, "cn=%s,%s", name, basedn);
@@ -147,18 +153,18 @@ static void modify_records(struct ldb_context *ldb,
msg.elements = el;
el[0].flags = LDB_FLAG_MOD_DELETE;
- el[0].name = "mail";
+ el[0].name = strdup("mail");
el[0].num_values = 0;
el[1].flags = LDB_FLAG_MOD_ADD;
- el[1].name = "mail";
+ el[1].name = strdup("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].name = strdup("mail");
el[2].num_values = 1;
el[2].values = &vals[2];
asprintf((char **)&vals[2].data, "%s@other2.example.com", name);
@@ -172,6 +178,9 @@ static void modify_records(struct ldb_context *ldb,
printf("Modifying uid %s\r", name);
fflush(stdout);
+ for (j=0;j<msg.num_elements;j++) {
+ free(el[j].name);
+ }
free(name);
free(msg.dn);
free(vals[1].data);