using DSInternals.Common; using System; namespace DSInternals.DataStore { /// /// Database setting flags stored in the hiddentable. /// public class DatabaseFlags { private const int AuxClassOffset = 0; private const int SDConversionRequiredOffset = 1; private const int RootGUIDUpdatedOffset = 2; private const int ADAMDatabaseOffset = 3; private const int ASCIIIndicesRebuiltOffset = 4; private const int ShowInABArrayRebuildOffset = 5; private const int UpdateNCTypeRequiredOffset = 6; private const int LinkQuotaUSNOffset = 7; private const int oldStructureSize = 200; private const int newStructureSize = 192; private const int DatabaseGUIDOffset = newStructureSize - 16; private byte[] binaryFlags; public DatabaseFlags(byte[] binaryFlags) { Validator.AssertNotNull(binaryFlags, "binaryFlags"); this.binaryFlags = binaryFlags; } private bool HasFlag(int offset) { byte value = this.binaryFlags[offset]; // The value is curiously stored as char. switch((char)value) { case '1': return true; case '0': case '\0': return false; default: // TODO: Extract as resource. // TODO: Exception type throw new Exception("Unknown flag value"); } } /// /// Indexes used into this array. /// public bool AuxClass { get { return this.HasFlag(AuxClassOffset); } } /// /// Set if SDs need to be updated (when an old DIT is detected without SD table) /// public bool SDConversionRequired { get { return this.HasFlag(SDConversionRequiredOffset); } } /// /// Root DNT GUID was updated. /// public bool RootGUIDUpdated { get { return this.HasFlag(RootGUIDUpdatedOffset); } } /// /// ADAM database. /// public bool ADAMDatabase { get { return this.HasFlag(ADAMDatabaseOffset); } } /// /// Win2k3 SP1 required rebuilt ASCII indices, this indicates that has been done. /// public bool ASCIIIndicesRebuilt { get { return this.HasFlag(ASCIIIndicesRebuiltOffset); } } /// /// Win2k3 SP1 to LH upgrade requires rebuild of showInAddressBookArray column. /// public bool ShowInABArrayRebuild { get { return this.HasFlag(ShowInABArrayRebuildOffset); } } /// /// Pre-LH to LH upgrade requires addition of msds-NCType. /// public bool UpdateNCTypeRequired { get { return this.HasFlag(UpdateNCTypeRequiredOffset); } } /// /// Link quota feature start USN in DBFLAGS. /// public long LinkQuotaUSN { get { return BitConverter.ToInt64(this.binaryFlags, LinkQuotaUSNOffset); } } /// /// The database GUID /// public Guid? DatabaseGUID { get { // Contains GUID in the last 16B in newer database versions. // Old size is 200 bytes, new size is 192 bytes. // TODO: Implement database GUID retrieval. throw new NotImplementedException(); } } } }