/// <summary>
        /// Returns true if the domain identified by sid is in a forest trusted by the caller's forest,
        /// as determined by the FOREST_TRUST_INFORMATION state of the caller's forest, false otherwise.
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="sid">The SID of a domain.</param>
        /// <returns></returns>
        static bool IsDomainSidInTrustedForest(DsServer dc, NT4SID sid)
        {
            FOREST_TRUST_INFORMATION f;
            bool b;

            RootDSE rootDse = LdapUtility.GetRootDSE(dc);

            string[] tdos = LdapUtility.GetAttributeValuesString(
                dc,
                rootDse.rootDomainNamingContext,
                "distinguishedName",
                "(&(objectClass=trustedDomain)(msDS-TrustForestTrustInfo=*)(trustAttributes:1.2.840.113556.1.4.803:=0x8))",
                System.DirectoryServices.Protocols.SearchScope.Subtree);

            foreach (string o in tdos)
            {
                byte[] trustInfo = (byte[])LdapUtility.GetAttributeValue(dc, o, "msDS-TrustForestTrustInfo");
                if (!TrustInfo.UnmarshalForestTrustInfo(trustInfo, out f))
                {
                    return(false);
                }

                foreach (Record e in f.Records)
                {
                    if (e.RecordType == (byte)FOREST_TRUST_RECORD_TYPE.ForestTrustDomainInfo &&
                        (DrsrHelper.IsByteArrayEqual(sid.Data, ((RecordDomainInfo)e.ForestTrustData).Sid.Data)) &&
                        ((e.Flags & TrustInfo.LSA_FTRECORD_DISABLED_REASONS) == 0))
                    {
                        b = true;
                        foreach (Record g in f.Records)
                        {
                            if (g.RecordType == (byte)FOREST_TRUST_RECORD_TYPE.ForestTrustTopLevelNameEx &&
                                (g.Flags & TrustInfo.LSA_FTRECORD_DISABLED_REASONS) == 0 &&
                                (
                                    ((RecordTopLevelName)g.ForestTrustData).TopLevelName
                                    == ((RecordDomainInfo)e.ForestTrustData).DnsName
                                    ||
                                    TrustInfo.IsSubdomainOf(
                                        ((RecordDomainInfo)e.ForestTrustData).DnsName,
                                        ((RecordTopLevelName)g.ForestTrustData).TopLevelName)
                                )
                                )
                            {
                                b = false;
                                break;
                            }
                        }

                        if (b)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public static uint MakeAttid(SCHEMA_PREFIX_TABLE t, string o)
        {
            string lastValueString;
            uint   lastValue, lowerWord;

            byte[] binaryOID, oidPrefix;
            uint   attr;
            uint   pos = 0;

            string[] ss = o.Split('.');
            lastValueString = ss[ss.Length - 1];
            lastValue       = Convert.ToUInt32(lastValueString);

            binaryOID = ToBinaryOID(o);

            if (lastValue < 128)
            {
                oidPrefix = SubBinary(binaryOID, 0, binaryOID.Length - 1);
            }
            else
            {
                oidPrefix = SubBinary(binaryOID, 0, binaryOID.Length - 2);
            }

            bool fToAdd = true;

            for (uint i = 0; i < t.PrefixCount; ++i)
            {
                if (DrsrHelper.IsByteArrayEqual(t.pPrefixEntry[i].prefix.elements, oidPrefix))
                {
                    fToAdd = false;
                    pos    = i;
                    break;
                }
            }

            if (fToAdd)
            {
                pos = (uint)t.PrefixCount;
                AddPrefixTableEntry(ref t, oidPrefix);
            }

            lowerWord = lastValue % 16384;
            if (lastValue >= 16384)
            {
                lowerWord += 32768;
            }
            uint upperWord = t.pPrefixEntry[pos].ndx;

            attr = upperWord * 65536 + lowerWord;

            return(attr);
        }