summaryrefslogtreecommitdiff
path: root/source4/dsdb/schema/schema_info_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/dsdb/schema/schema_info_attr.c')
-rw-r--r--source4/dsdb/schema/schema_info_attr.c75
1 files changed, 65 insertions, 10 deletions
diff --git a/source4/dsdb/schema/schema_info_attr.c b/source4/dsdb/schema/schema_info_attr.c
index a9c5e932a1..0b5d50b529 100644
--- a/source4/dsdb/schema/schema_info_attr.c
+++ b/source4/dsdb/schema/schema_info_attr.c
@@ -70,6 +70,28 @@ WERROR dsdb_schema_info_blob_new(TALLOC_CTX *mem_ctx, DATA_BLOB *_schema_info_bl
/**
+ * Verify the 'blob' is a valid schemaInfo blob
+ */
+bool dsdb_schema_info_blob_is_valid(const DATA_BLOB *blob)
+{
+ if (!blob || !blob->data) {
+ return false;
+ }
+
+ /* schemaInfo blob must be 21 bytes long */
+ if (blob->length != 21) {
+ return false;
+ }
+
+ /* schemaInfo blob should start with 0xFF */
+ if (blob->data[0] != 0xFF) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
* Parse schemaInfo structure from a data_blob
* (DATA_BLOB or ldb_val).
* Suitable for parsing blobs that comes from
@@ -83,16 +105,8 @@ WERROR dsdb_schema_info_from_blob(const DATA_BLOB *blob,
struct dsdb_schema_info *schema_info;
struct schemaInfoBlob schema_info_blob;
- if (!blob || !blob->data) {
- return WERR_INVALID_PARAMETER;
- }
-
- if (blob->length != 21) {
- return WERR_INVALID_PARAMETER;
- }
-
- /* schemaInfo blob should start with 0xFF */
- if (blob->data[0] != 0xFF) {
+ /* verify schemaInfo blob is valid */
+ if (!dsdb_schema_info_blob_is_valid(blob)) {
return WERR_INVALID_PARAMETER;
}
@@ -150,6 +164,47 @@ WERROR dsdb_blob_from_schema_info(const struct dsdb_schema_info *schema_info,
return WERR_OK;
}
+/**
+ * Compares schemaInfo signatures in dsdb_schema and prefixMap.
+ * NOTE: At present function compares schemaInfo values
+ * as string without taking into account schemVersion field
+ *
+ * @return WERR_OK if schemaInfos are equal
+ * WERR_DS_DRA_SCHEMA_MISMATCH if schemaInfos are different
+ */
+WERROR dsdb_schema_info_cmp(const struct dsdb_schema *schema,
+ const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
+{
+ bool bres;
+ DATA_BLOB blob;
+ char *schema_info_str;
+ struct drsuapi_DsReplicaOIDMapping *mapping;
+
+ /* we should have at least schemaInfo element */
+ if (ctr->num_mappings < 1) {
+ return WERR_INVALID_PARAMETER;
+ }
+
+ /* verify schemaInfo element is valid */
+ mapping = &ctr->mappings[ctr->num_mappings - 1];
+ if (mapping->id_prefix != 0) {
+ return WERR_INVALID_PARAMETER;
+ }
+
+ blob = data_blob_const(mapping->oid.binary_oid, mapping->oid.length);
+ if (!dsdb_schema_info_blob_is_valid(&blob)) {
+ return WERR_INVALID_PARAMETER;
+ }
+
+ schema_info_str = hex_encode_talloc(NULL, blob.data, blob.length);
+ W_ERROR_HAVE_NO_MEMORY(schema_info_str);
+
+ bres = strequal(schema->schema_info, schema_info_str);
+ talloc_free(schema_info_str);
+
+ return bres ? WERR_OK : WERR_DS_DRA_SCHEMA_MISMATCH;
+}
+
/**
* Reads schema_info structure from schemaInfo