Exemple #1
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter(new object[]
     {
         this.DataObject
     });
     base.InternalProcessRecord();
     if (this.recoverArchive && this.DataObject.ArchiveDatabase != null)
     {
         MailboxDatabase database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(new DatabaseIdParameter(this.DataObject.ArchiveDatabase), base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.DataObject.ArchiveDatabase.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.DataObject.ArchiveDatabase.ToString())));
         using (MapiAdministrationSession adminSession = MapiTaskHelper.GetAdminSession(RecipientTaskHelper.GetActiveManagerInstance(), this.DataObject.ArchiveDatabase.ObjectGuid))
         {
             ConnectMailbox.UpdateSDAndRefreshMailbox(adminSession, this.DataObject, database, this.DataObject.ArchiveGuid, null, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning));
         }
     }
     TaskLogger.LogExit();
 }
Exemple #2
0
 internal static void UpdateSDAndRefreshMailbox(MapiAdministrationSession mapiAdministrationSession, ADUser userToConnect, MailboxDatabase database, Guid mailboxGuid, string parameterSetName, Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger)
 {
     ConnectMailbox.UpdateMailboxSecurityDescriptor(userToConnect.Sid, userToConnect, mapiAdministrationSession, database, mailboxGuid, parameterSetName, verboseLogger);
     try
     {
         mapiAdministrationSession.ForceStoreToRefreshMailbox(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), mailboxGuid));
     }
     catch (FailedToRefreshMailboxException ex)
     {
         TaskLogger.Trace("An exception is caught and ignored when refreshing the mailbox '{0}'. Exception: {1}", new object[]
         {
             mailboxGuid,
             ex.Message
         });
         warningLogger(Strings.WarningReplicationLatency);
     }
     try
     {
         mapiAdministrationSession.SyncMailboxWithDS(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), mailboxGuid));
     }
     catch (DataSourceTransientException ex2)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex2
         });
         warningLogger(ex2.LocalizedString);
     }
     catch (DataSourceOperationException ex3)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex3
         });
         warningLogger(ex3.LocalizedString);
     }
     catch (ArgumentNullException ex4)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex4
         });
         warningLogger(Strings.ErrorNoDatabaseInfor);
     }
 }
Exemple #3
0
        // Token: 0x06000458 RID: 1112 RVA: 0x0000F868 File Offset: 0x0000DA68
        internal static string GetMailboxLegacyDN(MapiAdministrationSession mapiAdminSession, ADObjectId databaseId, Guid mailboxGuid)
        {
            string               result = null;
            DatabaseId           root   = MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(databaseId);
            MailboxContextFilter filter = new MailboxContextFilter(mailboxGuid);

            MailboxStatistics[] array = null;
            try
            {
                array = mapiAdminSession.Find <MailboxStatistics>(filter, root, QueryScope.SubTree, null, 1);
            }
            catch (MapiObjectNotFoundException)
            {
            }
            if (array != null)
            {
                result = array[0].LegacyDN;
                array[0].Dispose();
            }
            return(result);
        }
Exemple #4
0
 private static void ConnectArchiveCore(ADUser userToConnect, Guid deletedMailboxGuid, string parameterSetName, IRecipientSession recipientSession, IConfigurationSession configSession, MapiAdministrationSession mapiAdministrationSession, string alias, SecurityIdentifier linkedUserSid, DatabaseLocationInfo databaseLocationInfo, MailboxDatabase database, Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger)
 {
     userToConnect.ArchiveDatabase = (ADObjectId)database.Identity;
     userToConnect.ArchiveGuid     = deletedMailboxGuid;
     userToConnect.ArchiveName     = new MultiValuedProperty <string>(Strings.ArchiveNamePrefix + userToConnect.DisplayName);
     if (MailboxTaskHelper.SupportsMailboxReleaseVersioning(userToConnect))
     {
         userToConnect.ArchiveRelease = databaseLocationInfo.MailboxRelease;
     }
     userToConnect.ArchiveQuota        = ProvisioningHelper.DefaultArchiveQuota;
     userToConnect.ArchiveWarningQuota = ProvisioningHelper.DefaultArchiveWarningQuota;
     MailboxTaskHelper.ApplyDefaultArchivePolicy(userToConnect, configSession);
     recipientSession.Save(userToConnect);
     verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
     ConnectMailbox.UpdateSDAndRefreshMailbox(mapiAdministrationSession, userToConnect, database, deletedMailboxGuid, parameterSetName, verboseLogger, warningLogger);
 }
Exemple #5
0
 internal static void ConnectMailboxCore(ADUser userToConnect, Guid deletedMailboxGuid, StoreMailboxType mailboxType, string deletedMailboxLegacyDN, string parameterSetName, bool clearPropertiesBeforeConnecting, IRecipientSession recipientSession, MapiAdministrationSession mapiAdministrationSession, string alias, SecurityIdentifier linkedUserSid, DatabaseLocationInfo databaseLocationInfo, MailboxDatabase database, ADObjectId elcPolicyId, ADObjectId retentionPolicyId, ADObjectId mobilePolicyId, ADObjectId addressBookPolicyId, Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger, ADObjectId roleAssignmentPolicyId, Task task)
 {
     if (userToConnect.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012))
     {
         verboseLogger(Strings.VerboseUpdatingVersion(userToConnect.Identity.ToString(), userToConnect.ExchangeVersion.ToString(), ExchangeObjectVersion.Exchange2012.ToString()));
         userToConnect.SetExchangeVersion(ExchangeObjectVersion.Exchange2012);
         recipientSession.Save(userToConnect);
         verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
         bool useGlobalCatalog = recipientSession.UseGlobalCatalog;
         try
         {
             recipientSession.UseGlobalCatalog = false;
             userToConnect = (ADUser)recipientSession.Read(userToConnect.Id);
         }
         finally
         {
             recipientSession.UseGlobalCatalog = useGlobalCatalog;
         }
     }
     if (clearPropertiesBeforeConnecting)
     {
         List <PropertyDefinition> list = new List <PropertyDefinition>(RecipientConstants.DisableMailbox_PropertiesToReset);
         MailboxTaskHelper.RemovePersistentProperties(list);
         list.Remove(ADObjectSchema.ExchangeVersion);
         MailboxTaskHelper.ClearExchangeProperties(userToConnect, list);
     }
     userToConnect.Alias = alias;
     if ("Linked" == parameterSetName)
     {
         userToConnect.MasterAccountSid = linkedUserSid;
     }
     else if ("Shared" == parameterSetName)
     {
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     else if ("Room" == parameterSetName)
     {
         userToConnect.ResourceType     = new ExchangeResourceType?(ExchangeResourceType.Room);
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     else if ("Equipment" == parameterSetName)
     {
         userToConnect.ResourceType     = new ExchangeResourceType?(ExchangeResourceType.Equipment);
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     userToConnect.ServerLegacyDN             = databaseLocationInfo.ServerLegacyDN;
     userToConnect.ExchangeGuid               = deletedMailboxGuid;
     userToConnect.Database                   = (ADObjectId)database.Identity;
     userToConnect.LegacyExchangeDN           = deletedMailboxLegacyDN.ToLowerInvariant();
     userToConnect.ManagedFolderMailboxPolicy = elcPolicyId;
     userToConnect.RetentionPolicy            = retentionPolicyId;
     userToConnect.ActiveSyncMailboxPolicy    = mobilePolicyId;
     userToConnect.UseDatabaseQuotaDefaults   = new bool?(true);
     userToConnect.AddressBookPolicy          = addressBookPolicyId;
     if (roleAssignmentPolicyId != null)
     {
         userToConnect.RoleAssignmentPolicy = roleAssignmentPolicyId;
     }
     if (mailboxType == StoreMailboxType.PublicFolderPrimary || mailboxType == StoreMailboxType.PublicFolderSecondary)
     {
         userToConnect.MasterAccountSid            = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
         userToConnect.UserAccountControl          = (UserAccountControlFlags.AccountDisabled | UserAccountControlFlags.NormalAccount);
         userToConnect.ExchangeUserAccountControl |= UserAccountControlFlags.AccountDisabled;
         MailboxTaskHelper.StampMailboxRecipientTypes(userToConnect, "PublicFolder");
     }
     else
     {
         MailboxTaskHelper.StampMailboxRecipientTypes(userToConnect, parameterSetName);
     }
     if (MailboxTaskHelper.SupportsMailboxReleaseVersioning(userToConnect))
     {
         userToConnect.MailboxRelease = databaseLocationInfo.MailboxRelease;
     }
     userToConnect.EmailAddressPolicyEnabled = true;
     ProvisioningLayer.UpdateAffectedIConfigurable(task, RecipientTaskHelper.ConvertRecipientToPresentationObject(userToConnect), false);
     recipientSession.Save(userToConnect);
     verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
     ConnectMailbox.UpdateSDAndRefreshMailbox(mapiAdministrationSession, userToConnect, database, deletedMailboxGuid, parameterSetName, verboseLogger, warningLogger);
 }
Exemple #6
0
        private static RawSecurityDescriptor UpdateMailboxSecurityDescriptor(SecurityIdentifier userSid, ADUser userToConnect, MapiAdministrationSession mapiAdministrationSession, MailboxDatabase database, Guid deletedMailboxGuid, string parameterSetName, Task.TaskVerboseLoggingDelegate verboseLogger)
        {
            RawSecurityDescriptor rawSecurityDescriptor = null;

            try
            {
                rawSecurityDescriptor = mapiAdministrationSession.GetMailboxSecurityDescriptor(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), deletedMailboxGuid));
            }
            catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException)
            {
                rawSecurityDescriptor = new RawSecurityDescriptor(ControlFlags.DiscretionaryAclDefaulted | ControlFlags.SystemAclDefaulted | ControlFlags.SelfRelative, WindowsIdentity.GetCurrent().User, WindowsIdentity.GetCurrent().User, null, null);
                DiscretionaryAcl discretionaryAcl = new DiscretionaryAcl(true, true, 0);
                byte[]           binaryForm       = new byte[discretionaryAcl.BinaryLength];
                discretionaryAcl.GetBinaryForm(binaryForm, 0);
                rawSecurityDescriptor.DiscretionaryAcl = new RawAcl(binaryForm, 0);
            }
            bool flag = false;

            foreach (GenericAce genericAce in rawSecurityDescriptor.DiscretionaryAcl)
            {
                KnownAce knownAce = (KnownAce)genericAce;
                if (knownAce.SecurityIdentifier.IsWellKnown(WellKnownSidType.SelfSid))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                CommonAce ace = new CommonAce(AceFlags.ContainerInherit, AceQualifier.AccessAllowed, 131073, new SecurityIdentifier(WellKnownSidType.SelfSid, null), false, null);
                rawSecurityDescriptor.DiscretionaryAcl.InsertAce(0, ace);
            }
            rawSecurityDescriptor.SetFlags(rawSecurityDescriptor.ControlFlags | ControlFlags.SelfRelative);
            if ("Linked" == parameterSetName || "Shared" == parameterSetName || "Room" == parameterSetName || "Equipment" == parameterSetName)
            {
                RawSecurityDescriptor sd = userToConnect.ReadSecurityDescriptor();
                MailboxTaskHelper.GrantPermissionToLinkedUserAccount(userToConnect.MasterAccountSid, ref rawSecurityDescriptor, ref sd);
                verboseLogger(Strings.VerboseSaveADSecurityDescriptor(userToConnect.Id.ToString()));
                userToConnect.SaveSecurityDescriptor(sd);
            }
            mapiAdministrationSession.Administration.PurgeCachedMailboxObject(deletedMailboxGuid);
            return(rawSecurityDescriptor);
        }
Exemple #7
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter(new object[]
     {
         this.DataObject
     });
     if (this.PublicFolder)
     {
         MailboxTaskHelper.RemoveOrDisablePublicFolderMailbox(this.DataObject, this.exchangeGuid, this.TenantLocalConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), true, false);
     }
     base.InternalProcessRecord();
     if ("Archive" == base.ParameterSetName || "RemoteArchive" == base.ParameterSetName)
     {
         TaskLogger.Trace("DisableMailbox -Archive or -RemoteArchive skipping InternalProcessRecord", new object[0]);
         TaskLogger.LogExit();
         return;
     }
     try
     {
         MailboxDatabase mailboxDatabase = null;
         if (this.mdbId != null)
         {
             mailboxDatabase = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(new DatabaseIdParameter(this.mdbId)
             {
                 AllowLegacy = true
             }, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.mdbId.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.mdbId.ToString())));
         }
         if (mailboxDatabase != null && this.exchangeGuid != Guid.Empty)
         {
             Server server = mailboxDatabase.GetServer();
             if (server == null)
             {
                 this.WriteWarning(Strings.ErrorDBOwningServerNotFound(mailboxDatabase.Identity.ToString()));
             }
             else if (string.IsNullOrEmpty(server.ExchangeLegacyDN))
             {
                 this.WriteWarning(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, server.Identity.ToString(), ServerSchema.ExchangeLegacyDN.Name));
             }
             else if (string.IsNullOrEmpty(server.Fqdn))
             {
                 this.WriteWarning(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, server.Identity.ToString(), ServerSchema.Fqdn.Name));
             }
             else
             {
                 base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(server.Fqdn));
                 using (MapiAdministrationSession mapiAdministrationSession = new MapiAdministrationSession(server.ExchangeLegacyDN, Fqdn.Parse(server.Fqdn)))
                 {
                     base.WriteVerbose(Strings.VerboseSyncMailboxWithDS(this.Identity.ToString(), this.mdbId.ToString(), server.Fqdn));
                     mapiAdministrationSession.SyncMailboxWithDS(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(this.mdbId), this.exchangeGuid));
                 }
             }
         }
     }
     catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException ex)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex
         });
         base.WriteVerbose(ex.LocalizedString);
     }
     catch (DataSourceTransientException ex2)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex2
         });
         this.WriteWarning(ex2.LocalizedString);
     }
     catch (DataSourceOperationException ex3)
     {
         TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
         {
             ex3
         });
         this.WriteWarning(ex3.LocalizedString);
     }
     TaskLogger.LogExit();
 }
Exemple #8
0
        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();
            }
        }