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 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); } }
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) { this.CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException("targetForestName"); } if (targetForestName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } if ((direction < TrustDirection.Inbound) || (direction > TrustDirection.Bidirectional)) { throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection)); } if (trustPassword == null) { throw new ArgumentNullException("trustPassword"); } if (trustPassword.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "trustPassword"); } Locator.GetDomainControllerInfo(null, targetForestName, null, 80L); DirectoryContext targetContext = Utils.GetNewDirectoryContext(targetForestName, DirectoryContextType.Forest, this.context); TrustHelper.CreateTrust(this.context, this.Name, targetContext, targetForestName, true, direction, trustPassword); }
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) { this.CheckIfDisposed(); if (targetForest == null) { throw new ArgumentNullException("targetForest"); } if ((newTrustDirection < TrustDirection.Inbound) || (newTrustDirection > TrustDirection.Bidirectional)) { throw new InvalidEnumArgumentException("newTrustDirection", (int)newTrustDirection, typeof(TrustDirection)); } string password = TrustHelper.CreateTrustPassword(); TrustHelper.UpdateTrustDirection(this.context, this.Name, targetForest.Name, password, true, newTrustDirection); TrustDirection direction = (TrustDirection)0; if ((newTrustDirection & TrustDirection.Inbound) != ((TrustDirection)0)) { direction |= TrustDirection.Outbound; } if ((newTrustDirection & TrustDirection.Outbound) != ((TrustDirection)0)) { direction |= TrustDirection.Inbound; } TrustHelper.UpdateTrustDirection(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, password, true, direction); }
public void UpdateLocalSideOfTrustRelationship(string targetForestName, string newTrustPassword) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } if (newTrustPassword == null) { throw new ArgumentNullException(nameof(newTrustPassword)); } if (newTrustPassword.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(newTrustPassword)); } TrustHelper.UpdateTrust(_context, Name, targetForestName, newTrustPassword, true); }
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) { CheckIfDisposed(); if (targetForest == null) { throw new ArgumentNullException(nameof(targetForest)); } if (newTrustDirection < TrustDirection.Inbound || newTrustDirection > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException(nameof(newTrustDirection), (int)newTrustDirection, typeof(TrustDirection)); } // no we generate trust password string password = TrustHelper.CreateTrustPassword(); TrustHelper.UpdateTrustDirection(_context, Name, targetForest.Name, password, true /*is forest*/, newTrustDirection); // then create trust on remote side TrustDirection reverseDirection = 0; if ((newTrustDirection & TrustDirection.Inbound) != 0) { reverseDirection |= TrustDirection.Outbound; } if ((newTrustDirection & TrustDirection.Outbound) != 0) { reverseDirection |= TrustDirection.Inbound; } TrustHelper.UpdateTrustDirection(targetForest.GetDirectoryContext(), targetForest.Name, Name, password, true /*is forest*/, reverseDirection); }
public void UpdateLocalSideOfTrustRelationship(string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } if (newTrustDirection < TrustDirection.Inbound || newTrustDirection > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException(nameof(newTrustDirection), (int)newTrustDirection, typeof(TrustDirection)); } if (newTrustPassword == null) { throw new ArgumentNullException(nameof(newTrustPassword)); } if (newTrustPassword.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(newTrustPassword)); } TrustHelper.UpdateTrustDirection(_context, Name, targetForestName, newTrustPassword, true /*is forest*/, newTrustDirection); }
public void CreateTrustRelationship(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)); } string password = TrustHelper.CreateTrustPassword(); // first create trust on local side TrustHelper.CreateTrust(_context, Name, targetForest.GetDirectoryContext(), targetForest.Name, true, direction, password); // then create trust on remote side int reverseDirection = 0; if ((direction & TrustDirection.Inbound) != 0) { reverseDirection |= (int)TrustDirection.Outbound; } if ((direction & TrustDirection.Outbound) != 0) { reverseDirection |= (int)TrustDirection.Inbound; } TrustHelper.CreateTrust(targetForest.GetDirectoryContext(), targetForest.Name, _context, Name, true, (TrustDirection)reverseDirection, password); }
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 UpdateLocalSideOfTrustRelationship(string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) { this.CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException("targetForestName"); } if (targetForestName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } if ((newTrustDirection < TrustDirection.Inbound) || (newTrustDirection > TrustDirection.Bidirectional)) { throw new InvalidEnumArgumentException("newTrustDirection", (int)newTrustDirection, typeof(TrustDirection)); } if (newTrustPassword == null) { throw new ArgumentNullException("newTrustPassword"); } if (newTrustPassword.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "newTrustPassword"); } TrustHelper.UpdateTrustDirection(this.context, this.Name, targetForestName, newTrustPassword, true, newTrustDirection); }
public void CreateTrustRelationship(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)); } string password = TrustHelper.CreateTrustPassword(); TrustHelper.CreateTrust(this.context, this.Name, targetForest.GetDirectoryContext(), targetForest.Name, true, direction, password); int num = 0; if ((direction & TrustDirection.Inbound) != ((TrustDirection)0)) { num |= 2; } if ((direction & TrustDirection.Outbound) != ((TrustDirection)0)) { num |= 1; } TrustHelper.CreateTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.context, this.Name, true, (TrustDirection)num, password); }
public void DeleteTrustRelationship(Forest targetForest) { this.CheckIfDisposed(); if (targetForest == null) { throw new ArgumentNullException("targetForest"); } TrustHelper.DeleteTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true); TrustHelper.DeleteTrust(this.context, this.Name, targetForest.Name, true); }
public void DeleteLocalSideOfTrustRelationship(string targetForestName) { this.CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException("targetForestName"); } if (targetForestName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } TrustHelper.DeleteTrust(this.context, this.Name, targetForestName, true); }
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); }
public void SetSidFilteringStatus(string targetForestName, bool enable) { this.CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException("targetForestName"); } if (targetForestName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } TrustHelper.SetTrustedDomainInfoStatus(this.context, this.Name, targetForestName, TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_TREAT_AS_EXTERNAL, enable, true); }
public void SetSelectiveAuthenticationStatus(string targetForestName, bool enable) { this.CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException("targetForestName"); } if (targetForestName.Length == 0) { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } TrustHelper.SetTrustedDomainInfoStatus(this.context, this.Name, targetForestName, TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_CROSS_ORGANIZATION, enable, true); }
public void DeleteTrustRelationship(Forest targetForest) { CheckIfDisposed(); if (targetForest == null) { throw new ArgumentNullException(nameof(targetForest)); } // first delete the trust on the remote side TrustHelper.DeleteTrust(targetForest.GetDirectoryContext(), targetForest.Name, Name, true); // then delete the local side trust TrustHelper.DeleteTrust(_context, Name, targetForest.Name, true); }
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*/); }
public void SetSidFilteringStatus(string targetForestName, bool enable) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } TrustHelper.SetTrustedDomainInfoStatus(_context, Name, targetForestName, TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_TREAT_AS_EXTERNAL, enable, true); }
public bool GetSelectiveAuthenticationStatus(string targetForestName) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } return(TrustHelper.GetTrustedDomainInfoStatus(_context, Name, targetForestName, TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_CROSS_ORGANIZATION, true)); }
public void DeleteLocalSideOfTrustRelationship(string targetForestName) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } // delete local side of trust only TrustHelper.DeleteTrust(_context, Name, targetForestName, true); }
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); } }
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); } } }
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) { CheckIfDisposed(); if (targetForestName == null) { throw new ArgumentNullException(nameof(targetForestName)); } if (targetForestName.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(targetForestName)); } if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException(nameof(direction), (int)direction, typeof(TrustDirection)); } if (trustPassword == null) { throw new ArgumentNullException(nameof(trustPassword)); } if (trustPassword.Length == 0) { throw new ArgumentException(SR.EmptyStringParameter, nameof(trustPassword)); } // verify first that the target forest name is valid Locator.GetDomainControllerInfo(null, targetForestName, null, (long)(PrivateLocatorFlags.DirectoryServicesRequired | PrivateLocatorFlags.GCRequired)); DirectoryContext targetContext = Utils.GetNewDirectoryContext(targetForestName, DirectoryContextType.Forest, _context); TrustHelper.CreateTrust(_context, Name, targetContext, targetForestName, true, direction, trustPassword); }