// // this method is called when the forest name is explicitly specified // and we want to check if that matches the current logged on forest // internal bool isCurrentForest() { bool result = false; Debug.Assert(_name != null); DomainControllerInfo domainControllerInfo = Locator.GetDomainControllerInfo(null, _name, null, (long)(PrivateLocatorFlags.DirectoryServicesRequired | PrivateLocatorFlags.ReturnDNSName)); DomainControllerInfo currentDomainControllerInfo; string loggedOnDomain = GetLoggedOnDomain(); int errorCode = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, (long)(PrivateLocatorFlags.DirectoryServicesRequired | PrivateLocatorFlags.ReturnDNSName), out currentDomainControllerInfo); if (errorCode == 0) { Debug.Assert(domainControllerInfo.DnsForestName != null); Debug.Assert(currentDomainControllerInfo.DnsForestName != null); result = (Utils.Compare(domainControllerInfo.DnsForestName, currentDomainControllerInfo.DnsForestName) == 0); } // // if there is no forest associated with the logged on domain, then we return false // else if (errorCode != NativeMethods.ERROR_NO_SUCH_DOMAIN) { throw ExceptionHelper.GetExceptionFromErrorCode(errorCode); } return(result); }
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); }
internal bool isCurrentForest() { DomainControllerInfo info2; DomainControllerInfo info = Locator.GetDomainControllerInfo(null, this.name, null, 0x40000010L); string loggedOnDomain = GetLoggedOnDomain(); int errorCode = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, 0x40000010L, out info2); if (errorCode == 0) { return(Utils.Compare(info.DnsForestName, info2.DnsForestName) == 0); } if (errorCode != 0x54b) { throw System.DirectoryServices.ActiveDirectory.ExceptionHelper.GetExceptionFromErrorCode(errorCode); } return(false); }
internal bool isCurrentForest() { DomainControllerInfo domainControllerInfo = null; bool flag = false; DomainControllerInfo domainControllerInfo1 = Locator.GetDomainControllerInfo(null, this.name, null, (long)0x40000010); string loggedOnDomain = DirectoryContext.GetLoggedOnDomain(); int num = Locator.DsGetDcNameWrapper(null, loggedOnDomain, null, (long)0x40000010, out domainControllerInfo); if (num != 0) { if (num != 0x54b) { throw ExceptionHelper.GetExceptionFromErrorCode(num); } } else { flag = Utils.Compare(domainControllerInfo1.DnsForestName, domainControllerInfo.DnsForestName) == 0; } return(flag); }
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); }