public void VerifyTrustRelationship(Forest targetForest, TrustDirection direction)
 {
     this.CheckIfDisposed();
     if (targetForest == null)
     {
         throw new ArgumentNullException("targetForest");
     }
     if ((direction < TrustDirection.Inbound) || (direction > TrustDirection.Bidirectional))
     {
         throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection));
     }
     if ((direction & TrustDirection.Outbound) != ((TrustDirection)0))
     {
         try
         {
             TrustHelper.VerifyTrust(this.context, this.Name, targetForest.Name, true, TrustDirection.Outbound, false, null);
         }
         catch (ActiveDirectoryObjectNotFoundException)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", new object[] { this.Name, targetForest.Name, direction }), typeof(ForestTrustRelationshipInformation), null);
         }
     }
     if ((direction & TrustDirection.Inbound) != ((TrustDirection)0))
     {
         try
         {
             TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true, TrustDirection.Outbound, false, null);
         }
         catch (ActiveDirectoryObjectNotFoundException)
         {
             throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", new object[] { this.Name, targetForest.Name, direction }), typeof(ForestTrustRelationshipInformation), null);
         }
     }
 }
        public void RepairTrustRelationship(Forest targetForest)
        {
            TrustDirection bidirectional = TrustDirection.Bidirectional;

            this.CheckIfDisposed();
            if (targetForest == null)
            {
                throw new ArgumentNullException("targetForest");
            }
            try
            {
                bidirectional = this.GetTrustRelationship(targetForest.Name).TrustDirection;
                if ((bidirectional & TrustDirection.Outbound) != ((TrustDirection)0))
                {
                    TrustHelper.VerifyTrust(this.context, this.Name, targetForest.Name, true, TrustDirection.Outbound, true, null);
                }
                if ((bidirectional & TrustDirection.Inbound) != ((TrustDirection)0))
                {
                    TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true, TrustDirection.Outbound, true, null);
                }
            }
            catch (ActiveDirectoryOperationException)
            {
                this.RepairTrustHelper(targetForest, bidirectional);
            }
            catch (UnauthorizedAccessException)
            {
                this.RepairTrustHelper(targetForest, bidirectional);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", new object[] { this.Name, targetForest.Name, bidirectional }), typeof(ForestTrustRelationshipInformation), null);
            }
        }
        private void RepairTrustHelper(Forest targetForest, TrustDirection direction)
        {
            string password = TrustHelper.CreateTrustPassword();
            string preferredTargetServer = TrustHelper.UpdateTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, password, true);
            string str3 = TrustHelper.UpdateTrust(this.context, this.Name, targetForest.Name, password, true);

            if ((direction & TrustDirection.Outbound) != ((TrustDirection)0))
            {
                try
                {
                    TrustHelper.VerifyTrust(this.context, this.Name, targetForest.Name, true, TrustDirection.Outbound, true, preferredTargetServer);
                }
                catch (ActiveDirectoryObjectNotFoundException)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", new object[] { this.Name, targetForest.Name, direction }), typeof(ForestTrustRelationshipInformation), null);
                }
            }
            if ((direction & TrustDirection.Inbound) != ((TrustDirection)0))
            {
                try
                {
                    TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true, TrustDirection.Outbound, true, str3);
                }
                catch (ActiveDirectoryObjectNotFoundException)
                {
                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", new object[] { this.Name, targetForest.Name, direction }), typeof(ForestTrustRelationshipInformation), null);
                }
            }
        }
 public void VerifyOutboundTrustRelationship(string targetForestName)
 {
     this.CheckIfDisposed();
     if (targetForestName == null)
     {
         throw new ArgumentNullException("targetForestName");
     }
     if (targetForestName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName");
     }
     TrustHelper.VerifyTrust(this.context, this.Name, targetForestName, true, TrustDirection.Outbound, false, null);
 }
示例#5
0
        public void VerifyOutboundTrustRelationship(string targetForestName)
        {
            CheckIfDisposed();

            if (targetForestName == null)
            {
                throw new ArgumentNullException(nameof(targetForestName));
            }

            if (targetForestName.Length == 0)
            {
                throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName));
            }

            TrustHelper.VerifyTrust(_context, Name, targetForestName, true /*forest*/, TrustDirection.Outbound, false /*just TC verification*/, null /* no need to go to specific server*/);
        }
示例#6
0
        public void RepairTrustRelationship(Forest targetForest)
        {
            TrustDirection direction = TrustDirection.Bidirectional;

            CheckIfDisposed();

            if (targetForest == null)
            {
                throw new ArgumentNullException(nameof(targetForest));
            }

            // first try to reset the secure channel
            try
            {
                direction = GetTrustRelationship(targetForest.Name).TrustDirection;

                // verify outbound trust first
                if ((direction & TrustDirection.Outbound) != 0)
                {
                    TrustHelper.VerifyTrust(_context, Name, targetForest.Name, true /*is forest*/, TrustDirection.Outbound, true /*reset secure channel*/, null /* no need to go to specific server*/);
                }

                // verify inbound trust
                if ((direction & TrustDirection.Inbound) != 0)
                {
                    TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, Name, true /*is forest*/, TrustDirection.Outbound, true /*reset secure channel*/, null /* no need to go to specific server*/);
                }
            }
            catch (ActiveDirectoryOperationException)
            {
                RepairTrustHelper(targetForest, direction);
            }
            catch (UnauthorizedAccessException)
            {
                RepairTrustHelper(targetForest, direction);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.WrongTrustDirection, Name, targetForest.Name, direction), typeof(ForestTrustRelationshipInformation), null);
            }
        }
示例#7
0
        public void VerifyTrustRelationship(Forest targetForest, TrustDirection direction)
        {
            CheckIfDisposed();

            if (targetForest == null)
            {
                throw new ArgumentNullException(nameof(targetForest));
            }

            if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional)
            {
                throw new InvalidEnumArgumentException(nameof(direction), (int)direction, typeof(TrustDirection));
            }

            // verify outbound trust first
            if ((direction & TrustDirection.Outbound) != 0)
            {
                try
                {
                    TrustHelper.VerifyTrust(_context, Name, targetForest.Name, true /*forest*/, TrustDirection.Outbound, false /*just TC verification*/, null /* no need to go to specific server*/);
                }
                catch (ActiveDirectoryObjectNotFoundException)
                {
                    throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.WrongTrustDirection, Name, targetForest.Name, direction), typeof(ForestTrustRelationshipInformation), null);
                }
            }

            // verify inbound trust
            if ((direction & TrustDirection.Inbound) != 0)
            {
                try
                {
                    TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, Name, true /*forest*/, TrustDirection.Outbound, false /*just TC verification*/, null /* no need to go to specific server*/);
                }
                catch (ActiveDirectoryObjectNotFoundException)
                {
                    throw new ActiveDirectoryObjectNotFoundException(SR.Format(SR.WrongTrustDirection, Name, targetForest.Name, direction), typeof(ForestTrustRelationshipInformation), null);
                }
            }
        }