Example #1
0
        private void LoadClassList(Cursor dataTableCursor)
        {
            // Initialize the class list
            this.classesByName = new Dictionary <string, int>();

            // Load column IDs. We are in an early stage of schema loading, which means that we cannot search for non-system attributes by name.
            Columnid        dntCol             = this.FindColumnId(CommonDirectoryAttributes.DNTag);
            Columnid        governsIdCol       = this.attributesByInternalId[CommonDirectoryAttributes.GovernsIdId].ColumnID;
            SchemaAttribute ldapDisplayNameAtt = this.attributesByInternalId[CommonDirectoryAttributes.LdapDisplayNameId];

            // Search for all classes using this heuristics: (&(ldapDisplayName=*)(governsId=*))
            dataTableCursor.CurrentIndex = ldapDisplayNameAtt.Index;
            while (dataTableCursor.MoveNext())
            {
                int?governsId = dataTableCursor.RetrieveColumnAsInt(governsIdCol);
                if (!governsId.HasValue)
                {
                    // This is an attribute and not a class, so we skip to the next object.
                    continue;
                }
                // TODO: Load more data about classes
                int    classDNT  = dataTableCursor.RetrieveColumnAsDNTag(dntCol).Value;
                string className = dataTableCursor.RetrieveColumnAsString(ldapDisplayNameAtt.ColumnID);
                classesByName.Add(className, classDNT);
            }
        }
Example #2
0
        private void LoadColumnList(ColumnCollection columns)
        {
            this.attributesByName       = new Dictionary <string, SchemaAttribute>(columns.Count);
            this.attributesByInternalId = new Dictionary <int, SchemaAttribute>(columns.Count);

            foreach (var column in columns)
            {
                var attr = new SchemaAttribute();
                attr.ColumnName = column.Name;
                attr.ColumnID   = column.Columnid;
                if (IsAttributeColumn(attr.ColumnName))
                {
                    // Column is mapped to LDAP attribute
                    attr.InternalId = GetInternalIdFromColumnName(attr.ColumnName);
                    attributesByInternalId.Add(attr.InternalId.Value, attr);
                }
                else
                {
                    // System column. These normally do not appear in schema.
                    attr.IsSystemOnly = true;
                    attr.SystemFlags  = AttributeSystemFlags.NotReplicated | AttributeSystemFlags.Base | AttributeSystemFlags.DisallowRename | AttributeSystemFlags.Operational;
                    // Approximate Syntax from ColumnId
                    attr.Syntax   = GetSyntaxFromColumnType(column.Columnid);
                    attr.OmSyntax = AttributeOmSyntax.Undefined;
                    attr.Name     = NormalizeSystemColumnName(attr.ColumnName);
                    this.attributesByName.Add(attr.Name.ToLower(), attr);
                }
            }
        }
Example #3
0
        private void LoadAttributeIndices(IEnumerable <IndexInfo> indices)
        {
            //HACK: We are using low-level IndexInfo instead of high-level IndexCollection.

            /* There is a bug in Isam IndexCollection enumerator, which causes it to loop indefinitely
             * through the first few indices under some very rare circumstances. */
            foreach (var index in indices)
            {
                var segments = index.IndexSegments;
                if (segments.Count == 1)
                {
                    // We support only simple indexes
                    SchemaAttribute attr = FindAttributeByIndexName(index.Name);
                    if (attr != null)
                    {
                        // We found a single attribute to which this index corresponds
                        attr.Index = index.Name;
                    }
                }
            }

            // Manually assign PDNT_index to PDNT_col
            var pdnt = FindAttribute(CommonDirectoryAttributes.ParentDNTag);

            pdnt.Index = ParentDNTagIndex;
        }
Example #4
0
        public IEnumerable <int> GetLinkedDNTags(int dnTag, string attributeName)
        {
            SchemaAttribute attr = this.schema.FindAttribute(attributeName);

            if (!attr.LinkId.HasValue)
            {
                //TODO: Throw a proper 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.
            int linkBase = linkId >> 1;
            // Columns order in index: link_DNT, link_base, backlink_DNT
            Key key = Key.Compose(dnTag, linkBase);

            key.AddWildcard();
            cursor.FindRecords(MatchCriteria.EqualTo, key);
            while (cursor.MoveNext())
            {
                // TODO: Not deactivated?
                int foundTag = (int)cursor.IndexRecord[backlinkDNCol];
                yield return(foundTag);
            }
        }
Example #5
0
        private SchemaAttribute FindAttributeByIndexName(string indexName)
        {
            SchemaAttribute attribute = null;

            if (IsAttributeColumnIndex(indexName))
            {
                int internalId = GetInternalIdFromIndexName(indexName);
                this.attributesByInternalId.TryGetValue(internalId, out attribute);
            }
            else
            {
                string systemColName = NormalizeIndexName(indexName);
                this.attributesByName.TryGetValue(systemColName.ToLower(), out attribute);
            }
            return(attribute);
        }
Example #6
0
        private void FindLinkedRecords(int dnTag, string attributeName)
        {
            SchemaAttribute attr = this.schema.FindAttribute(attributeName);

            if (!attr.LinkId.HasValue)
            {
                //TODO: Throw a proper exception
                throw new Exception("This is not a linked multivalue attribute.");
            }

            int linkBase = attr.LinkBase.Value;
            // Columns order in index: link_DNT, link_base, backlink_DNT
            Key key = Key.Compose(dnTag, linkBase);

            key.AddWildcard();
            this.cursor.FindRecords(MatchCriteria.EqualTo, key);
        }
Example #7
0
        private void LoadAttributeProperties(Cursor dataTableCursor)
        {
            // With these built-in attributes, ID == Internal ID
            Columnid attributeIdCol = this.attributesByInternalId[CommonDirectoryAttributes.AttributeIdId].ColumnID;
            SchemaAttribute ldapDisplayNameAtt = this.attributesByInternalId[CommonDirectoryAttributes.LdapDisplayNameId];
            Columnid ldapDisplayNameCol = ldapDisplayNameAtt.ColumnID;
            // Set index to ldapDisplayName so that we can find attributes by their name
            dataTableCursor.CurrentIndex = ldapDisplayNameAtt.Index;

            // Load attribute ids of attributeSchema attributes by doing DB lookups
            // TODO: Hardcode IDs of these attributes so that we do not have to do DB lookups?
            Columnid internalIdCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.InternalId);
            Columnid linkIdCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.LinkId);
            Columnid isSingleValuedCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsSingleValued);
            Columnid attributeSyntaxCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeSyntax);
            Columnid isInGlobalCatalogCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsInGlobalCatalog);
            Columnid searchFlagsCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SearchFlags);
            Columnid systemOnlyCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SystemOnly);
            Columnid syntaxCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeSyntax);
            Columnid omSyntaxCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeOmSyntax);
            Columnid cnCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.CommonName);
            Columnid rangeLowerCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.RangeLower);
            Columnid rangeUpperCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.RangeUpper);
            Columnid schemaGuidCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SchemaGuid);
            Columnid systemFlagsCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SystemFlags);
            Columnid isDefunctCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsDefunct);

            // Now traverse through all schema attributes and load their properties
            dataTableCursor.CurrentIndex = this.attributesByInternalId[CommonDirectoryAttributes.ObjectClassId].Index;
            dataTableCursor.FindRecords(MatchCriteria.EqualTo, Key.Compose(CommonDirectoryClasses.AttributeSchemaId));
            while (dataTableCursor.MoveNext())
            {
                int? internalId = dataTableCursor.RetrieveColumnAsInt(internalIdCol);
                int attributeId = dataTableCursor.RetrieveColumnAsInt(attributeIdCol).Value;
                // Some built-in attributes do not have internal id set, which meand it is equal to the public id
                int id = internalId ?? attributeId;
                SchemaAttribute attribute;
                bool found = this.attributesByInternalId.TryGetValue(id, out attribute);
                if (! found)
                {
                    // Load info about a new attribute
                    attribute = new SchemaAttribute();
                    attribute.InternalId = internalId;
                }
                attribute.Id = dataTableCursor.RetrieveColumnAsInt(attributeIdCol).Value;
                attribute.Name = dataTableCursor.RetrieveColumnAsString(ldapDisplayNameCol);
                attribute.CommonName = dataTableCursor.RetrieveColumnAsString(cnCol);
                attribute.RangeLower = dataTableCursor.RetrieveColumnAsInt(rangeLowerCol);
                attribute.RangeUpper = dataTableCursor.RetrieveColumnAsInt(rangeUpperCol);
                attribute.SchemaGuid = dataTableCursor.RetrieveColumnAsGuid(schemaGuidCol).Value;
                attribute.IsDefunct = dataTableCursor.RetrieveColumnAsBoolean(isDefunctCol);
                attribute.SystemFlags = dataTableCursor.RetrieveColumnAsAttributeSystemFlags(systemFlagsCol);
                attribute.LinkId = dataTableCursor.RetrieveColumnAsInt(linkIdCol);
                attribute.IsInGlobalCatalog = dataTableCursor.RetrieveColumnAsBoolean(isInGlobalCatalogCol);
                attribute.IsSingleValued = dataTableCursor.RetrieveColumnAsBoolean(isSingleValuedCol);
                attribute.SearchFlags = dataTableCursor.RetrieveColumnAsSearchFlags(searchFlagsCol);
                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);
            }
        }
Example #8
0
        private void LoadColumnList(ColumnCollection columns)
        {
            this.attributesByName = new Dictionary<string, SchemaAttribute>(columns.Count);
            this.attributesByInternalId = new Dictionary<int, SchemaAttribute>(columns.Count);

            foreach (var column in columns)
            {
                var attr = new SchemaAttribute();
                attr.ColumnName = column.Name;
                attr.ColumnID = column.Columnid;
                if (IsAttributeColumn(attr.ColumnName))
                {
                    // Column is mapped to LDAP attribute
                    attr.InternalId = GetInternalIdFromColumnName(attr.ColumnName);
                    attributesByInternalId.Add(attr.InternalId.Value, attr);
                }
                else
                {
                    // System column. These normally do not appear in schema.
                    attr.IsSystemOnly = true;
                    attr.SystemFlags = AttributeSystemFlags.NotReplicated | AttributeSystemFlags.Base | AttributeSystemFlags.DisallowRename | AttributeSystemFlags.Operational;
                    // Approximate Syntax from ColumnId
                    attr.Syntax = GetSyntaxFromColumnType(column.Columnid);
                    attr.OmSyntax = AttributeOmSyntax.Undefined;
                    attr.Name = NormalizeSystemColumnName(attr.ColumnName);
                    this.attributesByName.Add(attr.Name.ToLower(), attr);
                }
            }
        }
Example #9
0
        private void LoadAttributeProperties(Cursor dataTableCursor)
        {
            // With these built-in attributes, ID == Internal ID
            Columnid        attributeIdCol     = this.attributesByInternalId[CommonDirectoryAttributes.AttributeIdId].ColumnID;
            SchemaAttribute ldapDisplayNameAtt = this.attributesByInternalId[CommonDirectoryAttributes.LdapDisplayNameId];
            Columnid        ldapDisplayNameCol = ldapDisplayNameAtt.ColumnID;

            // Set index to ldapDisplayName so that we can find attributes by their name
            dataTableCursor.CurrentIndex = ldapDisplayNameAtt.Index;

            // Load attribute ids of attributeSchema attributes by doing DB lookups
            // TODO: Hardcode IDs of these attributes so that we do not have to do DB lookups?
            Columnid internalIdCol        = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.InternalId);
            Columnid linkIdCol            = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.LinkId);
            Columnid isSingleValuedCol    = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsSingleValued);
            Columnid attributeSyntaxCol   = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeSyntax);
            Columnid isInGlobalCatalogCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsInGlobalCatalog);
            Columnid searchFlagsCol       = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SearchFlags);
            Columnid systemOnlyCol        = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SystemOnly);
            Columnid syntaxCol            = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeSyntax);
            Columnid omSyntaxCol          = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.AttributeOmSyntax);
            Columnid cnCol          = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.CommonName);
            Columnid rangeLowerCol  = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.RangeLower);
            Columnid rangeUpperCol  = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.RangeUpper);
            Columnid schemaGuidCol  = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SchemaGuid);
            Columnid systemFlagsCol = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.SystemFlags);
            Columnid isDefunctCol   = this.LoadColumnIdByAttributeName(dataTableCursor, CommonDirectoryAttributes.IsDefunct);

            // Now traverse through all schema attributes and load their properties
            // Use this filter: (objectCategory=attributeSchema)
            dataTableCursor.CurrentIndex = this.attributesByInternalId[CommonDirectoryAttributes.ObjectCategoryId].Index;
            dataTableCursor.FindRecords(MatchCriteria.EqualTo, Key.Compose(this.FindClassId(CommonDirectoryClasses.AttributeSchema)));
            while (dataTableCursor.MoveNext())
            {
                int?internalId  = dataTableCursor.RetrieveColumnAsInt(internalIdCol);
                int attributeId = dataTableCursor.RetrieveColumnAsInt(attributeIdCol).Value;
                // 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)
                {
                    // We are loading info about a new attribute
                    attribute            = new SchemaAttribute();
                    attribute.InternalId = internalId;
                }
                attribute.Id                = dataTableCursor.RetrieveColumnAsInt(attributeIdCol).Value;
                attribute.Name              = dataTableCursor.RetrieveColumnAsString(ldapDisplayNameCol);
                attribute.CommonName        = dataTableCursor.RetrieveColumnAsString(cnCol);
                attribute.RangeLower        = dataTableCursor.RetrieveColumnAsInt(rangeLowerCol);
                attribute.RangeUpper        = dataTableCursor.RetrieveColumnAsInt(rangeUpperCol);
                attribute.SchemaGuid        = dataTableCursor.RetrieveColumnAsGuid(schemaGuidCol).Value;
                attribute.IsDefunct         = dataTableCursor.RetrieveColumnAsBoolean(isDefunctCol);
                attribute.SystemFlags       = dataTableCursor.RetrieveColumnAsAttributeSystemFlags(systemFlagsCol);
                attribute.LinkId            = dataTableCursor.RetrieveColumnAsInt(linkIdCol);
                attribute.IsInGlobalCatalog = dataTableCursor.RetrieveColumnAsBoolean(isInGlobalCatalogCol);
                attribute.IsSingleValued    = dataTableCursor.RetrieveColumnAsBoolean(isSingleValuedCol);
                attribute.SearchFlags       = dataTableCursor.RetrieveColumnAsSearchFlags(searchFlagsCol);
                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);
            }
        }