summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-11-28 17:35:36 +1100
committerAndrew Tridgell <tridge@samba.org>2009-11-28 21:58:04 +1100
commit8a34cf6f51b29f2bb8ff210afb998c3822e65092 (patch)
treec820080e57c63090fe2c9392d0dcb8deda51be8e /source4/lib
parent1287c1d115fb7e8f3954bc05ff65007968403a9c (diff)
downloadsamba-8a34cf6f51b29f2bb8ff210afb998c3822e65092.tar.gz
samba-8a34cf6f51b29f2bb8ff210afb998c3822e65092.tar.bz2
samba-8a34cf6f51b29f2bb8ff210afb998c3822e65092.zip
s4-ldb: make it much easier to use common ldb controls
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/tools/cmdline.c77
-rw-r--r--source4/lib/ldb/tools/cmdline.h2
2 files changed, 64 insertions, 15 deletions
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index f0cd0a3a60..522bbed049 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -58,6 +58,11 @@ static struct poptOption popt_options[] = {
{ NULL, 'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
{ "controls", 0, POPT_ARG_STRING, NULL, 'c', "controls", NULL },
{ "show-binary", 0, POPT_ARG_NONE, &options.show_binary, 0, "display binary LDIF", NULL },
+ { "paged", 0, POPT_ARG_NONE, NULL, 'P', "use a paged search", NULL },
+ { "show-deleted", 0, POPT_ARG_NONE, NULL, 'D', "show deleted objects", NULL },
+ { "show-recycled", 0, POPT_ARG_NONE, NULL, 'R', "show recycled objects", NULL },
+ { "cross-ncs", 0, POPT_ARG_NONE, NULL, 'N', "search across NC boundaries", NULL },
+ { "extended-dn", 0, POPT_ARG_NONE, NULL, 'E', "show extended DNs", NULL },
#if (_SAMBA_BUILD_ >= 4)
POPT_COMMON_SAMBA
POPT_COMMON_CREDENTIALS
@@ -75,6 +80,25 @@ void ldb_cmdline_help(const char *cmdname, FILE *f)
poptPrintHelp(pc, f, 0);
}
+/*
+ add a control to the options structure
+ */
+static bool add_control(TALLOC_CTX *mem_ctx, const char *control)
+{
+ int i;
+
+ /* count how many controls we already have */
+ for (i=0; options.controls && options.controls[i]; i++) ;
+
+ options.controls = talloc_realloc(mem_ctx, options.controls, const char *, i + 2);
+ if (options.controls == NULL) {
+ return false;
+ }
+ options.controls[i] = control;
+ options.controls[i+1] = NULL;
+ return true;
+}
+
/**
process command line options
*/
@@ -162,32 +186,57 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
case 'c': {
const char *cs = poptGetOptArg(pc);
- const char *p, *q;
- int cc;
+ const char *p;
- for (p = cs, cc = 1; (q = strchr(p, ',')); cc++, p = q + 1) ;
-
- options.controls = talloc_array(ret, char *, cc + 1);
- if (options.controls == NULL) {
- fprintf(stderr, "Out of memory!\n");
- goto failed;
- }
- for (p = cs, cc = 0; p != NULL; cc++) {
- const char *t;
+ for (p = cs; p != NULL; ) {
+ const char *t, *c;
t = strchr(p, ',');
if (t == NULL) {
- options.controls[cc] = talloc_strdup(options.controls, p);
+ c = talloc_strdup(options.controls, p);
p = NULL;
} else {
- options.controls[cc] = talloc_strndup(options.controls, p, t-p);
+ c = talloc_strndup(options.controls, p, t-p);
p = t + 1;
}
+ if (c == NULL || !add_control(ret, c)) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
}
- options.controls[cc] = NULL;
break;
}
+ case 'P':
+ if (!add_control(ret, "paged_results:1:1024")) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
+ break;
+ case 'D':
+ if (!add_control(ret, "show_deleted:1")) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
+ break;
+ case 'R':
+ if (!add_control(ret, "show_recycled:1")) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
+ break;
+ case 'N':
+ if (!add_control(ret, "search_options:1:2")) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
+ break;
+ case 'E':
+ if (!add_control(ret, "extended_dn:1")) {
+ fprintf(stderr, __location__ ": out of memory\n");
+ goto failed;
+ }
+ break;
default:
fprintf(stderr, "Invalid option %s: %s\n",
poptBadOption(pc, 0), poptStrerror(opt));
diff --git a/source4/lib/ldb/tools/cmdline.h b/source4/lib/ldb/tools/cmdline.h
index 28061a5a7d..52e7eceabf 100644
--- a/source4/lib/ldb/tools/cmdline.h
+++ b/source4/lib/ldb/tools/cmdline.h
@@ -43,7 +43,7 @@ struct ldb_cmdline {
const char *sasl_mechanism;
const char *input;
const char *output;
- char **controls;
+ const char **controls;
int show_binary;
int tracing;
};