Example #1
0
        public DirectoryEntry Find(string sName)
        {
            //for instance, when CN=$LikewiseIdentityCell we need match the first portion
            foreach (DirectoryEntry entry in this)
            {
                string sProtocol, sServer, sCNs, sDCs = null;

                SDSUtils.CrackPath(entry.Path, out sProtocol, out sServer, out sCNs, out sDCs);

                if (sCNs != null)
                {
                    string[] splits = sCNs.Split(',');
                    if (splits[0].Equals(sName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(entry);
                    }
                }
            }

            return(null);
        }
Example #2
0
        public DirectoryEntry(string sLDAPPath)
        {
            this.sLDAPPath     = sLDAPPath;
            propertyCollection = null;
            nativeObject       = null;
            sName           = null;
            children        = null;
            objectSecurity  = null;
            guid            = Guid.Empty;
            parent          = null;
            objectClassType = null;

            SDSUtils.CrackPath(sLDAPPath, out sProtocol, out sServer, out sCNs, out sDCs);

            /*if (sProtocol != null) Console.WriteLine("sProtocol is " + sProtocol);
             * if (sServer != null) Console.WriteLine("sServer is " + sServer);
             * if (sCNs != null) Console.WriteLine("sCNs is " + sCNs);
             * if (sDCs != null) Console.WriteLine("sDCs is " + sDCs); */

            string[] rootDNcom;

            if (sServer != null)
            {
                rootDNcom = sServer.Split('.');

                rootDN = "";

                foreach (string str in rootDNcom)
                {
                    string temp = string.Concat("dc=", str, ",");
                    rootDN = string.Concat(rootDN, temp);
                }

                rootDN = rootDN.Substring(0, rootDN.Length - 1);
            }
            //beacuse rootDN is nothing but collection of all DC's from DN
            if (sDCs != null)
            {
                rootDN = sDCs;
            }

            baseDn = "";

            //sCNs = RootDSE, Configuration, Schema, Domain
            if (sCNs != null && sDCs == null)
            {
                if (sCNs.Equals("RootDSE", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = "";
                }
                else if (sCNs.Equals("Configuration", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Configuration,", rootDN);
                }
                else if (sCNs.Equals("Schema", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Schema,", rootDN);
                }
                else if (sCNs.Equals("Domain", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.Equals("", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.StartsWith("<"))
                {
                    if (rootDN != null)
                    {
                        baseDn = rootDN;
                    }
                }
                else
                {
                    baseDn = string.Concat(sCNs, ",", rootDN);
                }
            }

            if (sCNs != null && sDCs != null)
            {
                baseDn = string.Concat(sCNs, ",", sDCs);
            }

            if (sCNs == null && sDCs != null)
            {
                baseDn = sDCs;
            }

            if (sCNs == null && sDCs == null)
            {
                baseDn = rootDN;
            }

            //assign sName value using the dN of this node
            if (baseDn.Equals("", StringComparison.InvariantCultureIgnoreCase))
            {
                sName = "RootDSE";
            }
            else
            {
                sName = baseDn;
            }
        }