From ee44733f94864fb0a1ae15d48e3335c0705a82ae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 3 Apr 2004 12:29:21 +0000 Subject: added the rest of the ldb_modify() code, which required a fairly large change in the ldb API. The API is now much closer to LDAP. (This used to be commit e9e85c464411c561c5073d262a2e3533fec175ca) --- source4/lib/ldb/tools/ldbmodify.c | 85 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 source4/lib/ldb/tools/ldbmodify.c (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c new file mode 100644 index 0000000000..e1cff655db --- /dev/null +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -0,0 +1,85 @@ +/* + 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: ldbmodify + * + * Description: utility to modify records - modelled on ldapmodify + * + * Author: Andrew Tridgell + */ + +#include "includes.h" + + int main(void) +{ + static struct ldb_context *ldb; + struct ldb_ldif *ldif; + int ret; + int count=0, failures=0; + const char *ldb_url; + + ldb_url = getenv("LDB_URL"); + if (!ldb_url) { + ldb_url = "tdb://test.ldb"; + } + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + while ((ldif = ldif_read_file(stdin))) { + switch (ldif->changetype) { + case LDB_CHANGETYPE_NONE: + case LDB_CHANGETYPE_ADD: + ret = ldb_add(ldb, &ldif->msg); + break; + case LDB_CHANGETYPE_DELETE: + ret = ldb_delete(ldb, ldif->msg.dn); + break; + case LDB_CHANGETYPE_MODIFY: + ret = ldb_modify(ldb, &ldif->msg); + break; + } + if (ret != 0) { + fprintf(stderr, "ERR: \"%s\" on DN %s\n", + ldb_errstring(ldb), ldif->msg.dn); + failures++; + } else { + count++; + } + ldif_read_free(ldif); + } + + ldb_close(ldb); + + printf("Modified %d records with %d failures\n", count, failures); + + return 0; +} -- cgit 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/ldbmodify.c | 100 ++++++++++++++++++++++++++++++-------- 1 file changed, 81 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index e1cff655db..a93c710a7a 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -34,27 +34,27 @@ #include "includes.h" - int main(void) -{ - static struct ldb_context *ldb; - struct ldb_ldif *ldif; - int ret; - int count=0, failures=0; - const char *ldb_url; - - ldb_url = getenv("LDB_URL"); - if (!ldb_url) { - ldb_url = "tdb://test.ldb"; - } +static int failures; - ldb = ldb_connect(ldb_url, 0, NULL); - - if (!ldb) { - perror("ldb_connect"); - exit(1); - } +static void usage(void) +{ + printf("Usage: ldbmodify \n"); + printf("Options:\n"); + printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf("\n"); + printf("Modifies a ldb based upon ldif change records\n\n"); + exit(1); +} - while ((ldif = ldif_read_file(stdin))) { +/* + process modifies for one file +*/ +static int process_file(struct ldb_context *ldb, FILE *f) +{ + struct ldb_ldif *ldif; + int ret, count = 0; + + while ((ldif = ldif_read_file(f))) { switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: @@ -77,6 +77,68 @@ ldif_read_free(ldif); } + return count; +} + + int main(int argc, char * const argv[]) +{ + struct ldb_context *ldb; + int count=0; + const char *ldb_url; + int opt, i; + + ldb_url = getenv("LDB_URL"); + + while ((opt = getopt(argc, argv, "hH:")) != EOF) { + switch (opt) { + case 'H': + ldb_url = optarg; + break; + + case 'h': + default: + usage(); + break; + } + } + + if (!ldb_url) { + fprintf(stderr, "You must specify a ldb URL\n"); + exit(1); + } + + argc -= optind; + argv += optind; + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + if (argc == 0) { + usage(); + exit(1); + } + + for (i=0;i 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/ldbmodify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index a93c710a7a..ac32f90c3b 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -103,8 +103,8 @@ static int process_file(struct ldb_context *ldb, FILE *f) } 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 585d87a9590ecf64681700d70c37e5276ee8514a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 May 2004 05:16:15 +0000 Subject: r442: fixed some uninitialised variables pointed out by gcc -O3 (This used to be commit ff31cfb941b77e99e648011a6b7639b2a5923a6a) --- source4/lib/ldb/tools/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index ac32f90c3b..bc29369a5c 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -52,7 +52,7 @@ static void usage(void) static int process_file(struct ldb_context *ldb, FILE *f) { struct ldb_ldif *ldif; - int ret, count = 0; + int ret = -1, count = 0; while ((ldif = ldif_read_file(f))) { switch (ldif->changetype) { -- 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/ldbmodify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index bc29369a5c..6ac8e366c7 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -54,7 +54,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) struct ldb_ldif *ldif; int ret = -1, count = 0; - while ((ldif = ldif_read_file(f))) { + while ((ldif = ldif_read_file(ldb, f))) { switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: @@ -74,7 +74,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) } else { count++; } - ldif_read_free(ldif); + ldif_read_free(ldb, ldif); } return count; -- 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/ldbmodify.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 6ac8e366c7..9f7cbe4527 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -117,6 +117,8 @@ static int process_file(struct ldb_context *ldb, FILE *f) exit(1); } + ldb_set_debug_stderr(ldb); + if (argc == 0) { usage(); exit(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/ldbmodify.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') 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; } -- 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/ldbmodify.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 828b7d4865..b6ca2993ce 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -54,7 +54,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) struct ldb_ldif *ldif; int ret = -1, count = 0; - while ((ldif = ldif_read_file(ldb, f))) { + while ((ldif = ldb_ldif_read_file(ldb, f))) { switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: @@ -74,7 +74,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) } else { count++; } - ldif_read_free(ldb, ldif); + ldb_ldif_read_free(ldb, ldif); } return count; -- 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/ldbmodify.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index b6ca2993ce..823855ff1e 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -85,16 +85,34 @@ static int process_file(struct ldb_context *ldb, FILE *f) struct ldb_context *ldb; int count=0; const char *ldb_url; + const char **options = NULL; + int ldbopts; int opt, i; ldb_url = getenv("LDB_URL"); - while ((opt = getopt(argc, argv, "hH:")) != EOF) { + ldbopts = 0; + while ((opt = getopt(argc, argv, "hH:o:")) != EOF) { switch (opt) { case 'H': ldb_url = optarg; 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(); @@ -110,7 +128,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) argc -= optind; argv += optind; - ldb = ldb_connect(ldb_url, 0, NULL); + ldb = ldb_connect(ldb_url, 0, options); if (!ldb) { perror("ldb_connect"); -- cgit From 57d2043479d290bbfa8d2752da454efea330606e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 15 Nov 2004 14:16:10 +0000 Subject: r3760: mention -o switch in help message (This used to be commit 0e7d8753101f22aa192ac5628675a0374484d0e9) --- source4/lib/ldb/tools/ldbmodify.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 823855ff1e..ac8958f4ac 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -41,6 +41,8 @@ static void usage(void) printf("Usage: ldbmodify \n"); printf("Options:\n"); printf(" -H ldb_url choose the database (or $LDB_URL)\n"); + printf(" -o options pass options like modules to activate\n"); + printf(" e.g: -o modules:timestamps\n"); printf("\n"); printf("Modifies a ldb based upon ldif change records\n\n"); exit(1); -- 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/ldbmodify.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index ac8958f4ac..a660b814da 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -33,6 +33,7 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" static int failures; -- 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/ldbmodify.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index a660b814da..5fabba57b7 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" static int failures; @@ -102,18 +103,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) 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 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/ldbmodify.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 5fabba57b7..3bdb946897 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -62,18 +62,18 @@ static int process_file(struct ldb_context *ldb, FILE *f) switch (ldif->changetype) { case LDB_CHANGETYPE_NONE: case LDB_CHANGETYPE_ADD: - ret = ldb_add(ldb, &ldif->msg); + ret = ldb_add(ldb, ldif->msg); break; case LDB_CHANGETYPE_DELETE: - ret = ldb_delete(ldb, ldif->msg.dn); + ret = ldb_delete(ldb, ldif->msg->dn); break; case LDB_CHANGETYPE_MODIFY: - ret = ldb_modify(ldb, &ldif->msg); + ret = ldb_modify(ldb, ldif->msg); break; } if (ret != 0) { fprintf(stderr, "ERR: \"%s\" on DN %s\n", - ldb_errstring(ldb), ldif->msg.dn); + ldb_errstring(ldb), ldif->msg->dn); failures++; } else { count++; -- 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/ldbmodify.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 3bdb946897..97dec1050e 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.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 failures; static void usage(void) -- 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') 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); -- 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/ldbmodify.c | 59 +++++++++++---------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 78baa0e36c..c54c573ab0 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.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" @@ -88,66 +89,40 @@ static int process_file(struct ldb_context *ldb, FILE *f) return count; } - int main(int argc, char * const argv[]) + int main(int argc, const char **argv) { struct ldb_context *ldb; int count=0; - const char *ldb_url; - const char **options = NULL; - int ldbopts; - int opt, i; - - ldb_url = getenv("LDB_URL"); - - ldbopts = 0; - while ((opt = getopt(argc, argv, "hH:o:")) != EOF) { - switch (opt) { - case 'H': - ldb_url = optarg; - break; + int i, ret; + struct ldb_cmdline *options; - case 'o': - options = ldb_options_parse(options, &ldbopts, optarg); - break; + ldb = ldb_init(NULL); - 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(); - } - - argc -= optind; - argv += optind; - - ldb = ldb_connect(ldb_url, 0, options); - - if (!ldb) { - perror("ldb_connect"); + ret = ldb_connect(ldb, options->url, 0, 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); - - if (argc == 0) { + if (options->argc == 0) { usage(); exit(1); } - for (i=0;iargc;i++) { + const char *fname = options->argv[i]; FILE *f; - if (strcmp(argv[i],"-") == 0) { + if (strcmp(fname,"-") == 0) { f = stdin; } else { - f = fopen(argv[i], "r"); + f = fopen(fname, "r"); } if (!f) { - perror(argv[i]); + perror(fname); exit(1); } count += process_file(ldb, f); -- 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/ldbmodify.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index c54c573ab0..39725b195d 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -100,14 +100,6 @@ static int process_file(struct ldb_context *ldb, FILE *f) options = ldb_cmdline_process(ldb, argc, argv, usage); - ret = ldb_connect(ldb, options->url, 0, options->options); - if (ret != 0) { - fprintf(stderr, "Failed to connect to %s - %s\n", - options->url, ldb_errstring(ldb)); - talloc_free(ldb); - exit(1); - } - if (options->argc == 0) { usage(); exit(1); -- cgit From bf75ae41556a67739cd089a7e3182cf2a994448c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 13:18:43 +0000 Subject: r7726: - removed some unused variables - handle ldb_errstring() calls on failed connect (This used to be commit 8698a20fcc6a04ccbe533afd742e7a5df94423ee) --- source4/lib/ldb/tools/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 39725b195d..8fa0dcf0b6 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -93,7 +93,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) { struct ldb_context *ldb; int count=0; - int i, ret; + int i; struct ldb_cmdline *options; ldb = ldb_init(NULL); -- cgit From e485e80b512f17aba0b6b1dd5acc3f738f4189c1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 19 Jun 2005 04:20:54 +0000 Subject: r7743: be consistent in how stdin is supported for ldbadd and ldbmodify (This used to be commit 3d60b3a8eea5ac6c35cf2e579ae12cef3dc1794e) --- source4/lib/ldb/tools/ldbmodify.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 8fa0dcf0b6..901a4c9628 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -101,25 +101,17 @@ static int process_file(struct ldb_context *ldb, FILE *f) options = ldb_cmdline_process(ldb, argc, argv, usage); if (options->argc == 0) { - usage(); - exit(1); - } - - for (i=0;iargc;i++) { - const char *fname = options->argv[i]; - FILE *f; - if (strcmp(fname,"-") == 0) { - f = stdin; - } else { + count += process_file(ldb, stdin); + } else { + for (i=0;iargc;i++) { + const char *fname = options->argv[i]; + FILE *f; f = fopen(fname, "r"); - } - if (!f) { - perror(fname); - exit(1); - } - count += process_file(ldb, f); - if (f != stdin) { - fclose(f); + if (!f) { + perror(fname); + exit(1); + } + count += process_file(ldb, f); } } -- 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 901a4c9628..4c78e485b5 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -78,7 +78,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) } if (ret != 0) { fprintf(stderr, "ERR: \"%s\" on DN %s\n", - ldb_errstring(ldb), ldif->msg->dn); + ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn)); failures++; } else { count++; -- 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/ldbmodify.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 4c78e485b5..f067aef3f8 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -34,7 +34,6 @@ #include "includes.h" #include "ldb/include/ldb.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/ldbmodify.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index f067aef3f8..4c78e485b5 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.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/ldbmodify.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 4c78e485b5..e785a42a23 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -33,14 +33,9 @@ */ #include "includes.h" -#include "ldb/include/ldb.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 int failures; static void usage(void) -- 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/ldbmodify.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index e785a42a23..4ce49c2ce8 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -91,6 +91,8 @@ static int process_file(struct ldb_context *ldb, FILE *f) int i; struct ldb_cmdline *options; + 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 4ce49c2ce8..24f9386266 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -84,7 +84,7 @@ static int process_file(struct ldb_context *ldb, FILE *f) return count; } - int main(int argc, const char **argv) +int main(int argc, const char **argv) { struct ldb_context *ldb; int count=0; -- cgit From 04140ac3c75e3bdb2fad4b534d86c5fafabe58c5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Oct 2006 08:26:10 +0000 Subject: r19274: fix ldbdel and ldbmodify to return an error if the underlying ldb call fails (This used to be commit 330a722f1330059cbba19f99210a1a5a7c773a36) --- source4/lib/ldb/tools/ldbmodify.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 24f9386266..962045ef7d 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -53,10 +53,10 @@ static void usage(void) /* process modifies for one file */ -static int process_file(struct ldb_context *ldb, FILE *f) +static int process_file(struct ldb_context *ldb, FILE *f, int *count) { struct ldb_ldif *ldif; - int ret = -1, count = 0; + int ret = LDB_SUCCESS; while ((ldif = ldb_ldif_read_file(ldb, f))) { switch (ldif->changetype) { @@ -71,24 +71,24 @@ static int process_file(struct ldb_context *ldb, FILE *f) ret = ldb_modify(ldb, ldif->msg); break; } - if (ret != 0) { + if (ret != LDB_SUCCESS) { fprintf(stderr, "ERR: \"%s\" on DN %s\n", ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn)); failures++; } else { - count++; + (*count)++; } ldb_ldif_read_free(ldb, ldif); } - return count; + return ret; } int main(int argc, const char **argv) { struct ldb_context *ldb; int count=0; - int i; + int i, ret=LDB_SUCCESS; struct ldb_cmdline *options; ldb_global_init(); @@ -98,7 +98,7 @@ int main(int argc, const char **argv) options = ldb_cmdline_process(ldb, argc, argv, usage); if (options->argc == 0) { - count += process_file(ldb, stdin); + ret = process_file(ldb, stdin, &count); } else { for (i=0;iargc;i++) { const char *fname = options->argv[i]; @@ -108,7 +108,7 @@ int main(int argc, const char **argv) perror(fname); exit(1); } - count += process_file(ldb, f); + ret = process_file(ldb, f, &count); } } @@ -116,9 +116,5 @@ int main(int argc, const char **argv) printf("Modified %d records with %d failures\n", count, failures); - if (failures != 0) { - return -1; - } - - return 0; + return ret; } -- 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 962045ef7d..cc7219a156 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -73,7 +73,7 @@ static int process_file(struct ldb_context *ldb, FILE *f, int *count) } if (ret != LDB_SUCCESS) { fprintf(stderr, "ERR: \"%s\" on DN %s\n", - ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn)); + ldb_errstring(ldb), ldb_dn_get_linearized(ldif->msg->dn)); failures++; } else { (*count)++; -- 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/ldbmodify.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index cc7219a156..66ed3c8b5f 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.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 int failures; -- 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 66ed3c8b5f..40affe5f43 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.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/ldbmodify.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 40affe5f43..ed12380095 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.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/ldbmodify.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index ed12380095..dd6206b824 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -89,8 +89,6 @@ int main(int argc, const char **argv) int i, ret=LDB_SUCCESS; struct ldb_cmdline *options; - 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/ldbmodify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbmodify.c') diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index dd6206b824..6e355a10cf 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -89,7 +89,7 @@ int main(int argc, const char **argv) int i, ret=LDB_SUCCESS; struct ldb_cmdline *options; - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit