From 677b76bb8190b2b45fd039fcf220646520367aa0 Mon Sep 17 00:00:00 2001 From: Michael Grafnetter Date: Fri, 8 Oct 2021 18:14:02 +0200 Subject: [PATCH] Resolved #118: Support for ntds.dit files with conflicting defunct attributes. --- Src/DSInternals.DataStore/DirectorySchema.cs | 33 ++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/Src/DSInternals.DataStore/DirectorySchema.cs b/Src/DSInternals.DataStore/DirectorySchema.cs index 697f2dc..96f9b26 100644 --- a/Src/DSInternals.DataStore/DirectorySchema.cs +++ b/Src/DSInternals.DataStore/DirectorySchema.cs @@ -7,6 +7,7 @@ using Microsoft.Isam.Esent.Interop; using System; using System.Collections.Generic; + using System.Globalization; using System.Linq; /// @@ -25,7 +26,6 @@ private IDictionary attributesByName; private IDictionary classesByName; - // TODO: Internal? // TODO: ISchema public DirectorySchema(IsamDatabase database) { @@ -41,17 +41,6 @@ // TODO: Load Ext-Int Map from hiddentable } - /// - /// Gets the partition name. - /// - public string Name - { - get - { - throw new NotImplementedException(); - } - } - /// /// Gets the OID prefix map. /// @@ -112,15 +101,6 @@ return this.FindAttribute(attributeName).Index; } - - /// - /// Refreshes the schema cache. - /// - public void RefreshSchema() - { - throw new NotImplementedException(); - } - // TODO: Rename to CategoryDNT public int FindClassId(string className) { @@ -229,6 +209,7 @@ // Some built-in attributes do not have internal id set, which means it is equal to the public id int id = internalId ?? attributeId; SchemaAttribute attribute; + bool found = this.attributesByInternalId.TryGetValue(id, out attribute); if (! found) { @@ -236,6 +217,7 @@ attribute = new SchemaAttribute(); attribute.InternalId = internalId; } + attribute.Id = dataTableCursor.RetrieveColumnAsInt(attributeIdCol).Value; attribute.Name = dataTableCursor.RetrieveColumnAsString(ldapDisplayNameCol); attribute.CommonName = dataTableCursor.RetrieveColumnAsString(cnCol); @@ -251,8 +233,13 @@ attribute.IsSystemOnly = dataTableCursor.RetrieveColumnAsBoolean(systemOnlyCol); attribute.Syntax = dataTableCursor.RetrieveColumnAsAttributeSyntax(syntaxCol); attribute.OmSyntax = dataTableCursor.RetrieveColumnAsAttributeOmSyntax(omSyntaxCol); - // Make it case-insensitive by always lowering the name: - this.attributesByName.Add(attribute.Name.ToLower(), attribute); + + // Only index non-defunct attributes by name. A name conflict could arise otherwise. + if(!attribute.IsDefunct) + { + // Make the attribute name lookup case-insensitive by always lowercasing the name: + this.attributesByName.Add(attribute.Name.ToLower(CultureInfo.InvariantCulture), attribute); + } } }