Example #1
0
        private void GetSites()
        {
            NativeComInterfaces.IAdsPathname pathCracker = null;
            pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            ArrayList propertyList = new ArrayList();

            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;
            string propertyName = "siteList";

            propertyList.Add(propertyName);
            Hashtable values    = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base);
            ArrayList siteLists = (ArrayList)values[propertyName.ToLower(CultureInfo.InvariantCulture)];

            // somehow no site list
            if (siteLists == null)
            {
                return;
            }

            for (int i = 0; i < siteLists.Count; i++)
            {
                string dn = (string)siteLists[i];

                // escaping manipulation
                pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
                string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                rdn = rdn.Substring(3);
                ActiveDirectorySite site = new ActiveDirectorySite(context, rdn, true);

                // add to the collection
                _sites.Add(site);
            }
        }
Example #2
0
        private void GetLinks()
        {
            ArrayList propertyList = new ArrayList();

            NativeComInterfaces.IAdsPathname pathCracker = null;
            pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;
            string propertyName = "siteLinkList";

            propertyList.Add(propertyName);
            Hashtable values        = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base);
            ArrayList siteLinkLists = (ArrayList)values[propertyName.ToLowerInvariant()];

            // somehow no site link list
            if (siteLinkLists == null)
            {
                return;
            }

            // construct the site link object
            for (int i = 0; i < siteLinkLists.Count; i++)
            {
                string dn = (string)siteLinkLists[i];
                // escaping manipulation
                pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
                string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                rdn = rdn.Substring(3);
                DirectoryEntry          entry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
                ActiveDirectorySiteLink link  = new ActiveDirectorySiteLink(context, rdn, _transport, true, entry);

                _links.Add(link);
            }
        }
        private void GetLinks()
        {
            ArrayList propertiesToLoad = new ArrayList();

            NativeComInterfaces.IAdsPathname pathname = null;
            pathname             = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            pathname.EscapedMode = 4;
            string str = "siteLinkList";

            propertiesToLoad.Add(str);
            ArrayList list2 = (ArrayList)Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", propertiesToLoad, 0)[str.ToLower(CultureInfo.InvariantCulture)];

            if (list2 != null)
            {
                for (int i = 0; i < list2.Count; i++)
                {
                    string bstrADsPath = (string)list2[i];
                    pathname.Set(bstrADsPath, 4);
                    string                  siteLinkName   = pathname.Retrieve(11).Substring(3);
                    DirectoryEntry          directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, bstrADsPath);
                    ActiveDirectorySiteLink link           = new ActiveDirectorySiteLink(this.context, siteLinkName, this.transport, true, directoryEntry);
                    this.links.Add(link);
                }
            }
        }
Example #4
0
        private void GetSites()
        {
            NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
            ArrayList arrayLists = new ArrayList();

            pathname.EscapedMode = 4;
            string str = "siteList";

            arrayLists.Add(str);
            Hashtable valuesWithRangeRetrieval = Utils.GetValuesWithRangeRetrieval(this.cachedEntry, "(objectClass=*)", arrayLists, SearchScope.Base);
            ArrayList item = (ArrayList)valuesWithRangeRetrieval[str.ToLower(CultureInfo.InvariantCulture)];

            if (item != null)
            {
                for (int i = 0; i < item.Count; i++)
                {
                    string item1 = (string)item[i];
                    pathname.Set(item1, 4);
                    string str1 = pathname.Retrieve(11);
                    str1 = str1.Substring(3);
                    ActiveDirectorySite activeDirectorySite = new ActiveDirectorySite(this.context, str1, true);
                    this.sites.Add(activeDirectorySite);
                }
                return;
            }
            else
            {
                return;
            }
        }
Example #5
0
        internal static DirectoryEntry GetDirectoryEntry(DirectoryContext context, string dn)
        {
            string tempBindingPrefix = "LDAP://" + context.GetServerName() + "/";

            NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_ON;
            pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
            string escapedDN = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_X500_DN);

            return(Bind(tempBindingPrefix + escapedDN, context.UserName, context.Password, context.useServerBind()));
        }
        internal static DirectoryEntry GetDirectoryEntry(DirectoryContext context, string dn)
        {
            string str = "LDAP://" + context.GetServerName() + "/";

            NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            pathname.EscapedMode = 2;
            pathname.Set(dn, 4);
            string str2 = pathname.Retrieve(7);

            return(Bind(str + str2, context.UserName, context.Password, context.useServerBind()));
        }
Example #7
0
        public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
        {
            ValidateArgument(context, subnetName);

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config   = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string subnetdn = "CN=Subnets,CN=Sites," + config;
                de = DirectoryEntryManager.GetDirectoryEntry(context, subnetdn);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                ADSearcher adSearcher = new ADSearcher(de,
                                                       "(&(objectClass=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))",
                                                       new string[] { "distinguishedName" },
                                                       SearchScope.OneLevel,
                                                       false, /* don't need paged search */
                                                       false /* don't need to cache result */);
                SearchResult srchResult = adSearcher.FindOne();
                if (srchResult == null)
                {
                    // no such subnet object
                    Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName);
                    throw e;
                }
                else
                {
                    string         siteName        = null;
                    DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry();
                    // try to get the site that this subnet lives in
                    if (connectionEntry.Properties.Contains("siteObject"))
                    {
                        NativeComInterfaces.IAdsPathname pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
                        // need to turn off the escaping for name
                        pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;

                        string tmp = (string)connectionEntry.Properties["siteObject"][0];
                        // escaping manipulation
                        pathCracker.Set(tmp, NativeComInterfaces.ADS_SETTYPE_DN);
                        string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                        Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                        siteName = rdn.Substring(3);
                    }

                    // it is an existing subnet object
                    ActiveDirectorySubnet subnet = null;
                    if (siteName == null)
                    {
                        subnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                    }
                    else
                    {
                        subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true);
                    }

                    subnet.cachedEntry = connectionEntry;
                    return(subnet);
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked ((int)0x80072030))
                {
                    // object is not found since we cannot even find the container in which to search
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySubnet), subnetName);
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }
            finally
            {
                if (de != null)
                {
                    de.Dispose();
                }
            }
        }
Example #8
0
 internal DirectoryEntryManager(DirectoryContext context)
 {
     _context                 = context;
     _pathCracker             = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
     _pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_ON;
 }
 internal DirectoryEntryManager(DirectoryContext context)
 {
     this.context                 = context;
     this.pathCracker             = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
     this.pathCracker.EscapedMode = 2;
 }
Example #10
0
 internal DirectoryEntryManager(DirectoryContext context)
 {
     _context = context;
     _pathCracker = (NativeComInterfaces.IAdsPathname)new NativeComInterfaces.Pathname();
     _pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_ON;
 }
        public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
        {
            DirectoryEntry        directoryEntry;
            ActiveDirectorySubnet activeDirectorySubnet;
            ActiveDirectorySubnet activeDirectorySubnet1;

            ActiveDirectorySubnet.ValidateArgument(context, subnetName);
            context = new DirectoryContext(context);
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string str           = string.Concat("CN=Subnets,CN=Sites,", propertyValue);
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
            }
            catch (COMException cOMException1)
            {
                COMException cOMException = cOMException1;
                throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
            }
            catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
            {
                object[] name = new object[1];
                name[0] = context.Name;
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
            }
            using (directoryEntry)
            {
                try
                {
                    string[] strArrays = new string[1];
                    strArrays[0] = "distinguishedName";
                    ADSearcher   aDSearcher   = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=subnet)(objectCategory=subnet)(name=", Utils.GetEscapedFilterValue(subnetName), "))"), strArrays, SearchScope.OneLevel, false, false);
                    SearchResult searchResult = aDSearcher.FindOne();
                    if (searchResult != null)
                    {
                        string         str1            = null;
                        DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry();
                        if (directoryEntry1.Properties.Contains("siteObject"))
                        {
                            NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname)(new NativeComInterfaces.Pathname());
                            pathname.EscapedMode = 4;
                            string item = (string)directoryEntry1.Properties["siteObject"][0];
                            pathname.Set(item, 4);
                            string str2 = pathname.Retrieve(11);
                            str1 = str2.Substring(3);
                        }
                        if (str1 != null)
                        {
                            activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, str1, true);
                        }
                        else
                        {
                            activeDirectorySubnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                        }
                        activeDirectorySubnet.cachedEntry = directoryEntry1;
                        activeDirectorySubnet1            = activeDirectorySubnet;
                    }
                    else
                    {
                        Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                        throw exception;
                    }
                }
                catch (COMException cOMException3)
                {
                    COMException cOMException2 = cOMException3;
                    if (cOMException2.ErrorCode != -2147016656)
                    {
                        throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
                    }
                    else
                    {
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                    }
                }
            }
            return(activeDirectorySubnet1);
        }
        public static ActiveDirectorySubnet FindByName(DirectoryContext context, string subnetName)
        {
            DirectoryEntry        directoryEntry;
            ActiveDirectorySubnet subnet2;

            ValidateArgument(context, subnetName);
            context = new DirectoryContext(context);
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = "CN=Subnets,CN=Sites," + str;
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            try
            {
                SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=subnet)(objectCategory=subnet)(name=" + Utils.GetEscapedFilterValue(subnetName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
                if (result == null)
                {
                    Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                    throw exception2;
                }
                string         siteName = null;
                DirectoryEntry entry2   = result.GetDirectoryEntry();
                if (entry2.Properties.Contains("siteObject"))
                {
                    NativeComInterfaces.IAdsPathname pathname = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
                    pathname.EscapedMode = 4;
                    string bstrADsPath = (string)entry2.Properties["siteObject"][0];
                    pathname.Set(bstrADsPath, 4);
                    siteName = pathname.Retrieve(11).Substring(3);
                }
                ActiveDirectorySubnet subnet = null;
                if (siteName == null)
                {
                    subnet = new ActiveDirectorySubnet(context, subnetName, null, true);
                }
                else
                {
                    subnet = new ActiveDirectorySubnet(context, subnetName, siteName, true);
                }
                subnet.cachedEntry = entry2;
                subnet2            = subnet;
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode == -2147016656)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySubnet), subnetName);
                }
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
            }
            finally
            {
                if (directoryEntry != null)
                {
                    directoryEntry.Dispose();
                }
            }
            return(subnet2);
        }
 internal DirectoryEntryManager(DirectoryContext context)
 {
     this.context = context;
     this.pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
     this.pathCracker.EscapedMode = 2;
 }