[SCM] Samba Shared Repository - branch master updated

Matthieu Patou mat at samba.org
Mon Feb 21 01:48:02 MST 2011


The branch, master has been updated
       via  e37db96 s4: avoid overwritting the dceprc.h file from toplevel librpc
       via  175227b pyldb: add tests for getting control results
       via  95eb302 pyldb: Add tests for the ldb_result object
       via  4c74c5f pyldb: create LdbResult, return value from ldb.search is now a LdbResult
       via  6d48a6d s4-unittests: replace assertEquals(res, []) by assertEquals(len(res), 0)
       via  b1595f4 ldb: controls marshalling/unmarshalling improvement
      from  82fa772 Fix missing dependency on libreplace.

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


- Log -----------------------------------------------------------------
commit e37db96d2ae1ffccaaa79cf4ebb5506386ae45ba
Author: Matthieu Patou <mat at matws.net>
Date:   Sun Feb 20 13:23:48 2011 +0300

    s4: avoid overwritting the dceprc.h file from toplevel librpc
    
    Change back to what was the configuration of header_path before
    177ddcb084e8f8608bf2012a7c58f7b1e56d2acd so that dcerpc.h is installed
    in ${prefix}/include and not in ${prefix}/include/gen_ndr as the
    toplevel librpc wants also to put a dcerpc.h file in this directory.
    
    Add some documentation in order to avoid any new regression.
    
    This change should fix problems for openchange team.
    
    Autobuild-User: Matthieu Patou <mat at samba.org>
    Autobuild-Date: Mon Feb 21 09:47:05 CET 2011 on sn-devel-104

commit 175227bc7195931a264bca17e4993d982480294d
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Feb 9 12:50:35 2011 +0300

    pyldb: add tests for getting control results

commit 95eb3020dee7cf775c59cd2f7ba388821445649d
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Feb 9 11:22:46 2011 +0300

    pyldb: Add tests for the ldb_result object

commit 4c74c5f557f2fe6033f475126ada1f4d601df347
Author: Matthieu Patou <mat at matws.net>
Date:   Mon Feb 7 09:50:36 2011 +0300

    pyldb: create LdbResult, return value from ldb.search is now a LdbResult

commit 6d48a6ddb3af7547d4ad004858808d08ac8d1594
Author: Matthieu Patou <mat at matws.net>
Date:   Wed Feb 9 21:51:34 2011 +0300

    s4-unittests: replace assertEquals(res, []) by assertEquals(len(res), 0)

commit b1595f40c506bb180758b5ee60122de5e29e0ccd
Author: Matthieu Patou <mat at matws.net>
Date:   Sun Feb 20 15:23:27 2011 +0300

    ldb: controls marshalling/unmarshalling improvement
    
    Add a function to marshall a control to a string
    Refactor the code of ldb_control_parse_strings to allow to extract the
    core code into ldb_control_parse_from_string so that this function can
    be called for just 1 string

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

Summary of changes:
 source4/dsdb/tests/python/acl.py                   |   48 +-
 source4/dsdb/tests/python/ldap.py                  |    8 +
 source4/dsdb/tests/python/sec_descriptor.py        |    2 +-
 .../ldb/ABI/{ldb-0.9.24.sigs => ldb-1.0.2.sigs}    |    2 +
 source4/lib/ldb/common/ldb_controls.c              | 1282 ++++++++++----------
 source4/lib/ldb/include/ldb.h                      |   19 +
 source4/lib/ldb/pyldb.c                            |  323 +++++-
 source4/lib/ldb/pyldb.h                            |   14 +
 source4/lib/ldb/tests/python/api.py                |   87 ++
 source4/lib/ldb/wscript                            |    2 +-
 source4/librpc/wscript_build                       |    9 +-
 .../python/samba/tests/upgradeprovision.py         |    2 +-
 12 files changed, 1143 insertions(+), 655 deletions(-)
 copy source4/lib/ldb/ABI/{ldb-0.9.24.sigs => ldb-1.0.2.sigs} (99%)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/tests/python/acl.py b/source4/dsdb/tests/python/acl.py
index 2902f25..b131951 100755
--- a/source4/dsdb/tests/python/acl.py
+++ b/source4/dsdb/tests/python/acl.py
@@ -153,7 +153,7 @@ class AclAddTests(AclTests):
         res = self.ldb_admin.search(self.base_dn,
             expression="(distinguishedName=%s,%s)" % (
                 "OU=test_add_ou1", self.base_dn))
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
 
     def test_add_u1(self):
         """Testing OU with the rights of Doman Admin not creator of the OU """
@@ -193,9 +193,9 @@ class AclAddTests(AclTests):
             self.fail()
         # Make sure we HAVEN'T created any of two objects -- user or group
         res = self.ldb_admin.search(self.base_dn, expression="(distinguishedName=%s,%s)" % ("CN=test_add_user1,OU=test_add_ou2,OU=test_add_ou1", self.base_dn))
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn, expression="(distinguishedName=%s,%s)" % ("CN=test_add_group1,OU=test_add_ou2,OU=test_add_ou1", self.base_dn))
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
 
     def test_add_u3(self):
         """Testing OU with the rights of regular user granted the right 'Create User child objects' """
@@ -225,7 +225,7 @@ class AclAddTests(AclTests):
                 expression="(distinguishedName=%s,%s)" %
                 ("CN=test_add_group1,OU=test_add_ou2,OU=test_add_ou1",
                     self.base_dn) )
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
 
     def test_add_u4(self):
         """ 4 Testing OU with the rights of Doman Admin creator of the OU"""
@@ -627,7 +627,7 @@ class AclSearchTests(AclTests):
         res = self.ldb_admin.search(base=self.base_dn, scope=SCOPE_SUBTREE, \
                 expression="distinguishedName=%s" % object_dn)
         # Make sure top testing OU has been deleted before starting the test
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         self.ldb_admin.create_ou(object_dn)
         desc_sddl = self.sd_utils.get_sd_as_sddl(object_dn)
         # Make sure there are inheritable ACEs initially
@@ -925,7 +925,7 @@ class AclSearchTests(AclTests):
         res = self.ldb_user.search("OU=ou1," + self.base_dn, expression="(ou=ou3)",
                                     scope=SCOPE_SUBTREE)
         #nothing should be returned as ou is not accessible
-        self.assertEquals(res, [])
+        self.assertEquals(len(res), 0)
 
         #give read property on ou and assert user can only see dn and ou
         mod = "(OA;;RP;bf9679f0-0de6-11d0-a285-00aa003049e2;;%s)" % (str(self.user_sid))
@@ -986,7 +986,7 @@ class AclDeleteTests(AclTests):
         self.ldb_user.delete(user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
 
     def test_delete_u3(self):
         """User indentified by SID has RIGHT_DELETE to another User object"""
@@ -999,7 +999,7 @@ class AclDeleteTests(AclTests):
         self.ldb_user.delete(user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
 
     def test_delete_anonymous(self):
         """Test add operation with anonymous user"""
@@ -1078,10 +1078,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u3(self):
         """Test rename with rights granted to 'User object' SID"""
@@ -1098,10 +1098,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u4(self):
         """Rename 'User object' cross OU with WP, SD and CC right granted on reg. user to AU"""
@@ -1121,10 +1121,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u5(self):
         """Test rename with rights granted to 'User object' SID"""
@@ -1145,10 +1145,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u6(self):
         """Rename 'User object' cross OU with WP, DC and CC right granted on OU & user to AU"""
@@ -1171,10 +1171,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u7(self):
         """Rename 'User object' cross OU (second level) with WP, DC and CC right granted on OU to AU"""
@@ -1196,10 +1196,10 @@ class AclRenameTests(AclTests):
         self.ldb_user.rename(user_dn, rename_user_dn)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % user_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn,
                 expression="(distinguishedName=%s)" % rename_user_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
     def test_rename_u8(self):
         """Test rename on an object with and without modify access on the RDN attribute"""
@@ -1226,9 +1226,9 @@ class AclRenameTests(AclTests):
         self.sd_utils.dacl_add_ace(ou2_dn, mod)
         self.ldb_user.rename(ou2_dn, ou3_dn)
         res = self.ldb_admin.search(self.base_dn, expression="(distinguishedName=%s)" % ou2_dn)
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         res = self.ldb_admin.search(self.base_dn, expression="(distinguishedName=%s)" % ou3_dn)
-        self.assertNotEqual(res, [])
+        self.assertNotEqual(len(res), 0)
 
 #tests on Control Access Rights
 class AclCARTests(AclTests):
@@ -1547,14 +1547,14 @@ class AclExtendedTests(AclTests):
         #u2 must not read the descriptor
         res = self.ldb_user2.search("CN=ext_group1,OU=ext_ou1," + self.base_dn,
                                     SCOPE_BASE, None, ["nTSecurityDescriptor"])
-        self.assertNotEqual(res,[])
+        self.assertNotEqual(len(res), 0)
         self.assertFalse("nTSecurityDescriptor" in res[0].keys())
         #grant RC to u2 - still no access
         mod = "(A;;RC;;;%s)" % str(self.user_sid2)
         self.sd_utils.dacl_add_ace("CN=ext_group1,OU=ext_ou1," + self.base_dn, mod)
         res = self.ldb_user2.search("CN=ext_group1,OU=ext_ou1," + self.base_dn,
                                     SCOPE_BASE, None, ["nTSecurityDescriptor"])
-        self.assertNotEqual(res,[])
+        self.assertNotEqual(len(res), 0)
         self.assertFalse("nTSecurityDescriptor" in res[0].keys())
         #u3 is member of administrators group, should be able to read sd
         res = self.ldb_user3.search("CN=ext_group1,OU=ext_ou1," + self.base_dn,
diff --git a/source4/dsdb/tests/python/ldap.py b/source4/dsdb/tests/python/ldap.py
index d67ccc4..d324d40 100755
--- a/source4/dsdb/tests/python/ldap.py
+++ b/source4/dsdb/tests/python/ldap.py
@@ -2584,6 +2584,14 @@ nTSecurityDescriptor:: """ + desc_base64
         # restore old value
         self.ldb.set_dsheuristics(dsheuristics)
 
+    def test_ldapControlReturn(self):
+        """Testing that if we request a control that return a control it
+           really return something"""
+        res = self.ldb.search(attrs=["cn"],
+                              controls=["paged_result:1:10"])
+        self.assertEquals(len(res.controls), 1)
+        self.assertEquals(res.controls[0].oid, "1.2.840.113556.1.4.319")
+
 
 class BaseDnTests(unittest.TestCase):
 
diff --git a/source4/dsdb/tests/python/sec_descriptor.py b/source4/dsdb/tests/python/sec_descriptor.py
index 705bf89..b3e6207 100755
--- a/source4/dsdb/tests/python/sec_descriptor.py
+++ b/source4/dsdb/tests/python/sec_descriptor.py
@@ -1262,7 +1262,7 @@ class DaclDescriptorTests(DescriptorTests):
         res = self.ldb_admin.search(base=self.base_dn, scope=SCOPE_SUBTREE, \
                 expression="distinguishedName=%s" % object_dn)
         # Make sure top testing OU has been deleted before starting the test
-        self.assertEqual(res, [])
+        self.assertEqual(len(res), 0)
         self.ldb_admin.create_ou(object_dn)
         desc_sddl = self.sd_utils.get_sd_as_sddl(object_dn)
         # Make sure there are inheritable ACEs initially
diff --git a/source4/lib/ldb/ABI/ldb-0.9.24.sigs b/source4/lib/ldb/ABI/ldb-1.0.2.sigs
similarity index 99%
copy from source4/lib/ldb/ABI/ldb-0.9.24.sigs
copy to source4/lib/ldb/ABI/ldb-1.0.2.sigs
index 5cb32f7..c13ac87 100644
--- a/source4/lib/ldb/ABI/ldb-0.9.24.sigs
+++ b/source4/lib/ldb/ABI/ldb-1.0.2.sigs
@@ -24,6 +24,7 @@ ldb_check_critical_controls: int (struct ldb_control **)
 ldb_comparison_binary: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *)
 ldb_comparison_fold: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *)
 ldb_connect: int (struct ldb_context *, const char *, unsigned int, const char **)
+ldb_control_to_string: char *(TALLOC_CTX *, const struct ldb_control *)
 ldb_controls_except_specified: struct ldb_control **(struct ldb_control **, TALLOC_CTX *, struct ldb_control *)
 ldb_debug: void (struct ldb_context *, enum ldb_debug_level, const char *, ...)
 ldb_debug_add: void (struct ldb_context *, const char *, ...)
@@ -180,6 +181,7 @@ ldb_next_request: int (struct ldb_module *, struct ldb_request *)
 ldb_next_start_trans: int (struct ldb_module *)
 ldb_op_default_callback: int (struct ldb_request *, struct ldb_reply *)
 ldb_options_find: const char *(struct ldb_context *, const char **, const char *)
+ldb_parse_control_from_string: struct ldb_control *(struct ldb_context *, TALLOC_CTX *, const char *)
 ldb_parse_control_strings: struct ldb_control **(struct ldb_context *, TALLOC_CTX *, const char **)
 ldb_parse_tree: struct ldb_parse_tree *(TALLOC_CTX *, const char *)
 ldb_parse_tree_attr_replace: void (struct ldb_parse_tree *, const char *, const char *)
diff --git a/source4/lib/ldb/common/ldb_controls.c b/source4/lib/ldb/common/ldb_controls.c
index f3770b0..8c72250 100644
--- a/source4/lib/ldb/common/ldb_controls.c
+++ b/source4/lib/ldb/common/ldb_controls.c
@@ -257,6 +257,120 @@ int ldb_request_replace_control(struct ldb_request *req, const char *oid, bool c
 }
 
 /*
+ * Return a control as string
+ * the project (ie. name:value1:value2:...:valuen
+ * The string didn't include the criticity of the critical flag
+ */
+char *ldb_control_to_string(TALLOC_CTX *mem_ctx, const struct ldb_control *control)
+{
+	char *res = NULL;
+
+	if (strcmp(control->oid, LDB_CONTROL_PAGED_RESULTS_OID) == 0) {
+		struct ldb_paged_control *rep_control = talloc_get_type(control->data, struct ldb_paged_control);
+		char *cookie;
+
+		cookie = ldb_base64_encode(mem_ctx, rep_control->cookie, rep_control->cookie_len);
+		if (cookie == NULL) {
+			return NULL;
+		}
+		if (cookie[0] != '\0') {
+			res = talloc_asprintf(mem_ctx, "%s:%d:%s",
+						LDB_CONTROL_PAGED_RESULTS_NAME,
+						control->critical,
+						cookie);
+
+			talloc_free(cookie);
+		} else {
+			res = talloc_asprintf(mem_ctx, "%s:%d",
+						LDB_CONTROL_PAGED_RESULTS_NAME,
+						control->critical);
+		}
+		return res;
+	}
+
+	if (strcmp(control->oid, LDB_CONTROL_VLV_RESP_OID) == 0) {
+		struct ldb_vlv_resp_control *rep_control = talloc_get_type(control->data,
+								struct ldb_vlv_resp_control);
+
+		res = talloc_asprintf(mem_ctx, "%s:%d:%d:%d:%d:%d:%s",
+						LDB_CONTROL_VLV_RESP_NAME,
+						control->critical,
+						rep_control->targetPosition,
+						rep_control->contentCount,
+						rep_control->vlv_result,
+						rep_control->ctxid_len,
+						rep_control->contextId);
+
+		return res;
+	}
+
+	if (strcmp(control->oid, LDB_CONTROL_SORT_RESP_OID) == 0) {
+		struct ldb_sort_resp_control *rep_control = talloc_get_type(control->data,
+								struct ldb_sort_resp_control);
+
+		res = talloc_asprintf(mem_ctx, "%s:%d:%d:%s",
+					LDB_CONTROL_SORT_RESP_NAME,
+					control->critical,
+					rep_control->result,
+					rep_control->attr_desc);
+
+		return res;
+	}
+
+	if (strcmp(control->oid, LDB_CONTROL_ASQ_OID) == 0) {
+		struct ldb_asq_control *rep_control = talloc_get_type(control->data,
+								struct ldb_asq_control);
+
+		res = talloc_asprintf(mem_ctx, "%s:%d:%d",
+					LDB_CONTROL_SORT_RESP_NAME,
+					control->critical,
+					rep_control->result);
+
+		return res;
+	}
+
+	if (strcmp(control->oid, LDB_CONTROL_DIRSYNC_OID) == 0) {
+		char *cookie;
+		struct ldb_dirsync_control *rep_control = talloc_get_type(control->data,
+								struct ldb_dirsync_control);
+
+		cookie = ldb_base64_encode(mem_ctx, rep_control->cookie,
+				rep_control->cookie_len);
+		if (cookie == NULL) {
+			return NULL;
+		}
+		res = talloc_asprintf(mem_ctx, "%s:%d:%d:%d:%s",
+					LDB_CONTROL_DIRSYNC_NAME,
+					control->critical,
+					rep_control->flags,
+					rep_control->max_attributes,
+					cookie);
+
+		talloc_free(cookie);
+		return res;
+	}
+
+	/*
+	 * From here we don't know the control
+	 */
+	if (control->data == NULL) {
+		/*
+		 * We don't know the control but there is no real data attached to it
+		 * so we can represent it with local_oid:oid:criticity
+		 */
+		res = talloc_asprintf(mem_ctx, "local_oid:%s:%d",
+					control->oid,
+					control->critical);
+		return res;
+	}
+
+		res = talloc_asprintf(mem_ctx, "unknown oid:%s",
+					control->oid);
+	return res;
+}
+
+
+/*
  * A little trick to allow to use constants defined in headers rather than
  * hardwritten in the file hardwritten in the file
  * sizeof will return the \0 char as well so it will take the place of ":" in the
@@ -264,718 +378,642 @@ int ldb_request_replace_control(struct ldb_request *req, const char *oid, bool c
  */
 #define LDB_CONTROL_CMP(control, NAME) strncmp(control, NAME ":", sizeof(NAME))
 
-/* Parse controls from the format used on the command line and in ejs */
-struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char **control_strings)
+/* Parse one string and return associated control if parsing is successful*/
+struct ldb_control *ldb_parse_control_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *control_strings)
 {
-	unsigned int i;
-	struct ldb_control **ctrl;
-
+	struct ldb_control *ctrl;
 	char *error_string = NULL;
 
-	if (control_strings == NULL || control_strings[0] == NULL)
+	if (!(ctrl = talloc(mem_ctx, struct ldb_control))) {
+		ldb_oom(ldb);
 		return NULL;
+	}
 
-	for (i = 0; control_strings[i]; i++);
+	if (LDB_CONTROL_CMP(control_strings,
+				LDB_CONTROL_VLV_REQ_NAME) == 0) {
+		struct ldb_vlv_req_control *control;
+		const char *p;
+		char attr[1024];
+		char ctxid[1024];
+		int crit, bc, ac, os, cc, ret;
+
+		attr[0] = '\0';
+		ctxid[0] = '\0';
+		p = &(control_strings[sizeof(LDB_CONTROL_VLV_REQ_NAME)]);
+		ret = sscanf(p, "%d:%d:%d:%d:%d:%1023[^$]", &crit, &bc, &ac, &os, &cc, ctxid);
+		if (ret < 5) {
+			ret = sscanf(p, "%d:%d:%d:%1023[^:]:%1023[^$]", &crit, &bc, &ac, attr, ctxid);
+		}
+			
+		if ((ret < 4) || (crit < 0) || (crit > 1)) {
+			error_string = talloc_asprintf(mem_ctx, "invalid server_sort control syntax\n");
+			error_string = talloc_asprintf_append(error_string, " syntax: crit(b):bc(n):ac(n):<os(n):cc(n)|attr(s)>[:ctxid(o)]\n");
+			error_string = talloc_asprintf_append(error_string, "   note: b = boolean, n = number, s = string, o = b64 binary blob");
+			ldb_set_errstring(ldb, error_string);
+			talloc_free(error_string);
+			return NULL;
+		}
+		ctrl->oid = LDB_CONTROL_VLV_REQ_OID;
+		ctrl->critical = crit;
+		if (!(control = talloc(ctrl,
+					struct ldb_vlv_req_control))) {
+			ldb_oom(ldb);
+			return NULL;
+		}
+		control->beforeCount = bc;
+		control->afterCount = ac;
+		if (attr[0]) {
+			control->type = 1;
+			control->match.gtOrEq.value = talloc_strdup(control, attr);
+			control->match.gtOrEq.value_len = strlen(attr);
+		} else {
+			control->type = 0;
+			control->match.byOffset.offset = os;
+			control->match.byOffset.contentCount = cc;
+		}
+		if (ctxid[0]) {
+			control->ctxid_len = ldb_base64_decode(ctxid);
+			control->contextId = (char *)talloc_memdup(control, ctxid, control->ctxid_len);
+		} else {
+			control->ctxid_len = 0;
+			control->contextId = NULL;
+		}
+		ctrl->data = control;
 
-	ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1);
+		return ctrl;
+	}
 
-	for (i = 0; control_strings[i]; i++) {
-		if (LDB_CONTROL_CMP(control_strings[i],
-					LDB_CONTROL_VLV_REQ_NAME) == 0) {
-			struct ldb_vlv_req_control *control;
-			const char *p;
-			char attr[1024];
-			char ctxid[1024];
-			int crit, bc, ac, os, cc, ret;
-
-			attr[0] = '\0';
-			ctxid[0] = '\0';
-			p = &(control_strings[i][sizeof(LDB_CONTROL_VLV_REQ_NAME)]);
-			ret = sscanf(p, "%d:%d:%d:%d:%d:%1023[^$]", &crit, &bc, &ac, &os, &cc, ctxid);
-			if (ret < 5) {
-				ret = sscanf(p, "%d:%d:%d:%1023[^:]:%1023[^$]", &crit, &bc, &ac, attr, ctxid);
-			}
-			       
-			if ((ret < 4) || (crit < 0) || (crit > 1)) {
-				error_string = talloc_asprintf(mem_ctx, "invalid server_sort control syntax\n");
-				error_string = talloc_asprintf_append(error_string, " syntax: crit(b):bc(n):ac(n):<os(n):cc(n)|attr(s)>[:ctxid(o)]\n");
-				error_string = talloc_asprintf_append(error_string, "   note: b = boolean, n = number, s = string, o = b64 binary blob");
-				ldb_set_errstring(ldb, error_string);
-				talloc_free(error_string);
-				return NULL;
-			}
-			if (!(ctrl[i] = talloc(ctrl, struct ldb_control))) {
-				ldb_oom(ldb);
-				return NULL;
-			}
-			ctrl[i]->oid = LDB_CONTROL_VLV_REQ_OID;
-			ctrl[i]->critical = crit;
-			if (!(control = talloc(ctrl[i],
-					       struct ldb_vlv_req_control))) {
-				ldb_oom(ldb);
-				return NULL;
-			}
-			control->beforeCount = bc;
-			control->afterCount = ac;
-			if (attr[0]) {
-				control->type = 1;
-				control->match.gtOrEq.value = talloc_strdup(control, attr);
-				control->match.gtOrEq.value_len = strlen(attr);
-			} else {
-				control->type = 0;
-				control->match.byOffset.offset = os;
-				control->match.byOffset.contentCount = cc;
-			}
-			if (ctxid[0]) {
-				control->ctxid_len = ldb_base64_decode(ctxid);
-				control->contextId = (char *)talloc_memdup(control, ctxid, control->ctxid_len);
-			} else {
-				control->ctxid_len = 0;
-				control->contextId = NULL;
-			}
-			ctrl[i]->data = control;
+	if (LDB_CONTROL_CMP(control_strings, LDB_CONTROL_DIRSYNC_NAME) == 0) {
+		struct ldb_dirsync_control *control;
+		const char *p;
+		char cookie[1024];
+		int crit, flags, max_attrs, ret;
+		
+		cookie[0] = '\0';
+		p = &(control_strings[sizeof(LDB_CONTROL_DIRSYNC_NAME)]);
+		ret = sscanf(p, "%d:%d:%d:%1023[^$]", &crit, &flags, &max_attrs, cookie);
+
+		if ((ret < 3) || (crit < 0) || (crit > 1) || (flags < 0) || (max_attrs < 0)) {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list