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); }
internal TrustRelationshipInformation(DirectoryContext context, string source, TrustObject obj) { // security context this.context = context; // source this.source = source; // target this.target = (obj.DnsDomainName == null ? obj.NetbiosDomainName : obj.DnsDomainName); // direction if ((obj.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_OUTBOUND) != 0 && (obj.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_INBOUND) != 0) { direction = TrustDirection.Bidirectional; } else if ((obj.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_OUTBOUND) != 0) { direction = TrustDirection.Outbound; } else if ((obj.Flags & (int)DS_DOMAINTRUST_FLAG.DS_DOMAIN_DIRECT_INBOUND) != 0) { direction = TrustDirection.Inbound; } // type this.type = obj.TrustType; }
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); }
internal TrustRelationshipInformation(DirectoryContext context, string source, TrustObject obj) { string netbiosDomainName; this.context = context; this.source = source; TrustRelationshipInformation trustRelationshipInformation = this; if (obj.DnsDomainName == null) { netbiosDomainName = obj.NetbiosDomainName; } else { netbiosDomainName = obj.DnsDomainName; } trustRelationshipInformation.target = netbiosDomainName; if ((obj.Flags & 2) == 0 || (obj.Flags & 32) == 0) { if ((obj.Flags & 2) == 0) { if ((obj.Flags & 32) != 0) { this.direction = TrustDirection.Inbound; } } else { this.direction = TrustDirection.Outbound; } } else { this.direction = TrustDirection.Bidirectional; } this.type = obj.TrustType; }
public TrustRelationshipInformation(string sourcename, string targetname, TrustType trusttype, TrustDirection trustdirection) { this.sourcename = sourcename; this.targetname = targetname; this.trusttype = trusttype; this.trustdirection = trustdirection; }
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 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 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 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 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 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 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 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 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 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); }
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) { }
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) { throw new NotImplementedException(); }
public void VerifyTrustRelationship(Domain targetDomain, TrustDirection direction) { throw new NotImplementedException(); }
public void CreateTrustRelationship(Domain targetDomain, TrustDirection direction) {}
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) {}
public void CreateTrustRelationship(Forest targetForest, TrustDirection direction) {}
public void VerifyTrustRelationship(Forest targetForest, TrustDirection direction) {}
public void CreateLocalSideOfTrustRelationship(string targetDomainName, TrustDirection direction, string trustPassword) { base.CheckIfDisposed(); if (targetDomainName != null) { if (targetDomainName.Length != 0) { if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection)); } else { if (trustPassword != null) { if (trustPassword.Length != 0) { Locator.GetDomainControllerInfo(null, targetDomainName, null, (long)16); DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(targetDomainName, DirectoryContextType.Domain, this.context); TrustHelper.CreateTrust(this.context, base.Name, newDirectoryContext, targetDomainName, false, direction, trustPassword); return; } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "trustPassword"); } } else { throw new ArgumentNullException("trustPassword"); } } } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetDomainName"); } } else { throw new ArgumentNullException("targetDomainName"); } }
public void CreateTrustRelationship(Domain targetDomain, TrustDirection direction) { CheckIfDisposed(); if (targetDomain == null) throw new ArgumentNullException("targetDomain"); if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional) throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection)); string password = TrustHelper.CreateTrustPassword(); // first create trust on local side TrustHelper.CreateTrust(context, Name, targetDomain.GetDirectoryContext(), targetDomain.Name, false, 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(targetDomain.GetDirectoryContext(), targetDomain.Name, context, Name, false, (TrustDirection)reverseDirection, password); }
public void CreateLocalSideOfTrustRelationship(string targetDomainName, TrustDirection direction, string trustPassword) { CheckIfDisposed(); if (targetDomainName == null) throw new ArgumentNullException("targetDomainName"); if (targetDomainName.Length == 0) throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "targetDomainName"); 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(Res.EmptyStringParameter), "trustPassword"); // verify first that the target domain name is valid Locator.GetDomainControllerInfo(null, targetDomainName, null, (long)PrivateLocatorFlags.DirectoryServicesRequired); DirectoryContext targetContext = Utils.GetNewDirectoryContext(targetDomainName, DirectoryContextType.Domain, context); TrustHelper.CreateTrust(context, Name, targetContext, targetDomainName, false, direction, trustPassword); }
public void UpdateLocalSideOfTrustRelationship(string targetDomainName, TrustDirection newTrustDirection, string newTrustPassword) { throw new NotImplementedException(); }
public void CreateTrustRelationship(Forest targetForest, TrustDirection direction) { }
public void VerifyTrustRelationship(Domain targetDomain, TrustDirection direction) {}
internal static void UpdateTrustDirection(DirectoryContext context, string sourceName, string targetName, string password, bool isForest, TrustDirection newTrustDirection) { PolicySafeHandle handle = null; IntPtr zero = IntPtr.Zero; LSA_UNICODE_STRING result = null; IntPtr ptr = IntPtr.Zero; bool flag = false; LSA_AUTH_INFORMATION structure = null; IntPtr fileTime = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr ptr5 = IntPtr.Zero; TRUSTED_DOMAIN_AUTH_INFORMATION trusted_domain_auth_information = null; IntPtr s = IntPtr.Zero; string serverName = null; serverName = System.DirectoryServices.ActiveDirectory.Utils.GetPolicyServerName(context, isForest, false, sourceName); flag = System.DirectoryServices.ActiveDirectory.Utils.Impersonate(context); try { try { handle = new PolicySafeHandle(System.DirectoryServices.ActiveDirectory.Utils.GetPolicyHandle(serverName)); result = new LSA_UNICODE_STRING(); s = Marshal.StringToHGlobalUni(targetName); UnsafeNativeMethods.RtlInitUnicodeString(result, s); int status = UnsafeNativeMethods.LsaQueryTrustedDomainInfoByName(handle, result, TRUSTED_INFORMATION_CLASS.TrustedDomainFullInformation, ref zero); if (status != 0) { int errorCode = UnsafeNativeMethods.LsaNtStatusToWinError(status); if (errorCode != STATUS_OBJECT_NAME_NOT_FOUND) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode, serverName); } if (isForest) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("ForestTrustDoesNotExist", new object[] { sourceName, targetName }), typeof(ForestTrustRelationshipInformation), null); } throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DomainTrustDoesNotExist", new object[] { sourceName, targetName }), typeof(TrustRelationshipInformation), null); } TRUSTED_DOMAIN_FULL_INFORMATION trusted_domain_full_information = new TRUSTED_DOMAIN_FULL_INFORMATION(); Marshal.PtrToStructure(zero, trusted_domain_full_information); ValidateTrustAttribute(trusted_domain_full_information.Information, isForest, sourceName, targetName); structure = new LSA_AUTH_INFORMATION(); fileTime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FileTime))); UnsafeNativeMethods.GetSystemTimeAsFileTime(fileTime); FileTime time = new FileTime(); Marshal.PtrToStructure(fileTime, time); structure.LastUpdateTime = new LARGE_INTEGER(); structure.LastUpdateTime.lowPart = time.lower; structure.LastUpdateTime.highPart = time.higher; structure.AuthType = TRUST_AUTH_TYPE_CLEAR; hglobal = Marshal.StringToHGlobalUni(password); structure.AuthInfo = hglobal; structure.AuthInfoLength = password.Length * 2; ptr5 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LSA_AUTH_INFORMATION))); Marshal.StructureToPtr(structure, ptr5, false); trusted_domain_auth_information = new TRUSTED_DOMAIN_AUTH_INFORMATION(); if ((newTrustDirection & TrustDirection.Inbound) != ((TrustDirection) 0)) { trusted_domain_auth_information.IncomingAuthInfos = 1; trusted_domain_auth_information.IncomingAuthenticationInformation = ptr5; trusted_domain_auth_information.IncomingPreviousAuthenticationInformation = IntPtr.Zero; } else { trusted_domain_auth_information.IncomingAuthInfos = 0; trusted_domain_auth_information.IncomingAuthenticationInformation = IntPtr.Zero; trusted_domain_auth_information.IncomingPreviousAuthenticationInformation = IntPtr.Zero; } if ((newTrustDirection & TrustDirection.Outbound) != ((TrustDirection) 0)) { trusted_domain_auth_information.OutgoingAuthInfos = 1; trusted_domain_auth_information.OutgoingAuthenticationInformation = ptr5; trusted_domain_auth_information.OutgoingPreviousAuthenticationInformation = IntPtr.Zero; } else { trusted_domain_auth_information.OutgoingAuthInfos = 0; trusted_domain_auth_information.OutgoingAuthenticationInformation = IntPtr.Zero; trusted_domain_auth_information.OutgoingPreviousAuthenticationInformation = IntPtr.Zero; } trusted_domain_full_information.AuthInformation = trusted_domain_auth_information; trusted_domain_full_information.Information.TrustDirection = (int) newTrustDirection; ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TRUSTED_DOMAIN_FULL_INFORMATION))); Marshal.StructureToPtr(trusted_domain_full_information, ptr, false); status = UnsafeNativeMethods.LsaSetTrustedDomainInfoByName(handle, result, TRUSTED_INFORMATION_CLASS.TrustedDomainFullInformation, ptr); if (status != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(UnsafeNativeMethods.LsaNtStatusToWinError(status), serverName); } } finally { if (flag) { System.DirectoryServices.ActiveDirectory.Utils.Revert(); } if (s != IntPtr.Zero) { Marshal.FreeHGlobal(s); } if (zero != IntPtr.Zero) { UnsafeNativeMethods.LsaFreeMemory(zero); } if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } if (fileTime != IntPtr.Zero) { Marshal.FreeHGlobal(fileTime); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } if (ptr5 != IntPtr.Zero) { Marshal.FreeHGlobal(ptr5); } } } catch { throw; } }
public void UpdateTrustRelationship(Domain targetDomain, TrustDirection newTrustDirection) {}
public void VerifyTrustRelationship (Forest targetForest, TrustDirection direction) { throw new NotImplementedException (); }
public void UpdateTrustRelationship (Forest targetForest, TrustDirection newTrustDirection) { throw new NotImplementedException (); }
public void UpdateLocalSideOfTrustRelationship(string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) { this.CheckIfDisposed(); if (targetForestName != null) { if (targetForestName.Length != 0) { if (newTrustDirection < TrustDirection.Inbound || newTrustDirection > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException("newTrustDirection", (int)newTrustDirection, typeof(TrustDirection)); } else { if (newTrustPassword != null) { if (newTrustPassword.Length != 0) { TrustHelper.UpdateTrustDirection(this.context, this.Name, targetForestName, newTrustPassword, true, newTrustDirection); return; } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "newTrustPassword"); } } else { throw new ArgumentNullException("newTrustPassword"); } } } else { throw new ArgumentException(Res.GetString("EmptyStringParameter"), "targetForestName"); } } else { throw new ArgumentNullException("targetForestName"); } }
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) { throw new NotImplementedException(); }
public void VerifyTrustRelationship(Forest targetForest, TrustDirection direction) { this.CheckIfDisposed(); if (targetForest != null) { if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection)); } else { if ((direction & TrustDirection.Outbound) != 0) { try { TrustHelper.VerifyTrust(this.context, this.Name, targetForest.Name, true, TrustDirection.Outbound, false, null); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[3]; name[0] = this.Name; name[1] = targetForest.Name; name[2] = direction; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", name), typeof(ForestTrustRelationshipInformation), null); } } if ((direction & TrustDirection.Inbound) != 0) { try { TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true, TrustDirection.Outbound, false, null); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException1) { object[] objArray = new object[3]; objArray[0] = this.Name; objArray[1] = targetForest.Name; objArray[2] = direction; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", objArray), typeof(ForestTrustRelationshipInformation), null); } } return; } } else { throw new ArgumentNullException("targetForest"); } }
public void UpdateLocalSideOfTrustRelationship(string targetDomainName, TrustDirection newTrustDirection, string newTrustPassword) { CheckIfDisposed(); if (targetDomainName == null) throw new ArgumentNullException("targetDomainName"); if (targetDomainName.Length == 0) throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "targetDomainName"); 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(Res.EmptyStringParameter), "newTrustPassword"); TrustHelper.UpdateTrustDirection(context, Name, targetDomainName, newTrustPassword, false /*not a forest*/, newTrustDirection); }
public void UpdateTrustRelationship(Domain targetDomain, TrustDirection newTrustDirection) { throw new NotImplementedException(); }
/// <summary> /// Trust constructor. /// </summary> /// <param name="fqn">Fully qualified domain name.</param> /// <param name="trust">Domain trust, source of the domain information.</param> public WindowsDomainImpl(string fqn, TrustRelationshipInformation trust) { _fqn = fqn; _trustDirection = trust.TrustDirection; _trustType = trust.TrustType; }
public void UpdateTrustRelationship(Domain targetDomain, TrustDirection newTrustDirection) { CheckIfDisposed(); if (targetDomain == null) throw new ArgumentNullException("targetDomain"); if (newTrustDirection < TrustDirection.Inbound || newTrustDirection > TrustDirection.Bidirectional) throw new InvalidEnumArgumentException("newTrustDirection", (int)newTrustDirection, typeof(TrustDirection)); // no we generate trust password string password = TrustHelper.CreateTrustPassword(); TrustHelper.UpdateTrustDirection(context, Name, targetDomain.Name, password, false /* not a 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(targetDomain.GetDirectoryContext(), targetDomain.Name, Name, password, false /* not a forest */, reverseDirection); }
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) {}
public void CreateLocalSideOfTrustRelationship(string targetForestName, TrustDirection direction, string trustPassword) { Contract.Requires(!string.IsNullOrEmpty(targetForestName)); Contract.Requires(!string.IsNullOrEmpty(trustPassword)); }
public void UpdateLocalSideOfTrustRelationship(string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) {}
public void CreateTrustRelationship(Forest targetForest, TrustDirection direction) { Contract.Requires(targetForest != null); }
internal static void CreateTrust(DirectoryContext sourceContext, string sourceName, DirectoryContext targetContext, string targetName, bool isForest, TrustDirection direction, string password) { LSA_AUTH_INFORMATION structure = null; TRUSTED_DOMAIN_AUTH_INFORMATION authInfo = null; TRUSTED_DOMAIN_INFORMATION_EX domainEx = null; IntPtr zero = IntPtr.Zero; IntPtr hglobal = IntPtr.Zero; IntPtr ptr = IntPtr.Zero; IntPtr domainHandle = IntPtr.Zero; PolicySafeHandle handle = null; IntPtr ptr5 = IntPtr.Zero; bool flag = false; string serverName = null; ptr = GetTrustedDomainInfo(targetContext, targetName, isForest); try { try { POLICY_DNS_DOMAIN_INFO policy_dns_domain_info = new POLICY_DNS_DOMAIN_INFO(); Marshal.PtrToStructure(ptr, policy_dns_domain_info); structure = new LSA_AUTH_INFORMATION(); zero = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FileTime))); UnsafeNativeMethods.GetSystemTimeAsFileTime(zero); FileTime time = new FileTime(); Marshal.PtrToStructure(zero, time); structure.LastUpdateTime = new LARGE_INTEGER(); structure.LastUpdateTime.lowPart = time.lower; structure.LastUpdateTime.highPart = time.higher; structure.AuthType = TRUST_AUTH_TYPE_CLEAR; hglobal = Marshal.StringToHGlobalUni(password); structure.AuthInfo = hglobal; structure.AuthInfoLength = password.Length * 2; ptr5 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LSA_AUTH_INFORMATION))); Marshal.StructureToPtr(structure, ptr5, false); authInfo = new TRUSTED_DOMAIN_AUTH_INFORMATION(); if ((direction & TrustDirection.Inbound) != ((TrustDirection) 0)) { authInfo.IncomingAuthInfos = 1; authInfo.IncomingAuthenticationInformation = ptr5; authInfo.IncomingPreviousAuthenticationInformation = IntPtr.Zero; } if ((direction & TrustDirection.Outbound) != ((TrustDirection) 0)) { authInfo.OutgoingAuthInfos = 1; authInfo.OutgoingAuthenticationInformation = ptr5; authInfo.OutgoingPreviousAuthenticationInformation = IntPtr.Zero; } domainEx = new TRUSTED_DOMAIN_INFORMATION_EX { FlatName = policy_dns_domain_info.Name, Name = policy_dns_domain_info.DnsDomainName, Sid = policy_dns_domain_info.Sid, TrustType = TRUST_TYPE_UPLEVEL, TrustDirection = (int) direction }; if (isForest) { domainEx.TrustAttributes = TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_FOREST_TRANSITIVE; } else { domainEx.TrustAttributes = TRUST_ATTRIBUTE.TRUST_ATTRIBUTE_QUARANTINED_DOMAIN; } serverName = System.DirectoryServices.ActiveDirectory.Utils.GetPolicyServerName(sourceContext, isForest, false, sourceName); flag = System.DirectoryServices.ActiveDirectory.Utils.Impersonate(sourceContext); handle = new PolicySafeHandle(System.DirectoryServices.ActiveDirectory.Utils.GetPolicyHandle(serverName)); int status = UnsafeNativeMethods.LsaCreateTrustedDomainEx(handle, domainEx, authInfo, TRUSTED_SET_POSIX | TRUSTED_SET_AUTH, out domainHandle); if (status != 0) { status = UnsafeNativeMethods.LsaNtStatusToWinError(status); if (status != ERROR_ALREADY_EXISTS) { throw ExceptionHelper.GetExceptionFromErrorCode(status, serverName); } if (isForest) { throw new ActiveDirectoryObjectExistsException(Res.GetString("AlreadyExistingForestTrust", new object[] { sourceName, targetName })); } throw new ActiveDirectoryObjectExistsException(Res.GetString("AlreadyExistingDomainTrust", new object[] { sourceName, targetName })); } } finally { if (flag) { System.DirectoryServices.ActiveDirectory.Utils.Revert(); } if (zero != IntPtr.Zero) { Marshal.FreeHGlobal(zero); } if (domainHandle != IntPtr.Zero) { UnsafeNativeMethods.LsaClose(domainHandle); } if (ptr != IntPtr.Zero) { UnsafeNativeMethods.LsaFreeMemory(ptr); } if (hglobal != IntPtr.Zero) { Marshal.FreeHGlobal(hglobal); } if (ptr5 != IntPtr.Zero) { Marshal.FreeHGlobal(ptr5); } } } catch { throw; } }
public void UpdateTrustRelationship(Domain targetDomain, TrustDirection newTrustDirection) { }
internal static void VerifyTrust(DirectoryContext context, string sourceName, string targetName, bool isForest, TrustDirection direction, bool forceSecureChannelReset, string preferredTargetServer) { PolicySafeHandle handle = null; LSA_UNICODE_STRING result = null; int errorCode = 0; IntPtr zero = IntPtr.Zero; IntPtr ptr = IntPtr.Zero; IntPtr buffer = IntPtr.Zero; IntPtr ptr4 = IntPtr.Zero; bool flag = true; IntPtr s = IntPtr.Zero; string serverName = null; serverName = System.DirectoryServices.ActiveDirectory.Utils.GetPolicyServerName(context, isForest, false, sourceName); flag = System.DirectoryServices.ActiveDirectory.Utils.Impersonate(context); try { try { handle = new PolicySafeHandle(System.DirectoryServices.ActiveDirectory.Utils.GetPolicyHandle(serverName)); result = new LSA_UNICODE_STRING(); s = Marshal.StringToHGlobalUni(targetName); UnsafeNativeMethods.RtlInitUnicodeString(result, s); ValidateTrust(handle, result, sourceName, targetName, isForest, (int) direction, serverName); if (preferredTargetServer == null) { zero = Marshal.StringToHGlobalUni(targetName); } else { zero = Marshal.StringToHGlobalUni(targetName + @"\" + preferredTargetServer); } ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr))); Marshal.WriteIntPtr(ptr, zero); if (!forceSecureChannelReset) { errorCode = UnsafeNativeMethods.I_NetLogonControl2(serverName, NETLOGON_CONTROL_TC_VERIFY, NETLOGON_QUERY_LEVEL, ptr, out buffer); if (errorCode != 0) { if (errorCode == ERROR_INVALID_LEVEL) { throw new NotSupportedException(Res.GetString("TrustVerificationNotSupport")); } throw ExceptionHelper.GetExceptionFromErrorCode(errorCode); } NETLOGON_INFO_2 structure = new NETLOGON_INFO_2(); Marshal.PtrToStructure(buffer, structure); if ((structure.netlog2_flags & NETLOGON_VERIFY_STATUS_RETURNED) == 0) { throw ExceptionHelper.GetExceptionFromErrorCode(structure.netlog2_tc_connection_status); } int num2 = structure.netlog2_pdc_connection_status; if (num2 != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(num2); } } else { errorCode = UnsafeNativeMethods.I_NetLogonControl2(serverName, NETLOGON_CONTROL_REDISCOVER, NETLOGON_QUERY_LEVEL, ptr, out ptr4); if (errorCode != 0) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode); } } } finally { if (flag) { System.DirectoryServices.ActiveDirectory.Utils.Revert(); } if (s != IntPtr.Zero) { Marshal.FreeHGlobal(s); } if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } if (zero != IntPtr.Zero) { Marshal.FreeHGlobal(zero); } if (buffer != IntPtr.Zero) { UnsafeNativeMethods.NetApiBufferFree(buffer); } if (ptr4 != IntPtr.Zero) { UnsafeNativeMethods.NetApiBufferFree(ptr4); } } } catch { throw; } }
public void VerifyTrustRelationship(Domain targetDomain, TrustDirection direction) { }
public void UpdateLocalSideOfTrustRelationship (string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) { throw new NotImplementedException (); }
public void CreateTrustRelationship(Domain targetDomain, TrustDirection direction) { }
private void RepairTrustHelper(Forest targetForest, TrustDirection direction) { string str = TrustHelper.CreateTrustPassword(); string str1 = TrustHelper.UpdateTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, str, true); string str2 = TrustHelper.UpdateTrust(this.context, this.Name, targetForest.Name, str, true); if ((direction & TrustDirection.Outbound) != 0) { try { TrustHelper.VerifyTrust(this.context, this.Name, targetForest.Name, true, TrustDirection.Outbound, true, str1); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[3]; name[0] = this.Name; name[1] = targetForest.Name; name[2] = direction; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", name), typeof(ForestTrustRelationshipInformation), null); } } if ((direction & TrustDirection.Inbound) != 0) { try { TrustHelper.VerifyTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, true, TrustDirection.Outbound, true, str2); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException1) { object[] objArray = new object[3]; objArray[0] = this.Name; objArray[1] = targetForest.Name; objArray[2] = direction; throw new ActiveDirectoryObjectNotFoundException(Res.GetString("WrongTrustDirection", objArray), typeof(ForestTrustRelationshipInformation), null); } } }
public void UpdateLocalSideOfTrustRelationship(string targetForestName, TrustDirection newTrustDirection, string newTrustPassword) { }
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) { this.CheckIfDisposed(); if (targetForest != null) { if (newTrustDirection < TrustDirection.Inbound || newTrustDirection > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException("newTrustDirection", (int)newTrustDirection, typeof(TrustDirection)); } else { string str = TrustHelper.CreateTrustPassword(); TrustHelper.UpdateTrustDirection(this.context, this.Name, targetForest.Name, str, true, newTrustDirection); TrustDirection trustDirection = 0; if ((newTrustDirection & TrustDirection.Inbound) != 0) { trustDirection = trustDirection | TrustDirection.Outbound; } if ((newTrustDirection & TrustDirection.Outbound) != 0) { trustDirection = trustDirection | TrustDirection.Inbound; } TrustHelper.UpdateTrustDirection(targetForest.GetDirectoryContext(), targetForest.Name, this.Name, str, true, trustDirection); return; } } else { throw new ArgumentNullException("targetForest"); } }
public void UpdateTrustRelationship(Forest targetForest, TrustDirection newTrustDirection) { }
public void CreateTrustRelationship(Forest targetForest, TrustDirection direction) { this.CheckIfDisposed(); if (targetForest != null) { if (direction < TrustDirection.Inbound || direction > TrustDirection.Bidirectional) { throw new InvalidEnumArgumentException("direction", (int)direction, typeof(TrustDirection)); } else { string str = TrustHelper.CreateTrustPassword(); TrustHelper.CreateTrust(this.context, this.Name, targetForest.GetDirectoryContext(), targetForest.Name, true, direction, str); int num = 0; if ((direction & TrustDirection.Inbound) != 0) { num = num | 2; } if ((direction & TrustDirection.Outbound) != 0) { num = num | 1; } TrustHelper.CreateTrust(targetForest.GetDirectoryContext(), targetForest.Name, this.context, this.Name, true, (TrustDirection)num, str); return; } } else { throw new ArgumentNullException("targetForest"); } }
public void VerifyTrustRelationship(Forest targetForest, TrustDirection direction) { }