diff options
Diffstat (limited to 'source4/lib/ldb/tools/cmdline.c')
-rw-r--r-- | source4/lib/ldb/tools/cmdline.c | 77 |
1 files changed, 63 insertions, 14 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)); |