From ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 10 Apr 2004 20:18:22 +0000 Subject: r152: a quick airport commit .... added ldbedit, a _really_ useful command added ldbadd, ldbdel, ldbsearch and ldbmodify to build solved lots of timezone issues, we now pass the torture tests with client and server in different zones fixed several build issues I know this breaks the no-LDAP build. Wait till I arrive in San Jose for that fix. (This used to be commit af34710d4da1841653624fe304b1c8d812c0fdd9) --- source4/lib/ldb/tools/ldbedit.c | 365 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 source4/lib/ldb/tools/ldbedit.c (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c new file mode 100644 index 0000000000..c5eb1349dd --- /dev/null +++ b/source4/lib/ldb/tools/ldbedit.c @@ -0,0 +1,365 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2004 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Name: ldb + * + * Component: ldbedit + * + * Description: utility for ldb editing + * + * Author: Andrew Tridgell + */ + +#include "includes.h" + +/* + modify a database record so msg1 becomes msg2 +*/ +static int modify_record(struct ldb_context *ldb, + struct ldb_message *msg1, + struct ldb_message *msg2) +{ + struct ldb_message mod; + struct ldb_message_element *el; + int i; + + mod.dn = msg1->dn; + mod.num_elements = 0; + mod.elements = NULL; + + /* look in msg2 to find elements that need to be added + or modified */ + for (i=0;inum_elements;i++) { + el = ldb_msg_find_element(msg1, msg2->elements[i].name); + + if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) { + continue; + } + + if (ldb_msg_add(&mod, + &msg2->elements[i], + el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { + return -1; + } + } + + /* look in msg1 to find elements that need to be deleted */ + for (i=0;inum_elements;i++) { + el = ldb_msg_find_element(msg2, msg1->elements[i].name); + if (!el) { + if (ldb_msg_add_empty(&mod, + msg1->elements[i].name, + LDB_FLAG_MOD_DELETE) != 0) { + return -1; + } + } + } + + if (mod.num_elements == 0) { + return 0; + } + + if (ldb_modify(ldb, &mod) != 0) { + fprintf(stderr, "failed to modify %s\n", msg1->dn); + return -1; + } + + return 0; +} + +/* + find dn in msgs[] +*/ +static struct ldb_message *msg_find(struct ldb_message **msgs, int count, + const char *dn) +{ + int i; + for (i=0;idn) == 0) { + return msgs[i]; + } + } + return NULL; +} + +/* + merge the changes in msgs2 into the messages from msgs1 +*/ +static int merge_edits(struct ldb_context *ldb, + struct ldb_message **msgs1, int count1, + struct ldb_message **msgs2, int count2) +{ + int i; + struct ldb_message *msg; + int ret = 0; + + /* do the adds and modifies */ + for (i=0;idn); + if (!msg) { + if (ldb_add(ldb, msgs2[i]) != 0) { + fprintf(stderr, "failed to add %s\n", + msgs2[i]->dn); + return -1; + } + } else { + modify_record(ldb, msg, msgs2[i]); + } + } + + /* do the deletes */ + for (i=0;idn); + if (!msg) { + if (ldb_delete(ldb, msgs1[i]->dn) != 0) { + fprintf(stderr, "failed to delete %s\n", + msgs1[i]->dn); + return -1; + } + } + } + + return ret; +} + +/* + save a set of messages as ldif to a file +*/ +static int save_ldif(FILE *f, struct ldb_message **msgs, int count) +{ + int i; + + fprintf(f, "# returned %d records\n", count); + + for (i=0;imsg; + } + + fclose(f); + unlink(template); + + return merge_edits(ldb, msgs1, count1, msgs2, count2); +} + +static void usage(void) +{ + printf("Usage: ldbedit \n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf(" -s base|sub|one choose search scope\n"); + printf(" -b basedn choose baseDN\n"); + printf(" -a edit all records (expression 'dn=*')\n"); + printf(" -e editor choose editor (or $VISUAL or $EDITOR)\n"); + exit(1); +} + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; + struct ldb_message **msgs; + int ret; + const char *expression = NULL; + const char *ldb_url; + const char *basedn = NULL; + int opt; + enum ldb_scope scope = LDB_SCOPE_SUBTREE; + const char *editor; + + ldb_url = getenv("LDB_URL"); + + /* build the editor command to run - + use the same editor priorities as vipw */ + editor = getenv("VISUAL"); + if (!editor) { + editor = getenv("EDITOR"); + } + if (!editor) { + editor = "vi"; + } + + while ((opt = getopt(argc, argv, "ab:e:H:s:")) != EOF) { + switch (opt) { + case 'b': + basedn = optarg; + break; + + case 'H': + ldb_url = optarg; + break; + + case 's': + if (strcmp(optarg, "base") == 0) { + scope = LDB_SCOPE_BASE; + } else if (strcmp(optarg, "sub") == 0) { + scope = LDB_SCOPE_SUBTREE; + } else if (strcmp(optarg, "one") == 0) { + scope = LDB_SCOPE_ONELEVEL; + } + break; + + case 'e': + editor = optarg; + break; + + case 'a': + expression = "dn=*"; + break; + + case 'h': + default: + usage(); + break; + } + } + + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + if (!expression) { + if (argc == 0) { + usage(); + } + expression = argv[0]; + } + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + ret = ldb_search(ldb, basedn, scope, expression, NULL, &msgs); + + if (ret == -1) { + printf("search failed - %s\n", ldb_errstring(ldb)); + exit(1); + } + + if (ret == 0) { + printf("no matching records - cannot edit\n"); + return 0; + } + + do_edit(ldb, msgs, ret, editor); + + if (ret > 0) { + ret = ldb_search_free(ldb, msgs); + if (ret == -1) { + fprintf(stderr, "search_free failed\n"); + exit(1); + } + } + + ldb_close(ldb); + return 0; +} -- cgit From a7efe6c1c322467b8468399bec7ee294aeaeada8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Apr 2004 01:27:33 +0000 Subject: r159: nicer usage messages when no URL is given (This used to be commit 8655f0b435e06af21d5d9fa210441fbf318673f0) --- source4/lib/ldb/tools/ldbedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index c5eb1349dd..13516e59cf 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -281,7 +281,7 @@ static void usage(void) editor = "vi"; } - while ((opt = getopt(argc, argv, "ab:e:H:s:")) != EOF) { + while ((opt = getopt(argc, argv, "hab:e:H:s:")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -317,8 +317,8 @@ static void usage(void) } if (!ldb_url) { - fprintf(stderr, "You must specify a ldb URL\n"); - exit(1); + fprintf(stderr, "You must specify a ldb URL\n\n"); + usage(); } argc -= optind; -- cgit From 3185ace216586b6f1d676210630206bf00d5474e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Apr 2004 15:03:31 +0000 Subject: r163: - enable ldap in the sample makefile, and use /usr prefix - show number of adds/deletes/modifies after an edit - nicer error messages from ldbedit (This used to be commit 077951f6bcb1d0eba2de76d0df4c186b7fa19a14) --- source4/lib/ldb/tools/ldbedit.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 13516e59cf..5ae62d3ac1 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -27,7 +27,7 @@ * * Component: ldbedit * - * Description: utility for ldb editing + * Description: utility for ldb database editing * * Author: Andrew Tridgell */ @@ -36,6 +36,7 @@ /* modify a database record so msg1 becomes msg2 + returns the number of modified elements */ static int modify_record(struct ldb_context *ldb, struct ldb_message *msg1, @@ -44,6 +45,7 @@ static int modify_record(struct ldb_context *ldb, struct ldb_message mod; struct ldb_message_element *el; int i; + int count = 0; mod.dn = msg1->dn; mod.num_elements = 0; @@ -63,6 +65,7 @@ static int modify_record(struct ldb_context *ldb, el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { return -1; } + count++; } /* look in msg1 to find elements that need to be deleted */ @@ -74,6 +77,7 @@ static int modify_record(struct ldb_context *ldb, LDB_FLAG_MOD_DELETE) != 0) { return -1; } + count++; } } @@ -82,11 +86,12 @@ static int modify_record(struct ldb_context *ldb, } if (ldb_modify(ldb, &mod) != 0) { - fprintf(stderr, "failed to modify %s\n", msg1->dn); + fprintf(stderr, "failed to modify %s - %s\n", + msg1->dn, ldb_errstring(ldb)); return -1; } - return 0; + return count; } /* @@ -114,18 +119,22 @@ static int merge_edits(struct ldb_context *ldb, int i; struct ldb_message *msg; int ret = 0; + int adds=0, modifies=0, deletes=0; /* do the adds and modifies */ for (i=0;idn); if (!msg) { if (ldb_add(ldb, msgs2[i]) != 0) { - fprintf(stderr, "failed to add %s\n", - msgs2[i]->dn); + fprintf(stderr, "failed to add %s - %s\n", + msgs2[i]->dn, ldb_errstring(ldb)); return -1; } + adds++; } else { - modify_record(ldb, msg, msgs2[i]); + if (modify_record(ldb, msg, msgs2[i]) > 0) { + modifies++; + } } } @@ -134,13 +143,16 @@ static int merge_edits(struct ldb_context *ldb, msg = msg_find(msgs2, count2, msgs1[i]->dn); if (!msg) { if (ldb_delete(ldb, msgs1[i]->dn) != 0) { - fprintf(stderr, "failed to delete %s\n", - msgs1[i]->dn); + fprintf(stderr, "failed to delete %s - %s\n", + msgs1[i]->dn, ldb_errstring(ldb)); return -1; } + deletes++; } } + printf("# %d adds %d modifies %d deletes\n", adds, modifies, deletes); + return ret; } @@ -151,7 +163,7 @@ static int save_ldif(FILE *f, struct ldb_message **msgs, int count) { int i; - fprintf(f, "# returned %d records\n", count); + fprintf(f, "# editing %d records\n", count); for (i=0;i 0) { ret = ldb_search_free(ldb, msgs); if (ret == -1) { - fprintf(stderr, "search_free failed\n"); + fprintf(stderr, "search_free failed - %s\n", ldb_errstring(ldb)); exit(1); } } -- cgit From ee0489fff69533d04318de249aabd8d1d021d285 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 Apr 2004 06:43:35 +0000 Subject: r380: make sure that ldbedit -a works with all tdb and LDAP backends (This used to be commit b5cb5a1e62a4b9df6f163082498942553662436e) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 5ae62d3ac1..07ed66d68a 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -318,7 +318,7 @@ static void usage(void) break; case 'a': - expression = "objectclass=*"; + expression = "(|(objectclass=*)(dn=*))"; break; case 'h': -- cgit From 0dad5a34273bf5cadcfd4a36d69bdffbf69eb073 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 May 2004 09:45:56 +0000 Subject: r435: a major upgrade for ldb - added the ability to mark record attributes as being CASE_INSENSITIVE, WILDCARD or INTEGER. - added the ability to support objectclass subclasses, and to search by a parent class - added internal support for case insensitive versus case sensitive indexing (not UTF8 compliant yet) - cleaned up a number of const warnings - added a number of helper functions for fetching integers, strings and doubles - added a in-memory cache for important database properties, supported by a database sequence number - changed some variable names to avoid conflicts with C++ (This used to be commit f2bf06f25c2e6c744817711c7bedbd1d3b52f994) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 07ed66d68a..eb95ed3267 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -102,7 +102,7 @@ static struct ldb_message *msg_find(struct ldb_message **msgs, int count, { int i; for (i=0;idn) == 0) { + if (ldb_dn_cmp(dn, msgs[i]->dn) == 0) { return msgs[i]; } } -- cgit From d8ce7c6a2acbf371509a23775470e7614bcb6027 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 May 2004 04:40:15 +0000 Subject: r502: modified ldb to allow the use of an external pool memory allocator. The way to use this is to call ldb_set_alloc() with a function pointer to whatever memory allocator you like. It includes a context pointer to allow for pool based allocators. (This used to be commit 3955c482e6c2c9e975a4bb809ec8cb6068e48e34) --- source4/lib/ldb/tools/ldbedit.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index eb95ed3267..57c54cad40 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -60,7 +60,7 @@ static int modify_record(struct ldb_context *ldb, continue; } - if (ldb_msg_add(&mod, + if (ldb_msg_add(ldb, &mod, &msg2->elements[i], el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { return -1; @@ -72,7 +72,7 @@ static int modify_record(struct ldb_context *ldb, for (i=0;inum_elements;i++) { el = ldb_msg_find_element(msg2, msg1->elements[i].name); if (!el) { - if (ldb_msg_add_empty(&mod, + if (ldb_msg_add_empty(ldb, &mod, msg1->elements[i].name, LDB_FLAG_MOD_DELETE) != 0) { return -1; @@ -159,7 +159,8 @@ static int merge_edits(struct ldb_context *ldb, /* save a set of messages as ldif to a file */ -static int save_ldif(FILE *f, struct ldb_message **msgs, int count) +static int save_ldif(struct ldb_context *ldb, + FILE *f, struct ldb_message **msgs, int count) { int i; @@ -172,7 +173,7 @@ static int save_ldif(FILE *f, struct ldb_message **msgs, int count) ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = *msgs[i]; - ldif_write_file(f, &ldif); + ldif_write_file(ldb, f, &ldif); } return 0; @@ -211,13 +212,13 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun return -1; } - if (save_ldif(f, msgs1, count1) != 0) { + if (save_ldif(ldb, f, msgs1, count1) != 0) { return -1; } fclose(f); - asprintf(&cmd, "%s %s", editor, template); + ldb_asprintf(ldb, &cmd, "%s %s", editor, template); if (!cmd) { unlink(template); @@ -242,8 +243,8 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun return -1; } - while ((ldif = ldif_read_file(f))) { - msgs2 = realloc_p(msgs2, struct ldb_message *, count2+1); + while ((ldif = ldif_read_file(ldb, f))) { + msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); if (!msgs2) { fprintf(stderr, "out of memory"); return -1; -- cgit From 68293565de0b799dcc51e001dabf53adf88ee7ad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 May 2004 09:55:05 +0000 Subject: r513: added a generic ldb debug system to allow the Samba debug functions to be cleanly interfaced to ldb (This used to be commit 74b89d5f960d6b936751e3f057b4540eb80b79cd) --- source4/lib/ldb/tools/ldbedit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 57c54cad40..739c3b6301 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -351,6 +351,8 @@ static void usage(void) exit(1); } + ldb_set_debug_stderr(ldb); + ret = ldb_search(ldb, basedn, scope, expression, NULL, &msgs); if (ret == -1) { -- cgit From 265023fafa463c742f89510879acb2a830de8ab9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 May 2004 23:54:41 +0000 Subject: 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) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') 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); -- cgit From 55fa62be31c9027d84be0e4caad3ee59d78ca1b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 May 2004 12:37:35 +0000 Subject: r609: allow ldbedit to take a list of attributes to edit, just like ldbsearch. This allows you to edit the description of all users using something like: ldbedit 'objectclass=user' description and not get overwhelmed with fields. It also allows you to edit HIDDEN attributes by specifying them explicitly (This used to be commit dd83d39de23cdf8c574005829972dae8dc6bee6a) --- source4/lib/ldb/tools/ldbedit.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index debe06c231..7e41702422 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -260,7 +260,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun static void usage(void) { - printf("Usage: ldbedit \n"); + printf("Usage: ldbedit \n"); printf("Options:\n"); printf(" -H ldb_url choose the database (or $LDB_URL)\n"); printf(" -s base|sub|one choose search scope\n"); @@ -281,6 +281,7 @@ static void usage(void) int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; const char *editor; + const char * const * attrs = NULL; ldb_url = getenv("LDB_URL"); @@ -342,6 +343,12 @@ static void usage(void) usage(); } expression = argv[0]; + argc--; + argv++; + } + + if (argc > 0) { + attrs = (const char * const *)argv; } ldb = ldb_connect(ldb_url, 0, NULL); @@ -353,7 +360,7 @@ static void usage(void) ldb_set_debug_stderr(ldb); - ret = ldb_search(ldb, basedn, scope, expression, NULL, &msgs); + ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); if (ret == -1) { printf("search failed - %s\n", ldb_errstring(ldb)); -- cgit From f0a8f718ff474009300af6746fa0fbb61c649ea9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 May 2004 13:25:06 +0000 Subject: r792: - changed the ldb ldif_* functions to be in the ldb_ namespace - added better error reporting in ldbdel - fixed a bug in handling packing of records which contain elements with no values (it caused db corruption) - allow search with "dn" as target attribute (This used to be commit 36575396234e3d35dbd442c8f1ff54a17ae64e64) --- source4/lib/ldb/tools/ldbedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 7e41702422..f8e0fbb68a 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -173,7 +173,7 @@ static int save_ldif(struct ldb_context *ldb, ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = *msgs[i]; - ldif_write_file(ldb, f, &ldif); + ldb_ldif_write_file(ldb, f, &ldif); } return 0; @@ -243,7 +243,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun return -1; } - while ((ldif = ldif_read_file(ldb, f))) { + while ((ldif = ldb_ldif_read_file(ldb, f))) { msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); if (!msgs2) { fprintf(stderr, "out of memory"); -- cgit From 34ca729f733d9d22fc789a5fce6c448b03c96545 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 7 Jul 2004 01:02:54 +0000 Subject: r1374: Fix signed/unsigned warnings (actually found by g++) after unsigned int changes in r1018. (This used to be commit 45b4016530fc0bfa13146f73a503866b5dbed517) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index f8e0fbb68a..90a6f94750 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -44,7 +44,7 @@ static int modify_record(struct ldb_context *ldb, { struct ldb_message mod; struct ldb_message_element *el; - int i; + unsigned int i; int count = 0; mod.dn = msg1->dn; -- cgit From be480ac55c1f3ebe29781ad718f28e5b95441d13 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Sep 2004 10:42:33 +0000 Subject: r2381: added a -v debugging option to ldbedit (This used to be commit 03d4a7832cd3670a8166820a1b9b4aaf2307bd1a) --- source4/lib/ldb/tools/ldbedit.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 90a6f94750..b97c40ff1a 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -34,6 +34,22 @@ #include "includes.h" +static int verbose; + +/* + debug routine +*/ +static void ldif_write_msg(struct ldb_context *ldb, + FILE *f, + enum ldb_changetype changetype, + struct ldb_message *msg) +{ + struct ldb_ldif ldif; + ldif.changetype = changetype; + ldif.msg = *msg; + ldb_ldif_write_file(ldb, f, &ldif); +} + /* modify a database record so msg1 becomes msg2 returns the number of modified elements @@ -91,6 +107,10 @@ static int modify_record(struct ldb_context *ldb, return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, &mod); + } + return count; } @@ -130,6 +150,9 @@ static int merge_edits(struct ldb_context *ldb, msgs2[i]->dn, ldb_errstring(ldb)); return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); + } adds++; } else { if (modify_record(ldb, msg, msgs2[i]) > 0) { @@ -147,6 +170,9 @@ static int merge_edits(struct ldb_context *ldb, msgs1[i]->dn, ldb_errstring(ldb)); return -1; } + if (verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); + } deletes++; } } @@ -295,7 +321,7 @@ static void usage(void) editor = "vi"; } - while ((opt = getopt(argc, argv, "hab:e:H:s:")) != EOF) { + while ((opt = getopt(argc, argv, "hab:e:H:s:v")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -323,6 +349,10 @@ static void usage(void) expression = "(|(objectclass=*)(dn=*))"; break; + case 'v': + verbose++; + break; + case 'h': default: usage(); -- cgit From 679e95db033fd11d17c1f1ac5e44f6cc4df2220e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 15 Nov 2004 11:40:27 +0000 Subject: r3754: merge in ldb modules support from the tmp branch ldbPlugins (This used to be commit 71323f424b4561af1fdddd2358629049be3dad8c) --- source4/lib/ldb/tools/ldbedit.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index b97c40ff1a..fc3b28872e 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -304,6 +304,8 @@ static void usage(void) const char *expression = NULL; const char *ldb_url; const char *basedn = NULL; + const char **options = NULL; + int ldbopts; int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; const char *editor; @@ -321,7 +323,8 @@ static void usage(void) editor = "vi"; } - while ((opt = getopt(argc, argv, "hab:e:H:s:v")) != EOF) { + ldbopts = 0; + while ((opt = getopt(argc, argv, "hab:e:H:s:vo:")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -353,6 +356,21 @@ static void usage(void) verbose++; break; + case 'o': + ldbopts++; + if (options == NULL) { + options = (const char **)malloc(sizeof(char *) * (ldbopts + 1)); + } else { + options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1)); + if (options == NULL) { + fprintf(stderr, "Out of memory!\n"); + exit(-1); + } + } + options[ldbopts - 1] = optarg; + options[ldbopts] = NULL; + break; + case 'h': default: usage(); @@ -381,7 +399,7 @@ static void usage(void) attrs = (const char * const *)argv; } - ldb = ldb_connect(ldb_url, 0, NULL); + ldb = ldb_connect(ldb_url, 0, options); if (!ldb) { perror("ldb_connect"); -- cgit From 8a18778286a16423d7d6e483fdb308a91e294efe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 16 Nov 2004 09:00:52 +0000 Subject: r3783: - don't use make proto for ldb anymore - split ldh.h out of samba's includes.h - make ldb_context and ldb_module private to the subsystem - use ltdb_ prefix for all ldb_tdb functions metze (This used to be commit f5ee40d6ce8224e280070975efc9911558fe675c) --- source4/lib/ldb/tools/ldbedit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index fc3b28872e..fd45248c0e 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -33,6 +33,7 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" static int verbose; -- cgit From 9012a501533126c4c0ac25a16fd6439a45df3d9a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 4 Dec 2004 10:14:03 +0000 Subject: r4059: moved the ldb -o option parsing to a common routine (This used to be commit ee52c1e38c9bac852458196ffbd677cca62a3965) --- source4/lib/ldb/tools/ldbedit.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index fd45248c0e..f84d05440f 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" static int verbose; @@ -358,18 +359,7 @@ static void usage(void) break; case 'o': - ldbopts++; - if (options == NULL) { - options = (const char **)malloc(sizeof(char *) * (ldbopts + 1)); - } else { - options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1)); - if (options == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(-1); - } - } - options[ldbopts - 1] = optarg; - options[ldbopts] = NULL; + options = ldb_options_parse(options, &ldbopts, optarg); break; case 'h': -- cgit From 09c1b9cbe5175636bcf4b606edfd0022bd9cfd6b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 Dec 2004 03:51:42 +0000 Subject: r4427: - added ldb_msg_*() functions for sorting, comparing and copying messages - added a ldb_msg_canonicalize() function that fixes a record to not have any duplicate elements - changed ldbedit to use ldb_msg_canonicalize(). This fixes a bug when you rename multiple elements in a record in one edit (This used to be commit f006e724400843419c8b6155cbeae1876983855e) --- source4/lib/ldb/tools/ldbedit.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index f84d05440f..6cd6ef041b 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -69,6 +69,12 @@ static int modify_record(struct ldb_context *ldb, mod.num_elements = 0; mod.elements = NULL; + msg2 = ldb_msg_canonicalize(ldb, msg2); + if (msg2 == NULL) { + fprintf(stderr, "Failed to canonicalise msg2\n"); + return -1; + } + /* look in msg2 to find elements that need to be added or modified */ for (i=0;inum_elements;i++) { @@ -295,6 +301,7 @@ static void usage(void) printf(" -b basedn choose baseDN\n"); printf(" -a edit all records (expression 'objectclass=*')\n"); printf(" -e editor choose editor (or $VISUAL or $EDITOR)\n"); + printf(" -v verbose mode)\n"); exit(1); } -- cgit From 1a988ec9af7960616fb4661b20d86ff05146d836 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 07:49:29 +0000 Subject: r4474: - converted ldb to use talloc internally - added gcov flags to Makefile.ldb - expanded ldb test suite to get more coverage (This used to be commit 0ab98f50a7e0fe15347a99e5c29a6590a87729a0) --- source4/lib/ldb/tools/ldbedit.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 6cd6ef041b..66b684f4d5 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -48,7 +48,7 @@ static void ldif_write_msg(struct ldb_context *ldb, { struct ldb_ldif ldif; ldif.changetype = changetype; - ldif.msg = *msg; + ldif.msg = msg; ldb_ldif_write_file(ldb, f, &ldif); } @@ -60,14 +60,16 @@ static int modify_record(struct ldb_context *ldb, struct ldb_message *msg1, struct ldb_message *msg2) { - struct ldb_message mod; + struct ldb_message *mod; struct ldb_message_element *el; unsigned int i; int count = 0; - mod.dn = msg1->dn; - mod.num_elements = 0; - mod.elements = NULL; + mod = ldb_msg_new(ldb); + + mod->dn = msg1->dn; + mod->num_elements = 0; + mod->elements = NULL; msg2 = ldb_msg_canonicalize(ldb, msg2); if (msg2 == NULL) { @@ -84,7 +86,7 @@ static int modify_record(struct ldb_context *ldb, continue; } - if (ldb_msg_add(ldb, &mod, + if (ldb_msg_add(ldb, mod, &msg2->elements[i], el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { return -1; @@ -96,7 +98,7 @@ static int modify_record(struct ldb_context *ldb, for (i=0;inum_elements;i++) { el = ldb_msg_find_element(msg2, msg1->elements[i].name); if (!el) { - if (ldb_msg_add_empty(ldb, &mod, + if (ldb_msg_add_empty(ldb, mod, msg1->elements[i].name, LDB_FLAG_MOD_DELETE) != 0) { return -1; @@ -105,18 +107,18 @@ static int modify_record(struct ldb_context *ldb, } } - if (mod.num_elements == 0) { + if (mod->num_elements == 0) { return 0; } - if (ldb_modify(ldb, &mod) != 0) { + if (ldb_modify(ldb, mod) != 0) { fprintf(stderr, "failed to modify %s - %s\n", msg1->dn, ldb_errstring(ldb)); return -1; } if (verbose > 0) { - ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, &mod); + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod); } return count; @@ -205,7 +207,7 @@ static int save_ldif(struct ldb_context *ldb, fprintf(f, "# record %d\n", i+1); ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = *msgs[i]; + ldif.msg = msgs[i]; ldb_ldif_write_file(ldb, f, &ldif); } @@ -278,12 +280,12 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun } while ((ldif = ldb_ldif_read_file(ldb, f))) { - msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); + msgs2 = talloc_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); if (!msgs2) { fprintf(stderr, "out of memory"); return -1; } - msgs2[count2++] = &ldif->msg; + msgs2[count2++] = ldif->msg; } fclose(f); -- cgit From a2f77f979d7271a9708ed06f43b00ffb10ec7f4c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 12 Jan 2005 16:00:01 +0000 Subject: r4714: move the ldb code to the new talloc interface (eg remove _p suffix) this helps standalone building of ldb renew the schema module split code into functions to improve readability and code reuse add and modify works correctly but we need a proper testsuite Simo (This used to be commit a681ae365ff1b5a2771b42ebd90336651ce1e513) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 66b684f4d5..4c38ea6803 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -280,7 +280,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun } while ((ldif = ldb_ldif_read_file(ldb, f))) { - msgs2 = talloc_realloc_p(ldb, msgs2, struct ldb_message *, count2+1); + msgs2 = talloc_realloc(ldb, msgs2, struct ldb_message *, count2+1); if (!msgs2) { fprintf(stderr, "out of memory"); return -1; -- cgit From e82aad1ce39a6b7a2e51b9e2cb494d74ec70e158 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:09:35 +0000 Subject: r5298: - got rid of pstring.h from includes.h. This at least makes it a bit less likely that anyone will use pstring for new code - got rid of winbind_client.h from includes.h. This one triggered a huge change, as winbind_client.h was including system/filesys.h and defining the old uint32 and uint16 types, as well as its own pstring and fstring. (This used to be commit 9db6c79e902ec538108d6b7d3324039aabe1704f) --- source4/lib/ldb/tools/ldbedit.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 4c38ea6803..20cb7da810 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -36,6 +36,10 @@ #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" +#ifdef _SAMBA_BUILD_ +#include "system/filesys.h" +#endif + static int verbose; /* -- cgit From b1b14817eaa6e6579596d54166e17bc8d5605c01 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 27 Feb 2005 11:35:47 +0000 Subject: 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) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') 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; } -- cgit From fe4d985b6f3d318d9b58a16677be3b4ae34fba15 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 25 Apr 2005 12:46:18 +0000 Subject: r6470: Remove ldb_search_free() it is not needed anymore. Just use talloc_free() to release the memory after an ldb_search(). (This used to be commit 4f0948dab0aa5e8b6a4ce486f3668ca8dfae23db) --- source4/lib/ldb/tools/ldbedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index b9f82c282a..4c41b6b19a 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -427,9 +427,9 @@ static void usage(void) do_edit(ldb, msgs, ret, editor); if (ret > 0) { - ret = ldb_search_free(ldb, msgs); + ret = talloc_free(msgs); if (ret == -1) { - fprintf(stderr, "search_free failed - %s\n", ldb_errstring(ldb)); + fprintf(stderr, "talloc_free failed\n"); exit(1); } } -- cgit From 9a9cf9e0753c7cf040feecf670c0986a17c16dce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 May 2005 22:31:45 +0000 Subject: r6833: split out the routine that calculates the diff between two ldb messages from ldbedit, so other progs can use it. (This used to be commit fa4f33558af3c65ff31424c01db16cb9d427503d) --- source4/lib/ldb/tools/ldbedit.c | 47 ++++------------------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 4c41b6b19a..851eaeebdf 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -65,51 +65,12 @@ static int modify_record(struct ldb_context *ldb, struct ldb_message *msg2) { struct ldb_message *mod; - struct ldb_message_element *el; - unsigned int i; - int count = 0; - mod = ldb_msg_new(ldb); - - mod->dn = msg1->dn; - mod->num_elements = 0; - mod->elements = NULL; - - msg2 = ldb_msg_canonicalize(ldb, msg2); - if (msg2 == NULL) { - fprintf(stderr, "Failed to canonicalise msg2\n"); + mod = ldb_msg_diff(ldb, msg1, msg2); + if (mod == NULL) { + fprintf(stderr, "Failed to calculate message differences\n"); return -1; } - - /* look in msg2 to find elements that need to be added - or modified */ - for (i=0;inum_elements;i++) { - el = ldb_msg_find_element(msg1, msg2->elements[i].name); - - if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) { - continue; - } - - if (ldb_msg_add(ldb, mod, - &msg2->elements[i], - el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { - return -1; - } - count++; - } - - /* look in msg1 to find elements that need to be deleted */ - for (i=0;inum_elements;i++) { - el = ldb_msg_find_element(msg2, msg1->elements[i].name); - if (!el) { - if (ldb_msg_add_empty(ldb, mod, - msg1->elements[i].name, - LDB_FLAG_MOD_DELETE) != 0) { - return -1; - } - count++; - } - } if (mod->num_elements == 0) { return 0; @@ -125,7 +86,7 @@ static int modify_record(struct ldb_context *ldb, ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod); } - return count; + return mod->num_elements; } /* -- cgit From ed3d8091ce2b2014350a2f7f22202dde6846a130 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 07:42:21 +0000 Subject: r7709: - convert ldb to use popt, so that it can interact with the samba cmdline credentials code (which will be done soon) - added a ldb_init() call, and changed ldb_connect() to take a ldb context. This allows for much better error handling in ldb_connect(), and also made the popt conversion easier - fixed up all the existing backends with the new syntax - improved error handling in *_connect() - fixed a crash bug in the new case_fold_required() code - ensured that ltdb_rename() and all ltdb_search() paths get the read lock - added a ldb_oom() macro to make it easier to report out of memory situations in ldb code (This used to be commit f648fdf187669d6d87d01dd4e786b03cd420f220) --- source4/lib/ldb/tools/ldbedit.c | 103 ++++++++-------------------------------- 1 file changed, 20 insertions(+), 83 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 851eaeebdf..6c599ee2ec 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -35,6 +35,7 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" +#include "ldb/tools/cmdline.h" #ifdef _SAMBA_BUILD_ #include "system/filesys.h" @@ -272,109 +273,45 @@ static void usage(void) exit(1); } - int main(int argc, char * const argv[]) + int main(int argc, const char **argv) { struct ldb_context *ldb; struct ldb_message **msgs; int ret; const char *expression = NULL; - const char *ldb_url; - const char *basedn = NULL; - const char **options = NULL; - int ldbopts; - int opt; - enum ldb_scope scope = LDB_SCOPE_SUBTREE; - const char *editor; const char * const * attrs = NULL; + struct ldb_cmdline *options; - ldb_url = getenv("LDB_URL"); + ldb = ldb_init(NULL); - /* build the editor command to run - - use the same editor priorities as vipw */ - editor = getenv("VISUAL"); - if (!editor) { - editor = getenv("EDITOR"); - } - if (!editor) { - editor = "vi"; - } - - ldbopts = 0; - while ((opt = getopt(argc, argv, "hab:e:H:s:vo:")) != EOF) { - switch (opt) { - case 'b': - basedn = optarg; - break; - - case 'H': - ldb_url = optarg; - break; - - case 's': - if (strcmp(optarg, "base") == 0) { - scope = LDB_SCOPE_BASE; - } else if (strcmp(optarg, "sub") == 0) { - scope = LDB_SCOPE_SUBTREE; - } else if (strcmp(optarg, "one") == 0) { - scope = LDB_SCOPE_ONELEVEL; - } - break; - - case 'e': - editor = optarg; - break; - - case 'a': - expression = "(|(objectclass=*)(dn=*))"; - break; - - case 'v': - verbose++; - break; - - case 'o': - options = ldb_options_parse(options, &ldbopts, optarg); - break; - - case 'h': - default: - usage(); - break; - } - } + options = ldb_cmdline_process(ldb, argc, argv, usage); - if (!ldb_url) { - fprintf(stderr, "You must specify a ldb URL\n\n"); - usage(); + if (options->all_records) { + expression = "(|(objectclass=*)(dn=*))"; } - argc -= optind; - argv += optind; - if (!expression) { - if (argc == 0) { + if (options->argc == 0) { usage(); } - expression = argv[0]; - argc--; - argv++; + expression = options->argv[0]; + options->argc--; + options->argv++; } - if (argc > 0) { - attrs = (const char * const *)argv; + if (options->argc > 0) { + attrs = (const char * const *)options->argv; } - ldb = ldb_connect(ldb_url, 0, options); - - if (!ldb) { - perror("ldb_connect"); + ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options); + if (ret != 0) { + fprintf(stderr, "Failed to connect to %s - %s\n", + options->url, ldb_errstring(ldb)); + talloc_free(ldb); exit(1); } - ldb_set_debug_stderr(ldb); - - ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); - + ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs); if (ret == -1) { printf("search failed - %s\n", ldb_errstring(ldb)); exit(1); @@ -385,7 +322,7 @@ static void usage(void) return 0; } - do_edit(ldb, msgs, ret, editor); + do_edit(ldb, msgs, ret, options->editor); if (ret > 0) { ret = talloc_free(msgs); -- cgit From f40e69da2633771a42ec2b74fca63bd0b0a37e4a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 09:01:09 +0000 Subject: r7714: enable samba credentials handling in ldb tools. So you can now do a encrypted ldbedit against w2k3 (This used to be commit 6277c3923e7d9c26753424b1e77ac62f8e0729a4) --- source4/lib/ldb/tools/ldbedit.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 6c599ee2ec..73fb77dfd1 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -303,14 +303,6 @@ static void usage(void) attrs = (const char * const *)options->argv; } - ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options); - if (ret != 0) { - fprintf(stderr, "Failed to connect to %s - %s\n", - options->url, ldb_errstring(ldb)); - talloc_free(ldb); - exit(1); - } - ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs); if (ret == -1) { printf("search failed - %s\n", ldb_errstring(ldb)); -- cgit From aa6b2dcb9bdff582ac7628f0c2511de12da57242 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 19 Jun 2005 01:32:47 +0000 Subject: r7741: fixed the verbose option in ldbedit (This used to be commit a440133140a6adb5ea62d37690b9c4ae74dc6be0) --- source4/lib/ldb/tools/ldbedit.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 73fb77dfd1..e8497ba18f 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -41,7 +41,7 @@ #include "system/filesys.h" #endif -static int verbose; +static struct ldb_cmdline *options; /* debug routine @@ -77,16 +77,16 @@ static int modify_record(struct ldb_context *ldb, return 0; } + if (options->verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod); + } + if (ldb_modify(ldb, mod) != 0) { fprintf(stderr, "failed to modify %s - %s\n", msg1->dn, ldb_errstring(ldb)); return -1; } - if (verbose > 0) { - ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_MODIFY, mod); - } - return mod->num_elements; } @@ -121,14 +121,14 @@ static int merge_edits(struct ldb_context *ldb, for (i=0;idn); if (!msg) { + if (options->verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); + } if (ldb_add(ldb, msgs2[i]) != 0) { fprintf(stderr, "failed to add %s - %s\n", msgs2[i]->dn, ldb_errstring(ldb)); return -1; } - if (verbose > 0) { - ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); - } adds++; } else { if (modify_record(ldb, msg, msgs2[i]) > 0) { @@ -141,14 +141,14 @@ static int merge_edits(struct ldb_context *ldb, for (i=0;idn); if (!msg) { + if (options->verbose > 0) { + ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); + } if (ldb_delete(ldb, msgs1[i]->dn) != 0) { fprintf(stderr, "failed to delete %s - %s\n", msgs1[i]->dn, ldb_errstring(ldb)); return -1; } - if (verbose > 0) { - ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); - } deletes++; } } @@ -280,7 +280,6 @@ static void usage(void) int ret; const char *expression = NULL; const char * const * attrs = NULL; - struct ldb_cmdline *options; ldb = ldb_init(NULL); -- cgit From 0eb6bc1257f5f3638d8ed524c61d0ab43c8c7f02 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2005 03:10:40 +0000 Subject: r7833: changed ldbsearch and ldbedit to have command line syntax closer to ldapsearch. They look for an '=' in the first argument to see if it is a search expression, and if not then it does an 'all records' search (This used to be commit 91cc009fedefa7b263b345dfa511800e0f4f66a8) --- source4/lib/ldb/tools/ldbedit.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index e8497ba18f..12bf12bfff 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -278,28 +278,23 @@ static void usage(void) struct ldb_context *ldb; struct ldb_message **msgs; int ret; - const char *expression = NULL; + const char *expression = "(|(objectclass=*)(dn=*))"; const char * const * attrs = NULL; ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); - if (options->all_records) { - expression = "(|(objectclass=*)(dn=*))"; - } - - if (!expression) { - if (options->argc == 0) { - usage(); - } + /* the check for '=' is for compatibility with ldapsearch */ + if (options->argc > 0 && + strchr(options->argv[0], '=')) { expression = options->argv[0]; - options->argc--; options->argv++; + options->argc--; } if (options->argc > 0) { - attrs = (const char * const *)options->argv; + attrs = (const char * const *)(options->argv); } ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs); -- cgit From cb2c43f7b032c26adf82f3ba7d6e3dc855f89fa4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 16 Jul 2005 18:16:32 +0000 Subject: r8515: ldb_dn_cmp now uses ldb_dn_compare so that the DNs are compared on a content level not ona form level, his means that the 2 DNs: a) cn= user, dc=this, dc = is,dc=test b) cn=user,dc=this,dc=is,dc=test are now identical even if the string form differ (spaces) (This used to be commit 76d496c30867ae80434483a34b0d842523aed762) --- source4/lib/ldb/tools/ldbedit.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 12bf12bfff..1613f4ddc5 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -93,12 +93,14 @@ static int modify_record(struct ldb_context *ldb, /* find dn in msgs[] */ -static struct ldb_message *msg_find(struct ldb_message **msgs, int count, +static struct ldb_message *msg_find(struct ldb_context *ldb, + struct ldb_message **msgs, + int count, const char *dn) { int i; for (i=0;idn) == 0) { + if (ldb_dn_cmp(ldb, dn, msgs[i]->dn) == 0) { return msgs[i]; } } @@ -119,7 +121,7 @@ static int merge_edits(struct ldb_context *ldb, /* do the adds and modifies */ for (i=0;idn); + msg = msg_find(ldb, msgs1, count1, msgs2[i]->dn); if (!msg) { if (options->verbose > 0) { ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_ADD, msgs2[i]); @@ -139,7 +141,7 @@ static int merge_edits(struct ldb_context *ldb, /* do the deletes */ for (i=0;idn); + msg = msg_find(ldb, msgs2, count2, msgs1[i]->dn); if (!msg) { if (options->verbose > 0) { ldif_write_msg(ldb, stdout, LDB_CHANGETYPE_DELETE, msgs1[i]); -- cgit From 3e4c4cff2177af33efdb15f03a1bbcb639505cee Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 18 Aug 2005 15:02:01 +0000 Subject: r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names Provide more functions to handle DNs in this form (This used to be commit 692e35b7797e39533dd2a1c4b63d9da30f1eb5ba) --- source4/lib/ldb/tools/ldbedit.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 1613f4ddc5..a850562a7d 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -83,7 +83,7 @@ static int modify_record(struct ldb_context *ldb, if (ldb_modify(ldb, mod) != 0) { fprintf(stderr, "failed to modify %s - %s\n", - msg1->dn, ldb_errstring(ldb)); + ldb_dn_linearize(ldb, msg1->dn), ldb_errstring(ldb)); return -1; } @@ -96,11 +96,11 @@ static int modify_record(struct ldb_context *ldb, static struct ldb_message *msg_find(struct ldb_context *ldb, struct ldb_message **msgs, int count, - const char *dn) + const struct ldb_dn *dn) { int i; for (i=0;idn) == 0) { + if (ldb_dn_compare(ldb, dn, msgs[i]->dn) == 0) { return msgs[i]; } } @@ -128,7 +128,8 @@ static int merge_edits(struct ldb_context *ldb, } if (ldb_add(ldb, msgs2[i]) != 0) { fprintf(stderr, "failed to add %s - %s\n", - msgs2[i]->dn, ldb_errstring(ldb)); + ldb_dn_linearize(ldb, msgs2[i]->dn), + ldb_errstring(ldb)); return -1; } adds++; @@ -148,7 +149,8 @@ static int merge_edits(struct ldb_context *ldb, } if (ldb_delete(ldb, msgs1[i]->dn) != 0) { fprintf(stderr, "failed to delete %s - %s\n", - msgs1[i]->dn, ldb_errstring(ldb)); + ldb_dn_linearize(ldb, msgs1[i]->dn), + ldb_errstring(ldb)); return -1; } deletes++; @@ -279,6 +281,7 @@ static void usage(void) { struct ldb_context *ldb; struct ldb_message **msgs; + struct ldb_dn *basedn = NULL; int ret; const char *expression = "(|(objectclass=*)(dn=*))"; const char * const * attrs = NULL; @@ -299,7 +302,15 @@ static void usage(void) attrs = (const char * const *)(options->argv); } - ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs); + if (options->basedn != NULL) { + basedn = ldb_dn_explode(ldb, options->basedn); + if (basedn == NULL) { + printf("Invalid Base DN format\n"); + exit(1); + } + } + + ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &msgs); if (ret == -1) { printf("search failed - %s\n", ldb_errstring(ldb)); exit(1); -- cgit From 36d73b0e71eb3fbbe8d660b7609806b0355bd09c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Oct 2005 11:00:16 +0000 Subject: r10894: make the handling of dn/distinguishedName much closer to real ldap. Also ensure we put a objectclass on our private ldb's, so they have some chance of being stored in ldap if you want to (This used to be commit 1af2cc067f70f6654d08387fc28def67229bb06a) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index a850562a7d..bc629fef93 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -283,7 +283,7 @@ static void usage(void) struct ldb_message **msgs; struct ldb_dn *basedn = NULL; int ret; - const char *expression = "(|(objectclass=*)(dn=*))"; + const char *expression = "(|(objectclass=*)(distinguishedName=*))"; const char * const * attrs = NULL; ldb = ldb_init(NULL); -- cgit From 5c9590587197dcb95007fdc54318187d5716c7c6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 8 Nov 2005 00:11:45 +0000 Subject: r11567: Ldb API change patch. This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780) --- source4/lib/ldb/tools/ldbedit.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index bc629fef93..570179c2e1 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include "ldb/tools/cmdline.h" @@ -280,7 +281,7 @@ static void usage(void) int main(int argc, const char **argv) { struct ldb_context *ldb; - struct ldb_message **msgs; + struct ldb_result *result = NULL; struct ldb_dn *basedn = NULL; int ret; const char *expression = "(|(objectclass=*)(distinguishedName=*))"; @@ -310,21 +311,21 @@ static void usage(void) } } - ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &msgs); - if (ret == -1) { + ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &result); + if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); exit(1); } - if (ret == 0) { + if (result->count == 0) { printf("no matching records - cannot edit\n"); return 0; } - do_edit(ldb, msgs, ret, options->editor); + do_edit(ldb, result->msgs, result->count, options->editor); - if (ret > 0) { - ret = talloc_free(msgs); + if (result) { + ret = talloc_free(result); if (ret == -1) { fprintf(stderr, "talloc_free failed\n"); exit(1); -- cgit From a6d0d564597ea793e0a145ff39fafd6a0dfd6c0f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 30 Dec 2005 11:56:52 +0000 Subject: r12605: docs patch from Brad Hards (This used to be commit 874f16e055ec30bf2ee52a33464b4810a8f8cd89) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 570179c2e1..4d47cf27c9 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -274,7 +274,7 @@ static void usage(void) printf(" -b basedn choose baseDN\n"); printf(" -a edit all records (expression 'objectclass=*')\n"); printf(" -e editor choose editor (or $VISUAL or $EDITOR)\n"); - printf(" -v verbose mode)\n"); + printf(" -v verbose mode\n"); exit(1); } -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/lib/ldb/tools/ldbedit.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 4d47cf27c9..8818777ceb 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -35,7 +35,6 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_errors.h" -#include "ldb/include/ldb_private.h" #include "ldb/tools/cmdline.h" #ifdef _SAMBA_BUILD_ -- cgit From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/lib/ldb/tools/ldbedit.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 8818777ceb..4d47cf27c9 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -35,6 +35,7 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_errors.h" +#include "ldb/include/ldb_private.h" #include "ldb/tools/cmdline.h" #ifdef _SAMBA_BUILD_ -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/tools/ldbedit.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 4d47cf27c9..24fcf1a969 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -33,15 +33,9 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_errors.h" -#include "ldb/include/ldb_private.h" +#include "ldb/include/includes.h" #include "ldb/tools/cmdline.h" -#ifdef _SAMBA_BUILD_ -#include "system/filesys.h" -#endif - static struct ldb_cmdline *options; /* -- cgit From 2e8937c334b20b07d28f1a6647f97c1df5da44e7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 11 Jan 2006 15:03:20 +0000 Subject: r12843: get special objects with ldbsearch -a too, to match ldbedit -a metze (This used to be commit bb68f2e602dbcc94c05b2dd764c163be1e5a583d) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 24fcf1a969..9cef81f1db 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -278,7 +278,7 @@ static void usage(void) struct ldb_result *result = NULL; struct ldb_dn *basedn = NULL; int ret; - const char *expression = "(|(objectclass=*)(distinguishedName=*))"; + const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; ldb = ldb_init(NULL); -- cgit From 26af14c39b88b0e7eb53657b89be65d865804688 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 2 Mar 2006 16:32:53 +0000 Subject: r13786: [merge] Add registration functions for LDB modules Applications that use LDB modules will now have to run ldb_global_init() before they can use LDB. The next step will be adding support for loading LDB modules from .so files. This will also allow us to use one LDB without difference between the standalone and the Samba-specific build (This used to be commit 52a235650514039bf8ffee99a784bbc1b6ae6b92) --- source4/lib/ldb/tools/ldbedit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 9cef81f1db..b4e2b0a848 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -281,6 +281,8 @@ static void usage(void) const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; + ldb_global_init(); + ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit From 47bf79eac5c5c23394778b7e20a5263be71a9c66 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 May 2006 01:34:04 +0000 Subject: r15370: Fix more dependencies for shared libs (This used to be commit 9a518661fbb76bf1c153afc6f581e888186dc165) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index b4e2b0a848..f2cbeedb64 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -272,7 +272,7 @@ static void usage(void) exit(1); } - int main(int argc, const char **argv) +int main(int argc, const char **argv) { struct ldb_context *ldb; struct ldb_result *result = NULL; -- cgit From 0a98d909952c658d754c3d33594f58d8d30c21cf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 23 Aug 2006 05:08:55 +0000 Subject: r17740: get rid of dependence on asprintf(), using talloc_asprintf() instead (This used to be commit 0e350ea0c1bba278995da5e8de677c5651eb623e) --- source4/lib/ldb/tools/ldbedit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index f2cbeedb64..24df98d728 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -219,7 +219,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun fclose(f); - asprintf(&cmd, "%s %s", editor, template); + cmd = talloc_asprintf(ldb, "%s %s", editor, template); if (!cmd) { unlink(template); @@ -229,7 +229,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun /* run the editor */ ret = system(cmd); - free(cmd); + talloc_free(cmd); if (ret != 0) { unlink(template); -- cgit From 088c24e4e6e72568d4362ac39dc5ff7734782197 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 23 Sep 2006 04:36:30 +0000 Subject: r18840: make these compatible with g++ warnings (This used to be commit bcfa93954fdb00f500f174cd227e3d9b2ef94fdc) --- source4/lib/ldb/tools/ldbedit.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 24df98d728..17ade152b7 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -189,7 +189,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun { int fd, ret; FILE *f; - char template[] = "/tmp/ldbedit.XXXXXX"; + char file_template[] = "/tmp/ldbedit.XXXXXX"; char *cmd; struct ldb_ldif *ldif; struct ldb_message **msgs2 = NULL; @@ -197,10 +197,10 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun /* write out the original set of messages to a temporary file */ - fd = mkstemp(template); + fd = mkstemp(file_template); if (fd == -1) { - perror(template); + perror(file_template); return -1; } @@ -209,7 +209,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun if (!f) { perror("fopen"); close(fd); - unlink(template); + unlink(file_template); return -1; } @@ -219,10 +219,10 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun fclose(f); - cmd = talloc_asprintf(ldb, "%s %s", editor, template); + cmd = talloc_asprintf(ldb, "%s %s", editor, file_template); if (!cmd) { - unlink(template); + unlink(file_template); fprintf(stderr, "out of memory\n"); return -1; } @@ -232,15 +232,15 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun talloc_free(cmd); if (ret != 0) { - unlink(template); + unlink(file_template); fprintf(stderr, "edit with %s failed\n", editor); return -1; } /* read the resulting ldif into msgs2 */ - f = fopen(template, "r"); + f = fopen(file_template, "r"); if (!f) { - perror(template); + perror(file_template); return -1; } @@ -254,7 +254,7 @@ static int do_edit(struct ldb_context *ldb, struct ldb_message **msgs1, int coun } fclose(f); - unlink(template); + unlink(file_template); return merge_edits(ldb, msgs1, count1, msgs2, count2); } -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/tools/ldbedit.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 17ade152b7..429febb75b 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -91,11 +91,11 @@ static int modify_record(struct ldb_context *ldb, static struct ldb_message *msg_find(struct ldb_context *ldb, struct ldb_message **msgs, int count, - const struct ldb_dn *dn) + struct ldb_dn *dn) { int i; for (i=0;idn) == 0) { + if (ldb_dn_compare(dn, msgs[i]->dn) == 0) { return msgs[i]; } } @@ -300,8 +300,8 @@ int main(int argc, const char **argv) } if (options->basedn != NULL) { - basedn = ldb_dn_explode(ldb, options->basedn); - if (basedn == NULL) { + basedn = ldb_dn_new(ldb, ldb, options->basedn); + if ( ! ldb_dn_validate(basedn)) { printf("Invalid Base DN format\n"); exit(1); } -- cgit From a9e31b33b55a873c2f01db5e348560176adf863d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 02:05:19 +0000 Subject: r19832: better prototypes for the linearization functions: - ldb_dn_get_linearized returns a const string - ldb_dn_alloc_linearized allocs astring with the linearized dn (This used to be commit 3929c086d5d0b3f08b1c4f2f3f9602c3f4a9a4bd) --- source4/lib/ldb/tools/ldbedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 429febb75b..2edbe34b6f 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -78,7 +78,7 @@ static int modify_record(struct ldb_context *ldb, if (ldb_modify(ldb, mod) != 0) { fprintf(stderr, "failed to modify %s - %s\n", - ldb_dn_linearize(ldb, msg1->dn), ldb_errstring(ldb)); + ldb_dn_get_linearized(msg1->dn), ldb_errstring(ldb)); return -1; } @@ -123,7 +123,7 @@ static int merge_edits(struct ldb_context *ldb, } if (ldb_add(ldb, msgs2[i]) != 0) { fprintf(stderr, "failed to add %s - %s\n", - ldb_dn_linearize(ldb, msgs2[i]->dn), + ldb_dn_get_linearized(msgs2[i]->dn), ldb_errstring(ldb)); return -1; } @@ -144,7 +144,7 @@ static int merge_edits(struct ldb_context *ldb, } if (ldb_delete(ldb, msgs1[i]->dn) != 0) { fprintf(stderr, "failed to delete %s - %s\n", - ldb_dn_linearize(ldb, msgs1[i]->dn), + ldb_dn_get_linearized(msgs1[i]->dn), ldb_errstring(ldb)); return -1; } -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/tools/ldbedit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 2edbe34b6f..80ffbb5915 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -32,9 +32,8 @@ * Author: Andrew Tridgell */ -#include "includes.h" -#include "ldb/include/includes.h" -#include "ldb/tools/cmdline.h" +#include "ldb_includes.h" +#include "tools/cmdline.h" static struct ldb_cmdline *options; -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 80ffbb5915..1306bb8eea 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -10,7 +10,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/tools/ldbedit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 1306bb8eea..ed98a6d615 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -18,8 +18,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ /* -- cgit From 0020793515ade04f3ef5754717490e2eb2ca6bb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 03:40:44 +0100 Subject: Fix static module list generation for ldb. (This used to be commit 92c1c0e9137f0845cac6cc96bf78711b6aaffe21) --- source4/lib/ldb/tools/ldbedit.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index ed98a6d615..a9fd064bf8 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -279,8 +279,6 @@ int main(int argc, const char **argv) const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit From 929adc9efa5cf985f0585214d30d18521aa1a821 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jun 2008 11:24:17 -0400 Subject: Make up the right dependencies now that ldb depends on libevents (This used to be commit 3b8eec7ca334528cad3cdcd5e3fc5ee555d8d0e0) --- source4/lib/ldb/tools/ldbedit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbedit.c') diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index a9fd064bf8..e58a5a271e 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -279,7 +279,7 @@ int main(int argc, const char **argv) const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit