public static Guid GetSystemMailboxGuid(Guid mdbGuid, string dcName, NetworkCredential cred, FindServerFlags flags) { Guid guid = Guid.Empty; if ((flags & FindServerFlags.ForceRediscovery) == FindServerFlags.None) { lock (MapiUtils.syncRoot) { if (MapiUtils.mdbToSystemMailboxMap.TryGetValue(mdbGuid, out guid)) { return(guid); } } } try { ADSystemMailbox adsystemMailbox = MapiUtils.GetADSystemMailbox(mdbGuid, dcName, cred); guid = adsystemMailbox.ExchangeGuid; } catch (SystemMailboxNotFoundPermanentException) { if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None) { throw; } return(Guid.Empty); } lock (MapiUtils.syncRoot) { MapiUtils.mdbToSystemMailboxMap[mdbGuid] = guid; } return(guid); }
public static MapiStore GetSystemMailbox(Guid mdbGuid, string dcName, NetworkCredential cred, bool allowCrossSiteLogon) { bool flag = false; ConnectFlag connectFlag = ConnectFlag.UseAdminPrivilege | ConnectFlag.AllowLegacyStore; string userName; string password; string domainName; TimeSpan connectionTimeout; TimeSpan callTimeout; if (cred != null) { userName = cred.UserName; password = cred.Password; domainName = cred.Domain; connectionTimeout = TestIntegration.Instance.RemoteMailboxConnectionTimeout; callTimeout = TestIntegration.Instance.RemoteMailboxCallTimeout; } else { userName = null; password = null; domainName = null; connectFlag |= ConnectFlag.UseRpcContextPool; connectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout; callTimeout = TestIntegration.Instance.LocalMailboxCallTimeout; } DatabaseInformation databaseInformation; for (;;) { FindServerFlags findServerFlags = FindServerFlags.FindSystemMailbox; if (flag) { findServerFlags |= FindServerFlags.ForceRediscovery; } databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, dcName, cred, findServerFlags); if (!allowCrossSiteLogon && !databaseInformation.IsInLocalSite) { break; } MapiStore result; try { MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), databaseInformation.SystemMailboxGuid, mdbGuid, userName, domainName, password, connectFlag, OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.MailboxGuid, CultureInfo.InvariantCulture, null, "Client=MSExchangeMigration", connectionTimeout, callTimeout, null); MapiUtils.StartMapiDeadSessionChecking(mapiStore, mdbGuid.ToString()); result = mapiStore; } catch (MapiExceptionWrongServer) { if (!flag) { MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]); flag = true; continue; } throw; } catch (MapiExceptionLogonFailed) { if (!flag) { MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]); flag = true; continue; } throw; } catch (MapiExceptionUnknownUser) { if (!flag) { MrsTracer.Common.Debug("OpenMailbox returned UnknownUser, forcing AM rediscovery", new object[0]); flag = true; continue; } throw; } return(result); } throw new CrossSiteLogonTransientException(mdbGuid, databaseInformation.ServerGuid, databaseInformation.ServerSite.ToString(), CommonUtils.LocalSiteId.ToString()); }
public static DatabaseInformation FindServerForMdb(Guid mdbGuid, string dcName, NetworkCredential cred, FindServerFlags flags) { Guid systemMailboxGuid = Guid.Empty; if (flags.HasFlag(FindServerFlags.FindSystemMailbox)) { systemMailboxGuid = MapiUtils.GetSystemMailboxGuid(mdbGuid, dcName, cred, flags); } if (cred == null) { try { GetServerForDatabaseFlags getServerForDatabaseFlags = GetServerForDatabaseFlags.IgnoreAdSiteBoundary; if (flags.HasFlag(FindServerFlags.ForceRediscovery)) { MrsTracer.Common.Debug("Looking up MDB {0} with rediscovery", new object[] { mdbGuid }); getServerForDatabaseFlags |= GetServerForDatabaseFlags.ReadThrough; } DatabaseLocationInfo serverForDatabase = ActiveManager.GetCachingActiveManagerInstance().GetServerForDatabase(mdbGuid, getServerForDatabaseFlags); if (serverForDatabase != null) { return(DatabaseInformation.FromDatabaseLocationInfo(mdbGuid, serverForDatabase, systemMailboxGuid)); } } catch (ObjectNotFoundException) { } MrsTracer.Common.Debug("ActiveManager was unable to locate MDB {0}, will search AD instead.", new object[] { mdbGuid }); } ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(dcName, true, ConsistencyMode.PartiallyConsistent, cred, ADSessionSettings.FromRootOrgScopeSet(), 686, "FindServerForMdb", "f:\\15.00.1497\\sources\\dev\\mrs\\src\\Common\\MapiUtils.cs"); Database database = topologyConfigurationSession.FindDatabaseByGuid <Database>(mdbGuid); if (database == null) { MrsTracer.Common.Error("Unable to locate MDB by guid {0}", new object[] { mdbGuid }); if (!flags.HasFlag(FindServerFlags.AllowMissing)) { throw new DatabaseNotFoundByGuidPermanentException(mdbGuid); } return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN)); } else { PropertyDefinition[] properties = new PropertyDefinition[] { ServerSchema.ExchangeLegacyDN, ServerSchema.Fqdn, ServerSchema.ServerSite, ServerSchema.VersionNumber, ActiveDirectoryServerSchema.MailboxRelease }; MiniServer miniServer = topologyConfigurationSession.ReadMiniServer(database.Server, properties); if (miniServer != null) { return(DatabaseInformation.FromAD(database, miniServer, systemMailboxGuid)); } MrsTracer.Common.Error("Unable to locate DB server {0}", new object[] { database.Server.DistinguishedName }); if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None) { throw new UnexpectedErrorPermanentException(-2147221233); } return(DatabaseInformation.Missing(mdbGuid, PartitionId.LocalForest.ForestFQDN)); } }
public static DatabaseInformation FindServerForMdb(ADObjectId database, string dcName, NetworkCredential cred, FindServerFlags flags) { if (!ConfigBase <MRSConfigSchema> .GetConfig <bool>("CrossResourceForestEnabled")) { return(MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags)); } Guid empty = Guid.Empty; DatabaseInformation result; try { if (database.GetPartitionId().IsLocalForestPartition()) { result = MapiUtils.FindServerForMdb(database.ObjectGuid, dcName, cred, flags); } else { BackEndServer backEndServer = BackEndLocator.GetBackEndServer(database); result = DatabaseInformation.FromBackEndServer(database, backEndServer); } } catch (BackEndLocatorException) { MrsTracer.Common.Debug("BE Locator was unable to locate MDB {0}.", new object[] { database.ObjectGuid }); if ((flags & FindServerFlags.AllowMissing) == FindServerFlags.None) { throw; } result = DatabaseInformation.Missing(database.ObjectGuid, database.PartitionFQDN); } return(result); }
public static MapiStore GetUserMailbox(Guid mailboxGuid, Guid mdbGuid, UserMailboxFlags umFlags) { OpenStoreFlag openStoreFlag = OpenStoreFlag.UseAdminPrivilege | OpenStoreFlag.TakeOwnership | OpenStoreFlag.NoLocalization | OpenStoreFlag.MailboxGuid; ConnectFlag connectFlags = ConnectFlag.UseAdminPrivilege | ConnectFlag.UseRpcContextPool | ConnectFlag.AllowLegacyStore; if (umFlags.HasFlag(UserMailboxFlags.RecoveryMDB)) { openStoreFlag |= OpenStoreFlag.RestoreDatabase; } if (umFlags.HasFlag(UserMailboxFlags.Disconnected) || umFlags.HasFlag(UserMailboxFlags.SoftDeleted) || umFlags.HasFlag(UserMailboxFlags.MoveDestination)) { openStoreFlag |= (OpenStoreFlag.OverrideHomeMdb | OpenStoreFlag.DisconnectedMailbox); } bool flag = false; TimeSpan localMailboxConnectionTimeout = TestIntegration.Instance.LocalMailboxConnectionTimeout; TimeSpan localMailboxCallTimeout = TestIntegration.Instance.LocalMailboxCallTimeout; MapiStore result; for (;;) { FindServerFlags findServerFlags = FindServerFlags.None; if (flag) { findServerFlags |= FindServerFlags.ForceRediscovery; } DatabaseInformation databaseInformation = MapiUtils.FindServerForMdb(mdbGuid, null, null, findServerFlags); try { MrsTracer.Common.Debug("Opening MapiStore: serverFqdn=\"{0}\", mailboxGuid=\"{1}\", mdbGuid=\"{2}\", flags=[{3}].", new object[] { databaseInformation.ServerFqdn, mailboxGuid, mdbGuid, openStoreFlag }); MapiStore mapiStore = MapiStore.OpenMailbox(databaseInformation.ServerFqdn, Server.GetSystemAttendantLegacyDN(databaseInformation.ServerDN), mailboxGuid, mdbGuid, null, null, null, connectFlags, openStoreFlag, null, null, "Client=MSExchangeMigration", localMailboxConnectionTimeout, localMailboxCallTimeout, null); MapiUtils.StartMapiDeadSessionChecking(mapiStore, mailboxGuid.ToString()); result = mapiStore; } catch (MapiExceptionWrongServer) { if (!flag) { MrsTracer.Common.Debug("OpenMailbox returned WrongServer, forcing AM rediscovery", new object[0]); flag = true; continue; } throw; } catch (MapiExceptionLogonFailed) { if (!flag) { MrsTracer.Common.Debug("OpenMailbox returned LogonFailed, forcing AM rediscovery", new object[0]); flag = true; continue; } throw; } break; } return(result); }