From 2251526bfa4516e230535307fb9195657314d682 Mon Sep 17 00:00:00 2001 From: MichaelGrafnetter Date: Sat, 2 Jan 2016 16:30:17 +0100 Subject: [PATCH] Minor code cleanup --- Src/DSInternals.Common/Cryptography/Crc32.cs | 5 ++- .../Data/Schema/CommonDirectoryAttributes.cs | 1 + Src/DSInternals.DataStore/LinkResolver.cs | 37 +++++++++++-------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Src/DSInternals.Common/Cryptography/Crc32.cs b/Src/DSInternals.Common/Cryptography/Crc32.cs index e026040..0abcc39 100644 --- a/Src/DSInternals.Common/Cryptography/Crc32.cs +++ b/Src/DSInternals.Common/Cryptography/Crc32.cs @@ -1,6 +1,9 @@  namespace DSInternals.Common.Cryptography { + /// + /// Implements the CRC32 algorithm, as used by AD replication. + /// public static class Crc32 { private static readonly uint[] crcTable = new uint[] { @@ -76,7 +79,7 @@ namespace DSInternals.Common.Cryptography uint crc = uint.MaxValue; for(int i = 0; i < buffer.Length; i++) { - crc = crcTable[(crc ^ buffer[i]) & 0xFF] ^ (crc >> 8); + crc = crcTable[(crc ^ buffer[i]) & byte.MaxValue] ^ (crc >> 8 ); } return crc ^ uint.MaxValue; } diff --git a/Src/DSInternals.Common/Data/Schema/CommonDirectoryAttributes.cs b/Src/DSInternals.Common/Data/Schema/CommonDirectoryAttributes.cs index fcd0ea7..9548aa8 100644 --- a/Src/DSInternals.Common/Data/Schema/CommonDirectoryAttributes.cs +++ b/Src/DSInternals.Common/Data/Schema/CommonDirectoryAttributes.cs @@ -59,6 +59,7 @@ public const string OrganizationalUnitName = "ou"; public const string ParentDNTag = "PDNT"; public const string PEKList = "pekList"; + public const string PEKChangeInterval = "pekKeyChangeInterval"; public const string PrimaryGroupId = "primaryGroupID"; public const int PrimaryGroupIdId = 589922; public const string PropertyMetaData = "replPropertyMetaData"; diff --git a/Src/DSInternals.DataStore/LinkResolver.cs b/Src/DSInternals.DataStore/LinkResolver.cs index 17f567b..dca4e00 100644 --- a/Src/DSInternals.DataStore/LinkResolver.cs +++ b/Src/DSInternals.DataStore/LinkResolver.cs @@ -12,6 +12,10 @@ namespace DSInternals.DataStore private const string linkDNCol = "link_DNT"; private const string backlinkDNCol = "backlink_DNT"; private const string linkBaseCol = "link_base"; + private const string linkDataCol = "link_data"; + private const string linkMetadataCol = "link_metadata"; + private const string linkDeletedTimeCol = "link_deltime"; + private const string linkDeactivatedTimeCol = "link_deactivetime"; private const string linkIndex = "link_present_active_index"; private Cursor cursor; @@ -27,29 +31,25 @@ namespace DSInternals.DataStore public int? GetLinkedDNTag(int dnTag, string attributeName) { - int[] result = this.GetLinkedDNTags(dnTag, attributeName); - switch(result.Length) + try { - case 0: - return null; - case 1: - return result[0]; - default: - // TODO: Make this a special exception type. Move message to resources. - throw new Exception("More than 1 objects have been found."); + return this.GetLinkedDNTags(dnTag, attributeName).SingleOrDefault(); + } + catch(InvalidOperationException) + { + // TODO: Make this a special exception type. Move message to resources. + throw new Exception("More than 1 objects have been found."); } } - public int[] GetLinkedDNTags(int dnTag, string attributeName) + public IEnumerable GetLinkedDNTags(int dnTag, string attributeName) { - var result = new List(); SchemaAttribute attr = this.schema.FindAttribute(attributeName); if(!attr.LinkId.HasValue) { - // This is not a linked multivalue attribute. //TODO: Throw a proper exception - throw new Exception(); - + // TODO: Check that attribute type is DN + throw new Exception("This is not a linked multivalue attribute."); } int linkId = attr.LinkId.Value; // Remove the rightmost bit that indicates if this is a forward link or a backlink. @@ -62,9 +62,14 @@ namespace DSInternals.DataStore { // TODO: Not deactivated? int foundTag = (int)cursor.IndexRecord[backlinkDNCol]; - result.Add(foundTag); + yield return foundTag; } - return result.ToArray(); + } + + public IEnumerable GetDNBinaryValues(int dnTag, string attributeName) + { + // TODO: Implement DN-Binary attribute value retrieval from linktable. + throw new NotImplementedException(); } public void Dispose()