public static ADRecipient ReadADRecipient(Guid mailboxGuid, bool isArchive, IRecipientSession recipientSession) { if (isArchive) { return(recipientSession.FindByExchangeGuidIncludingArchive(mailboxGuid)); } return(recipientSession.FindByExchangeGuid(mailboxGuid)); }
internal static ADUser GetADUser(MailboxSession session, bool readOnly, out IRecipientSession recipSession) { recipSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(readOnly, ConsistencyMode.FullyConsistent, session.MailboxOwner.MailboxInfo.OrganizationId.ToADSessionSettings(), 43, "GetADUser", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\ELC\\AdReader.cs"); ADRecipient adrecipient = null; string text = session.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(); try { if (session.MailboxOwner.MailboxInfo.MailboxGuid != Guid.Empty) { adrecipient = recipSession.FindByExchangeGuidIncludingArchive(session.MailboxOwner.MailboxInfo.MailboxGuid); } else if (SmtpAddress.IsValidSmtpAddress(text)) { SmtpProxyAddress proxyAddress = new SmtpProxyAddress(text, true); adrecipient = recipSession.FindByProxyAddress(proxyAddress); } else { AdReader.Tracer.TraceDebug <string>(0L, "Mailbox '{0}' does not have a valid smtp address.", text); } } catch (DataValidationException) { AdReader.Tracer.TraceError <string>(0L, "AD object for '{0}' has a data validation issue.", text); return(null); } if (adrecipient == null) { AdReader.Tracer.TraceDebug <string>(0L, "Mailbox '{0}' does not have a user associated with it.", text); return(null); } ADUser aduser = adrecipient as ADUser; if (aduser == null) { AdReader.Tracer.TraceDebug <string>(0L, "'{0}': Is not an ADUser.", text); return(null); } return(aduser); }
protected void ResolveRequestedADRecipient() { string resolveMethod = "Unknown"; try { if (this.Caller != null) { if (!string.IsNullOrEmpty(this.RequestData.LegacyDN) && string.Equals(this.Caller.LegacyExchangeDN, this.RequestData.LegacyDN, StringComparison.OrdinalIgnoreCase)) { this.RequestedRecipient = this.Caller; resolveMethod = "CallerByLegacyDN"; return; } if (!string.IsNullOrEmpty(this.RequestData.LegacyDN) && this.Caller.EmailAddresses != null) { string x500 = "x500:" + this.RequestData.LegacyDN; ProxyAddress a = this.Caller.EmailAddresses.Find((ProxyAddress x) => string.Equals(x.ToString(), x500, StringComparison.OrdinalIgnoreCase)); if (a != null) { this.RequestedRecipient = this.Caller; resolveMethod = "CallerByX500"; return; } } if (!string.IsNullOrEmpty(this.RequestData.EMailAddress) && SmtpAddress.IsValidSmtpAddress(this.RequestData.EMailAddress)) { SmtpProxyAddress smtpProxy = new SmtpProxyAddress(this.RequestData.EMailAddress, true); ProxyAddress a2 = this.Caller.EmailAddresses.Find((ProxyAddress x) => x.Equals(smtpProxy)); if (a2 != null) { this.RequestedRecipient = this.Caller; resolveMethod = "CallerByProxy"; return; } } if (AutodiscoverCommonUserSettings.HasLocalArchive(this.Caller) && AutodiscoverCommonUserSettings.IsEmailAddressTargetingArchive(this.Caller as ADUser, this.RequestData.EMailAddress)) { this.RequestedRecipient = this.Caller; resolveMethod = "CallerByArchive"; return; } } if (this.Caller == null) { if (VariantConfiguration.InvariantNoFlightingSnapshot.Autodiscover.NoADLookupForUser.Enabled) { goto IL_285; } } try { RequestDetailsLoggerBase <RequestDetailsLogger> .Current.TrackLatency(ServiceLatencyMetadata.RequestedUserADLatency, delegate() { IRecipientSession callerScopedRecipientSession = this.GetCallerScopedRecipientSession(); if (!string.IsNullOrEmpty(this.RequestData.LegacyDN)) { this.RequestedRecipient = callerScopedRecipientSession.FindByLegacyExchangeDN(this.RequestData.LegacyDN); if (this.RequestedRecipient != null) { resolveMethod = "FoundByLegacyDN"; } } if (this.RequestedRecipient == null && this.RequestData.EMailAddress != null && SmtpAddress.IsValidSmtpAddress(this.RequestData.EMailAddress)) { Guid guid; if (AutodiscoverCommonUserSettings.TryGetExchangeGuidFromEmailAddress(this.RequestData.EMailAddress, out guid)) { this.RequestedRecipient = callerScopedRecipientSession.FindByExchangeGuidIncludingArchive(guid); ADUser aduser = this.RequestedRecipient as ADUser; if (aduser != null && aduser.ArchiveGuid.Equals(guid) && RemoteMailbox.IsRemoteMailbox(aduser.RecipientTypeDetails) && aduser.ArchiveDatabase == null) { this.RequestedRecipient = null; } if (this.RequestedRecipient != null) { resolveMethod = "FoundByGUID"; } } if (this.RequestedRecipient == null) { SmtpProxyAddress proxyAddress = new SmtpProxyAddress(this.RequestData.EMailAddress, true); this.RequestedRecipient = callerScopedRecipientSession.FindByProxyAddress(proxyAddress); if (this.RequestedRecipient != null) { resolveMethod = "FoundBySMTP"; } } } }); } catch (LocalizedException ex) { ExTraceGlobals.FrameworkTracer.TraceError <string, string>(0L, "[UpdateCacheCallback()] 'LocalizedException' Message=\"{0}\";StackTrace=\"{1}\"", ex.Message, ex.StackTrace); Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_ErrWebException, Common.PeriodicKey, new object[] { ex.Message, ex.StackTrace }); resolveMethod = "Exception"; } IL_285 :; } finally { RequestDetailsLoggerBase <RequestDetailsLogger> .Current.AppendGenericInfo("ResolveMethod", resolveMethod); } }
protected override void InternalValidate() { TaskLogger.LogEnter(); try { base.ValidateRootFolders(this.SourceRootFolder, this.TargetRootFolder); bool wildcardedSearch = false; if (!string.IsNullOrEmpty(base.Name)) { base.ValidateName(); base.RequestName = base.Name; } else { wildcardedSearch = true; base.RequestName = "MailboxRestore"; } this.targetUser = RequestTaskHelper.ResolveADUser(base.RecipSession, base.GCSession, base.ServerSettings, this.TargetMailbox, base.OptionalIdentityData, base.DomainController, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADUser>), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError), true); this.CheckForInvalidPublicFolderRestoreParameters(); if (this.targetUser.HasLocalArchive && this.targetUser.RecipientType == RecipientType.MailUser && this.targetUser.Database == null && !this.TargetIsArchive) { base.WriteError(new MissingArchiveParameterForRestorePermanentException(this.targetUser.ToString()), ErrorCategory.InvalidArgument, this.TargetMailbox); } if (this.targetUser.RecipientType != RecipientType.UserMailbox && (!this.TargetIsArchive || this.targetUser.RecipientType != RecipientType.MailUser)) { base.WriteError(new InvalidRecipientTypePermanentException(this.targetUser.ToString(), this.targetUser.RecipientType.ToString()), ErrorCategory.InvalidArgument, this.TargetMailbox); } if (this.TargetIsArchive && (this.targetUser.ArchiveGuid == Guid.Empty || this.targetUser.ArchiveDatabase == null)) { base.WriteError(new MailboxLacksArchivePermanentException(this.targetUser.ToString()), ErrorCategory.InvalidArgument, this.TargetIsArchive); } if (!this.TargetIsArchive && this.targetUser.Database == null) { base.WriteError(new MailboxLacksDatabasePermanentException(this.targetUser.ToString()), ErrorCategory.InvalidArgument, this.TargetMailbox); } if (base.ParameterSetName.Equals("RemoteMailboxRestore")) { if (!Guid.TryParse(this.SourceStoreMailbox.RawIdentity, out this.sourceMailboxGuid)) { base.WriteError(new RecipientTaskException(Strings.ErrorParameterValueNotAllowed("SourceStoreMailbox")), ErrorCategory.InvalidArgument, this.SourceStoreMailbox); } if (!base.Fields.IsModified("AllowLegacyDNMismatch") || !this.AllowLegacyDNMismatch) { base.WriteError(new RecipientTaskException(Strings.ErrorParameterValueNotAllowed("AllowLegacyDNMismatch")), ErrorCategory.InvalidArgument, this.AllowLegacyDNMismatch); } base.Flags = (RequestFlags.CrossOrg | RequestFlags.Pull); switch (this.RemoteRestoreType) { case RemoteRestoreType.RecoveryDatabase: this.restoreFlags |= MailboxRestoreType.Recovery; this.restoreFlags |= MailboxRestoreType.SoftDeleted; break; case RemoteRestoreType.DisconnectedMailbox: this.restoreFlags |= MailboxRestoreType.SoftDeleted; break; case RemoteRestoreType.SoftDeletedRecipient: this.restoreFlags |= MailboxRestoreType.SoftDeletedRecipient; break; default: base.WriteError(new RecipientTaskException(Strings.ErrorParameterValueNotAllowed("RemoteRestoreType")), ErrorCategory.InvalidArgument, this.RemoteRestoreType); break; } } else { base.Flags = (RequestFlags.IntraOrg | RequestFlags.Pull); string fqdn; string serverExchangeLegacyDn; ADObjectId adobjectId; int num; MailboxDatabase mailboxDatabase = base.CheckDatabase <MailboxDatabase>(this.SourceDatabase, NewRequest <MailboxRestoreRequest> .DatabaseSide.Source, this.SourceDatabase, out fqdn, out serverExchangeLegacyDn, out adobjectId, out num); if (mailboxDatabase.Recovery) { this.restoreFlags |= MailboxRestoreType.Recovery; } this.sourceDatabase = mailboxDatabase.Id; this.SourceStoreMailbox.Flags |= 1UL; using (MapiSession mapiSession = new MapiAdministrationSession(serverExchangeLegacyDn, Fqdn.Parse(fqdn))) { using (MailboxStatistics mailboxStatistics = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(this.SourceStoreMailbox, mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(mailboxDatabase), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.SourceStoreMailbox.ToString(), this.SourceDatabase.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.SourceStoreMailbox.ToString(), this.SourceDatabase.ToString())))) { MailboxState?disconnectReason = mailboxStatistics.DisconnectReason; if (mailboxStatistics.MailboxType == StoreMailboxType.PublicFolderPrimary || mailboxStatistics.MailboxType == StoreMailboxType.PublicFolderSecondary) { this.restoreFlags |= MailboxRestoreType.PublicFolderMailbox; } bool flag = false; if (disconnectReason == null && !mailboxDatabase.Recovery) { mapiSession.Administration.SyncMailboxWithDS(mailboxDatabase.Guid, mailboxStatistics.MailboxGuid); using (MailboxStatistics mailboxStatistics2 = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(this.SourceStoreMailbox, mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(mailboxDatabase), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.SourceStoreMailbox.ToString(), this.SourceDatabase.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.SourceStoreMailbox.ToString(), this.SourceDatabase.ToString())))) { disconnectReason = mailboxStatistics2.DisconnectReason; if (disconnectReason == null) { if (this.targetUser.OrganizationId != null && this.targetUser.OrganizationId.OrganizationalUnit != null && VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Global.MultiTenancy.Enabled) { IRecipientSession recipientSession = CommonUtils.CreateRecipientSession(mailboxStatistics.ExternalDirectoryOrganizationId, null, null); ADRecipient adrecipient = this.TargetIsArchive ? recipientSession.FindByExchangeGuidIncludingArchive(mailboxStatistics.MailboxGuid) : recipientSession.FindByExchangeGuid(mailboxStatistics.MailboxGuid); flag = (adrecipient != null && adrecipient.RecipientSoftDeletedStatus != 0); } if (!this.IsPublicFolderMailboxRestore && !flag) { base.WriteError(new CannotRestoreConnectedMailboxPermanentException(this.SourceStoreMailbox.ToString()), ErrorCategory.InvalidArgument, this.SourceStoreMailbox); } } } } if (flag) { this.restoreFlags |= MailboxRestoreType.SoftDeletedRecipient; } else if (disconnectReason != null) { if (disconnectReason != MailboxState.SoftDeleted) { this.restoreFlags |= MailboxRestoreType.Disabled; } else { this.restoreFlags |= MailboxRestoreType.SoftDeleted; } } this.sourceMailboxGuid = mailboxStatistics.MailboxGuid; this.sourceMailboxDN = mailboxStatistics.LegacyDN; } } if ((this.TargetIsArchive && this.sourceMailboxGuid == this.targetUser.ArchiveGuid && this.sourceDatabase.Equals(this.targetUser.ArchiveDatabase)) || (!this.TargetIsArchive && this.sourceMailboxGuid == this.targetUser.ExchangeGuid && this.sourceDatabase.Equals(this.targetUser.Database))) { base.WriteError(new CannotRestoreIntoSelfPermanentException(this.targetUser.ToString()), ErrorCategory.InvalidArgument, this.TargetMailbox); } } if (this.restoreFlags.HasFlag(MailboxRestoreType.PublicFolderMailbox)) { if (this.targetUser.RecipientTypeDetails != RecipientTypeDetails.PublicFolderMailbox) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotRestoreFromPublicToPrivateMailbox), ErrorCategory.InvalidArgument, this.SourceStoreMailbox); } } else if (this.targetUser.RecipientTypeDetails == RecipientTypeDetails.PublicFolderMailbox) { base.WriteError(new RecipientTaskException(Strings.ErrorCannotRestoreFromPrivateToPublicMailbox), ErrorCategory.InvalidArgument, this.SourceStoreMailbox); } base.RescopeToOrgId(this.targetUser.OrganizationId); if (base.ParameterSetName.Equals("RemoteMailboxRestore")) { base.PerRecordReportEntries.Add(new ReportEntry(MrsStrings.ReportRequestAllowedMismatch(base.ExecutingUserIdentity))); } else { base.ValidateLegacyDNMatch(this.sourceMailboxDN, this.targetUser, this.TargetMailbox); } ADObjectId mdbId = null; ADObjectId mdbServerSite = null; this.LocateAndChooseMdb(null, this.TargetIsArchive ? this.targetUser.ArchiveDatabase : this.targetUser.Database, null, this.TargetMailbox, this.TargetMailbox, out mdbId, out mdbServerSite); base.MdbId = mdbId; base.MdbServerSite = mdbServerSite; base.RequestName = this.CheckRequestNameAvailability(base.RequestName, this.targetUser.Id, true, MRSRequestType.MailboxRestore, this.TargetMailbox, wildcardedSearch); base.InternalValidate(); } finally { TaskLogger.LogExit(); } }