[SCM] Samba Shared Repository - branch master updated

Andrew Tridgell tridge at samba.org
Sat Nov 28 03:58:52 MST 2009


The branch, master has been updated
       via  8a34cf6... s4-ldb: make it much easier to use common ldb controls
      from  1287c1d... s4-drs: cope with bogus empty attributes from w2k8-r2

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 8a34cf6f51b29f2bb8ff210afb998c3822e65092
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Nov 28 17:35:36 2009 +1100

    s4-ldb: make it much easier to use common ldb controls

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/ldb/tools/cmdline.c |   77 ++++++++++++++++++++++++++++++++-------
 source4/lib/ldb/tools/cmdline.h |    2 +-
 2 files changed, 64 insertions(+), 15 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index f0cd0a3..522bbed 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 28061a5..52e7ece 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;
 };


-- 
Samba Shared Repository


More information about the samba-cvs mailing list