コード例 #1
0
        public override void Initialize(LdapConnection conn)
        {
            SearchRequest  req  = new SearchRequest("", (string)null, SearchScope.Base, "schemaNamingContext");
            SearchResponse resp = (SearchResponse)conn.SendRequest(req);

            string schemaNcDn = StringOrNull(resp.Entries[0], "schemaNamingContext");

            //
            // Find the attributes
            //
            string[] wantedAttrs = new string[] {
                "lDAPDisplayName",
                "isSingleValued",
                "attributeSyntax",
                "attributeID",
                "searchFlags"
            };

            PagingHelper helper = new PagingHelper()
            {
                MaxPages          = 0,
                Connection        = conn,
                Attrs             = wantedAttrs,
                Filter            = "(&(objectClass=attributeSchema))",
                DistinguishedName = schemaNcDn
            };

            foreach (SearchResultEntry se in helper.GetResults())
            {
                string attrName = StringOrNull(se, wantedAttrs[0]);

                try
                {
                    _attrs.Add(attrName.ToLower(), new AttributeSchema()
                    {
                        DisplayName   = attrName,
                        IsMultiValued = !"TRUE".Equals(StringOrNull(se, wantedAttrs[1])),
                        LangType      = this.InferType(StringOrNull(se, wantedAttrs[2])),
                        OID           = StringOrNull(se, wantedAttrs[3]),
                        SearchFlags   = Convert.ToInt32(StringOrNull(se, wantedAttrs[4]) ?? "0")
                    });
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Couldn't add attr '" + attrName
                                          + "' from " + se.DistinguishedName + " to collection: " + ex.Message, ex);
                }
            }

            //
            // Find the objectclasses
            //
            wantedAttrs = new string[] {
                "lDAPDisplayName",
                "mustContain",
                "systemMustContain",
                "mayContain",
                "systemMayContain",
                "objectClassCategory",
                "subClassOf",
                "governsID"
            };

            helper.Attrs  = wantedAttrs;
            helper.Filter = "(&(objectClass=classSchema))";

            foreach (SearchResultEntry se in helper.GetResults())
            {
                ObjectClassSchema oc = new ObjectClassSchema();
                oc.DisplayName       = StringOrNull(se, wantedAttrs[0]);
                oc.SuperiorClassName = StringOrNull(se, wantedAttrs[6]);
                oc.OID = StringOrNull(se, wantedAttrs[7]);

                foreach (string src in new string[] { wantedAttrs[1], wantedAttrs[2] })
                {
                    if (se.Attributes.Contains(src))
                    {
                        foreach (string s in se.Attributes[src].GetValues(typeof(string)))
                        {
                            oc.AddMandatory(_attrs[s.ToLower()]);
                        }
                    }
                }

                foreach (string src in new string[] { wantedAttrs[3], wantedAttrs[4] })
                {
                    if (se.Attributes.Contains(src))
                    {
                        foreach (string s in se.Attributes[src].GetValues(typeof(string)))
                        {
                            oc.AddOptional(_attrs[s.ToLower()]);
                        }
                    }
                }

                switch (StringOrNull(se, wantedAttrs[5]))
                {
                case "1":
                    oc.ClassType = ObjectClassType.Structural;
                    break;

                case "2":
                    oc.ClassType = ObjectClassType.Abstract;
                    break;

                case "3":
                    oc.ClassType = ObjectClassType.Auxiliary;
                    break;

                default:
                    oc.ClassType = ObjectClassType.Unknown;
                    break;
                }

                try
                {
                    this._ocs.Add(oc.DisplayName.ToLower(), oc);
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Couldn't add OC '" + oc.DisplayName
                                          + "' from " + se.DistinguishedName + " to collection: " + ex.Message, ex);
                }
            }
        }
コード例 #2
0
ファイル: AdsSchemaInfo.cs プロジェクト: dowens/Zetetic.Ldap
        public override void Initialize(LdapConnection conn)
        {
            SearchRequest req = new SearchRequest("", (string)null, SearchScope.Base, "schemaNamingContext");
            SearchResponse resp = (SearchResponse)conn.SendRequest(req);

            string schemaNcDn = StringOrNull(resp.Entries[0], "schemaNamingContext");

            //
            // Find the attributes
            //
            string[] wantedAttrs = new string[]{
                "lDAPDisplayName",
                "isSingleValued",
                "attributeSyntax",
                "attributeID"
            };

            req = new SearchRequest(schemaNcDn, "(&(objectClass=attributeSchema))", SearchScope.Subtree, wantedAttrs);
            resp = (SearchResponse)conn.SendRequest(req);

            foreach (SearchResultEntry se in resp.Entries)
            {
                string attrName = StringOrNull(se, wantedAttrs[0]);

                try
                {
                    _attrs.Add(attrName.ToLower(), new AttributeSchema()
                    {
                        DisplayName = attrName,
                        IsMultiValued = !"TRUE".Equals(StringOrNull(se, wantedAttrs[1])),
                        LangType = this.InferType(StringOrNull(se, wantedAttrs[2])),
                        OID = StringOrNull(se, wantedAttrs[3])
                    });
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Couldn't add attr '" + attrName
                        + "' from " + se.DistinguishedName + " to collection: " + ex.Message, ex);
                }
            }

            //
            // Find the objectclasses
            //
            wantedAttrs = new string[]{
                "lDAPDisplayName",
                "mustContain",
                "systemMustContain",
                "mayContain",
                "systemMayContain",
                "objectClassCategory",
                "subClassOf",
                "governsID"
            };
            req = new SearchRequest(schemaNcDn, "(&(objectClass=classSchema))", SearchScope.Subtree, wantedAttrs);
            resp = (SearchResponse)conn.SendRequest(req);

            foreach (SearchResultEntry se in resp.Entries)
            {
                ObjectClassSchema oc = new ObjectClassSchema();
                oc.DisplayName = StringOrNull(se, wantedAttrs[0]);
                oc.SuperiorClassName = StringOrNull(se, wantedAttrs[6]);
                oc.OID = StringOrNull(se, wantedAttrs[7]);

                foreach (string src in new string[] { wantedAttrs[1], wantedAttrs[2] })
                {
                    if (se.Attributes.Contains(src))
                        foreach (string s in se.Attributes[src].GetValues(typeof(string)))
                        {
                            oc.AddMandatory(_attrs[s.ToLower()]);
                        }
                }

                foreach (string src in new string[] { wantedAttrs[3], wantedAttrs[4] })
                {
                    if (se.Attributes.Contains(src))
                        foreach (string s in se.Attributes[src].GetValues(typeof(string)))
                        {
                            oc.AddOptional(_attrs[s.ToLower()]);
                        }
                }

                switch (StringOrNull(se, wantedAttrs[5]))
                {
                    case "1":
                        oc.ClassType = ObjectClassType.Structural;
                        break;

                    case "2":
                        oc.ClassType = ObjectClassType.Abstract;
                        break;

                    case "3":
                        oc.ClassType = ObjectClassType.Auxiliary;
                        break;

                    default:
                        oc.ClassType = ObjectClassType.Unknown;
                        break;
                }

                try
                {
                    this._ocs.Add(oc.DisplayName.ToLower(), oc);
                }
                catch (Exception ex)
                {
                    logger.ErrorException("Couldn't add OC '" + oc.DisplayName 
                        + "' from " + se.DistinguishedName + " to collection: " + ex.Message, ex);
                }
            } 
        }