Exemple #1
0
        internal IEnumerable <DatabaseEvent> ReadEvents(MapiSession mapiSession, Database database, long startCounter, Restriction restriction, bool includeMoveDestinationEvents, int resultSize)
        {
            if (mapiSession == null)
            {
                throw new ArgumentException("mapiSession");
            }
            if (database == null)
            {
                throw new ArgumentException("database");
            }
            int  count      = 0;
            long endCounter = (0L < startCounter) ? (startCounter - 1L) : 0L;

            MapiEvent[]      events       = null;
            DatabaseId       databaseId   = MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database);
            MapiEventManager eventManager = MapiEventManager.Create(mapiSession.Administration, Guid.NewGuid(), databaseId.Guid);

            for (;;)
            {
                startCounter = endCounter + 1L;
                ReadEventsFlags flags = includeMoveDestinationEvents ? ReadEventsFlags.IncludeMoveDestinationEvents : ReadEventsFlags.None;
                mapiSession.InvokeWithWrappedException(delegate()
                {
                    events = eventManager.ReadEvents(startCounter, (0 < resultSize) ? resultSize : 1000, 0, restriction, flags, out endCounter);
                }, Strings.ErrorCannotReadDatabaseEvents(databaseId.ToString()), databaseId);
                foreach (MapiEvent mapiEvent in events)
                {
                    yield return(new DatabaseEvent(mapiEvent, databaseId, this.server, database.Server.ObjectGuid == this.server.Guid));

                    count++;
                    if (0 < resultSize && count == resultSize)
                    {
                        goto Block_6;
                    }
                }
                if (endCounter == startCounter)
                {
                    goto Block_8;
                }
            }
Block_6:
            yield break;
Block_8:
            yield break;
        }
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);
     }
 }
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     this.isToInactiveMailbox         = false;
     this.isDisconnectInactiveMailbox = false;
     if (this.Identity != null)
     {
         base.InternalValidate();
         this.isToInactiveMailbox         = this.IsToInactiveMailbox();
         this.isDisconnectInactiveMailbox = this.IsDisconnectInactiveMailbox();
         if (!this.isToInactiveMailbox && !this.isDisconnectInactiveMailbox)
         {
             MailboxTaskHelper.BlockRemoveOrDisableIfLitigationHoldEnabled(base.DataObject, new Task.ErrorLoggerDelegate(base.WriteError), false, this.IgnoreLegalHold.ToBool());
             MailboxTaskHelper.BlockRemoveOrDisableIfDiscoveryHoldEnabled(base.DataObject, new Task.ErrorLoggerDelegate(base.WriteError), false, this.IgnoreLegalHold.ToBool());
         }
         MailboxTaskHelper.BlockRemoveOrDisableIfJournalNDRMailbox(base.DataObject, this.TenantLocalConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), false);
         if (ComplianceConfigImpl.JournalArchivingHardeningEnabled && !this.skipJournalArchivingCheck)
         {
             MailboxTaskHelper.BlockRemoveOrDisableMailboxIfJournalArchiveEnabled(base.DataSession as IRecipientSession, this.ConfigurationSession, base.DataObject, new Task.ErrorLoggerDelegate(base.WriteError), false);
         }
         if (base.DataObject.RecipientTypeDetails == RecipientTypeDetails.ArbitrationMailbox && this.ArbitrationMailboxUsageValidationRequired)
         {
             ADUser dataObject = base.DataObject;
             Task.ErrorLoggerDelegate writeError = new Task.ErrorLoggerDelegate(base.WriteError);
             TIdentity identity = this.Identity;
             MailboxTaskHelper.ValidateNotBuiltInArbitrationMailbox(dataObject, writeError, Strings.ErrorRemoveArbitrationMailbox(identity.ToString()));
             ADUser                   dataObject2 = base.DataObject;
             IRecipientSession        tenantGlobalCatalogSession = base.TenantGlobalCatalogSession;
             Task.ErrorLoggerDelegate writeError2 = new Task.ErrorLoggerDelegate(base.WriteError);
             TIdentity                identity2   = this.Identity;
             MailboxTaskHelper.ValidateArbitrationMailboxHasNoGroups(dataObject2, tenantGlobalCatalogSession, writeError2, Strings.ErrorRemoveMailboxWithAssociatedApprovalRecipents(identity2.ToString()));
             ADUser dataObject3   = base.DataObject;
             bool   overrideCheck = this.RemoveArbitrationMailboxWithOABsAllowed.ToBool();
             Task.ErrorLoggerDelegate writeError3 = new Task.ErrorLoggerDelegate(base.WriteError);
             TIdentity identity3 = this.Identity;
             MailboxTaskHelper.ValidateNoOABsAssignedToArbitrationMailbox(dataObject3, overrideCheck, writeError3, Strings.ErrorRemoveArbitrationMailboxWithOABsAssigned(identity3.ToString()));
             ADUser            dataObject4 = base.DataObject;
             IRecipientSession tenantGlobalCatalogSession2 = base.TenantGlobalCatalogSession;
             ADObjectId        rootOrgContainerId          = base.RootOrgContainerId;
             bool isPresent = this.RemoveLastArbitrationMailboxAllowed.IsPresent;
             Task.ErrorLoggerDelegate writeError4 = new Task.ErrorLoggerDelegate(base.WriteError);
             TIdentity identity4 = this.Identity;
             MailboxTaskHelper.ValidateNotLastArbitrationMailbox(dataObject4, tenantGlobalCatalogSession2, rootOrgContainerId, isPresent, writeError4, Strings.ErrorCannotRemoveLastArbitrationMailboxInOrganization(identity4.ToString()));
         }
         if (this.AuditLog)
         {
             if (base.DataObject.RecipientTypeDetails != RecipientTypeDetails.AuditLogMailbox)
             {
                 LocalizedException    exception = new RecipientTaskException(Strings.ErrorSpecifiedMailboxShouldBeAuditLogMailbox(base.DataObject.Identity.ToString()));
                 ExchangeErrorCategory category  = ExchangeErrorCategory.Context;
                 TIdentity             identity5 = this.Identity;
                 base.WriteError(exception, category, identity5.ToString());
             }
         }
         else if (base.DataObject.RecipientTypeDetails == RecipientTypeDetails.AuditLogMailbox)
         {
             LocalizedException    exception2 = new RecipientTaskException(Strings.ErrorAuditLogMailboxShouldBeDeletedWithAuditLogSpecified(base.DataObject.Identity.ToString()));
             ExchangeErrorCategory category2  = ExchangeErrorCategory.Context;
             TIdentity             identity6  = this.Identity;
             base.WriteError(exception2, category2, identity6.ToString());
         }
     }
     else
     {
         this.InternalValidateStoreMailboxIdentity();
         try
         {
             this.mailboxStatistics = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(this.StoreMailboxIdentity, this.mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(this.database), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.StoreMailboxIdentity.ToString(), this.Database.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.StoreMailboxIdentity.ToString(), this.Database.ToString())), ExchangeErrorCategory.Client);
             MailboxTaskHelper.ValidateMailboxIsDisconnected(base.TenantGlobalCatalogSession, this.mailboxStatistics.MailboxGuid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
             this.mailboxStatistics.Database = this.database.Identity;
         }
         catch (DataSourceTransientException exception3)
         {
             base.WriteError(exception3, ExchangeErrorCategory.ServerTransient, this.StoreMailboxIdentity);
         }
     }
     if (this.PublicFolder)
     {
         Organization orgContainer = this.TenantLocalConfigurationSession.GetOrgContainer();
         if (orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid == Guid.Empty && !this.Force)
         {
             LocalizedException    exception4 = new RecipientTaskException(Strings.ErrorPrimaryPublicFolderMailboxNotFound);
             ExchangeErrorCategory category3  = ExchangeErrorCategory.Context;
             TIdentity             identity7  = this.Identity;
             base.WriteError(exception4, category3, identity7.ToString());
         }
         if (this.currentOrganizationId == null || this.currentOrganizationId != base.DataObject.OrganizationId)
         {
             this.currentOrganizationId = base.DataObject.OrganizationId;
             TenantPublicFolderConfigurationCache.Instance.RemoveValue(base.DataObject.OrganizationId);
         }
         MailboxTaskHelper.RemoveOrDisablePublicFolderMailbox(base.DataObject, Guid.Empty, this.tenantLocalConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), false, this.Force);
     }
     TaskLogger.LogExit();
 }
        internal bool GetMailboxQuarantineStatus()
        {
            if (this.mapiSession == null)
            {
                this.mapiSession = new MapiAdministrationSession(this.DbLocationInfo.ServerLegacyDN, Fqdn.Parse(this.DbLocationInfo.ServerFqdn));
            }
            StoreMailboxIdParameter id = StoreMailboxIdParameter.Parse(this.exchangeGuid.ToString());
            bool isQuarantined;

            using (MailboxStatistics mailboxStatistics = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(id, this.mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(this.database), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.Identity.ToString(), this.Database.Identity.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.Identity.ToString(), this.Database.Identity.ToString()))))
            {
                isQuarantined = mailboxStatistics.IsQuarantined;
            }
            return(isQuarantined);
        }
Exemple #5
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 #6
0
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         MailboxState?mailboxState = null;
         Database     database     = null;
         database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(this.Database, base.DataSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString())), ExchangeErrorCategory.Client);
         if (database.Recovery)
         {
             base.WriteError(new TaskArgumentException(Strings.ErrorInvalidOperationOnRecoveryMailboxDatabase(this.Database.ToString())), ExchangeErrorCategory.Client, this.Identity);
         }
         DatabaseLocationInfo databaseLocationInfo = null;
         try
         {
             databaseLocationInfo = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(database.Id.ObjectGuid);
         }
         catch (ObjectNotFoundException exception)
         {
             base.WriteError(exception, ExchangeErrorCategory.ServerOperation, null);
         }
         if (base.IsVerboseOn)
         {
             base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(databaseLocationInfo.ServerFqdn));
         }
         this.mapiSession       = new MapiAdministrationSession(databaseLocationInfo.ServerLegacyDN, Fqdn.Parse(databaseLocationInfo.ServerFqdn));
         this.guidMdb           = database.Guid;
         this.Identity.Flags   |= 1UL;
         this.mailboxStatistics = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(this.Identity, this.mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.Identity.ToString(), this.Database.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.Identity.ToString(), this.Database.ToString())));
         this.guidMailbox       = this.mailboxStatistics.MailboxGuid;
         mailboxState           = this.mailboxStatistics.DisconnectReason;
         if (mailboxState == null)
         {
             this.mapiSession.Administration.SyncMailboxWithDS(this.guidMdb, this.guidMailbox);
             this.mailboxStatistics.Dispose();
             this.mailboxStatistics = null;
             this.mailboxStatistics = (MailboxStatistics)base.GetDataObject <MailboxStatistics>(this.Identity, this.mapiSession, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), new LocalizedString?(Strings.ErrorStoreMailboxNotFound(this.Identity.ToString(), this.Database.ToString())), new LocalizedString?(Strings.ErrorStoreMailboxNotUnique(this.Identity.ToString(), this.Database.ToString())));
             mailboxState           = this.mailboxStatistics.DisconnectReason;
             if (mailboxState == null)
             {
                 base.WriteError(new RemoveNotDisconnectedStoreMailboxPermanentException(this.Identity.ToString()), ErrorCategory.InvalidArgument, this.Identity);
             }
         }
         if (MailboxStateParameter.SoftDeleted == this.MailboxState && Microsoft.Exchange.Data.Mapi.MailboxState.SoftDeleted == mailboxState)
         {
             this.deleteMailboxFlags = 18;
         }
         else if (MailboxStateParameter.Disabled == this.MailboxState && Microsoft.Exchange.Data.Mapi.MailboxState.Disabled == mailboxState)
         {
             this.deleteMailboxFlags = 2;
         }
         else
         {
             base.WriteError(new UnexpectedRemoveStoreMailboxStatePermanentException(this.Identity.ToString(), mailboxState.ToString(), this.MailboxState.ToString()), ErrorCategory.InvalidArgument, this.Identity);
         }
     }
     catch (MapiPermanentException exception2)
     {
         base.WriteError(exception2, ExchangeErrorCategory.ServerOperation, this.Identity);
     }
     catch (MapiRetryableException exception3)
     {
         base.WriteError(exception3, ExchangeErrorCategory.ServerTransient, this.Identity);
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
Exemple #7
0
        internal IEnumerable <DatabaseEventWatermark> ReadWatermarks(MapiSession mapiSession, Database database, Guid?consumerGuid, Guid?mailboxGuid)
        {
            if (mapiSession == null)
            {
                throw new ArgumentException("mapiSession");
            }
            if (database == null)
            {
                throw new ArgumentException("database");
            }
            Watermark[] wms         = null;
            long        lastCounter = 0L;
            DatabaseId  databaseId  = MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database);

            if (consumerGuid != null)
            {
                MapiEventManager eventManager = MapiEventManager.Create(mapiSession.Administration, consumerGuid.Value, databaseId.Guid);
                mapiSession.InvokeWithWrappedException(delegate()
                {
                    lastCounter = eventManager.ReadLastEvent().EventCounter;
                    if (mailboxGuid != null)
                    {
                        Watermark watermark = eventManager.GetWatermark(mailboxGuid.Value);
                        wms = ((watermark == null) ? new Watermark[0] : new Watermark[]
                        {
                            watermark
                        });
                        return;
                    }
                    wms = eventManager.GetWatermarks();
                }, Strings.ErrorCannotReadDatabaseWatermarks(databaseId.ToString()), databaseId);
                foreach (Watermark wm in wms)
                {
                    yield return(new DatabaseEventWatermark(wm, databaseId, lastCounter, this.server, database.Server.ObjectGuid == this.server.Guid));
                }
            }
            else
            {
                GetDatabaseEventWatermark.< > c__DisplayClass7 CS$ < > 8__locals3 = new GetDatabaseEventWatermark.< > c__DisplayClass7();
                CS$ < > 8__locals3.eventManager = MapiEventManager.Create(mapiSession.Administration, Guid.Empty, databaseId.Guid);
                if (mailboxGuid != null)
                {
                    CS$ < > 8__locals3.mailboxGuids = new Guid[]
                    {
                        mailboxGuid.Value
                    };
                }
                else if (database.IsPublicFolderDatabase)
                {
                    CS$ < > 8__locals3.mailboxGuids = new Guid[]
                    {
                        Guid.Empty
                    };
                }
                else
                {
                    PropValue[][] mailboxTable = null;
                    mapiSession.InvokeWithWrappedException(delegate()
                    {
                        mailboxTable = mapiSession.Administration.GetMailboxTable(databaseId.Guid, new PropTag[]
                        {
                            PropTag.UserGuid
                        });
                    }, Strings.ErrorCannotReadDatabaseWatermarks(databaseId.ToString()), databaseId);
                    CS$ < > 8__locals3.mailboxGuids    = new Guid[mailboxTable.Length + 1];
                    CS$ < > 8__locals3.mailboxGuids[0] = Guid.Empty;
                    for (int j = 0; j < mailboxTable.Length; j++)
                    {
                        CS$ < > 8__locals3.mailboxGuids[j + 1] = new Guid(mailboxTable[j][0].GetBytes());
                    }
                }
                CS$ < > 8__locals3.databaseVersionGuid = Guid.Empty;
                int i;
                for (i = 0; i < CS$ < > 8__locals3.mailboxGuids.Length; i++)
                {
                    mapiSession.InvokeWithWrappedException(delegate()
                    {
                        lastCounter = CS$ < > 8__locals3.eventManager.ReadLastEvent().EventCounter;
                        wms         = mapiSession.Administration.GetWatermarksForMailbox(databaseId.Guid, ref CS$ < > 8__locals3.databaseVersionGuid, CS$ < > 8__locals3.mailboxGuids[i]);
                    }, Strings.ErrorCannotReadDatabaseWatermarks(databaseId.ToString()), databaseId);
                    foreach (Watermark wm2 in wms)
                    {
                        yield return(new DatabaseEventWatermark(wm2, databaseId, lastCounter, this.server, database.Server.ObjectGuid == this.server.Guid));
                    }
                }
            }
            yield break;
        }
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     foreach (Database database in this.databases)
     {
         try
         {
             Guid mailboxGuid = Guid.Empty;
             MailboxTableFlags mailboxTableFlags = MailboxTableFlags.MailboxTableFlagsNone;
             if (null != this.identity)
             {
                 mailboxGuid = this.identity.MailboxGuid;
             }
             if (this.isRunningMailboxStatisticsTask)
             {
                 mailboxTableFlags |= MailboxTableFlags.IncludeSoftDeletedMailbox;
             }
             QueryFilter filter = new MailboxContextFilter(mailboxGuid, (ulong)((long)mailboxTableFlags), this.NoADLookupForMailboxStatistics);
             IEnumerable <TPresentationObject> enumerable = this.mapiSession.FindPaged <TDataObject, TPresentationObject>(filter, MapiTaskHelper.ConvertDatabaseADObjectToDatabaseId(database), QueryScope.SubTree, null, 0, 0);
             foreach (TPresentationObject tpresentationObject in enumerable)
             {
                 try
                 {
                     MailboxId mailboxId = tpresentationObject.Identity as MailboxId;
                     if (this.Identity == null || (null != mailboxId && ((Guid.Empty != this.identity.MailboxGuid && this.identity.MailboxGuid == mailboxId.MailboxGuid) || (!string.IsNullOrEmpty(this.identity.MailboxExchangeLegacyDn) && string.Equals(this.identity.MailboxExchangeLegacyDn, mailboxId.MailboxExchangeLegacyDn, StringComparison.OrdinalIgnoreCase)))))
                     {
                         if (this.isRunningLogonStatisticsTask)
                         {
                             ((LogonStatistics)((object)tpresentationObject)).ServerName   = database.ServerName;
                             ((LogonStatistics)((object)tpresentationObject)).DatabaseName = database.Name;
                         }
                         else if (this.isRunningResourceMonitorDigestTask)
                         {
                             ((MailboxResourceMonitor)((object)tpresentationObject)).ServerName           = this.server.Name;
                             ((MailboxResourceMonitor)((object)tpresentationObject)).DatabaseName         = database.Name;
                             ((MailboxResourceMonitor)((object)tpresentationObject)).IsDatabaseCopyActive = (database.Server.ObjectGuid == this.server.Guid);
                         }
                         else if (this.isRunningMailboxStatisticsTask)
                         {
                             Microsoft.Exchange.Management.MapiTasks.Presentation.MailboxStatistics mailboxStatistics = (Microsoft.Exchange.Management.MapiTasks.Presentation.MailboxStatistics)((object)tpresentationObject);
                             mailboxStatistics.ServerName           = this.server.Name;
                             mailboxStatistics.DatabaseName         = database.Name;
                             mailboxStatistics.Database             = database.Identity;
                             mailboxStatistics.IsDatabaseCopyActive = (database.Server.ObjectGuid == this.server.Guid);
                             MailboxDatabase mailboxDatabase = database as MailboxDatabase;
                             if (mailboxDatabase != null)
                             {
                                 mailboxStatistics.DatabaseIssueWarningQuota        = mailboxDatabase.IssueWarningQuota;
                                 mailboxStatistics.DatabaseProhibitSendQuota        = mailboxDatabase.ProhibitSendQuota;
                                 mailboxStatistics.DatabaseProhibitSendReceiveQuota = mailboxDatabase.ProhibitSendReceiveQuota;
                             }
                             if (mailboxId != null && this.GetMoveHistoryOption() != MoveHistoryOption.None)
                             {
                                 UserMailboxFlags userMailboxFlags = UserMailboxFlags.None;
                                 if (database.Recovery)
                                 {
                                     userMailboxFlags |= UserMailboxFlags.RecoveryMDB;
                                 }
                                 if (mailboxStatistics.IsMoveDestination ?? false)
                                 {
                                     userMailboxFlags |= UserMailboxFlags.MoveDestination;
                                 }
                                 else if (mailboxStatistics.DisconnectReason != null)
                                 {
                                     if (mailboxStatistics.DisconnectReason.Value == MailboxState.SoftDeleted)
                                     {
                                         userMailboxFlags |= UserMailboxFlags.SoftDeleted;
                                     }
                                     else
                                     {
                                         userMailboxFlags |= UserMailboxFlags.Disconnected;
                                     }
                                 }
                                 try
                                 {
                                     mailboxStatistics.MoveHistory = MoveHistoryEntry.LoadMoveHistory(mailboxId.MailboxGuid, database.Id.ObjectGuid, this.GetMoveHistoryOption() == MoveHistoryOption.IncludeMoveHistoryAndReport, userMailboxFlags);
                                 }
                                 catch (LocalizedException exception)
                                 {
                                     base.WriteError(exception, ErrorCategory.ResourceUnavailable, mailboxId);
                                 }
                             }
                         }
                         bool flag = true;
                         if (this.isRunningMailboxStatisticsTask)
                         {
                             Exception ex = null;
                             try
                             {
                                 QueryFilter internalFilter = this.InternalFilter;
                                 if (internalFilter != null && !OpathFilterEvaluator.FilterMatches(internalFilter, (Microsoft.Exchange.Data.Mapi.MailboxStatistics)((object)tpresentationObject)))
                                 {
                                     flag = false;
                                 }
                             }
                             catch (InvalidCastException ex2)
                             {
                                 ex = ex2;
                             }
                             catch (ParsingException ex3)
                             {
                                 ex = ex3;
                             }
                             catch (ArgumentOutOfRangeException ex4)
                             {
                                 ex = ex4;
                             }
                             if (ex != null)
                             {
                                 base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidMailboxStatisticsFilter(this.InternalFilter.ToString())), ErrorCategory.InvalidArgument, this.InternalFilter);
                             }
                         }
                         if (flag)
                         {
                             this.WriteResult(tpresentationObject);
                         }
                         if (this.Identity != null && this.isRunningMailboxStatisticsTask)
                         {
                             TaskLogger.LogExit();
                             return;
                         }
                     }
                 }
                 finally
                 {
                     if (tpresentationObject != null)
                     {
                         tpresentationObject.Dispose();
                     }
                 }
             }
         }
         catch (DatabaseUnavailableException ex5)
         {
             if (this.Identity == null && this.Database == null)
             {
                 base.WriteWarning(ex5.Message);
             }
             else
             {
                 base.WriteError(ex5, ErrorCategory.ResourceUnavailable, database);
             }
         }
         catch (MapiObjectNotFoundException exception2)
         {
             if (this.Identity == null || !this.isRunningMailboxStatisticsTask)
             {
                 base.WriteError(exception2, ErrorCategory.ObjectNotFound, this.Identity);
             }
         }
     }
     if (this.Identity != null && this.isRunningMailboxStatisticsTask)
     {
         TIdentity tidentity = this.Identity;
         this.WriteWarning(Strings.WarningMailboxNeverBeenLoggedOn(tidentity.ToString(), this.identity.ToString()));
     }
     TaskLogger.LogExit();
 }
Exemple #9
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();
            }
        }