From 58d50a614f1b4a3fc6b60ad5f777d987263fe54f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 31 Mar 2004 06:45:39 +0000 Subject: make a more recent snapshot of ldb available to interested people. Note that I decided to make it LGPL. ldb is not finished yet, but enough of it is there for people to get an idea of what it does, and quite a few simple tests work (This used to be commit dc6f41f9e777d37f883303ddef0d96840d80f78e) --- source4/lib/ldb/tools/ldbsearch.c | 122 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 source4/lib/ldb/tools/ldbsearch.c (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c new file mode 100644 index 0000000000..d7d3c83162 --- /dev/null +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -0,0 +1,122 @@ +/* + 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: ldbsearch + * + * Description: utility for ldb search - modelled on ldapsearch + * + * Author: Andrew Tridgell + */ + +#include "includes.h" +#include + + int main(int argc, char * const argv[]) +{ + static struct ldb_context *ldb; + struct ldb_message **msgs; + int ret, i; + const char *expression; + const char * const *attrs = NULL; + const char *ldb_url; + const char *basedn = NULL; + int opt; + enum ldb_scope scope = LDB_SCOPE_DEFAULT; + + ldb_url = getenv("LDB_URL"); + if (!ldb_url) { + ldb_url = "tdb://test.ldb"; + } + + while ((opt = getopt(argc, argv, "b: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; + } + } + + argc -= optind; + argv += optind; + + if (argc < 1) { + printf("Usage: ldbsearch [attrs...]\n"); + exit(1); + } + + if (argc > 1) { + attrs = argv+1; + } + + expression = argv[0]; + + ldb = ldb_connect(ldb_url, 0, NULL); + + if (!ldb) { + perror("ldb_connect"); + exit(1); + } + + ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); + + if (ret == -1) { + printf("search failed\n"); + exit(1); + } + + printf("# returned %d records\n", ret); + + for (i=0;i 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 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/ldbsearch.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index d7d3c83162..f4eb8f00db 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -45,7 +45,7 @@ const char *ldb_url; const char *basedn = NULL; int opt; - enum ldb_scope scope = LDB_SCOPE_DEFAULT; + enum ldb_scope scope = LDB_SCOPE_SUBTREE; ldb_url = getenv("LDB_URL"); if (!ldb_url) { @@ -98,15 +98,20 @@ ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); if (ret == -1) { - printf("search failed\n"); + printf("search failed - %s\n", ldb_errstring(ldb)); exit(1); } printf("# returned %d records\n", ret); for (i=0;i 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/ldbsearch.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f4eb8f00db..327feb28ef 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -33,26 +33,32 @@ */ #include "includes.h" -#include + +static void usage(void) +{ + printf("Usage: ldbsearch \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"); + exit(1); +} int main(int argc, char * const argv[]) { - static struct ldb_context *ldb; + struct ldb_context *ldb; struct ldb_message **msgs; int ret, i; const char *expression; - const char * const *attrs = NULL; + char * const *attrs = NULL; const char *ldb_url; const char *basedn = NULL; int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; ldb_url = getenv("LDB_URL"); - if (!ldb_url) { - ldb_url = "tdb://test.ldb"; - } - while ((opt = getopt(argc, argv, "b:H:s:")) != EOF) { + while ((opt = getopt(argc, argv, "b:H:s:h")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -71,14 +77,24 @@ scope = LDB_SCOPE_ONELEVEL; } 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 (argc < 1) { - printf("Usage: ldbsearch [attrs...]\n"); + usage(); exit(1); } -- 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/ldbsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 327feb28ef..45412f6104 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -86,8 +86,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 208e09747c242ab5bd59a658033db49efa8d8696 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 May 2004 14:51:26 +0000 Subject: r456: - added -i option to ldbsearch - fixed sorting bug in ldb index handing (This used to be commit cdd48e2b9b3ca6be5503eec401e09db162408ac8) --- source4/lib/ldb/tools/ldbsearch.c | 84 ++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 33 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 45412f6104..e8275e87c1 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -41,24 +41,59 @@ static void usage(void) 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(" -i read search expressions from stdin\n"); exit(1); } +static void do_search(struct ldb_context *ldb, + const char *basedn, + int scope, + const char *expression, + const char * const *attrs) +{ + int ret, i; + struct ldb_message **msgs; + + ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); + if (ret == -1) { + printf("search failed - %s\n", ldb_errstring(ldb)); + return; + } + + printf("# returned %d records\n", ret); + + for (i=0;i 0) { + ret = ldb_search_free(ldb, msgs); + if (ret == -1) { + fprintf(stderr, "search_free failed\n"); + exit(1); + } + } +} + int main(int argc, char * const argv[]) { struct ldb_context *ldb; - struct ldb_message **msgs; - int ret, i; - const char *expression; - char * const *attrs = NULL; + const char * const * attrs = NULL; const char *ldb_url; const char *basedn = NULL; int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; + int interactive = 0; ldb_url = getenv("LDB_URL"); - while ((opt = getopt(argc, argv, "b:H:s:h")) != EOF) { + while ((opt = getopt(argc, argv, "b:H:s:hi")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -78,6 +113,10 @@ static void usage(void) } break; + case 'i': + interactive = 1; + break; + case 'h': default: usage(); @@ -93,7 +132,7 @@ static void usage(void) argc -= optind; argv += optind; - if (argc < 1) { + if (argc < 1 && !interactive) { usage(); exit(1); } @@ -102,40 +141,19 @@ static void usage(void) attrs = argv+1; } - expression = argv[0]; - ldb = ldb_connect(ldb_url, 0, NULL); - if (!ldb) { perror("ldb_connect"); exit(1); } - ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); - - if (ret == -1) { - printf("search failed - %s\n", ldb_errstring(ldb)); - exit(1); - } - - printf("# returned %d records\n", ret); - - for (i=0;i 0) { - ret = ldb_search_free(ldb, msgs); - if (ret == -1) { - fprintf(stderr, "search_free failed\n"); - exit(1); + if (interactive) { + char line[1024]; + while (fgets(line, sizeof(line), stdin)) { + do_search(ldb, basedn, scope, line, attrs); } + } else { + do_search(ldb, basedn, scope, argv[0], attrs); } ldb_close(ldb); -- cgit From 232bc1503fc0e3f85b4711f077d2566dc0f0c823 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 May 2004 04:27:29 +0000 Subject: r490: - expanded the test suite to test modify and delete operations - made yet another attempt to make ldb const clean. - "make test" now runs both the tdb and ldap backend tests, and run the ldbtest utility with and without indexing - added prototypes in ldb.h for ldb_msg_*() public functions (This used to be commit 01e87406768cb5a98ac8530a2f361a4987a36cd3) --- source4/lib/ldb/tools/ldbsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index e8275e87c1..541024dd2d 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -49,7 +49,7 @@ static void do_search(struct ldb_context *ldb, const char *basedn, int scope, const char *expression, - const char * const *attrs) + char * const *attrs) { int ret, i; struct ldb_message **msgs; @@ -84,7 +84,7 @@ static void do_search(struct ldb_context *ldb, int main(int argc, char * const argv[]) { struct ldb_context *ldb; - const char * const * attrs = NULL; + char * const * attrs = NULL; const char *ldb_url; const char *basedn = NULL; int opt; -- 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/ldbsearch.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 541024dd2d..edda31b793 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -45,11 +45,11 @@ static void usage(void) exit(1); } -static void do_search(struct ldb_context *ldb, - const char *basedn, - int scope, - const char *expression, - char * const *attrs) +static int do_search(struct ldb_context *ldb, + const char *basedn, + int scope, + const char *expression, + char * const *attrs) { int ret, i; struct ldb_message **msgs; @@ -57,7 +57,7 @@ static void do_search(struct ldb_context *ldb, ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); if (ret == -1) { printf("search failed - %s\n", ldb_errstring(ldb)); - return; + return -1; } printf("# returned %d records\n", ret); @@ -69,7 +69,7 @@ static void do_search(struct ldb_context *ldb, ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = *msgs[i]; - ldif_write_file(stdout, &ldif); + ldif_write_file(ldb, stdout, &ldif); } if (ret > 0) { @@ -79,6 +79,8 @@ static void do_search(struct ldb_context *ldb, exit(1); } } + + return 0; } int main(int argc, char * const argv[]) @@ -89,7 +91,7 @@ static void do_search(struct ldb_context *ldb, const char *basedn = NULL; int opt; enum ldb_scope scope = LDB_SCOPE_SUBTREE; - int interactive = 0; + int interactive = 0, ret=0; ldb_url = getenv("LDB_URL"); @@ -150,12 +152,14 @@ static void do_search(struct ldb_context *ldb, if (interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { - do_search(ldb, basedn, scope, line, attrs); + if (do_search(ldb, basedn, scope, line, attrs) == -1) { + ret = -1; + } } } else { - do_search(ldb, basedn, scope, argv[0], attrs); + ret = do_search(ldb, basedn, scope, argv[0], attrs); } ldb_close(ldb); - return 0; + return ret; } -- 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/ldbsearch.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index edda31b793..f80f81b50e 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -149,6 +149,8 @@ static int do_search(struct ldb_context *ldb, exit(1); } + ldb_set_debug_stderr(ldb); + if (interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { -- 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/ldbsearch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f80f81b50e..478601ec7e 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -49,7 +49,7 @@ static int do_search(struct ldb_context *ldb, const char *basedn, int scope, const char *expression, - char * const *attrs) + const char * const *attrs) { int ret, i; struct ldb_message **msgs; @@ -86,7 +86,7 @@ static int do_search(struct ldb_context *ldb, int main(int argc, char * const argv[]) { struct ldb_context *ldb; - char * const * attrs = NULL; + const char * const * attrs = NULL; const char *ldb_url; const char *basedn = NULL; int opt; @@ -140,7 +140,7 @@ static int do_search(struct ldb_context *ldb, } if (argc > 1) { - attrs = argv+1; + attrs = (const char * const *)(argv+1); } ldb = ldb_connect(ldb_url, 0, NULL); -- 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 478601ec7e..137299d89b 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -69,7 +69,7 @@ static int do_search(struct ldb_context *ldb, ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = *msgs[i]; - ldif_write_file(ldb, stdout, &ldif); + ldb_ldif_write_file(ldb, stdout, &ldif); } if (ret > 0) { -- 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/ldbsearch.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 137299d89b..1e7bb1ce4c 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -89,13 +89,15 @@ static int do_search(struct ldb_context *ldb, const char * const * attrs = NULL; const char *ldb_url; const char *basedn = NULL; - int opt; + const char **options = NULL; + int opt, ldbopts; enum ldb_scope scope = LDB_SCOPE_SUBTREE; int interactive = 0, ret=0; ldb_url = getenv("LDB_URL"); - while ((opt = getopt(argc, argv, "b:H:s:hi")) != EOF) { + ldbopts = 0; + while ((opt = getopt(argc, argv, "b:H:s:o:hi")) != EOF) { switch (opt) { case 'b': basedn = optarg; @@ -119,6 +121,21 @@ static int do_search(struct ldb_context *ldb, interactive = 1; 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(); @@ -143,7 +160,7 @@ static int do_search(struct ldb_context *ldb, attrs = (const char * const *)(argv+1); } - ldb = ldb_connect(ldb_url, 0, NULL); + ldb = ldb_connect(ldb_url, 0, options); if (!ldb) { perror("ldb_connect"); exit(1); -- 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/ldbsearch.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 1e7bb1ce4c..81c46b437c 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -42,6 +42,8 @@ static void usage(void) printf(" -s base|sub|one choose search scope\n"); printf(" -b basedn choose baseDN\n"); printf(" -i read search expressions from stdin\n"); + printf(" -o options pass options like modules to activate\n"); + printf(" e.g: -o modules:timestamps\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/ldbsearch.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 81c46b437c..9f6b2f617a 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -33,6 +33,7 @@ */ #include "includes.h" +#include "ldb/include/ldb.h" static void usage(void) { -- 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/ldbsearch.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 9f6b2f617a..fced589572 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -34,6 +34,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" static void usage(void) { @@ -125,18 +126,7 @@ static int do_search(struct ldb_context *ldb, 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index fced589572..9041231faf 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -71,7 +71,7 @@ static int do_search(struct ldb_context *ldb, printf("# record %d\n", i+1); ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = *msgs[i]; + ldif.msg = msgs[i]; ldb_ldif_write_file(ldb, stdout, &ldif); } -- cgit From 09a76e204cf339862f8b0b45979d65cc34aa3c36 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2005 09:46:59 +0000 Subject: r4477: expanded the test suite to increase code coverage a lot (This used to be commit 4edbd1b18ee38e584cf844b64c7fcb2645921837) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 9041231faf..5e0246d7a9 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -153,7 +153,7 @@ static int do_search(struct ldb_context *ldb, attrs = (const char * const *)(argv+1); } - ldb = ldb_connect(ldb_url, 0, options); + ldb = ldb_connect(ldb_url, LDB_FLG_RDONLY, options); if (!ldb) { perror("ldb_connect"); exit(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/ldbsearch.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 5e0246d7a9..f764b28557 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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 void usage(void) { printf("Usage: ldbsearch \n"); -- 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f764b28557..8d435e7661 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -176,6 +176,6 @@ static int do_search(struct ldb_context *ldb, ret = do_search(ldb, basedn, scope, argv[0], attrs); } - ldb_close(ldb); + talloc_free(ldb); return ret; } -- 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/ldbsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 8d435e7661..3e6e7d7feb 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -81,9 +81,9 @@ static int do_search(struct ldb_context *ldb, } if (ret > 0) { - ret = ldb_search_free(ldb, msgs); + ret = talloc_free(msgs); if (ret == -1) { - fprintf(stderr, "search_free failed\n"); + fprintf(stderr, "talloc_free failed\n"); exit(1); } } -- cgit From a1ba224107fbcf6f8a9a3091f42cde2a0c47f85e Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 4 Jun 2005 17:13:43 +0000 Subject: r7276: - moved static tdb function ltdb_dn_fold() into common/ so that it can be called from multiple backends. (ldb_sqlite3 needs it too.) Added parameter for a callback function that determines whether an attribute needs case folding. - begin to prepare for sqlite3 in build process - work-in-progress updates, on ldb_sqlite3 (This used to be commit a80bced0b96ffb655559a43cf7f4d7a34deb5a7d) --- source4/lib/ldb/tools/ldbsearch.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 3e6e7d7feb..26bd198d1d 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -48,6 +48,7 @@ static void usage(void) printf(" -s base|sub|one choose search scope\n"); printf(" -b basedn choose baseDN\n"); printf(" -i read search expressions from stdin\n"); + printf(" -S sort returned attributes\n"); printf(" -o options pass options like modules to activate\n"); printf(" e.g: -o modules:timestamps\n"); exit(1); @@ -56,6 +57,7 @@ static void usage(void) static int do_search(struct ldb_context *ldb, const char *basedn, int scope, + int sort_attribs, const char *expression, const char * const *attrs) { @@ -77,6 +79,15 @@ static int do_search(struct ldb_context *ldb, ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = msgs[i]; + if (sort_attribs) { + /* + * Ensure attributes are always returned in the same + * order. For testing, this makes comparison of old + * vs. new much easier. + */ + ldb_msg_sort_elements(ldif.msg); + } + ldb_ldif_write_file(ldb, stdout, &ldif); } @@ -100,7 +111,7 @@ static int do_search(struct ldb_context *ldb, const char **options = NULL; int opt, ldbopts; enum ldb_scope scope = LDB_SCOPE_SUBTREE; - int interactive = 0, ret=0; + int interactive = 0, sort_attribs=0, ret=0; ldb_url = getenv("LDB_URL"); @@ -129,6 +140,10 @@ static int do_search(struct ldb_context *ldb, interactive = 1; break; + case 'S': + sort_attribs = 1; + break; + case 'o': options = ldb_options_parse(options, &ldbopts, optarg); break; @@ -168,12 +183,12 @@ static int do_search(struct ldb_context *ldb, if (interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { - if (do_search(ldb, basedn, scope, line, attrs) == -1) { + if (do_search(ldb, basedn, scope, sort_attribs, line, attrs) == -1) { ret = -1; } } } else { - ret = do_search(ldb, basedn, scope, argv[0], attrs); + ret = do_search(ldb, basedn, scope, sort_attribs, argv[0], attrs); } talloc_free(ldb); -- cgit From ee3f4b12d22459405372e1c72efe3079a052601d Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 9 Jun 2005 14:50:32 +0000 Subject: r7438: work in progress (This used to be commit 2fc5343f0637ef3109b079dbc33d6cf4e58c8d5e) --- source4/lib/ldb/tools/ldbsearch.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 26bd198d1d..4bf9db8d90 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -54,6 +54,12 @@ static void usage(void) exit(1); } +static int do_compare_msg(struct ldb_message **el1, + struct ldb_message **el2) +{ + return ldb_dn_cmp((*el1)->dn, (*el2)->dn); +} + static int do_search(struct ldb_context *ldb, const char *basedn, int scope, @@ -72,6 +78,11 @@ static int do_search(struct ldb_context *ldb, printf("# returned %d records\n", ret); + if (sort_attribs) { + qsort(msgs, ret, sizeof(struct ldb_message *), + (comparison_fn_t)do_compare_msg); + } + for (i=0;i 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/ldbsearch.c | 87 +++++++++------------------------------ 1 file changed, 20 insertions(+), 67 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 4bf9db8d90..04f83ca366 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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" @@ -113,93 +114,45 @@ static int do_search(struct ldb_context *ldb, return 0; } - int main(int argc, char * const argv[]) + int main(int argc, const char **argv) { struct ldb_context *ldb; const char * const * attrs = NULL; - const char *ldb_url; - const char *basedn = NULL; - const char **options = NULL; - int opt, ldbopts; - enum ldb_scope scope = LDB_SCOPE_SUBTREE; - int interactive = 0, sort_attribs=0, ret=0; - - ldb_url = getenv("LDB_URL"); - - ldbopts = 0; - while ((opt = getopt(argc, argv, "b:H:s:o:hiS")) != 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 'i': - interactive = 1; - break; - - case 'S': - sort_attribs = 1; - break; + struct ldb_cmdline *options; + int ret; - case 'o': - options = ldb_options_parse(options, &ldbopts, optarg); - break; - - case 'h': - default: - usage(); - break; - } - } + ldb = ldb_init(NULL); - if (!ldb_url) { - fprintf(stderr, "You must specify a ldb URL\n\n"); - usage(); - } - - argc -= optind; - argv += optind; - - if (argc < 1 && !interactive) { + options = ldb_cmdline_process(ldb, argc, argv, usage); + + if (options->argc < 1 && !options->interactive) { usage(); exit(1); } - if (argc > 1) { - attrs = (const char * const *)(argv+1); + if (options->argc > 1) { + attrs = (const char * const *)(options->argv+1); } - ldb = ldb_connect(ldb_url, LDB_FLG_RDONLY, 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); - - if (interactive) { + if (options->interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { - if (do_search(ldb, basedn, scope, sort_attribs, line, attrs) == -1) { + if (do_search(ldb, options->basedn, + options->scope, options->sorted, line, attrs) == -1) { ret = -1; } } } else { - ret = do_search(ldb, basedn, scope, sort_attribs, argv[0], attrs); + ret = do_search(ldb, options->basedn, options->scope, options->sorted, + options->argv[0], attrs); } talloc_free(ldb); -- 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/ldbsearch.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 04f83ca366..0e81da5de3 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -119,7 +119,7 @@ static int do_search(struct ldb_context *ldb, struct ldb_context *ldb; const char * const * attrs = NULL; struct ldb_cmdline *options; - int ret; + int ret = -1; ldb = ldb_init(NULL); @@ -134,14 +134,6 @@ static int do_search(struct ldb_context *ldb, attrs = (const char * const *)(options->argv+1); } - 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); - } - if (options->interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { -- 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/ldbsearch.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 0e81da5de3..396bb7797a 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -120,18 +120,23 @@ static int do_search(struct ldb_context *ldb, const char * const * attrs = NULL; struct ldb_cmdline *options; int ret = -1; + const char *expression = "(|(objectclass=*)(dn=*))"; ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); - - if (options->argc < 1 && !options->interactive) { - usage(); - exit(1); + + /* the check for '=' is for compatibility with ldapsearch */ + if (!options->interactive && + options->argc > 0 && + strchr(options->argv[0], '=')) { + expression = options->argv[0]; + options->argv++; + options->argc--; } - if (options->argc > 1) { - attrs = (const char * const *)(options->argv+1); + if (options->argc > 0) { + attrs = (const char * const *)(options->argv); } if (options->interactive) { @@ -144,7 +149,7 @@ static int do_search(struct ldb_context *ldb, } } else { ret = do_search(ldb, options->basedn, options->scope, options->sorted, - options->argv[0], attrs); + expression, attrs); } talloc_free(ldb); -- 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/ldbsearch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 396bb7797a..5604436980 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -55,10 +55,12 @@ static void usage(void) exit(1); } +struct ldb_context *ldbsearch_ldb; + static int do_compare_msg(struct ldb_message **el1, - struct ldb_message **el2) + struct ldb_message **el2) { - return ldb_dn_cmp((*el1)->dn, (*el2)->dn); + return ldb_dn_cmp(ldbsearch_ldb, (*el1)->dn, (*el2)->dn); } static int do_search(struct ldb_context *ldb, @@ -79,6 +81,7 @@ static int do_search(struct ldb_context *ldb, printf("# returned %d records\n", ret); + ldbsearch_ldb = ldb; if (sort_attribs) { qsort(msgs, ret, sizeof(struct ldb_message *), (comparison_fn_t)do_compare_msg); -- 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/ldbsearch.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 5604436980..4499bc9359 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -60,11 +60,11 @@ struct ldb_context *ldbsearch_ldb; static int do_compare_msg(struct ldb_message **el1, struct ldb_message **el2) { - return ldb_dn_cmp(ldbsearch_ldb, (*el1)->dn, (*el2)->dn); + return ldb_dn_compare(ldbsearch_ldb, (*el1)->dn, (*el2)->dn); } static int do_search(struct ldb_context *ldb, - const char *basedn, + const struct ldb_dn *basedn, int scope, int sort_attribs, const char *expression, @@ -120,6 +120,7 @@ static int do_search(struct ldb_context *ldb, int main(int argc, const char **argv) { struct ldb_context *ldb; + struct ldb_dn *basedn = NULL; const char * const * attrs = NULL; struct ldb_cmdline *options; int ret = -1; @@ -142,16 +143,24 @@ static int do_search(struct ldb_context *ldb, attrs = (const char * const *)(options->argv); } + if (options->basedn != NULL) { + basedn = ldb_dn_explode(ldb, options->basedn); + if (basedn == NULL) { + fprintf(stderr, "Invalid Base DN format\n"); + exit(1); + } + } + if (options->interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { - if (do_search(ldb, options->basedn, + if (do_search(ldb, basedn, options->scope, options->sorted, line, attrs) == -1) { ret = -1; } } } else { - ret = do_search(ldb, options->basedn, options->scope, options->sorted, + ret = do_search(ldb, basedn, options->scope, options->sorted, expression, attrs); } -- 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 4499bc9359..4abc7269d5 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -124,7 +124,7 @@ static int do_search(struct ldb_context *ldb, const char * const * attrs = NULL; struct ldb_cmdline *options; int ret = -1; - const char *expression = "(|(objectclass=*)(dn=*))"; + const char *expression = "(objectclass=*)"; 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/ldbsearch.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 4abc7269d5..f8c06f0fa4 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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" @@ -71,10 +72,10 @@ static int do_search(struct ldb_context *ldb, const char * const *attrs) { int ret, i; - struct ldb_message **msgs; + struct ldb_result *result = NULL; - ret = ldb_search(ldb, basedn, scope, expression, attrs, &msgs); - if (ret == -1) { + ret = ldb_search(ldb, basedn, scope, expression, attrs, &result); + if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); return -1; } @@ -83,16 +84,16 @@ static int do_search(struct ldb_context *ldb, ldbsearch_ldb = ldb; if (sort_attribs) { - qsort(msgs, ret, sizeof(struct ldb_message *), + qsort(result->msgs, ret, sizeof(struct ldb_message *), (comparison_fn_t)do_compare_msg); } - for (i=0;icount; i++) { struct ldb_ldif ldif; printf("# record %d\n", i+1); ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = msgs[i]; + ldif.msg = result->msgs[i]; if (sort_attribs) { /* @@ -106,8 +107,8 @@ static int do_search(struct ldb_context *ldb, ldb_ldif_write_file(ldb, stdout, &ldif); } - 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 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/ldbsearch.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f8c06f0fa4..c493356405 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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/ldbsearch.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index c493356405..a340e16d08 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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_ @@ -55,12 +56,12 @@ static void usage(void) exit(1); } -struct ldb_context *ldbsearch_ldb; - static int do_compare_msg(struct ldb_message **el1, - struct ldb_message **el2) + struct ldb_message **el2, + void *opaque) { - return ldb_dn_compare(ldbsearch_ldb, (*el1)->dn, (*el2)->dn); + struct ldb_context *ldb = talloc_get_type(opaque, struct ldb_context); + return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); } static int do_search(struct ldb_context *ldb, @@ -81,10 +82,9 @@ static int do_search(struct ldb_context *ldb, printf("# returned %d records\n", ret); - ldbsearch_ldb = ldb; if (sort_attribs) { - qsort(result->msgs, ret, sizeof(struct ldb_message *), - (comparison_fn_t)do_compare_msg); + ldb_qsort(result->msgs, ret, sizeof(struct ldb_message *), + ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); } for (i = 0; i < result->count; i++) { -- cgit From b51fe793c7cefb693d6d3633272b82238e712abe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 19:42:08 +0000 Subject: r12745: Initial work to support a syntax to pass over controls via command line to ldbsearch. Very rough work, no checks are done on the input yet (will segfault if you make it wrong). Controls are passed via the --controls switch an are comma separated (no escaping yet). General syntax is : is a string is 1 or 0 Current semi-parsed controls are: server_sort syntax: server_sort:1:0:attributename 1st parm: criticality 2nd parm: reversed 3rd parm: attribute name to be used for sorting todo: still missing suport for multiple sorting attributes and ordering rule no check on result code paged_results syntax: paged_results:1:100 1st parm: criticality 2nd parm: number of results to be returned todo: ldbsearch will return only the first batch (missing code to cycle over conditionally) no check on result code extended_dn syntax: extended_dn:1:0 1st parm: criticality 2nd parm: type, see MS docs on meaning Simo. (This used to be commit 4c685ac0d1638a1d5392dfe733baf0db77e84858) --- source4/lib/ldb/tools/ldbsearch.c | 84 ++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index a340e16d08..406c81f765 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -64,25 +64,93 @@ static int do_compare_msg(struct ldb_message **el1, return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); } +static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings) +{ + int i; + struct ldb_control **ctrl; + + if (control_strings == NULL || control_strings[0] == NULL) + return NULL; + + for (i = 0; control_strings[i]; i++); + + ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1); + + for (i = 0; control_strings[i]; i++) { + if (strncmp(control_strings[i], "extended_dn:", 12) == 0) { + struct ldb_extended_dn_control *control; + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_EXTENDED_DN_OID; + ctrl[i]->critical = control_strings[i][12]=='1'?1:0; + control = talloc(ctrl[i], struct ldb_extended_dn_control); + control->type = atoi(&control_strings[i][14]); + ctrl[i]->data = control; + } + + if (strncmp(control_strings[i], "paged_results:", 14) == 0) { + struct ldb_paged_control *control; + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_PAGED_RESULTS_OID; + ctrl[i]->critical = control_strings[i][14]=='1'?1:0; + control = talloc(ctrl[i], struct ldb_paged_control); + control->size = atoi(&control_strings[i][16]); + control->cookie = NULL; + control->cookie_len = 0; + ctrl[i]->data = control; + } + + if (strncmp(control_strings[i], "server_sort:", 12) == 0) { + struct ldb_server_sort_control **control; + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_SERVER_SORT_OID; + ctrl[i]->critical = control_strings[i][12]=='1'?1:0; + control = talloc_array(ctrl[i], struct ldb_server_sort_control *, 2); + control[0] = talloc(control, struct ldb_server_sort_control); + control[0]->attributeName = talloc_strdup(control, &control_strings[i][16]); + control[0]->orderingRule = NULL; + control[0]->reverse = control_strings[i][14]=='1'?1:0; + control[1] = NULL; + ctrl[i]->data = control; + } + } + + ctrl[i + 1] = NULL; + + return ctrl; +} + static int do_search(struct ldb_context *ldb, const struct ldb_dn *basedn, - int scope, - int sort_attribs, + struct ldb_cmdline *options, const char *expression, const char * const *attrs) { int ret, i; + struct ldb_request req; struct ldb_result *result = NULL; - ret = ldb_search(ldb, basedn, scope, expression, attrs, &result); + req.operation = LDB_REQ_SEARCH; + req.op.search.base = basedn; + req.op.search.scope = options->scope; + req.op.search.tree = ldb_parse_tree(ldb, expression); + req.op.search.attrs = attrs; + req.op.search.res = NULL; + req.controls = parse_controls(ldb, options->controls); + req.creds = NULL; + + ret = ldb_request(ldb, &req); if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); return -1; } + result = req.op.search.res; printf("# returned %d records\n", ret); - if (sort_attribs) { + if (options->sorted) { ldb_qsort(result->msgs, ret, sizeof(struct ldb_message *), ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); } @@ -94,7 +162,7 @@ static int do_search(struct ldb_context *ldb, ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = result->msgs[i]; - if (sort_attribs) { + if (options->sorted) { /* * Ensure attributes are always returned in the same * order. For testing, this makes comparison of old @@ -154,14 +222,12 @@ static int do_search(struct ldb_context *ldb, if (options->interactive) { char line[1024]; while (fgets(line, sizeof(line), stdin)) { - if (do_search(ldb, basedn, - options->scope, options->sorted, line, attrs) == -1) { + if (do_search(ldb, basedn, options, line, attrs) == -1) { ret = -1; } } } else { - ret = do_search(ldb, basedn, options->scope, options->sorted, - expression, attrs); + ret = do_search(ldb, basedn, options, expression, attrs); } talloc_free(ldb); -- cgit From 6f18b19519efdd4d60146eaea4cfda849731efba Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 10 Jan 2006 00:52:05 +0000 Subject: r12810: handle control options gracefully and don't segfault (This used to be commit 300d48bc9daa13e1475c10eaa1ec0717c822a7f7) --- source4/lib/ldb/tools/ldbsearch.c | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 406c81f765..b9ce1282a3 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -79,42 +79,81 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings for (i = 0; control_strings[i]; i++) { if (strncmp(control_strings[i], "extended_dn:", 12) == 0) { struct ldb_extended_dn_control *control; + const char *p; + int crit, type, ret; + + p = &(control_strings[i][12]); + ret = sscanf(p, "%d:%d", &crit, &type); + if ((ret != 2) || (crit < 0) || (crit > 1) || (type < 0) || (type > 1)) { + fprintf(stderr, "invalid extended_dn control syntax\n"); + return NULL; + } ctrl[i] = talloc(ctrl, struct ldb_control); ctrl[i]->oid = LDB_CONTROL_EXTENDED_DN_OID; - ctrl[i]->critical = control_strings[i][12]=='1'?1:0; + ctrl[i]->critical = crit; control = talloc(ctrl[i], struct ldb_extended_dn_control); - control->type = atoi(&control_strings[i][14]); + control->type = type; ctrl[i]->data = control; + + continue; } if (strncmp(control_strings[i], "paged_results:", 14) == 0) { struct ldb_paged_control *control; + const char *p; + int crit, size, ret; + + p = &(control_strings[i][14]); + ret = sscanf(p, "%d:%d", &crit, &size); + + if ((ret != 2) || (crit < 0) || (crit > 1) || (size < 0)) { + fprintf(stderr, "invalid paged_results control syntax\n"); + return NULL; + } ctrl[i] = talloc(ctrl, struct ldb_control); ctrl[i]->oid = LDB_CONTROL_PAGED_RESULTS_OID; - ctrl[i]->critical = control_strings[i][14]=='1'?1:0; + ctrl[i]->critical = crit; control = talloc(ctrl[i], struct ldb_paged_control); - control->size = atoi(&control_strings[i][16]); + control->size = size; control->cookie = NULL; control->cookie_len = 0; ctrl[i]->data = control; + + continue; } if (strncmp(control_strings[i], "server_sort:", 12) == 0) { struct ldb_server_sort_control **control; - + const char *p; + char attr[256]; + char rule[128]; + int crit, rev, ret; + + p = &(control_strings[i][12]); + ret = sscanf(p, "%d:%d:%255[^:]:%127[^:]", &crit, &rev, attr, rule); + if ((ret < 3) || (crit < 0) || (crit > 1) || (rev < 0 ) || (rev > 1) ||attr[0] == '\0') { + fprintf(stderr, "invalid server_sort control syntax\n"); + return NULL; + } ctrl[i] = talloc(ctrl, struct ldb_control); ctrl[i]->oid = LDB_CONTROL_SERVER_SORT_OID; - ctrl[i]->critical = control_strings[i][12]=='1'?1:0; + ctrl[i]->critical = crit; control = talloc_array(ctrl[i], struct ldb_server_sort_control *, 2); control[0] = talloc(control, struct ldb_server_sort_control); - control[0]->attributeName = talloc_strdup(control, &control_strings[i][16]); - control[0]->orderingRule = NULL; - control[0]->reverse = control_strings[i][14]=='1'?1:0; + control[0]->attributeName = talloc_strdup(control, attr); + control[0]->orderingRule = talloc_strdup(control, rule); + control[0]->reverse = rev; control[1] = NULL; ctrl[i]->data = control; + + continue; } + + /* no controls matched, throw an error */ + fprintf(stderr, "Invalid control name\n"); + return NULL; } ctrl[i + 1] = NULL; @@ -139,6 +178,7 @@ static int do_search(struct ldb_context *ldb, req.op.search.attrs = attrs; req.op.search.res = NULL; req.controls = parse_controls(ldb, options->controls); + if (options->controls != NULL && req.controls == NULL) return -1; req.creds = NULL; ret = ldb_request(ldb, &req); -- 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/ldbsearch.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index b9ce1282a3..4ce974c6fa 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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 void usage(void) { printf("Usage: ldbsearch \n"); -- cgit From 5ecc64dcab1089cf134a264de28aca0b21100cca Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 10 Jan 2006 17:19:32 +0000 Subject: r12833: complete ldbsearch support for controls now the three supported controls (paged_results, server_sort, extended_dn) are fully functional and the infrastructure to add more is in place. valgrind is happy too :) Simo. (This used to be commit bd8e2629378700198e16287823970f52d1150a86) --- source4/lib/ldb/tools/ldbsearch.c | 172 ++++++++++++++++++++++++++++++-------- 1 file changed, 135 insertions(+), 37 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 4ce974c6fa..46a67ad324 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -125,6 +125,8 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings char rule[128]; int crit, rev, ret; + attr[0] = '\0'; + rule[0] = '\0'; p = &(control_strings[i][12]); ret = sscanf(p, "%d:%d:%255[^:]:%127[^:]", &crit, &rev, attr, rule); if ((ret < 3) || (crit < 0) || (crit > 1) || (rev < 0 ) || (rev > 1) ||attr[0] == '\0') { @@ -137,7 +139,10 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings control = talloc_array(ctrl[i], struct ldb_server_sort_control *, 2); control[0] = talloc(control, struct ldb_server_sort_control); control[0]->attributeName = talloc_strdup(control, attr); - control[0]->orderingRule = talloc_strdup(control, rule); + if (rule[0]) + control[0]->orderingRule = talloc_strdup(control, rule); + else + control[0]->orderingRule = NULL; control[0]->reverse = rev; control[1] = NULL; ctrl[i]->data = control; @@ -150,11 +155,90 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings return NULL; } - ctrl[i + 1] = NULL; + ctrl[i] = NULL; return ctrl; } +/* this function check controls reply and determines if more + * processing is needed setting up the request controls correctly + * + * returns: + * -1 error + * 0 all ok + * 1 all ok, more processing required + */ +static int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request) +{ + int i, j; + int ret = 0; + + if (reply == NULL || request == NULL) return -1; + + for (i = 0; reply[i]; i++) { + if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, reply[i]->oid) == 0) { + struct ldb_paged_control *rep_control, *req_control; + + rep_control = talloc_get_type(reply[i]->data, struct ldb_paged_control); + if (rep_control->cookie_len == 0) /* we are done */ + break; + + /* more processing required */ + /* let's fill in the request control with the new cookie */ + + for (j = 0; request[j]; j++) { + if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, request[j]->oid) == 0) + break; + } + /* if there's a reply control we must find a request + * control matching it */ + if (! request[j]) return -1; + + req_control = talloc_get_type(request[j]->data, struct ldb_paged_control); + + if (req_control->cookie) + talloc_free(req_control->cookie); + req_control->cookie = talloc_memdup(req_control, + rep_control->cookie, + rep_control->cookie_len); + req_control->cookie_len = rep_control->cookie_len; + + ret = 1; + + continue; + } + + if (strcmp(LDB_CONTROL_SORT_RESP_OID, reply[i]->oid) == 0) { + struct ldb_sort_resp_control *rep_control; + + rep_control = talloc_get_type(reply[i]->data, struct ldb_sort_resp_control); + + /* check we have a matching control in the request */ + for (j = 0; request[j]; j++) { + if (strcmp(LDB_CONTROL_SERVER_SORT_OID, request[j]->oid) == 0) + break; + } + if (! request[j]) { + fprintf(stderr, "Warning Server Sort reply received but no request found\n"); + continue; + } + + /* check the result */ + if (rep_control->result != 0) { + fprintf(stderr, "Warning: Sorting not performed with error: %d\n", rep_control->result); + } + + continue; + } + + /* no controls matched, throw a warning */ + fprintf(stderr, "Unknown reply control oid: %s\n", reply[i]->oid); + } + + return ret; +} + + static int do_search(struct ldb_context *ldb, const struct ldb_dn *basedn, struct ldb_cmdline *options, @@ -162,6 +246,8 @@ static int do_search(struct ldb_context *ldb, const char * const *attrs) { int ret, i; + int loop = 0; + int total = 0; struct ldb_request req; struct ldb_result *result = NULL; @@ -175,46 +261,58 @@ static int do_search(struct ldb_context *ldb, if (options->controls != NULL && req.controls == NULL) return -1; req.creds = NULL; - ret = ldb_request(ldb, &req); - if (ret != LDB_SUCCESS) { - printf("search failed - %s\n", ldb_errstring(ldb)); - return -1; - } + do { + loop = 0; + + ret = ldb_request(ldb, &req); + if (ret != LDB_SUCCESS) { + printf("search failed - %s\n", ldb_errstring(ldb)); + return -1; + } - result = req.op.search.res; - printf("# returned %d records\n", ret); + result = req.op.search.res; + printf("# returned %d records\n", result->count); - if (options->sorted) { - ldb_qsort(result->msgs, ret, sizeof(struct ldb_message *), - ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); - } + if (options->sorted) { + ldb_qsort(result->msgs, ret, sizeof(struct ldb_message *), + ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); + } - for (i = 0; i < result->count; i++) { - struct ldb_ldif ldif; - printf("# record %d\n", i+1); - - ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = result->msgs[i]; - - if (options->sorted) { - /* - * Ensure attributes are always returned in the same - * order. For testing, this makes comparison of old - * vs. new much easier. - */ - ldb_msg_sort_elements(ldif.msg); - } - - ldb_ldif_write_file(ldb, stdout, &ldif); - } + for (i = 0; i < result->count; i++, total++) { + struct ldb_ldif ldif; + printf("# record %d\n", total + 1); + + ldif.changetype = LDB_CHANGETYPE_NONE; + ldif.msg = result->msgs[i]; + + if (options->sorted) { + /* + * Ensure attributes are always returned in the same + * order. For testing, this makes comparison of old + * vs. new much easier. + */ + ldb_msg_sort_elements(ldif.msg); + } + + ldb_ldif_write_file(ldb, stdout, &ldif); + } - if (result) { - ret = talloc_free(result); - if (ret == -1) { - fprintf(stderr, "talloc_free failed\n"); - exit(1); + if (result->controls) { + if (handle_controls_reply(result->controls, req.controls) == 1) + loop = 1; } - } + + if (result) { + ret = talloc_free(result); + if (ret == -1) { + fprintf(stderr, "talloc_free failed\n"); + exit(1); + } + } + + req.op.search.res = NULL; + + } while(loop); return 0; } -- 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 46a67ad324..3b4f84c929 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -324,7 +324,7 @@ static int do_search(struct ldb_context *ldb, const char * const * attrs = NULL; struct ldb_cmdline *options; int ret = -1; - const char *expression = "(objectclass=*)"; + const char *expression = "(|(objectClass=*)(distinguishedName=*))"; ldb = ldb_init(NULL); -- cgit From 5db0c6b3042292e0f343ced3d45f2f7a8f97de12 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jan 2006 01:06:16 +0000 Subject: r12925: implement client side of ASQ control (This used to be commit dd386bdc6ca6fe0b25705d5a375d29e6940b437f) --- source4/lib/ldb/tools/ldbsearch.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 3b4f84c929..c81db7eb4d 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -71,6 +71,32 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1); for (i = 0; control_strings[i]; i++) { + if (strncmp(control_strings[i], "asq:", 4) == 0) { + struct ldb_asq_control *control; + const char *p; + char attr[256]; + int crit, ret; + + attr[0] = '\0'; + p = &(control_strings[i][4]); + ret = sscanf(p, "%d:%255[^$]", &crit, attr); + if ((ret != 2) || (crit < 0) || (crit > 1) || (attr[0] == '\0')) { + fprintf(stderr, "invalid asq control syntax\n"); + return NULL; + } + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_ASQ_OID; + ctrl[i]->critical = crit; + control = talloc(ctrl[i], struct ldb_asq_control); + control->request = 1; + control->source_attribute = talloc_strdup(control, attr); + control->src_attr_len = strlen(attr); + ctrl[i]->data = control; + + continue; + } + if (strncmp(control_strings[i], "extended_dn:", 12) == 0) { struct ldb_extended_dn_control *control; const char *p; @@ -176,6 +202,18 @@ static int handle_controls_reply(struct ldb_control **reply, struct ldb_control if (reply == NULL || request == NULL) return -1; for (i = 0; reply[i]; i++) { + if (strcmp(LDB_CONTROL_ASQ_OID, reply[i]->oid) == 0) { + struct ldb_asq_control *rep_control; + + rep_control = talloc_get_type(reply[i]->data, struct ldb_asq_control); + + /* check the result */ + if (rep_control->result != 0) { + fprintf(stderr, "Warning: ASQ not performed with error: %d\n", rep_control->result); + } + + continue; + } if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, reply[i]->oid) == 0) { struct ldb_paged_control *rep_control, *req_control; -- cgit From 3725b1817f1e26370015d955622f0705e9121714 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jan 2006 06:12:29 +0000 Subject: r12941: Add Attribute Scoped Search control want to see what it does ? do aq make test and try: ./bin/ldbsearch -H st/private/sam.ldb --controls=asq:1:member -s base -b 'CN=Administrators,CN=Builtin,DC=samba,DC=example,DC=com' 'objectclass=*' have fun. simo. (This used to be commit 900f4fd3435aacc3351f30afb77d3488d2cb4804) --- source4/lib/ldb/tools/ldbsearch.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index c81db7eb4d..582861eae2 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -305,6 +305,10 @@ static int do_search(struct ldb_context *ldb, ret = ldb_request(ldb, &req); if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); + if (req.op.search.res && req.op.search.res->controls) { + /* TODO: handle_control */ + ; + } return -1; } -- cgit From 3b447ab4a131509491b42a1843c52ba69bab5e11 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 17 Jan 2006 04:04:57 +0000 Subject: r12977: Some code to implement the client side of the Dirsync control Still investigating how it works. Simo. (This used to be commit bebd403523e581606505e05e7cb621efbc22fa36) --- source4/lib/ldb/tools/ldbsearch.c | 74 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 582861eae2..6c1071318e 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -71,6 +71,40 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1); for (i = 0; control_strings[i]; i++) { + if (strncmp(control_strings[i], "dirsync:", 8) == 0) { + struct ldb_dirsync_control *control; + const char *p; + char cookie[1024]; + int crit, flags, max_attrs, ret; + + cookie[0] = '\0'; + p = &(control_strings[i][8]); + ret = sscanf(p, "%d:%d:%d:%1023[^$]", &crit, &flags, &max_attrs, cookie); + + if ((ret < 3) || (crit < 0) || (crit > 1) || (flags < 0) || (max_attrs < 0)) { + fprintf(stderr, "invalid paged_results control syntax\n"); + return NULL; + } + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_DIRSYNC_OID; + ctrl[i]->critical = crit; + control = talloc(ctrl[i], struct ldb_dirsync_control); + control->flags = flags; + control->max_attributes = max_attrs; + if (*cookie) { + ldb_base64_decode(cookie); + control->cookie = talloc_strdup(control, cookie); + control->cookie_len = strlen(cookie); + } else { + control->cookie = NULL; + control->cookie_len = 0; + } + ctrl[i]->data = control; + + continue; + } + if (strncmp(control_strings[i], "asq:", 4) == 0) { struct ldb_asq_control *control; const char *p; @@ -269,6 +303,42 @@ static int handle_controls_reply(struct ldb_control **reply, struct ldb_control continue; } + if (strcmp(LDB_CONTROL_DIRSYNC_OID, reply[i]->oid) == 0) { + struct ldb_dirsync_control *rep_control, *req_control; + char *cookie; + + rep_control = talloc_get_type(reply[i]->data, struct ldb_dirsync_control); + if (rep_control->cookie_len == 0) /* we are done */ + break; + + /* more processing required */ + /* let's fill in the request control with the new cookie */ + + for (j = 0; request[j]; j++) { + if (strcmp(LDB_CONTROL_DIRSYNC_OID, request[j]->oid) == 0) + break; + } + /* if there's a reply control we must find a request + * control matching it */ + if (! request[j]) return -1; + + req_control = talloc_get_type(request[j]->data, struct ldb_dirsync_control); + + if (req_control->cookie) + talloc_free(req_control->cookie); + req_control->cookie = talloc_memdup(req_control, + rep_control->cookie, + rep_control->cookie_len); + req_control->cookie_len = rep_control->cookie_len; + + cookie = ldb_base64_encode(req_control, rep_control->cookie, rep_control->cookie_len); + fprintf(stderr, "Debug: The cookie returned was: %s\n", cookie); + + ret = 1; + + continue; + } + /* no controls matched, throw a warning */ fprintf(stderr, "Unknown reply control oid: %s\n", reply[i]->oid); } @@ -306,8 +376,8 @@ static int do_search(struct ldb_context *ldb, if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); if (req.op.search.res && req.op.search.res->controls) { - /* TODO: handle_control */ - ; + + /* TODO: handle_control */ } return -1; } -- cgit From 8139c1e6f2cf154dad0c0c3fbf8c4fac960bdfe0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 17 Jan 2006 17:23:11 +0000 Subject: r12983: - fix using a DIRSYNC cookie from the command line - also w2k doesn't work correct with max_attrs = 0, so we should use a high number, with this I'm getting the same results from w2k and w2k3 metze (This used to be commit ce9f086c3c1a65bf1b4c843ec44e8817d9361182) --- source4/lib/ldb/tools/ldbsearch.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 6c1071318e..df895350ee 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -82,10 +82,17 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings ret = sscanf(p, "%d:%d:%d:%1023[^$]", &crit, &flags, &max_attrs, cookie); if ((ret < 3) || (crit < 0) || (crit > 1) || (flags < 0) || (max_attrs < 0)) { - fprintf(stderr, "invalid paged_results control syntax\n"); + fprintf(stderr, "invalid dirsync control syntax\n"); return NULL; } + /* w2k3 seems to ignore the parameter, + * but w2k sends a wrong cookie when this value is to small + * this would cause looping forever, while getting + * the same data and same cookie forever + */ + if (max_attrs == 0) max_attrs = 0x0FFFFFFF; + ctrl[i] = talloc(ctrl, struct ldb_control); ctrl[i]->oid = LDB_CONTROL_DIRSYNC_OID; ctrl[i]->critical = crit; @@ -93,9 +100,8 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings control->flags = flags; control->max_attributes = max_attrs; if (*cookie) { - ldb_base64_decode(cookie); - control->cookie = talloc_strdup(control, cookie); - control->cookie_len = strlen(cookie); + control->cookie_len = ldb_base64_decode(cookie); + control->cookie = talloc_memdup(control, cookie, control->cookie_len); } else { control->cookie = NULL; control->cookie_len = 0; @@ -332,7 +338,7 @@ static int handle_controls_reply(struct ldb_control **reply, struct ldb_control req_control->cookie_len = rep_control->cookie_len; cookie = ldb_base64_encode(req_control, rep_control->cookie, rep_control->cookie_len); - fprintf(stderr, "Debug: The cookie returned was: %s\n", cookie); + printf("# DIRSYNC cookie returned was:\n# %s\n", cookie); ret = 1; -- cgit From 828ee2bc6fa4f757c63a31054a0046fe09f8c26e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 17 Jan 2006 18:56:04 +0000 Subject: r12984: add parse code and ldbsearch cmdline code for NOTIFICATION LDAP Controls http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp this doesn't work yet, but it shows that we need to extend ldb to correctly handle async requests... metze (This used to be commit 1fe67189490c9faf499b68a28071a6294a53db0e) --- source4/lib/ldb/tools/ldbsearch.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index df895350ee..df14aac0b2 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -216,6 +216,25 @@ static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings continue; } + if (strncmp(control_strings[i], "notification:", 13) == 0) { + const char *p; + int crit, ret; + + p = &(control_strings[i][13]); + ret = sscanf(p, "%d", &crit); + if ((ret != 1) || (crit < 0) || (crit > 1)) { + fprintf(stderr, "invalid notification control syntax\n"); + return NULL; + } + + ctrl[i] = talloc(ctrl, struct ldb_control); + ctrl[i]->oid = LDB_CONTROL_NOTIFICATION_OID; + ctrl[i]->critical = crit; + ctrl[i]->data = NULL; + + continue; + } + /* no controls matched, throw an error */ fprintf(stderr, "Invalid control name\n"); return NULL; -- cgit From f81d80a4afd77cd100832b80bc2383d7c19a71a8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 18 Jan 2006 04:36:30 +0000 Subject: r12989: move the control parsing and handleng functions to cmdline.c so that they can be used by the other ldb tools as well (This used to be commit c12b3c5cb46d428f815c623efacff8edebb6f6e3) --- source4/lib/ldb/tools/ldbsearch.c | 316 +------------------------------------- 1 file changed, 1 insertion(+), 315 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index df14aac0b2..e3b3a9e6de 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -58,320 +58,6 @@ static int do_compare_msg(struct ldb_message **el1, return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); } -static struct ldb_control **parse_controls(void *mem_ctx, char **control_strings) -{ - int i; - struct ldb_control **ctrl; - - if (control_strings == NULL || control_strings[0] == NULL) - return NULL; - - for (i = 0; control_strings[i]; i++); - - ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1); - - for (i = 0; control_strings[i]; i++) { - if (strncmp(control_strings[i], "dirsync:", 8) == 0) { - struct ldb_dirsync_control *control; - const char *p; - char cookie[1024]; - int crit, flags, max_attrs, ret; - - cookie[0] = '\0'; - p = &(control_strings[i][8]); - ret = sscanf(p, "%d:%d:%d:%1023[^$]", &crit, &flags, &max_attrs, cookie); - - if ((ret < 3) || (crit < 0) || (crit > 1) || (flags < 0) || (max_attrs < 0)) { - fprintf(stderr, "invalid dirsync control syntax\n"); - return NULL; - } - - /* w2k3 seems to ignore the parameter, - * but w2k sends a wrong cookie when this value is to small - * this would cause looping forever, while getting - * the same data and same cookie forever - */ - if (max_attrs == 0) max_attrs = 0x0FFFFFFF; - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_DIRSYNC_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_dirsync_control); - control->flags = flags; - control->max_attributes = max_attrs; - if (*cookie) { - control->cookie_len = ldb_base64_decode(cookie); - control->cookie = talloc_memdup(control, cookie, control->cookie_len); - } else { - control->cookie = NULL; - control->cookie_len = 0; - } - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "asq:", 4) == 0) { - struct ldb_asq_control *control; - const char *p; - char attr[256]; - int crit, ret; - - attr[0] = '\0'; - p = &(control_strings[i][4]); - ret = sscanf(p, "%d:%255[^$]", &crit, attr); - if ((ret != 2) || (crit < 0) || (crit > 1) || (attr[0] == '\0')) { - fprintf(stderr, "invalid asq control syntax\n"); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_ASQ_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_asq_control); - control->request = 1; - control->source_attribute = talloc_strdup(control, attr); - control->src_attr_len = strlen(attr); - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "extended_dn:", 12) == 0) { - struct ldb_extended_dn_control *control; - const char *p; - int crit, type, ret; - - p = &(control_strings[i][12]); - ret = sscanf(p, "%d:%d", &crit, &type); - if ((ret != 2) || (crit < 0) || (crit > 1) || (type < 0) || (type > 1)) { - fprintf(stderr, "invalid extended_dn control syntax\n"); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_EXTENDED_DN_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_extended_dn_control); - control->type = type; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "paged_results:", 14) == 0) { - struct ldb_paged_control *control; - const char *p; - int crit, size, ret; - - p = &(control_strings[i][14]); - ret = sscanf(p, "%d:%d", &crit, &size); - - if ((ret != 2) || (crit < 0) || (crit > 1) || (size < 0)) { - fprintf(stderr, "invalid paged_results control syntax\n"); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_PAGED_RESULTS_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_paged_control); - control->size = size; - control->cookie = NULL; - control->cookie_len = 0; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "server_sort:", 12) == 0) { - struct ldb_server_sort_control **control; - const char *p; - char attr[256]; - char rule[128]; - int crit, rev, ret; - - attr[0] = '\0'; - rule[0] = '\0'; - p = &(control_strings[i][12]); - ret = sscanf(p, "%d:%d:%255[^:]:%127[^:]", &crit, &rev, attr, rule); - if ((ret < 3) || (crit < 0) || (crit > 1) || (rev < 0 ) || (rev > 1) ||attr[0] == '\0') { - fprintf(stderr, "invalid server_sort control syntax\n"); - return NULL; - } - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_SERVER_SORT_OID; - ctrl[i]->critical = crit; - control = talloc_array(ctrl[i], struct ldb_server_sort_control *, 2); - control[0] = talloc(control, struct ldb_server_sort_control); - control[0]->attributeName = talloc_strdup(control, attr); - if (rule[0]) - control[0]->orderingRule = talloc_strdup(control, rule); - else - control[0]->orderingRule = NULL; - control[0]->reverse = rev; - control[1] = NULL; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "notification:", 13) == 0) { - const char *p; - int crit, ret; - - p = &(control_strings[i][13]); - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - fprintf(stderr, "invalid notification control syntax\n"); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_NOTIFICATION_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = NULL; - - continue; - } - - /* no controls matched, throw an error */ - fprintf(stderr, "Invalid control name\n"); - return NULL; - } - - ctrl[i] = NULL; - - return ctrl; -} - -/* this function check controls reply and determines if more - * processing is needed setting up the request controls correctly - * - * returns: - * -1 error - * 0 all ok - * 1 all ok, more processing required - */ -static int handle_controls_reply(struct ldb_control **reply, struct ldb_control **request) -{ - int i, j; - int ret = 0; - - if (reply == NULL || request == NULL) return -1; - - for (i = 0; reply[i]; i++) { - if (strcmp(LDB_CONTROL_ASQ_OID, reply[i]->oid) == 0) { - struct ldb_asq_control *rep_control; - - rep_control = talloc_get_type(reply[i]->data, struct ldb_asq_control); - - /* check the result */ - if (rep_control->result != 0) { - fprintf(stderr, "Warning: ASQ not performed with error: %d\n", rep_control->result); - } - - continue; - } - if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, reply[i]->oid) == 0) { - struct ldb_paged_control *rep_control, *req_control; - - rep_control = talloc_get_type(reply[i]->data, struct ldb_paged_control); - if (rep_control->cookie_len == 0) /* we are done */ - break; - - /* more processing required */ - /* let's fill in the request control with the new cookie */ - - for (j = 0; request[j]; j++) { - if (strcmp(LDB_CONTROL_PAGED_RESULTS_OID, request[j]->oid) == 0) - break; - } - /* if there's a reply control we must find a request - * control matching it */ - if (! request[j]) return -1; - - req_control = talloc_get_type(request[j]->data, struct ldb_paged_control); - - if (req_control->cookie) - talloc_free(req_control->cookie); - req_control->cookie = talloc_memdup(req_control, - rep_control->cookie, - rep_control->cookie_len); - req_control->cookie_len = rep_control->cookie_len; - - ret = 1; - - continue; - } - - if (strcmp(LDB_CONTROL_SORT_RESP_OID, reply[i]->oid) == 0) { - struct ldb_sort_resp_control *rep_control; - - rep_control = talloc_get_type(reply[i]->data, struct ldb_sort_resp_control); - - /* check we have a matching control in the request */ - for (j = 0; request[j]; j++) { - if (strcmp(LDB_CONTROL_SERVER_SORT_OID, request[j]->oid) == 0) - break; - } - if (! request[j]) { - fprintf(stderr, "Warning Server Sort reply received but no request found\n"); - continue; - } - - /* check the result */ - if (rep_control->result != 0) { - fprintf(stderr, "Warning: Sorting not performed with error: %d\n", rep_control->result); - } - - continue; - } - - if (strcmp(LDB_CONTROL_DIRSYNC_OID, reply[i]->oid) == 0) { - struct ldb_dirsync_control *rep_control, *req_control; - char *cookie; - - rep_control = talloc_get_type(reply[i]->data, struct ldb_dirsync_control); - if (rep_control->cookie_len == 0) /* we are done */ - break; - - /* more processing required */ - /* let's fill in the request control with the new cookie */ - - for (j = 0; request[j]; j++) { - if (strcmp(LDB_CONTROL_DIRSYNC_OID, request[j]->oid) == 0) - break; - } - /* if there's a reply control we must find a request - * control matching it */ - if (! request[j]) return -1; - - req_control = talloc_get_type(request[j]->data, struct ldb_dirsync_control); - - if (req_control->cookie) - talloc_free(req_control->cookie); - req_control->cookie = talloc_memdup(req_control, - rep_control->cookie, - rep_control->cookie_len); - req_control->cookie_len = rep_control->cookie_len; - - cookie = ldb_base64_encode(req_control, rep_control->cookie, rep_control->cookie_len); - printf("# DIRSYNC cookie returned was:\n# %s\n", cookie); - - ret = 1; - - continue; - } - - /* no controls matched, throw a warning */ - fprintf(stderr, "Unknown reply control oid: %s\n", reply[i]->oid); - } - - return ret; -} - - static int do_search(struct ldb_context *ldb, const struct ldb_dn *basedn, struct ldb_cmdline *options, @@ -402,7 +88,7 @@ static int do_search(struct ldb_context *ldb, printf("search failed - %s\n", ldb_errstring(ldb)); if (req.op.search.res && req.op.search.res->controls) { - /* TODO: handle_control */ + /* TODO: handle_control */ } return -1; } -- cgit From cd7553959e194b5695f9fb1b0de01ceb915a2f13 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 26 Jan 2006 16:42:25 +0000 Subject: r13167: handle cotrols' reply even in error (This used to be commit b9d1d02f381cf81883c9f22a1702319f5fce6eb8) --- source4/lib/ldb/tools/ldbsearch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index e3b3a9e6de..08a8b7f179 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -87,8 +87,7 @@ static int do_search(struct ldb_context *ldb, if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); if (req.op.search.res && req.op.search.res->controls) { - - /* TODO: handle_control */ + handle_controls_reply(req.op.search.res->controls, req.controls); } return -1; } -- cgit From ab6a39fa4f6442412f3629c4b9b64feeb1e32b19 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 1 Feb 2006 20:48:05 +0000 Subject: r13289: Check the tree is not NULL Thanks to Aaron J. Seigo for spotting this (This used to be commit 4b5c0493e2276a9eba1bada7c4bac99999a465e2) --- source4/lib/ldb/tools/ldbsearch.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 08a8b7f179..f96c14f5ec 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -74,6 +74,7 @@ static int do_search(struct ldb_context *ldb, req.op.search.base = basedn; req.op.search.scope = options->scope; req.op.search.tree = ldb_parse_tree(ldb, expression); + if (req.op.search.tree == NULL) return -1; req.op.search.attrs = attrs; req.op.search.res = NULL; req.controls = parse_controls(ldb, options->controls); -- cgit From 77445df4b4dcda3e0051d40c2eee29a084264658 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 20 Feb 2006 22:21:21 +0000 Subject: r13580: fix broken client side sort (This used to be commit cbbc0d7cc4f589235d209011bdb0a0401b492d9e) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f96c14f5ec..b4120c0dce 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -97,7 +97,7 @@ static int do_search(struct ldb_context *ldb, printf("# returned %d records\n", result->count); if (options->sorted) { - ldb_qsort(result->msgs, ret, sizeof(struct ldb_message *), + ldb_qsort(result->msgs, result->count, sizeof(struct ldb_message *), ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); } -- cgit From 00fe70e5b917769418f68eaa255d3a06a9a08ce7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 01:31:35 +0000 Subject: r13609: Get in the initial work on making ldb async Currently only ldb_ildap is async, the plan is to first make all backend support the async calls, and then remove the sync functions from backends and keep the only in the API. Modules will need to be transformed along the way. Simo (This used to be commit 1e2c13b2d52de7c534493dd79a2c0596a3e8c1f5) --- source4/lib/ldb/tools/ldbsearch.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index b4120c0dce..c380862c5d 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -64,9 +64,10 @@ static int do_search(struct ldb_context *ldb, const char *expression, const char * const *attrs) { - int ret, i; + int ret, i, n; int loop = 0; int total = 0; + int refs = 0; struct ldb_request req; struct ldb_result *result = NULL; @@ -94,7 +95,6 @@ static int do_search(struct ldb_context *ldb, } result = req.op.search.res; - printf("# returned %d records\n", result->count); if (options->sorted) { ldb_qsort(result->msgs, result->count, sizeof(struct ldb_message *), @@ -120,6 +120,12 @@ static int do_search(struct ldb_context *ldb, ldb_ldif_write_file(ldb, stdout, &ldif); } + if (result->refs) { + for(n = 0;result->refs[n]; n++, refs++) { + printf("# referral %d\nref: %s\n\n", refs + 1, result->refs[n]); + } + } + if (result->controls) { if (handle_controls_reply(result->controls, req.controls) == 1) loop = 1; @@ -137,6 +143,8 @@ static int do_search(struct ldb_context *ldb, } while(loop); + printf("# returned %d records\n# %d entries\n# %d referrals\n", total + refs, total, refs); + return 0; } -- 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/ldbsearch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index c380862c5d..fbf32c0777 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -148,7 +148,7 @@ static int do_search(struct ldb_context *ldb, return 0; } - int main(int argc, const char **argv) +int main(int argc, const char **argv) { struct ldb_context *ldb; struct ldb_dn *basedn = NULL; @@ -157,6 +157,8 @@ static int do_search(struct ldb_context *ldb, int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; + ldb_global_init(); + ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit From 82da2d401e54d0b3124b727fab755d94dd5402d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 8 Mar 2006 01:01:14 +0000 Subject: r13998: From now on ldb_request() will require an alloced request By freeing the request you will be sure everything down the path get freed. this also means you have to steal the results if you want to keep them :) simo. (This used to be commit e8075e6a062ce5edb84485e45d0b841c2ee2af7d) --- source4/lib/ldb/tools/ldbsearch.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index fbf32c0777..77f54fee65 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -68,33 +68,34 @@ static int do_search(struct ldb_context *ldb, int loop = 0; int total = 0; int refs = 0; - struct ldb_request req; + struct ldb_request *req; struct ldb_result *result = NULL; - req.operation = LDB_REQ_SEARCH; - req.op.search.base = basedn; - req.op.search.scope = options->scope; - req.op.search.tree = ldb_parse_tree(ldb, expression); - if (req.op.search.tree == NULL) return -1; - req.op.search.attrs = attrs; - req.op.search.res = NULL; - req.controls = parse_controls(ldb, options->controls); - if (options->controls != NULL && req.controls == NULL) return -1; - req.creds = NULL; + req = talloc(ldb, struct ldb_request); + req->operation = LDB_REQ_SEARCH; + req->op.search.base = basedn; + req->op.search.scope = options->scope; + req->op.search.tree = ldb_parse_tree(ldb, expression); + if (req->op.search.tree == NULL) return -1; + req->op.search.attrs = attrs; + req->op.search.res = NULL; + req->controls = parse_controls(ldb, options->controls); + if (options->controls != NULL && req->controls == NULL) return -1; + req->creds = NULL; do { loop = 0; - ret = ldb_request(ldb, &req); + ret = ldb_request(ldb, req); if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); - if (req.op.search.res && req.op.search.res->controls) { - handle_controls_reply(req.op.search.res->controls, req.controls); + if (req->op.search.res && req->op.search.res->controls) { + handle_controls_reply(req->op.search.res->controls, req->controls); } return -1; } - result = req.op.search.res; + result = req->op.search.res; if (options->sorted) { ldb_qsort(result->msgs, result->count, sizeof(struct ldb_message *), @@ -127,7 +128,7 @@ static int do_search(struct ldb_context *ldb, } if (result->controls) { - if (handle_controls_reply(result->controls, req.controls) == 1) + if (handle_controls_reply(result->controls, req->controls) == 1) loop = 1; } @@ -139,7 +140,7 @@ static int do_search(struct ldb_context *ldb, } } - req.op.search.res = NULL; + req->op.search.res = NULL; } while(loop); -- cgit From fe9312609694011d9201a3d07df2cde5a75eec05 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 1 May 2006 06:49:02 +0000 Subject: r15372: Don't look at possibly undefined controls in failure cases. Andrew Bartlett (This used to be commit 04f383048ae48af6b28052ba6461fe2e476e7c44) --- source4/lib/ldb/tools/ldbsearch.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 77f54fee65..3c36d3be14 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -89,9 +89,6 @@ static int do_search(struct ldb_context *ldb, ret = ldb_request(ldb, req); if (ret != LDB_SUCCESS) { printf("search failed - %s\n", ldb_errstring(ldb)); - if (req->op.search.res && req->op.search.res->controls) { - handle_controls_reply(req->op.search.res->controls, req->controls); - } return -1; } -- cgit From f1655e0298e2178b6551543bae56f37b09ce603f Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 23 May 2006 23:52:05 +0000 Subject: r15846: An async version of ldbsearch (This used to be commit 2c1af6556a2d57df6626a9f0d9fd758602ac3c5c) --- source4/lib/ldb/tools/ldbsearch.c | 245 +++++++++++++++++++++++++++++--------- 1 file changed, 186 insertions(+), 59 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 3c36d3be14..a069614d47 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -58,90 +58,219 @@ static int do_compare_msg(struct ldb_message **el1, return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); } +struct async_context { + struct ldb_control **req_ctrls; + + int sort; + int num_stored; + struct ldb_message **store; + char **refs_store; + + int entries; + int refs; + + int pending; + int status; +}; + +static int store_message(struct ldb_message *msg, struct async_context *actx) { + + actx->store = talloc_realloc(actx, actx->store, struct ldb_message *, actx->num_stored + 2); + if (!actx->store) { + fprintf(stderr, "talloc_realloc failed while storing messages\n"); + return -1; + } + + actx->store[actx->num_stored] = talloc_steal(actx->store, msg); + if (!actx->store[actx->num_stored]) { + fprintf(stderr, "talloc_steal failed while storing messages\n"); + return -1; + } + + actx->num_stored++; + actx->store[actx->num_stored] = NULL; + + return 0; +} + +static int store_referral(char *referral, struct async_context *actx) { + + actx->refs_store = talloc_realloc(actx, actx->refs_store, char *, actx->refs + 2); + if (!actx->refs_store) { + fprintf(stderr, "talloc_realloc failed while storing referrals\n"); + return -1; + } + + actx->refs_store[actx->refs] = talloc_steal(actx->refs_store, referral); + if (!actx->refs_store[actx->refs]) { + fprintf(stderr, "talloc_steal failed while storing referrals\n"); + return -1; + } + + actx->refs++; + actx->refs_store[actx->refs] = NULL; + + return 0; +} + +static int display_message(struct ldb_context *ldb, struct ldb_message *msg, struct async_context *actx) { + struct ldb_ldif ldif; + + actx->entries++; + printf("# record %d\n", actx->entries); + + ldif.changetype = LDB_CHANGETYPE_NONE; + ldif.msg = msg; + + if (actx->sort) { + /* + * Ensure attributes are always returned in the same + * order. For testing, this makes comparison of old + * vs. new much easier. + */ + ldb_msg_sort_elements(ldif.msg); + } + + ldb_ldif_write_file(ldb, stdout, &ldif); + + return 0; +} + +static int display_referral(char *referral, struct async_context *actx) { + + actx->refs++; + printf("# Referral\nref: %s\n\n", referral); + + return 0; +} + +static int search_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct async_context *actx = talloc_get_type(context, struct async_context); + int ret; + + switch (ares->type) { + + case LDB_REPLY_ENTRY: + if (actx->sort) { + ret = store_message(ares->message, actx); + } else { + ret = display_message(ldb, ares->message, actx); + } + break; + + case LDB_REPLY_REFERRAL: + if (actx->sort) { + ret = store_referral(ares->referral, actx); + } else { + ret = display_referral(ares->referral, actx); + } + break; + + case LDB_REPLY_DONE: + if (ares->controls) { + if (handle_controls_reply(ares->controls, actx->req_ctrls) == 1) + actx->pending = 1; + } + ret = 0; + break; + + default: + fprintf(stderr, "unknown Reply Type\n"); + return LDB_ERR_OTHER; + } + + if (talloc_free(ares) == -1) { + fprintf(stderr, "talloc_free failed\n"); + actx->pending = 0; + return LDB_ERR_OPERATIONS_ERROR; + } + + if (ret) { + return LDB_ERR_OPERATIONS_ERROR; + } + + return LDB_SUCCESS; +} + static int do_search(struct ldb_context *ldb, const struct ldb_dn *basedn, struct ldb_cmdline *options, const char *expression, const char * const *attrs) { - int ret, i, n; - int loop = 0; - int total = 0; - int refs = 0; struct ldb_request *req; - struct ldb_result *result = NULL; + struct async_context *actx; + int ret; req = talloc(ldb, struct ldb_request); - req->operation = LDB_REQ_SEARCH; + if (!req) return -1; + + actx = talloc(req, struct async_context); + if (!actx) return -1; + + actx->sort = options->sorted; + actx->num_stored = 0; + actx->store = NULL; + actx->req_ctrls = parse_controls(ldb, options->controls); + if (options->controls != NULL && actx->req_ctrls== NULL) return -1; + actx->entries = 0; + actx->refs = 0; + + req->operation = LDB_ASYNC_SEARCH; req->op.search.base = basedn; req->op.search.scope = options->scope; req->op.search.tree = ldb_parse_tree(ldb, expression); if (req->op.search.tree == NULL) return -1; req->op.search.attrs = attrs; - req->op.search.res = NULL; - req->controls = parse_controls(ldb, options->controls); - if (options->controls != NULL && req->controls == NULL) return -1; + req->controls = actx->req_ctrls; req->creds = NULL; + req->async.context = actx; + req->async.callback = &search_callback; + req->async.timeout = 3600; /* TODO: make this settable by command line */ - do { - loop = 0; +again: + actx->pending = 0; - ret = ldb_request(ldb, req); - if (ret != LDB_SUCCESS) { - printf("search failed - %s\n", ldb_errstring(ldb)); - return -1; - } + ret = ldb_request(ldb, req); + if (ret != LDB_SUCCESS) { + printf("search failed - %s\n", ldb_errstring(ldb)); + return -1; + } - result = req->op.search.res; + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + if (ret != LDB_SUCCESS) { + printf("search error - %s\n", ldb_errstring(ldb)); + return -1; + } - if (options->sorted) { - ldb_qsort(result->msgs, result->count, sizeof(struct ldb_message *), - ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); - } + if (actx->pending) + goto again; - for (i = 0; i < result->count; i++, total++) { - struct ldb_ldif ldif; - printf("# record %d\n", total + 1); - - ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = result->msgs[i]; - - if (options->sorted) { - /* - * Ensure attributes are always returned in the same - * order. For testing, this makes comparison of old - * vs. new much easier. - */ - ldb_msg_sort_elements(ldif.msg); - } - - ldb_ldif_write_file(ldb, stdout, &ldif); - } + if (actx->sort && actx->num_stored != 0) { + int i; - if (result->refs) { - for(n = 0;result->refs[n]; n++, refs++) { - printf("# referral %d\nref: %s\n\n", refs + 1, result->refs[n]); - } + ldb_qsort(actx->store, ret, sizeof(struct ldb_message *), + ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); + + if (ret != 0) { + fprintf(stderr, "An error occurred while sorting messages\n"); + exit(1); } - - if (result->controls) { - if (handle_controls_reply(result->controls, req->controls) == 1) - loop = 1; + + for (i = 0; i < actx->num_stored; i++) { + display_message(ldb, actx->store[i], actx); } - if (result) { - ret = talloc_free(result); - if (ret == -1) { - fprintf(stderr, "talloc_free failed\n"); - exit(1); - } + for (i = 0; i < actx->refs; i++) { + display_referral(actx->refs_store[i], actx); } + } - req->op.search.res = NULL; - - } while(loop); + printf("# returned %d records\n# %d entries\n# %d referrals\n", + actx->entries + actx->refs, actx->entries, actx->refs); - printf("# returned %d records\n# %d entries\n# %d referrals\n", total + refs, total, refs); + talloc_free(req); return 0; } @@ -155,8 +284,6 @@ int main(int argc, const char **argv) int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit From 71152824efbad4dd15886766739b7f00e5efc0d3 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 23 May 2006 23:59:26 +0000 Subject: r15847: We probably want to keep the global init (This used to be commit 35df457fe61e1b1f0746eadba867f7ac149e9600) --- source4/lib/ldb/tools/ldbsearch.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index a069614d47..ba65df49e8 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -284,6 +284,8 @@ int main(int argc, const char **argv) int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; + ldb_global_init(); + ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit From 03703a58d7fe441ec5dcbe1814cea3f55544de55 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 11:57:09 +0000 Subject: r15932: Remove per request creds They have never benn used and make little sense too imo (This used to be commit f0c1d08d50f8a3e25650ac85b178ec7a43e433d9) --- source4/lib/ldb/tools/ldbsearch.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index ba65df49e8..3378ade244 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -224,7 +224,6 @@ static int do_search(struct ldb_context *ldb, if (req->op.search.tree == NULL) return -1; req->op.search.attrs = attrs; req->controls = actx->req_ctrls; - req->creds = NULL; req->async.context = actx; req->async.callback = &search_callback; req->async.timeout = 3600; /* TODO: make this settable by command line */ -- cgit From 2d19dca9c80a5e3990296dde67163fce36ac883d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 30 May 2006 00:33:52 +0000 Subject: r15944: rename LDB_ASYNC_ADD -> LDB_ADD, LDB_ASYNC_MODIFY -> LDB_MODIFY, etc... (This used to be commit 55d97ef88f377ef1dbf7b1774a15cf9035e2f320) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 3378ade244..854360b723 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -217,7 +217,7 @@ static int do_search(struct ldb_context *ldb, actx->entries = 0; actx->refs = 0; - req->operation = LDB_ASYNC_SEARCH; + req->operation = LDB_SEARCH; req->op.search.base = basedn; req->op.search.scope = options->scope; req->op.search.tree = ldb_parse_tree(ldb, expression); -- cgit From ca5accf224dc3ef998235603797b519866b57b1c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Jun 2006 05:28:13 +0000 Subject: r16036: Add a couple of new functions to corretly deal with timeouts. Check timeouts are correctly verified. Some minor fixed and removal of unused code. (This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 854360b723..2c8108c9ad 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -226,7 +226,7 @@ static int do_search(struct ldb_context *ldb, req->controls = actx->req_ctrls; req->async.context = actx; req->async.callback = &search_callback; - req->async.timeout = 3600; /* TODO: make this settable by command line */ + ldb_set_timeout(ldb, req, 0); /* TODO: make this settable by command line */ again: actx->pending = 0; -- cgit From c93817b36d3ff7f44cb7b3e1d1a29e37ec12affe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 16:56:33 +0000 Subject: r17185: Oh, I wanted to do this for sooo long time. Finally acknowledge that ldb is inherently async and does not have a dual personality anymore Rename all ldb_async_XXX functions to ldb_XXX except for ldb_async_result, it is now ldb_reply to reflect the real function of this structure. Simo. (This used to be commit 25fc7354049d62efeba17681ef1cdd326bc3f2ef) --- source4/lib/ldb/tools/ldbsearch.c | 108 +++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 2c8108c9ad..45826f0996 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -58,7 +58,7 @@ static int do_compare_msg(struct ldb_message **el1, return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); } -struct async_context { +struct search_context { struct ldb_control **req_ctrls; int sort; @@ -73,56 +73,56 @@ struct async_context { int status; }; -static int store_message(struct ldb_message *msg, struct async_context *actx) { +static int store_message(struct ldb_message *msg, struct search_context *sctx) { - actx->store = talloc_realloc(actx, actx->store, struct ldb_message *, actx->num_stored + 2); - if (!actx->store) { + sctx->store = talloc_realloc(sctx, sctx->store, struct ldb_message *, sctx->num_stored + 2); + if (!sctx->store) { fprintf(stderr, "talloc_realloc failed while storing messages\n"); return -1; } - actx->store[actx->num_stored] = talloc_steal(actx->store, msg); - if (!actx->store[actx->num_stored]) { + sctx->store[sctx->num_stored] = talloc_steal(sctx->store, msg); + if (!sctx->store[sctx->num_stored]) { fprintf(stderr, "talloc_steal failed while storing messages\n"); return -1; } - actx->num_stored++; - actx->store[actx->num_stored] = NULL; + sctx->num_stored++; + sctx->store[sctx->num_stored] = NULL; return 0; } -static int store_referral(char *referral, struct async_context *actx) { +static int store_referral(char *referral, struct search_context *sctx) { - actx->refs_store = talloc_realloc(actx, actx->refs_store, char *, actx->refs + 2); - if (!actx->refs_store) { + sctx->refs_store = talloc_realloc(sctx, sctx->refs_store, char *, sctx->refs + 2); + if (!sctx->refs_store) { fprintf(stderr, "talloc_realloc failed while storing referrals\n"); return -1; } - actx->refs_store[actx->refs] = talloc_steal(actx->refs_store, referral); - if (!actx->refs_store[actx->refs]) { + sctx->refs_store[sctx->refs] = talloc_steal(sctx->refs_store, referral); + if (!sctx->refs_store[sctx->refs]) { fprintf(stderr, "talloc_steal failed while storing referrals\n"); return -1; } - actx->refs++; - actx->refs_store[actx->refs] = NULL; + sctx->refs++; + sctx->refs_store[sctx->refs] = NULL; return 0; } -static int display_message(struct ldb_context *ldb, struct ldb_message *msg, struct async_context *actx) { +static int display_message(struct ldb_context *ldb, struct ldb_message *msg, struct search_context *sctx) { struct ldb_ldif ldif; - actx->entries++; - printf("# record %d\n", actx->entries); + sctx->entries++; + printf("# record %d\n", sctx->entries); ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = msg; - if (actx->sort) { + if (sctx->sort) { /* * Ensure attributes are always returned in the same * order. For testing, this makes comparison of old @@ -136,41 +136,41 @@ static int display_message(struct ldb_context *ldb, struct ldb_message *msg, str return 0; } -static int display_referral(char *referral, struct async_context *actx) { +static int display_referral(char *referral, struct search_context *sctx) { - actx->refs++; + sctx->refs++; printf("# Referral\nref: %s\n\n", referral); return 0; } -static int search_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { - struct async_context *actx = talloc_get_type(context, struct async_context); + struct search_context *sctx = talloc_get_type(context, struct search_context); int ret; switch (ares->type) { case LDB_REPLY_ENTRY: - if (actx->sort) { - ret = store_message(ares->message, actx); + if (sctx->sort) { + ret = store_message(ares->message, sctx); } else { - ret = display_message(ldb, ares->message, actx); + ret = display_message(ldb, ares->message, sctx); } break; case LDB_REPLY_REFERRAL: - if (actx->sort) { - ret = store_referral(ares->referral, actx); + if (sctx->sort) { + ret = store_referral(ares->referral, sctx); } else { - ret = display_referral(ares->referral, actx); + ret = display_referral(ares->referral, sctx); } break; case LDB_REPLY_DONE: if (ares->controls) { - if (handle_controls_reply(ares->controls, actx->req_ctrls) == 1) - actx->pending = 1; + if (handle_controls_reply(ares->controls, sctx->req_ctrls) == 1) + sctx->pending = 1; } ret = 0; break; @@ -182,7 +182,7 @@ static int search_callback(struct ldb_context *ldb, void *context, struct ldb_as if (talloc_free(ares) == -1) { fprintf(stderr, "talloc_free failed\n"); - actx->pending = 0; + sctx->pending = 0; return LDB_ERR_OPERATIONS_ERROR; } @@ -200,22 +200,22 @@ static int do_search(struct ldb_context *ldb, const char * const *attrs) { struct ldb_request *req; - struct async_context *actx; + struct search_context *sctx; int ret; req = talloc(ldb, struct ldb_request); if (!req) return -1; - actx = talloc(req, struct async_context); - if (!actx) return -1; + sctx = talloc(req, struct search_context); + if (!sctx) return -1; - actx->sort = options->sorted; - actx->num_stored = 0; - actx->store = NULL; - actx->req_ctrls = parse_controls(ldb, options->controls); - if (options->controls != NULL && actx->req_ctrls== NULL) return -1; - actx->entries = 0; - actx->refs = 0; + sctx->sort = options->sorted; + sctx->num_stored = 0; + sctx->store = NULL; + sctx->req_ctrls = parse_controls(ldb, options->controls); + if (options->controls != NULL && sctx->req_ctrls== NULL) return -1; + sctx->entries = 0; + sctx->refs = 0; req->operation = LDB_SEARCH; req->op.search.base = basedn; @@ -223,13 +223,13 @@ static int do_search(struct ldb_context *ldb, req->op.search.tree = ldb_parse_tree(ldb, expression); if (req->op.search.tree == NULL) return -1; req->op.search.attrs = attrs; - req->controls = actx->req_ctrls; - req->async.context = actx; + req->controls = sctx->req_ctrls; + req->async.context = sctx; req->async.callback = &search_callback; ldb_set_timeout(ldb, req, 0); /* TODO: make this settable by command line */ again: - actx->pending = 0; + sctx->pending = 0; ret = ldb_request(ldb, req); if (ret != LDB_SUCCESS) { @@ -237,19 +237,19 @@ again: return -1; } - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + ret = ldb_wait(req->async.handle, LDB_WAIT_ALL); if (ret != LDB_SUCCESS) { printf("search error - %s\n", ldb_errstring(ldb)); return -1; } - if (actx->pending) + if (sctx->pending) goto again; - if (actx->sort && actx->num_stored != 0) { + if (sctx->sort && sctx->num_stored != 0) { int i; - ldb_qsort(actx->store, ret, sizeof(struct ldb_message *), + ldb_qsort(sctx->store, ret, sizeof(struct ldb_message *), ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); if (ret != 0) { @@ -257,17 +257,17 @@ again: exit(1); } - for (i = 0; i < actx->num_stored; i++) { - display_message(ldb, actx->store[i], actx); + for (i = 0; i < sctx->num_stored; i++) { + display_message(ldb, sctx->store[i], sctx); } - for (i = 0; i < actx->refs; i++) { - display_referral(actx->refs_store[i], actx); + for (i = 0; i < sctx->refs; i++) { + display_referral(sctx->refs_store[i], sctx); } } printf("# returned %d records\n# %d entries\n# %d referrals\n", - actx->entries + actx->refs, actx->entries, actx->refs); + sctx->entries + sctx->refs, sctx->entries, sctx->refs); talloc_free(req); -- cgit From 49f68caed20d2a7d1850e493005bdf85929d6365 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 17:21:59 +0000 Subject: r17186: "async" word abuse clean-up part 2 (This used to be commit c6aa60c7e69abf1f83efc150b1c3ed02751c45fc) --- source4/lib/ldb/tools/ldbsearch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 45826f0996..93bb89a1d3 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -224,8 +224,8 @@ static int do_search(struct ldb_context *ldb, if (req->op.search.tree == NULL) return -1; req->op.search.attrs = attrs; req->controls = sctx->req_ctrls; - req->async.context = sctx; - req->async.callback = &search_callback; + req->context = sctx; + req->callback = &search_callback; ldb_set_timeout(ldb, req, 0); /* TODO: make this settable by command line */ again: @@ -237,7 +237,7 @@ again: return -1; } - ret = ldb_wait(req->async.handle, LDB_WAIT_ALL); + ret = ldb_wait(req->handle, LDB_WAIT_ALL); if (ret != LDB_SUCCESS) { printf("search error - %s\n", ldb_errstring(ldb)); return -1; -- cgit From 2b4249e7bac55066d9a7614644d4f6920956fc41 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 19 Aug 2006 20:44:41 +0000 Subject: r17613: style fix (This used to be commit 86fc149ca805e4c801f6251c8c9f2480010b4962) --- source4/lib/ldb/tools/ldbsearch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 93bb89a1d3..6bbd9e2f74 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -136,7 +136,8 @@ static int display_message(struct ldb_context *ldb, struct ldb_message *msg, str return 0; } -static int display_referral(char *referral, struct search_context *sctx) { +static int display_referral(char *referral, struct search_context *sctx) +{ sctx->refs++; printf("# Referral\nref: %s\n\n", referral); -- cgit From a2ca0b5e3cf2e1ac485f7046d67de9fc4e5171f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Aug 2006 06:41:37 +0000 Subject: r17821: changed ldb_search() and the ldbsearch command line utility to automatically work out the basedn when basedn==NULL. The basedn is fetched from the rootDSE defaultNamingContext value (if there is one) This means we don't have to have the defaultNamingContext logic in lots of places. It makes a lot of sense to me to have basedn==NULL mean "use the default, as given by the database" Note that explicitly specifing a basedn of '' is not the same thing, and will not trigger this code The baseDN is cached in a ldb opaque, so we only have to fetch it once (This used to be commit 5d1b66b68fc517ce684f75e466ed5f25e46857d5) --- source4/lib/ldb/tools/ldbsearch.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 6bbd9e2f74..f151164559 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -218,6 +218,10 @@ static int do_search(struct ldb_context *ldb, sctx->entries = 0; sctx->refs = 0; + if (basedn == NULL) { + basedn = ldb_auto_basedn(ldb); + } + req->operation = LDB_SEARCH; req->op.search.base = basedn; req->op.search.scope = options->scope; -- cgit From 88b04ab6e65137079b2dad76d1cea07e7ea9ab80 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 25 Aug 2006 12:59:03 +0000 Subject: r17830: Set the default_basedn (hey, it comes from the "default" naming contex :-) once at connection time, after modules have been loaded. Introduce a function to retrieve the value where needed. (This used to be commit 0caf6a44e03393c645030a9288e7dfd31e97c98b) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f151164559..e6b8a48a95 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -219,7 +219,7 @@ static int do_search(struct ldb_context *ldb, sctx->refs = 0; if (basedn == NULL) { - basedn = ldb_auto_basedn(ldb); + basedn = ldb_get_default_basedn(ldb); } req->operation = LDB_SEARCH; -- cgit From 7f63cebd331793d059b1dbfd2f7d7ce38105c4fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 00:10:38 +0000 Subject: r18436: converted ldb to use talloc_move() instead of talloc_steal() when appropriate. Note that I also removed the error checks that were being done on the result of talloc_steal(). They are pointless as talloc_steal() doesn't have any failure modes that wouldn't cause a segv anyway, and they tend to clutter the code (This used to be commit c0d9e7d473b8e3eb2524a9fc29cf88680f994b36) --- source4/lib/ldb/tools/ldbsearch.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index e6b8a48a95..181d857efc 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -81,12 +81,7 @@ static int store_message(struct ldb_message *msg, struct search_context *sctx) { return -1; } - sctx->store[sctx->num_stored] = talloc_steal(sctx->store, msg); - if (!sctx->store[sctx->num_stored]) { - fprintf(stderr, "talloc_steal failed while storing messages\n"); - return -1; - } - + sctx->store[sctx->num_stored] = talloc_move(sctx->store, msg); sctx->num_stored++; sctx->store[sctx->num_stored] = NULL; @@ -101,12 +96,7 @@ static int store_referral(char *referral, struct search_context *sctx) { return -1; } - sctx->refs_store[sctx->refs] = talloc_steal(sctx->refs_store, referral); - if (!sctx->refs_store[sctx->refs]) { - fprintf(stderr, "talloc_steal failed while storing referrals\n"); - return -1; - } - + sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, referral); sctx->refs++; sctx->refs_store[sctx->refs] = NULL; -- cgit From 05cdd9ccafeeb384792b9ce7ca044bcec1bfc839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:33:51 +0000 Subject: r18439: 2nd try at a talloc_move() api. This type with the ** ptr interface exposed. Unfortunately this generates a large number of type punning warnings. We'll have to find some magic to hide those. (This used to be commit 254cbf09dee5a1e20c47e47a298f1a8d172b41b9) --- source4/lib/ldb/tools/ldbsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 181d857efc..23d8115c20 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -81,7 +81,7 @@ static int store_message(struct ldb_message *msg, struct search_context *sctx) { return -1; } - sctx->store[sctx->num_stored] = talloc_move(sctx->store, msg); + sctx->store[sctx->num_stored] = talloc_move(sctx->store, &msg); sctx->num_stored++; sctx->store[sctx->num_stored] = NULL; @@ -96,7 +96,7 @@ static int store_referral(char *referral, struct search_context *sctx) { return -1; } - sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, referral); + sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, &referral); sctx->refs++; sctx->refs_store[sctx->refs] = NULL; -- cgit From 549dd10f0f4bbc15c47a6da885db5d802b0a9a24 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 16 Oct 2006 12:03:55 +0000 Subject: r19332: ldb_parse_tree leaks (This used to be commit 3e0e2787c1da1c3831e21b163e1370001d725a3d) --- source4/lib/ldb/tools/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 23d8115c20..837dfc9088 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -215,7 +215,7 @@ static int do_search(struct ldb_context *ldb, req->operation = LDB_SEARCH; req->op.search.base = basedn; req->op.search.scope = options->scope; - req->op.search.tree = ldb_parse_tree(ldb, expression); + req->op.search.tree = ldb_parse_tree(req, expression); if (req->op.search.tree == NULL) return -1; req->op.search.attrs = attrs; req->controls = sctx->req_ctrls; -- 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/ldbsearch.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 837dfc9088..7bf9d64fc2 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -54,8 +54,7 @@ static int do_compare_msg(struct ldb_message **el1, struct ldb_message **el2, void *opaque) { - struct ldb_context *ldb = talloc_get_type(opaque, struct ldb_context); - return ldb_dn_compare(ldb, (*el1)->dn, (*el2)->dn); + return ldb_dn_compare((*el1)->dn, (*el2)->dn); } struct search_context { @@ -185,7 +184,7 @@ static int search_callback(struct ldb_context *ldb, void *context, struct ldb_re } static int do_search(struct ldb_context *ldb, - const struct ldb_dn *basedn, + struct ldb_dn *basedn, struct ldb_cmdline *options, const char *expression, const char * const *attrs) @@ -298,8 +297,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)) { fprintf(stderr, "Invalid Base DN format\n"); exit(1); } -- cgit From 7dc7156bd76425df129102a42dd29a85fd8c7ebc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 22 Feb 2007 01:54:40 +0000 Subject: r21496: A number of ldb control and LDAP changes, surrounding the 'phantom_root' flag in the search_options control - Add in support for LDB controls to the js layer - Test the behaviour - Implement support for the 'phantom_root' flag in the partitions module - Make the LDAP server set the 'phantom_root' flag in the search_options control - This replaces the global_catalog flag passed down as an opaque pointer - Rework the string-format control parsing function into ldb_parse_control_strings(), returning errors by ldb_errorstring() method, rather than with printf to stderr - Rework some of the ldb_control handling logic Andrew Bartlett (This used to be commit 2b3df7f38d7790358dbb4de1b8609bf794a351fb) --- source4/lib/ldb/tools/ldbsearch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 7bf9d64fc2..e5b9091b5c 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -202,8 +202,11 @@ static int do_search(struct ldb_context *ldb, sctx->sort = options->sorted; sctx->num_stored = 0; sctx->store = NULL; - sctx->req_ctrls = parse_controls(ldb, options->controls); - if (options->controls != NULL && sctx->req_ctrls== NULL) return -1; + sctx->req_ctrls = ldb_parse_control_strings(ldb, sctx, (const char **)options->controls); + if (options->controls != NULL && sctx->req_ctrls== NULL) { + printf("parsing controls failed: %s\n", ldb_errstring(ldb)); + return -1; + } sctx->entries = 0; sctx->refs = 0; -- 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/ldbsearch.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index e5b9091b5c..d492f98d44 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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 void usage(void) { -- 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/ldbsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index d492f98d44..f436667a80 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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/ldbsearch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index f436667a80..c33cba1d77 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.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 3dab82394ef950148f3da55c7d3179b0c9c05cc2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 Jan 2008 12:47:51 +1100 Subject: Fix segfault when sorting LDAP replies on the client. Andrew Bartlett (This used to be commit c72c39326b263b3aacd178ddc2fc3b1a2906f3d3) --- source4/lib/ldb/tools/ldbsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index c33cba1d77..dba0549b44 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -241,10 +241,10 @@ again: if (sctx->pending) goto again; - if (sctx->sort && sctx->num_stored != 0) { + if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) { int i; - ldb_qsort(sctx->store, ret, sizeof(struct ldb_message *), + ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); if (ret != 0) { -- cgit From f5277a3e2129f713cba3f63ffa96b1706f8d802f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 Jan 2008 13:15:49 +1100 Subject: Rework ldbsearch to avoid segfault when remote LDAP server returns referrals. Andrew Bartlett (This used to be commit 8099facff99dab4de27ea6f857d0e8f5eaa3db5a) --- source4/lib/ldb/tools/ldbsearch.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index dba0549b44..24ceb30963 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -61,6 +61,7 @@ struct search_context { int sort; int num_stored; struct ldb_message **store; + int refs_stored; char **refs_store; int entries; @@ -87,15 +88,15 @@ static int store_message(struct ldb_message *msg, struct search_context *sctx) { static int store_referral(char *referral, struct search_context *sctx) { - sctx->refs_store = talloc_realloc(sctx, sctx->refs_store, char *, sctx->refs + 2); + sctx->refs_store = talloc_realloc(sctx, sctx->refs_store, char *, sctx->refs_stored + 2); if (!sctx->refs_store) { fprintf(stderr, "talloc_realloc failed while storing referrals\n"); return -1; } - sctx->refs_store[sctx->refs] = talloc_move(sctx->refs_store, &referral); - sctx->refs++; - sctx->refs_store[sctx->refs] = NULL; + sctx->refs_store[sctx->refs_stored] = talloc_move(sctx->refs_store, &referral); + sctx->refs_stored++; + sctx->refs_store[sctx->refs_stored] = NULL; return 0; } @@ -199,6 +200,7 @@ static int do_search(struct ldb_context *ldb, sctx->sort = options->sorted; sctx->num_stored = 0; + sctx->refs_stored = 0; sctx->store = NULL; sctx->req_ctrls = ldb_parse_control_strings(ldb, sctx, (const char **)options->controls); if (options->controls != NULL && sctx->req_ctrls== NULL) { @@ -244,19 +246,15 @@ again: if (sctx->sort && (sctx->num_stored != 0 || sctx->refs != 0)) { int i; - ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), - ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); - - if (ret != 0) { - fprintf(stderr, "An error occurred while sorting messages\n"); - exit(1); + if (sctx->num_stored) { + ldb_qsort(sctx->store, sctx->num_stored, sizeof(struct ldb_message *), + ldb, (ldb_qsort_cmp_fn_t)do_compare_msg); } - for (i = 0; i < sctx->num_stored; i++) { display_message(ldb, sctx->store[i], sctx); } - for (i = 0; i < sctx->refs; i++) { + for (i = 0; i < sctx->refs_stored; i++) { display_referral(sctx->refs_store[i], sctx); } } -- 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/ldbsearch.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 24ceb30963..e25bd19965 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -276,8 +276,6 @@ int main(int argc, const char **argv) int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; - 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/ldbsearch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/tools/ldbsearch.c') diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index e25bd19965..b3d1f934a6 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -276,7 +276,10 @@ int main(int argc, const char **argv) int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; - ldb = ldb_init(NULL); + ldb = ldb_init(NULL, NULL); + if (ldb == NULL) { + return -1; + } options = ldb_cmdline_process(ldb, argc, argv, usage); -- cgit