[SCM] Samba Shared Repository - branch master updated

Kamen Mazdrashki kamenim at samba.org
Tue Oct 26 16:45:01 MDT 2010


The branch, master has been updated
       via  e5ebc48 s4-dsdb_syntax: *_OID_oid_ldb_to_drsuapi() functions should use
       via  6a6c7c9 s4-pfm_test: no need to test created prefixMap contents here - it already tested
       via  45e1c0c s4-pfm_test: Tests for dsdb_schema_pfm_attid_from_oid()
       via  0fc2427 s4-prefixMap: split dsdb_schema_make_attid() function into read-only and
       via  5e108fc s4-prefixmap: Use WERR_NOT_FOUND when OID is not found in current prefixMap
      from  d8e246c Add a script for formating test result of st/subunit

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


- Log -----------------------------------------------------------------
commit e5ebc486975cc172d9547b34151204c58f0d14c2
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Oct 26 22:14:43 2010 +0300

    s4-dsdb_syntax: *_OID_oid_ldb_to_drsuapi() functions should use
    
    dsdb_schema_pfm_attid_from_oid() instead of
    dsdb_schema_pfm_make_attid() as those functions are
    supposed to return ATTIDs only for OIDs we already know about
    (i.e. are in prefixMap)
    
    Autobuild-User: Kamen Mazdrashki <kamenim at samba.org>
    Autobuild-Date: Tue Oct 26 22:44:36 UTC 2010 on sn-devel-104

commit 6a6c7c9aa2a8a04d6c1b6c6c8c5841efa4cb8e09
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Oct 26 21:20:11 2010 +0300

    s4-pfm_test: no need to test created prefixMap contents here - it already tested

commit 45e1c0c151b6a98858a6cc580ded6a1ffff51afc
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Oct 26 21:17:55 2010 +0300

    s4-pfm_test: Tests for dsdb_schema_pfm_attid_from_oid()

commit 0fc2427224c2826e5ee0b09631ae77d0b08b5ba9
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Tue Oct 26 18:33:32 2010 +0300

    s4-prefixMap: split dsdb_schema_make_attid() function into read-only and
    
    read-write functions.
    dsdb_schema_make_attid() may change prefixMap implicitly
    and this is not always desired behavior.
    The problem was that
    (1) callers had no control on this behavior
    (2) callers had no way to know wheter prefixMap has been
        changed which can lead to hard to find bugs like
        prefixMap is changed in read operation

commit 5e108fc5f94e6a08083f8852a59fc4b79b198af8
Author: Kamen Mazdrashki <kamenim at samba.org>
Date:   Fri Oct 22 16:22:08 2010 +0300

    s4-prefixmap: Use WERR_NOT_FOUND when OID is not found in current prefixMap
    
    rather than WERR_DS_NO_MSDS_INTID.
    WERR_DS_NO_MSDS_INTID is intended to be used for msDsIntId
    attribute values handling

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

Summary of changes:
 source4/dsdb/samdb/ldb_modules/schema_data.c |    2 +-
 source4/dsdb/schema/schema_init.c            |    2 +-
 source4/dsdb/schema/schema_prefixmap.c       |   41 ++++++++-
 source4/dsdb/schema/schema_syntax.c          |   12 ++--
 source4/torture/drs/unit/prefixmap_tests.c   |  120 +++++++++++++++++++++++++-
 5 files changed, 164 insertions(+), 13 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/samdb/ldb_modules/schema_data.c b/source4/dsdb/samdb/ldb_modules/schema_data.c
index 7b7d7d0..4818a54 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_data.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_data.c
@@ -191,7 +191,7 @@ static int schema_data_add(struct ldb_module *module, struct ldb_request *req)
 	status = dsdb_schema_pfm_find_oid(schema->prefixmap, oid, NULL);
 	if (!W_ERROR_IS_OK(status)) {
 		/* check for internal errors */
-		if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
+		if (!W_ERROR_EQUAL(status, WERR_NOT_FOUND)) {
 			ldb_debug_set(ldb, LDB_DEBUG_ERROR,
 			              "schema_data_add: failed to map %s[%s]: %s\n",
 			              oid_attr, oid, win_errstr(status));
diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c
index d80f209..4e1c14d 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -233,7 +233,7 @@ WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *s
 		/* prefix found*/
 		talloc_free(mem_ctx);
 		return status;
-	} else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
+	} else if (!W_ERROR_EQUAL(status, WERR_NOT_FOUND)) {
 		/* error */
 		DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
 			win_errstr(status)));
diff --git a/source4/dsdb/schema/schema_prefixmap.c b/source4/dsdb/schema/schema_prefixmap.c
index 79894fe..1892050 100644
--- a/source4/dsdb/schema/schema_prefixmap.c
+++ b/source4/dsdb/schema/schema_prefixmap.c
@@ -229,7 +229,7 @@ WERROR dsdb_schema_pfm_find_binary_oid(const struct dsdb_schema_prefixmap *pfm,
 		}
 	}
 
-	return WERR_DS_NO_MSDS_INTID;
+	return WERR_NOT_FOUND;
 }
 
 /**
@@ -259,9 +259,14 @@ WERROR dsdb_schema_pfm_find_oid(const struct dsdb_schema_prefixmap *pfm,
 
 /**
  * Make ATTID for given OID
+ * If OID is not in prefixMap, new prefix
+ * may be added depending on 'can_change_pfm' flag
  * Reference: [MS-DRSR] section 5.12.2
  */
-WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char *oid, uint32_t *attid)
+static WERROR dsdb_schema_pfm_make_attid_impl(struct dsdb_schema_prefixmap *pfm,
+					      const char *oid,
+					      bool can_change_pfm,
+					      uint32_t *attid)
 {
 	WERROR werr;
 	uint32_t idx;
@@ -287,6 +292,11 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
 		/* free memory allocated for bin_oid */
 		data_blob_free(&bin_oid);
 	} else {
+		/* return error in read-only mode */
+		if (!can_change_pfm) {
+			return werr;
+		}
+
 		/* entry does not exists, add it */
 		werr = _dsdb_schema_pfm_add_entry(pfm, bin_oid, &idx);
 		W_ERROR_NOT_OK_RETURN(werr);
@@ -309,6 +319,33 @@ WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm, const char
 	return WERR_OK;
 }
 
+/**
+ * Make ATTID for given OID
+ * Reference: [MS-DRSR] section 5.12.2
+ *
+ * Note: This function may change prefixMap if prefix
+ * for supplied 'oid' doesn't exists yet.
+ * It is recommended to be used mostly when caller
+ * want to add new prefixes.
+ * Otherwise dsdb_schema_pfm_attid_from_oid() should be used.
+ */
+WERROR dsdb_schema_pfm_make_attid(struct dsdb_schema_prefixmap *pfm,
+				  const char *oid,
+				  uint32_t *attid)
+{
+	return dsdb_schema_pfm_make_attid_impl(pfm, oid, true, attid);
+}
+
+/**
+ * Make ATTID for given OID
+ * Reference: [MS-DRSR] section 5.12.2
+ */
+WERROR dsdb_schema_pfm_attid_from_oid(struct dsdb_schema_prefixmap *pfm,
+				      const char *oid,
+				      uint32_t *attid)
+{
+	return dsdb_schema_pfm_make_attid_impl(pfm, oid, false, attid);
+}
 
 /**
  * Make OID for given ATTID.
diff --git a/source4/dsdb/schema/schema_syntax.c b/source4/dsdb/schema/schema_syntax.c
index 2f68ea2..4267cd7 100644
--- a/source4/dsdb/schema/schema_syntax.c
+++ b/source4/dsdb/schema/schema_syntax.c
@@ -1087,9 +1087,9 @@ static WERROR _dsdb_syntax_auto_OID_ldb_to_drsuapi(const struct dsdb_syntax_ctx
 		} else {
 			uint32_t attid;
 			WERROR werr;
-			werr = dsdb_schema_pfm_make_attid(ctx->schema->prefixmap,
-							  (const char *)v->data,
-							  &attid);
+			werr = dsdb_schema_pfm_attid_from_oid(ctx->schema->prefixmap,
+							      (const char *)v->data,
+							      &attid);
 			W_ERROR_NOT_OK_RETURN(werr);
 			SIVAL(blobs[i].data, 0, attid);
 		}
@@ -1210,9 +1210,9 @@ static WERROR _dsdb_syntax_OID_oid_ldb_to_drsuapi(const struct dsdb_syntax_ctx *
 		blobs[i] = data_blob_talloc(blobs, NULL, 4);
 		W_ERROR_HAVE_NO_MEMORY(blobs[i].data);
 
-		status = dsdb_schema_pfm_make_attid(ctx->schema->prefixmap,
-						    (const char *)in->values[i].data,
-						    &attid);
+		status = dsdb_schema_pfm_attid_from_oid(ctx->schema->prefixmap,
+						        (const char *)in->values[i].data,
+						        &attid);
 		W_ERROR_NOT_OK_RETURN(status);
 
 		SIVAL(blobs[i].data, 0, attid);
diff --git a/source4/torture/drs/unit/prefixmap_tests.c b/source4/torture/drs/unit/prefixmap_tests.c
index a954399..5aba5d1 100644
--- a/source4/torture/drs/unit/prefixmap_tests.c
+++ b/source4/torture/drs/unit/prefixmap_tests.c
@@ -306,9 +306,6 @@ static bool torture_drs_unit_pfm_make_attid_small_map(struct torture_context *tc
 	/* create new prefix map */
 	werr = dsdb_schema_pfm_new(mem_ctx, &pfm);
 	torture_assert_werr_ok(tctx, werr, "dsdb_schema_pfm_new() failed!");
-	torture_assert(tctx, pfm != NULL, "NULL prefixMap created!");
-	torture_assert(tctx, pfm->length > 0, "Empty prefixMap created!");
-	torture_assert(tctx, pfm->prefixes != NULL, "No prefixes for newly created prefixMap!");
 
 	/* make some ATTIDs and check result */
 	for (i = 0; i < ARRAY_SIZE(_prefixmap_test_data); i++) {
@@ -351,6 +348,117 @@ static bool torture_drs_unit_pfm_make_attid_small_map(struct torture_context *tc
 }
 
 /**
+ * Tests dsdb_schema_pfm_attid_from_oid() using full prefixMap.
+ * In this test we know exactly which ATTID and prefixMap->ID
+ * should be returned- dsdb_schema_pfm_attid_from_oid() should succeed.
+ */
+static bool torture_drs_unit_pfm_attid_from_oid_full_map(struct torture_context *tctx,
+							 struct drsut_prefixmap_data *priv)
+{
+	WERROR werr;
+	uint32_t i, count;
+	uint32_t attid;
+	char *err_msg;
+
+	count = ARRAY_SIZE(_prefixmap_test_data);
+	for (i = 0; i < count; i++) {
+		werr = dsdb_schema_pfm_attid_from_oid(priv->pfm_full,
+						      _prefixmap_test_data[i].oid,
+						      &attid);
+		/* prepare error message */
+		err_msg = talloc_asprintf(priv, "dsdb_schema_pfm_attid_from_oid() failed with %s",
+						_prefixmap_test_data[i].oid);
+		torture_assert(tctx, err_msg, "Unexpected: Have no memory!");
+		/* verify result and returned ATTID */
+		torture_assert_werr_ok(tctx, werr, err_msg);
+		torture_assert_int_equal(tctx, attid, _prefixmap_test_data[i].attid, err_msg);
+		/* reclaim memory for prepared error message */
+		talloc_free(err_msg);
+	}
+
+	return true;
+}
+
+/**
+ * Tests dsdb_schema_pfm_attid_from_oid() using base (initial) prefixMap.
+ * dsdb_schema_pfm_attid_from_oid() should fail when testing with OID
+ * that are not already in the prefixMap.
+ */
+static bool torture_drs_unit_pfm_attid_from_oid_base_map(struct torture_context *tctx,
+							 struct drsut_prefixmap_data *priv)
+{
+	WERROR werr;
+	uint32_t i;
+	uint32_t attid;
+	char *err_msg;
+	struct dsdb_schema_prefixmap *pfm = NULL;
+	struct dsdb_schema_prefixmap pfm_prev;
+	TALLOC_CTX *mem_ctx;
+	const struct {
+		const char 	*oid;
+		uint32_t 	attid;
+		bool		exists;	/* if this prefix already exists or should be added */
+	} _test_data[] = {
+		{.oid="2.5.4.0", 		.attid=0x00000000, true},
+		{.oid="2.5.4.42", 		.attid=0x0000002a, true},
+		{.oid="1.2.840.113556.1.2.1", 	.attid=0x00020001, true},
+		{.oid="1.2.840.113556.1.2.13", 	.attid=0x0002000d, true},
+		{.oid="1.2.840.113556.1.2.281", .attid=0x00020119, true},
+		{.oid="1.2.840.113556.1.4.125", .attid=0x0009007d, true},
+		{.oid="1.2.840.113556.1.4.146", .attid=0x00090092, true},
+		{.oid="1.2.250.1", 	 	.attid=0x1b860001, false},
+		{.oid="1.2.250.16386", 	 	.attid=0x1c788002, false},
+		{.oid="1.2.250.2097154", 	.attid=0x1c7b8002, false},
+	};
+
+	mem_ctx = talloc_new(priv);
+	torture_assert(tctx, mem_ctx, "Unexpected: Have no memory!");
+
+	/* create new prefix map */
+	werr = dsdb_schema_pfm_new(mem_ctx, &pfm);
+	torture_assert_werr_ok(tctx, werr, "dsdb_schema_pfm_new() failed!");
+
+	/* keep initial pfm around for testing */
+	pfm_prev = *pfm;
+	pfm_prev.prefixes = talloc_reference(mem_ctx, pfm->prefixes);
+
+	/* get some ATTIDs and check result */
+	for (i = 0; i < ARRAY_SIZE(_test_data); i++) {
+		werr = dsdb_schema_pfm_attid_from_oid(pfm, _test_data[i].oid, &attid);
+
+		/* prepare error message */
+		err_msg = talloc_asprintf(mem_ctx,
+					  "dsdb_schema_pfm_attid_from_oid() failed for %s",
+					  _test_data[i].oid);
+		torture_assert(tctx, err_msg, "Unexpected: Have no memory!");
+
+
+		/* verify pfm hasn't been altered */
+		if (_test_data[i].exists) {
+			/* should succeed and return valid ATTID */
+			torture_assert_werr_ok(tctx, werr, err_msg);
+			/* verify ATTID */
+			torture_assert_int_equal(tctx, attid, _test_data[i].attid, err_msg);
+		} else {
+			/* should fail */
+			torture_assert_werr_equal(tctx, werr, WERR_NOT_FOUND, err_msg);
+		}
+
+		/* prefixMap should never be changed */
+		if (!_torture_drs_pfm_compare_same(tctx, &pfm_prev, pfm, true)) {
+			torture_fail(tctx, "schema->prefixmap has changed");
+		}
+
+		/* reclaim memory for prepared error message */
+		talloc_free(err_msg);
+	}
+
+	talloc_free(mem_ctx);
+
+	return true;
+}
+
+/**
  * Tests dsdb_schema_pfm_oid_from_attid() using full prefixMap.
  */
 static bool torture_drs_unit_pfm_oid_from_attid(struct torture_context *tctx, struct drsut_prefixmap_data *priv)
@@ -779,6 +887,12 @@ struct torture_tcase * torture_drs_unit_prefixmap(struct torture_suite *suite)
 
 	torture_tcase_add_simple_test(tc, "make_attid_full_map", (pfn_run)torture_drs_unit_pfm_make_attid_full_map);
 	torture_tcase_add_simple_test(tc, "make_attid_small_map", (pfn_run)torture_drs_unit_pfm_make_attid_small_map);
+
+	torture_tcase_add_simple_test(tc, "attid_from_oid_full_map",
+				      (pfn_run)torture_drs_unit_pfm_attid_from_oid_full_map);
+	torture_tcase_add_simple_test(tc, "attid_from_oid_empty_map",
+				      (pfn_run)torture_drs_unit_pfm_attid_from_oid_base_map);
+
 	torture_tcase_add_simple_test(tc, "oid_from_attid_full_map", (pfn_run)torture_drs_unit_pfm_oid_from_attid);
 	torture_tcase_add_simple_test(tc, "oid_from_attid_check_attid",
 				      (pfn_run)torture_drs_unit_pfm_oid_from_attid_check_attid);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list