Exemplo n.º 1
0
        private void InternalValidateStoreMailboxIdentity()
        {
            TaskLogger.LogEnter();
            MailboxDatabase mailboxDatabase = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(this.Database, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString())), ExchangeErrorCategory.Client);

            if (mailboxDatabase.Recovery)
            {
                base.WriteError(new TaskArgumentException(Strings.ErrorInvalidOperationOnRecoveryMailboxDatabase(this.Database.ToString())), ExchangeErrorCategory.Client, this.StoreMailboxIdentity);
            }
            DatabaseLocationInfo databaseLocationInfo = null;

            try
            {
                databaseLocationInfo = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(mailboxDatabase.Id.ObjectGuid);
            }
            catch (ObjectNotFoundException exception)
            {
                base.WriteError(exception, ExchangeErrorCategory.ServerOperation, null);
            }
            try
            {
                base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(databaseLocationInfo.ServerFqdn));
                this.mapiSession = new MapiAdministrationSession(databaseLocationInfo.ServerLegacyDN, Fqdn.Parse(databaseLocationInfo.ServerFqdn));
            }
            catch (MapiPermanentException exception2)
            {
                base.WriteError(exception2, ExchangeErrorCategory.ServerOperation, null);
            }
            catch (MapiRetryableException exception3)
            {
                base.WriteError(exception3, ExchangeErrorCategory.ServerTransient, null);
            }
            this.database = mailboxDatabase;
            TaskLogger.LogExit();
        }
Exemplo n.º 2
0
        internal static bool CheckFullAccessPermissions(ADUser executingAdUser, ADUser accessRequestedForADUser, IRecipientSession session)
        {
            ExTraceGlobals.TaskTracer.TraceDebug <string, string>(0L, "Checking if {0} has full access for mailbox {1}", executingAdUser.Alias, accessRequestedForADUser.Alias);
            ActiveManager         activeManagerInstance = ActiveManager.GetActiveManagerInstance();
            DatabaseLocationInfo  serverForDatabase     = activeManagerInstance.GetServerForDatabase(accessRequestedForADUser.Database.ObjectGuid);
            RawSecurityDescriptor rawSecurityDescriptor = null;

            using (MapiMessageStoreSession mapiMessageStoreSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, Server.GetSystemAttendantLegacyDN(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn)))
            {
                MailboxId mailboxId = new MailboxId(new DatabaseId(accessRequestedForADUser.Database.ObjectGuid), accessRequestedForADUser.ExchangeGuid);
                try
                {
                    rawSecurityDescriptor = mapiMessageStoreSession.GetMailboxSecurityDescriptor(mailboxId);
                }
                catch (MailboxNotFoundException)
                {
                    ExTraceGlobals.TaskTracer.TraceDebug <MailboxId>(0L, "Could not find mailbox {0} when attempting to read its security descriptor.", mailboxId);
                    return(false);
                }
            }
            byte[] array = new byte[rawSecurityDescriptor.BinaryLength];
            rawSecurityDescriptor.GetBinaryForm(array, 0);
            ActiveDirectorySecurity activeDirectorySecurity = new ActiveDirectorySecurity();

            activeDirectorySecurity.SetSecurityDescriptorBinaryForm(array);
            int num = AuthzAuthorization.CheckGenericPermission(executingAdUser.Sid, rawSecurityDescriptor, AccessMask.CreateChild);

            return((num & 1) == 1);
        }
Exemplo n.º 3
0
        private void CallMailboxAssociationReplicationAssistant(ADUser groupMailbox)
        {
            Exception ex = null;

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(groupMailbox.Database.ObjectGuid);
                base.WriteVerbose("Group mailbox database is on server {0}", new object[]
                {
                    serverForDatabase.ServerFqdn
                });
                using (AssistantsRpcClient assistantsRpcClient = new AssistantsRpcClient(serverForDatabase.ServerFqdn))
                {
                    assistantsRpcClient.StartWithParams("MailboxAssociationReplicationAssistant", groupMailbox.ExchangeGuid, groupMailbox.Database.ObjectGuid, string.Empty);
                }
                base.WriteVerbose("Started update of the user mailboxes for the new ExternalDirectoryObjectId", new object[0]);
            }
            catch (RpcException ex2)
            {
                ex = ex2;
            }
            catch (LocalizedException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                base.WriteVerbose("Failed to call RPC to MailboxAssociationReplicationAssistant due the following exception: {0}", new object[]
                {
                    ex
                });
                this.WriteWarning(Strings.WarningUnableToUpdateUserMailboxes);
            }
        }
Exemplo n.º 4
0
        internal static ADUser SplitArchiveFromPrimary(ADUser primaryUser, IRecipientSession recipientSession = null)
        {
            ADUser aduser = null;

            if (!primaryUser.ArchiveGuid.Equals(Guid.Empty))
            {
                aduser = new ADUser();
                aduser.StampPersistableDefaultValues();
                aduser.StampDefaultValues(RecipientType.UserMailbox);
                aduser.ResetChangeTracking();
                AuxMailboxTaskHelper.AuxMailboxStampDefaultValues(aduser);
                aduser.AddressListMembership = primaryUser.AddressListMembership;
                aduser.DisplayName           = string.Format("{0} {1}", Strings.ArchiveNamePrefix, primaryUser.DisplayName);
                aduser.OrganizationId        = primaryUser.OrganizationId;
                aduser.ExchangeGuid          = primaryUser.ArchiveGuid;
                aduser.Database = primaryUser.ArchiveDatabase;
                aduser.Alias    = RecipientTaskHelper.GenerateAlias(string.Format("{0}{1}", Strings.ArchiveNamePrefix, aduser.ExchangeGuid));
                aduser.Name     = string.Format("{0}{1}", Strings.ArchiveNamePrefix, primaryUser.ExchangeGuid);
                if (recipientSession == null)
                {
                    recipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(primaryUser.OrganizationId), 74, "SplitArchiveFromPrimary", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Common\\recipient\\AuxMailboxTaskHelper.cs");
                }
                IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(primaryUser.OrganizationId), 80, "SplitArchiveFromPrimary", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\Common\\recipient\\AuxMailboxTaskHelper.cs");
                aduser.UserPrincipalName = RecipientTaskHelper.GenerateUniqueUserPrincipalName(recipientSession, aduser.Alias, tenantOrTopologyConfigurationSession.GetDefaultAcceptedDomain().DomainName.Domain, null);
                aduser.EmailAddresses.Add(new SmtpProxyAddress(aduser.UserPrincipalName, false));
                DatabaseLocationInfo serverForDatabase = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(primaryUser.ArchiveDatabase.ObjectGuid);
                aduser.ServerLegacyDN = serverForDatabase.ServerLegacyDN;
                aduser.SetId(primaryUser.Id.Parent.GetChildId(aduser.Name));
            }
            return(aduser);
        }
Exemplo n.º 5
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     if (this.unlockMoveTarget)
     {
         ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
         DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(this.databaseObject.Guid);
         string serverFqdn = serverForDatabase.ServerFqdn;
         if (!this.DetectOnly)
         {
             UnlockMoveTargetUtil.UnlockMoveTarget(serverFqdn, this.databaseObject.Guid, this.mailboxGuid, this.organizationId);
             this.WriteResult(this.DataObject);
         }
     }
     else
     {
         StoreIntegrityCheckRequestFlags requestFlags           = this.GetRequestFlags();
         StoreIntegrityCheckJob          storeIntegrityCheckJob = StoreIntegrityCheckAdminRpc.CreateStoreIntegrityCheckJob(this.databaseObject, this.mailboxGuid, requestFlags, this.CorruptionType, new Task.TaskErrorLoggingDelegate(base.WriteError), new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
         if (storeIntegrityCheckJob != null)
         {
             this.WriteResult(storeIntegrityCheckJob);
         }
     }
     TaskLogger.LogExit();
 }
Exemplo n.º 6
0
        private static void SaveArchiveSecurityDescriptor(ADUser mailbox, IConfigDataProvider writableAdSession, RawSecurityDescriptor rawSd, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
        {
            ADObjectId adobjectId = mailbox.ArchiveDatabase ?? mailbox.Database;
            MailboxId  mailboxId  = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(adobjectId), mailbox.ArchiveGuid);

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(adobjectId.ObjectGuid);
                using (MapiMessageStoreSession mapiMessageStoreSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, PermissionTaskHelper.CalcuteSystemAttendantMailboxLegacyDistingushName(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn)))
                {
                    logVerbose(Strings.VerboseSaveStoreMailboxSecurityDescriptor(mailboxId.ToString(), mapiMessageStoreSession.ServerName));
                    mapiMessageStoreSession.ForceStoreToRefreshMailbox(mailboxId);
                }
            }
            catch (FormatException)
            {
                logError(new TaskInvalidOperationException(Strings.ErrorInvalidServerLegacyDistinguishName(mailbox.DistinguishedName.ToString())), ExchangeErrorCategory.ServerOperation, null);
            }
            catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException)
            {
                logVerbose(Strings.VerboseArchiveNotExistInStore(mailbox.Name));
                PermissionTaskHelper.SaveAdSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            }
            catch (LocalizedException exception)
            {
                logError(new SetArchivePermissionException(mailbox.Name, exception), ExchangeErrorCategory.ServerOperation, null);
            }
        }
Exemplo n.º 7
0
        // Token: 0x06000453 RID: 1107 RVA: 0x0000F6CC File Offset: 0x0000D8CC
        private static void GetServerForDatabase(Guid publicFolderDatabaseGuid, out string serverLegacyDn, out Fqdn serverFqdn)
        {
            ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(publicFolderDatabaseGuid, GetServerForDatabaseFlags.ThrowServerForDatabaseNotFoundException);

            serverFqdn     = Fqdn.Parse(serverForDatabase.ServerFqdn);
            serverLegacyDn = serverForDatabase.ServerLegacyDN;
        }
        private static void ExecuteAdminRpc(Guid databaseGuid, Action <ExRpcAdmin, string> action, Task.TaskErrorLoggingDelegate writeError, Task.TaskWarningLoggingDelegate writeWarning, Task.TaskVerboseLoggingDelegate writeVerbose)
        {
            ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(databaseGuid);
            string serverFqdn = serverForDatabase.ServerFqdn;

            using (ExRpcAdmin exRpcAdmin = ExRpcAdmin.Create("Client=Management", serverFqdn, null, null, null))
            {
                action(exRpcAdmin, serverFqdn);
            }
        }
Exemplo n.º 9
0
        private void ResolveDatabaseAndServer()
        {
            ActiveManager activeManagerInstance = ActiveManager.GetActiveManagerInstance();

            if (this.Server != null)
            {
                this.server = MapiTaskHelper.GetMailboxServer(this.Server, (ITopologyConfigurationSession)this.ConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            else if (this.Identity != null)
            {
                DatabaseIdParameter identity = this.Identity;
                identity.AllowLegacy = false;
                Database          database = (Database)base.GetDataObject <Database>(identity, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(identity.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(identity.ToString())));
                ServerIdParameter serverIdParameter;
                if (this.CopyOnServer != null)
                {
                    serverIdParameter = this.CopyOnServer;
                }
                else
                {
                    if (database.Server == null)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Database).Name, identity.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, database);
                    }
                    DatabaseLocationInfo serverForDatabase = activeManagerInstance.GetServerForDatabase(database.Guid);
                    serverIdParameter = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                }
                this.server = (Server)base.GetDataObject <Server>(serverIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorServerNotFound(serverIdParameter.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(serverIdParameter.ToString())));
                if (!this.server.IsExchange2007OrLater || !this.server.IsMailboxServer)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorLocalServerIsNotMailboxServer), ErrorCategory.InvalidArgument, this.server);
                }
                this.databases = new List <Database>(new Database[]
                {
                    database
                });
            }
            else
            {
                ServerIdParameter serverIdParameter2 = new ServerIdParameter();
                this.server = (Server)base.GetDataObject <Server>(serverIdParameter2, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorLocalMachineIsNotExchangeServer), new LocalizedString?(Strings.ErrorServerNotUnique(serverIdParameter2.ToString())));
                if (!this.server.IsExchange2007OrLater || !this.server.IsMailboxServer)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorLocalServerIsNotMailboxServer), ErrorCategory.InvalidArgument, this.server);
                }
            }
            if (this.databases.Count == 0)
            {
                this.databases = StoreCommon.PopulateDatabasesFromServer(activeManagerInstance, this.server, this.IncludePassive);
            }
        }
Exemplo n.º 10
0
        public static void SaveMailboxSecurityDescriptor(ADUser mailbox, ActiveDirectorySecurity adSecurity, IConfigDataProvider writableAdSession, ref MapiMessageStoreSession storeSession, Task.TaskVerboseLoggingDelegate logVerbose, Task.ErrorLoggerDelegate logError)
        {
            if (writableAdSession == null)
            {
                throw new ArgumentException("writableAdSession");
            }
            RawSecurityDescriptor rawSd = new RawSecurityDescriptor(adSecurity.GetSecurityDescriptorBinaryForm(), 0);

            PermissionTaskHelper.SaveAdSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            string text = null;

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(mailbox.Database.ObjectGuid);
                text = serverForDatabase.ServerFqdn;
                if (storeSession == null)
                {
                    storeSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, PermissionTaskHelper.CalcuteSystemAttendantMailboxLegacyDistingushName(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn));
                }
                else
                {
                    storeSession.RedirectServer(serverForDatabase.ServerLegacyDN, Fqdn.Parse(serverForDatabase.ServerFqdn));
                }
                MailboxId mailboxId = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(mailbox.Database), mailbox.ExchangeGuid);
                logVerbose(Strings.VerboseSaveStoreMailboxSecurityDescriptor(mailboxId.ToString(), storeSession.ServerName));
                storeSession.Administration.PurgeCachedMailboxObject(mailboxId.MailboxGuid);
            }
            catch (DatabaseNotFoundException)
            {
                logVerbose(Strings.ErrorMailboxDatabaseNotFound(mailbox.Database.ToString()));
            }
            catch (MapiExceptionNetworkError)
            {
                logVerbose(Strings.ErrorFailedToConnectToStore((text != null) ? text : string.Empty));
            }
            catch (FormatException)
            {
                logVerbose(Strings.ErrorInvalidServerLegacyDistinguishName(mailbox.DistinguishedName.ToString()));
            }
            catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException)
            {
                logVerbose(Strings.VerboseMailboxNotExistInStore(mailbox.DistinguishedName));
            }
            if (mailbox.HasLocalArchive)
            {
                PermissionTaskHelper.SaveArchiveSecurityDescriptor(mailbox, writableAdSession, rawSd, logVerbose, logError);
            }
        }
Exemplo n.º 11
0
        private Server GetActiveServer(Guid dbGuid)
        {
            if (dbGuid == Guid.Empty)
            {
                throw new ArgumentNullException("dbGuid");
            }
            ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(dbGuid);
            Server server = base.GlobalConfigSession.FindServerByFqdn(serverForDatabase.ServerFqdn);

            if (server == null)
            {
                throw new RecipientTaskException(new LocalizedString(new ServerNotFoundException("couldn't find server", serverForDatabase.ServerFqdn).Message));
            }
            return(server);
        }
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         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;
         if (!Guid.TryParse(this.Identity.ToString(), out this.guidMailbox))
         {
             base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidGuidFormat), ErrorCategory.InvalidArgument, this.Identity.ToString());
         }
     }
     catch (MapiPermanentException exception2)
     {
         base.WriteError(exception2, ExchangeErrorCategory.ServerOperation, this.Identity);
     }
     catch (MapiRetryableException exception3)
     {
         base.WriteError(exception3, ExchangeErrorCategory.ServerTransient, this.Identity);
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
Exemplo n.º 13
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            this.unlockMoveTarget = false;
            foreach (MailboxCorruptionType mailboxCorruptionType in this.CorruptionType)
            {
                MailboxCorruptionType mailboxCorruptionType2 = mailboxCorruptionType;
                if (mailboxCorruptionType2 == MailboxCorruptionType.LockedMoveTarget)
                {
                    this.unlockMoveTarget = true;
                }
            }
            if (this.unlockMoveTarget)
            {
                ADUser aduser = ((ADRecipient)base.GetDataObject <ADRecipient>(this.Mailbox, this.RecipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.Mailbox.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.Mailbox.ToString())))) as ADUser;
                if (this.CorruptionType.Length != 1)
                {
                    base.WriteError(new CorruptionTypeParameterIncompatibleException(MailboxCorruptionType.LockedMoveTarget.ToString()), ErrorCategory.InvalidArgument, this.CorruptionType);
                }
                if (UnlockMoveTargetUtil.IsValidLockedStatus(aduser.MailboxMoveStatus))
                {
                    base.WriteError(new UnableToUnlockMailboxDueToOutstandingMoveRequestException(this.Mailbox.ToString(), aduser.MailboxMoveStatus.ToString()), ErrorCategory.InvalidArgument, this.Mailbox);
                }
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(this.databaseObject.Guid);
                if (!UnlockMoveTargetUtil.IsMailboxLocked(serverForDatabase.ServerFqdn, this.databaseObject.Guid, aduser.ExchangeGuid))
                {
                    base.WriteError(new MailboxIsNotLockedException(this.Mailbox.ToString()), ErrorCategory.InvalidArgument, this.Mailbox);
                }
            }
            if (!this.databaseObject.IsMailboxDatabase)
            {
                base.WriteError(new OnlineIsIntegException(this.databaseObject.Name, Strings.NotMailboxDatabase, null), ErrorCategory.InvalidArgument, null);
            }
            Guid guid;

            if (this.StoreMailbox != null && !Guid.TryParse(this.StoreMailbox.RawIdentity, out guid))
            {
                throw new ArgumentException("StoreMailbox");
            }
            TaskLogger.LogExit();
        }
Exemplo n.º 14
0
        private void ResolveDatabaseAndServer()
        {
            DatabaseIdParameter database = this.Database;

            database.AllowLegacy = false;
            Database database2 = (Database)base.GetDataObject <Database>(database, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(database.ToString())));

            if (database2.Server == null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Database).Name, database.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, database2);
            }
            ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
            DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(database2.Guid);
            ServerIdParameter    serverIdParameter     = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);

            this.targetServer = (Server)base.GetDataObject <Server>(serverIdParameter, this.ConfigurationSession, null, new LocalizedString?(Strings.ErrorServerNotFound(serverIdParameter.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(serverIdParameter.ToString())));
            if (!this.TargetServer.IsE14OrLater || !this.TargetServer.IsMailboxServer)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorLocalServerIsNotMailboxServer), ErrorCategory.InvalidArgument, this.TargetServer);
            }
            this.targetDatabase = database2;
        }
Exemplo n.º 15
0
        public void Refresh(ADUser mailbox, IRecipientSession writableAdSession)
        {
            if (mailbox == null)
            {
                throw new ArgumentNullException("mailbox");
            }
            if (writableAdSession == null)
            {
                throw new ArgumentNullException("writableAdSession");
            }
            MapiMessageStoreSession mapiMessageStoreSession = null;

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(mailbox.Database.ObjectGuid);
                mapiMessageStoreSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, TeamMailboxSecurityRefresher.CalculateSystemAttendantMailboxLegacyDistingushName(serverForDatabase.ServerLegacyDN), Fqdn.Parse(serverForDatabase.ServerFqdn));
                MailboxId mailboxId = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(mailbox.Database), mailbox.ExchangeGuid);
                try
                {
                    mapiMessageStoreSession.Administration.PurgeCachedMailboxObject(mailboxId.MailboxGuid);
                }
                catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException ex)
                {
                    throw new ObjectNotFoundException(new LocalizedString(ex.ToString()));
                }
                catch (DatabaseUnavailableException ex2)
                {
                    throw new ObjectNotFoundException(new LocalizedString(ex2.ToString()));
                }
            }
            finally
            {
                if (mapiMessageStoreSession != null)
                {
                    mapiMessageStoreSession.Dispose();
                }
            }
        }
Exemplo n.º 16
0
        internal void RefreshStoreCache()
        {
            this.AddVerboseLog("Start: RefreshStoreCache");
            bool flag = this.groupMailbox.WhenMailboxCreated == null || this.groupMailbox.WhenMailboxCreated.Value.AddMinutes(15.0).ToUniversalTime() > DateTime.UtcNow;

            if (flag)
            {
                return;
            }
            string text = null;

            try
            {
                ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(this.groupMailbox.Database.ObjectGuid);
                text = serverForDatabase.ServerFqdn;
                using (MapiMessageStoreSession mapiMessageStoreSession = new MapiMessageStoreSession(serverForDatabase.ServerLegacyDN, serverForDatabase.ServerLegacyDN + "/cn=Microsoft System Attendant", Fqdn.Parse(serverForDatabase.ServerFqdn)))
                {
                    MailboxId mailboxId = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(this.groupMailbox.Database), this.groupMailbox.ExchangeGuid);
                    this.AddVerboseLog(Strings.VerboseSaveStoreMailboxSecurityDescriptor(mailboxId.ToString(), mapiMessageStoreSession.ServerName));
                    mapiMessageStoreSession.Administration.PurgeCachedMailboxObject(mailboxId.MailboxGuid);
                }
            }
            catch (DatabaseNotFoundException)
            {
                this.AddVerboseLog(Strings.ErrorMailboxDatabaseNotFound(this.groupMailbox.Database.ToString()));
            }
            catch (MapiExceptionNetworkError)
            {
                this.AddVerboseLog(Strings.ErrorFailedToConnectToStore((text != null) ? text : string.Empty));
            }
            catch (MailboxNotFoundException)
            {
                this.AddVerboseLog(Strings.VerboseMailboxNotExistInStore(this.groupMailbox.DistinguishedName));
            }
            this.AddVerboseLog("End: RefreshStoreCache");
        }
Exemplo n.º 17
0
        protected override void InternalValidate()
        {
            bool flag = false;

            try
            {
                ADRecipient            adrecipient = null;
                List <MailboxDatabase> list        = new List <MailboxDatabase>();
                bool          flag2 = false;
                ActiveManager activeManagerInstance = ActiveManager.GetActiveManagerInstance();
                base.TenantGlobalCatalogSession.ServerTimeout = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout));
                this.ConfigurationSession.ServerTimeout       = new TimeSpan?(TimeSpan.FromSeconds((double)this.ActiveDirectoryTimeout));
                this.transactionTargets = new List <MapiTransaction>();
                if (this.Identity != null)
                {
                    if (this.EnableSoftDeletedRecipientLogon)
                    {
                        IDirectorySession directorySession = base.DataSession as IDirectorySession;
                        directorySession.SessionSettings.IncludeSoftDeletedObjects = true;
                    }
                    ADUser aduser = (ADUser)RecipientTaskHelper.ResolveDataObject <ADUser>(base.DataSession, base.TenantGlobalCatalogSession, base.ServerSettings, this.Identity, null, base.OptionalIdentityData, base.DomainController, new DataAccessHelper.CategorizedGetDataObjectDelegate(base.GetDataObject <ADUser>), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
                    if (this.Archive)
                    {
                        if (aduser.ArchiveDatabase == null)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorArchiveNotEnabled(aduser.ToString())), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        else
                        {
                            this.Database = new DatabaseIdParameter(aduser.ArchiveDatabase);
                        }
                    }
                    else
                    {
                        this.Database = new DatabaseIdParameter(aduser.Database);
                    }
                    flag        = true;
                    adrecipient = aduser;
                }
                if (this.Database != null)
                {
                    MailboxDatabase mailboxDatabase  = null;
                    MailboxDatabase mailboxDatabase2 = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(this.Database, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(this.Database.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(this.Database.ToString())));
                    if (mailboxDatabase2.Recovery)
                    {
                        string name = mailboxDatabase2.Name;
                        RecoveryMailboxDatabaseNotMonitoredException exception = new RecoveryMailboxDatabaseNotMonitoredException(name);
                        this.WriteErrorAndMonitoringEvent(exception, ErrorCategory.InvalidOperation, null, 1006, "MSExchange Monitoring MAPIConnectivity");
                        return;
                    }
                    mailboxDatabase = mailboxDatabase2;
                    if (!flag)
                    {
                        try
                        {
                            MapiTaskHelper.VerifyDatabaseAndItsOwningServerInScope(base.SessionSettings, mailboxDatabase, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                            flag = true;
                        }
                        catch (InvalidOperationException exception2)
                        {
                            this.WriteErrorAndMonitoringEvent(exception2, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                            return;
                        }
                    }
                    list.Add(mailboxDatabase);
                    if (this.CopyOnServer != null)
                    {
                        this.Server = this.CopyOnServer;
                    }
                    else
                    {
                        DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase.Guid);
                        if (serverForDatabase != null)
                        {
                            this.Server = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                        }
                        else
                        {
                            this.Server = ServerIdParameter.Parse(mailboxDatabase.Server.DistinguishedName);
                        }
                    }
                }
                if (this.Server == null)
                {
                    string machineName = Environment.MachineName;
                    this.Server = ServerIdParameter.Parse(machineName);
                }
                this.targetServer = (Server)base.GetDataObject <Server>(this.Server, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorServerNotFound(this.Server.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(this.Server.ToString())));
                LocalizedException ex = null;
                if (!this.targetServer.IsExchange2007OrLater)
                {
                    ex = new OperationOnOldServerException(this.targetServer.Name);
                }
                else if (!this.targetServer.IsMailboxServer)
                {
                    ex = new OperationOnlyOnMailboxServerException(this.targetServer.Name);
                }
                if (ex != null)
                {
                    this.WriteErrorAndMonitoringEvent(ex, ErrorCategory.InvalidArgument, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                }
                else
                {
                    if (!flag)
                    {
                        try
                        {
                            MapiTaskHelper.VerifyIsWithinConfigWriteScope(base.SessionSettings, this.targetServer, new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                        }
                        catch (InvalidOperationException exception3)
                        {
                            this.WriteErrorAndMonitoringEvent(exception3, ErrorCategory.InvalidOperation, null, 1005, "MSExchange Monitoring MAPIConnectivity");
                            return;
                        }
                    }
                    if (list.Count == 0)
                    {
                        MailboxDatabase[] mailboxDatabases = this.targetServer.GetMailboxDatabases();
                        if (mailboxDatabases.Length > 0)
                        {
                            flag2 = true;
                        }
                        foreach (MailboxDatabase mailboxDatabase3 in mailboxDatabases)
                        {
                            if (!mailboxDatabase3.AutoDagExcludeFromMonitoring)
                            {
                                if (this.IncludePassive)
                                {
                                    list.Add(mailboxDatabase3);
                                }
                                else
                                {
                                    DatabaseLocationInfo serverForDatabase = this.GetServerForDatabase(activeManagerInstance, mailboxDatabase3.Guid);
                                    if ((serverForDatabase != null && serverForDatabase.ServerGuid == this.targetServer.Guid) || (serverForDatabase == null && mailboxDatabase3.Server.ObjectGuid == this.targetServer.Guid))
                                    {
                                        list.Add(mailboxDatabase3);
                                    }
                                }
                            }
                        }
                    }
                    if (adrecipient != null)
                    {
                        this.wasTargetMailboxSpecified = true;
                        this.transactionTargets.Add(new MapiTransaction(this.targetServer, list[0], adrecipient, this.Archive, list[0].Server.ObjectGuid == this.targetServer.Guid));
                    }
                    else
                    {
                        foreach (MailboxDatabase mailboxDatabase4 in list)
                        {
                            if (!mailboxDatabase4.Recovery)
                            {
                                GeneralMailboxIdParameter id = GeneralMailboxIdParameter.Parse(string.Format(CultureInfo.InvariantCulture, "SystemMailbox{{{0}}}", new object[]
                                {
                                    mailboxDatabase4.Guid.ToString()
                                }));
                                IEnumerable <ADSystemMailbox> dataObjects = base.GetDataObjects <ADSystemMailbox>(id, base.RootOrgGlobalCatalogSession, null);
                                using (IEnumerator <ADSystemMailbox> enumerator2 = dataObjects.GetEnumerator())
                                {
                                    adrecipient = (enumerator2.MoveNext() ? enumerator2.Current : null);
                                    this.transactionTargets.Add(new MapiTransaction(this.targetServer, mailboxDatabase4, adrecipient, false, mailboxDatabase4.Server.ObjectGuid == this.targetServer.Guid));
                                }
                            }
                        }
                    }
                    this.transactionTargets.Sort();
                    if (this.transactionTargets.Count < 1)
                    {
                        if (flag2)
                        {
                            this.WriteWarning(Strings.MapiTransactionServerWithoutMdbs(this.targetServer.Name));
                            this.onlyPassives = true;
                        }
                        else
                        {
                            this.WriteErrorAndMonitoringEvent(new NoMdbForOperationException(this.targetServer.Name), ErrorCategory.ReadError, null, 1010, "MSExchange Monitoring MAPIConnectivity");
                        }
                    }
                }
            }
            finally
            {
                if (base.HasErrors && this.MonitoringContext)
                {
                    base.WriteObject(this.monitoringData);
                }
                TaskLogger.LogExit();
            }
        }
Exemplo n.º 18
0
        protected void ResolveDatabaseAndServer()
        {
            DatabaseIdParameter databaseIdParameter   = this.Database;
            ServerIdParameter   serverIdParameter     = this.Server ?? new ServerIdParameter();
            ActiveManager       activeManagerInstance = ActiveManager.GetActiveManagerInstance();

            if (this.Identity != null)
            {
                bool flag = false;
                if (this.isRunningLogonStatisticsTask)
                {
                    TIdentity tidentity            = this.Identity;
                    IEnumerable <Database> objects = tidentity.GetObjects <Database>(null, base.GlobalConfigSession);
                    foreach (Database item in objects)
                    {
                        this.databases.Add(item);
                    }
                    if (this.databases.Count > 0)
                    {
                        if (this.databases[0].Server == null)
                        {
                            string    name       = typeof(Database).Name;
                            TIdentity tidentity2 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name, tidentity2.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        DatabaseLocationInfo serverForDatabase = activeManagerInstance.GetServerForDatabase(this.databases[0].Guid);
                        serverIdParameter = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                        if (string.IsNullOrEmpty(this.databases[0].ExchangeLegacyDN))
                        {
                            string    name2      = typeof(Database).Name;
                            TIdentity tidentity3 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name2, tidentity3.ToString(), DatabaseSchema.ExchangeLegacyDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        this.identity = new MailboxId(this.databases[0].ExchangeLegacyDN);
                        flag          = true;
                    }
                }
                if (!flag)
                {
                    IIdentityParameter  id            = this.Identity;
                    IConfigDataProvider session       = this.readOnlyRecipientSession;
                    ObjectId            rootID        = null;
                    TIdentity           tidentity4    = this.Identity;
                    LocalizedString?    notFoundError = new LocalizedString?(Strings.ErrorMailboxNotFound(tidentity4.ToString()));
                    TIdentity           tidentity5    = this.Identity;
                    ADRecipient         adrecipient   = (ADRecipient)base.GetDataObject <ADRecipient>(id, session, rootID, notFoundError, new LocalizedString?(Strings.ErrorMailboxNotUnique(tidentity5.ToString())));
                    Guid       guid = Guid.Empty;
                    string     mailboxExchangeLegacyDn = null;
                    ADObjectId adobjectId = null;
                    if (string.IsNullOrEmpty(adrecipient.LegacyExchangeDN))
                    {
                        string    name3      = typeof(ADRecipient).Name;
                        TIdentity tidentity6 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name3, tidentity6.ToString(), ADRecipientSchema.LegacyExchangeDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
                    }
                    ADUser                   aduser                   = adrecipient as ADUser;
                    ADSystemMailbox          adsystemMailbox          = adrecipient as ADSystemMailbox;
                    ADSystemAttendantMailbox adsystemAttendantMailbox = adrecipient as ADSystemAttendantMailbox;
                    ADPublicDatabase         adpublicDatabase         = adrecipient as ADPublicDatabase;
                    if (aduser != null)
                    {
                        if (this.isRunningMailboxStatisticsTask && aduser.RecipientTypeDetails == RecipientTypeDetails.AuditLogMailbox && !this.GetAuditLogMailboxStatistics())
                        {
                            TIdentity tidentity7 = this.Identity;
                            base.WriteError(new MdbAdminTaskException(Strings.RecipientNotFoundException(tidentity7.ToString())), ErrorCategory.InvalidArgument, null);
                        }
                        bool archiveMailboxStatistics = this.GetArchiveMailboxStatistics();
                        if (aduser.RecipientType == RecipientType.MailUser && !archiveMailboxStatistics)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.RecipientTypeNotValid(aduser.ToString())), (ErrorCategory)1003, this.Identity);
                        }
                        RecipientIdParameter recipientIdParameter = this.Identity as RecipientIdParameter;
                        if (this.isRunningMailboxStatisticsTask && recipientIdParameter != null && recipientIdParameter.RawMailboxGuidInvolvedInSearch != Guid.Empty && aduser.MailboxLocations != null)
                        {
                            IMailboxLocationInfo mailboxLocation = aduser.MailboxLocations.GetMailboxLocation(recipientIdParameter.RawMailboxGuidInvolvedInSearch);
                            if (mailboxLocation != null)
                            {
                                guid       = mailboxLocation.MailboxGuid;
                                adobjectId = mailboxLocation.DatabaseLocation;
                            }
                        }
                        if (guid == Guid.Empty || adobjectId == null)
                        {
                            if (archiveMailboxStatistics)
                            {
                                if (aduser.ArchiveGuid != Guid.Empty)
                                {
                                    if (aduser.ArchiveDomain != null)
                                    {
                                        base.WriteError(new MdbAdminTaskException(Strings.ErrorRemoteArchiveNoStats(aduser.ToString())), (ErrorCategory)1003, this.Identity);
                                    }
                                    else
                                    {
                                        guid       = aduser.ArchiveGuid;
                                        adobjectId = (aduser.ArchiveDatabase ?? aduser.Database);
                                    }
                                }
                                else
                                {
                                    base.WriteError(new MdbAdminTaskException(Strings.ErrorArchiveNotEnabled(aduser.ToString())), ErrorCategory.InvalidArgument, this.Identity);
                                }
                            }
                            else
                            {
                                guid       = aduser.ExchangeGuid;
                                adobjectId = aduser.Database;
                            }
                        }
                        mailboxExchangeLegacyDn = aduser.LegacyExchangeDN;
                    }
                    else if (adsystemMailbox != null)
                    {
                        guid = adsystemMailbox.ExchangeGuid;
                        mailboxExchangeLegacyDn = adsystemMailbox.LegacyExchangeDN;
                        adobjectId = adsystemMailbox.Database;
                    }
                    else if (adsystemAttendantMailbox != null)
                    {
                        guid = adsystemAttendantMailbox.Guid;
                        mailboxExchangeLegacyDn = adsystemAttendantMailbox.LegacyExchangeDN;
                        adobjectId = adsystemAttendantMailbox.Database;
                    }
                    else if (adpublicDatabase != null)
                    {
                        mailboxExchangeLegacyDn = adpublicDatabase.LegacyExchangeDN;
                        adobjectId = (ADObjectId)adpublicDatabase.Identity;
                    }
                    if (adobjectId == null)
                    {
                        string    name4      = adrecipient.GetType().Name;
                        TIdentity tidentity8 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(name4, tidentity8.ToString(), IADMailStorageSchema.Database.Name)), ErrorCategory.InvalidArgument, adrecipient);
                    }
                    databaseIdParameter = new DatabaseIdParameter(adobjectId);
                    if (this.isRunningLogonStatisticsTask)
                    {
                        this.identity = new MailboxId(mailboxExchangeLegacyDn);
                    }
                    else
                    {
                        this.identity = new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(adobjectId), guid);
                    }
                }
            }
            if (databaseIdParameter != null)
            {
                databaseIdParameter.AllowLegacy = true;
                LocalizedString empty  = LocalizedString.Empty;
                LocalizedString empty2 = LocalizedString.Empty;
                Database        database;
                if (this.isRunningLogonStatisticsTask)
                {
                    database = (Database)base.GetDataObject <Database>(databaseIdParameter, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(databaseIdParameter.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(databaseIdParameter.ToString())));
                }
                else
                {
                    database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(databaseIdParameter, base.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorMailboxDatabaseNotFound(databaseIdParameter.ToString())), new LocalizedString?(Strings.ErrorMailboxDatabaseNotUnique(databaseIdParameter.ToString())));
                }
                if (database.Server == null)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(this.isRunningLogonStatisticsTask ? typeof(Database).Name : typeof(MailboxDatabase).Name, databaseIdParameter.ToString(), DatabaseSchema.Server.Name)), ErrorCategory.InvalidArgument, database);
                }
                this.databases = new List <Database>(new Database[]
                {
                    database
                });
                if (this.CopyOnServer != null)
                {
                    serverIdParameter = this.CopyOnServer;
                }
                else
                {
                    DatabaseLocationInfo serverForDatabase = activeManagerInstance.GetServerForDatabase(database.Guid);
                    serverIdParameter = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
                }
            }
            if (this.Server != null)
            {
                serverIdParameter = this.Server;
                this.server       = MapiTaskHelper.GetMailboxServer(this.Server, base.GlobalConfigSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            else
            {
                this.server = (Server)base.GetDataObject <Server>(serverIdParameter, base.GlobalConfigSession, null, new LocalizedString?((this.Identity == null && this.Database == null) ? Strings.ErrorLocalMachineIsNotExchangeServer : Strings.ErrorServerNotFound(serverIdParameter.ToString())), new LocalizedString?(Strings.ErrorServerNotUnique(serverIdParameter.ToString())));
                if (!this.server.IsExchange2007OrLater || !this.server.IsMailboxServer)
                {
                    if (this.Identity != null)
                    {
                        TIdentity tidentity9 = this.Identity;
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorMailboxInNonMailboxServer(tidentity9.ToString())), ErrorCategory.InvalidArgument, this.server);
                    }
                    if (this.Database != null)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorDatabaseInNonMailboxServer(this.Database.ToString())), ErrorCategory.InvalidArgument, this.server);
                    }
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorLocalServerIsNotMailboxServer), ErrorCategory.InvalidArgument, this.server);
                }
            }
            if (string.IsNullOrEmpty(this.server.ExchangeLegacyDN))
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(typeof(Server).Name, serverIdParameter.ToString(), ServerSchema.ExchangeLegacyDN.Name)), ErrorCategory.InvalidArgument, this.Identity);
            }
            if (this.databases.Count == 0)
            {
                if (this.isRunningLogonStatisticsTask)
                {
                    this.FilterActiveDatabases(activeManagerInstance, this.server.GetDatabases());
                    return;
                }
                this.FilterActiveDatabases(activeManagerInstance, this.server.GetMailboxDatabases());
            }
        }
Exemplo n.º 19
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();
     }
 }
Exemplo n.º 20
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            ADObjectId adobjectId = null;
            Guid       guid       = Guid.Empty;
            string     text       = string.Empty;
            bool       flag       = this.ShouldSoftDeleteObject();
            ADUser     dataObject = base.DataObject;

            if (Globals.IsMicrosoftHostedOnly)
            {
                if (flag)
                {
                    bool flag2 = SoftDeletedTaskHelper.MSOSyncEnabled(this.ConfigurationSession, dataObject.OrganizationId);
                    bool includeInGarbageCollection = (!flag2 || base.ForReconciliation) && !this.isToInactiveMailbox;
                    SoftDeletedTaskHelper.UpdateRecipientForSoftDelete(base.DataSession as IRecipientSession, dataObject, includeInGarbageCollection, this.isToInactiveMailbox);
                }
                else
                {
                    if (this.isDisconnectInactiveMailbox)
                    {
                        SoftDeletedTaskHelper.UpdateMailboxForDisconnectInactiveMailbox(dataObject);
                        base.DataSession.Save(dataObject);
                        TaskLogger.LogExit();
                        this.LogRemoveMailboxDetails(dataObject);
                        return;
                    }
                    dataObject.RecipientSoftDeletedStatus = 0;
                }
            }
            if (this.Identity != null)
            {
                adobjectId = base.DataObject.Database;
                guid       = base.DataObject.ExchangeGuid;
                if (adobjectId == null)
                {
                    TaskLogger.Trace("The homeMDB is empty for this user, we just try to remove the user AD object", new object[0]);
                }
                else if (guid == Guid.Empty)
                {
                    TaskLogger.Trace("The ExchangeGuid is empty for this user, we just try to remove the user AD object", new object[0]);
                }
                else if (base.DataObject.RecipientTypeDetails == RecipientTypeDetails.MailboxPlan)
                {
                    TaskLogger.Trace("This user is MailboxPlan, we just try to remove the user AD object", new object[0]);
                }
                else if (!flag)
                {
                    try
                    {
                        DatabaseLocationInfo databaseLocationInfo = null;
                        try
                        {
                            databaseLocationInfo = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(adobjectId.ObjectGuid);
                        }
                        catch (ObjectNotFoundException exception)
                        {
                            base.WriteError(exception, ExchangeErrorCategory.ServerOperation, null);
                        }
                        if (databaseLocationInfo == null)
                        {
                            if (this.Permanent)
                            {
                                base.WriteError(new TaskInvalidOperationException(Strings.ErrorGetServerNameFromMailbox(base.DataObject.Identity.ToString())), ExchangeErrorCategory.ServerOperation, base.DataObject);
                            }
                            else
                            {
                                TaskLogger.Trace("cannot get the server name for mailbox {0}", new object[]
                                {
                                    base.DataObject.Identity
                                });
                            }
                        }
                        else
                        {
                            text = databaseLocationInfo.ServerFqdn;
                            base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(text));
                            this.mapiSession = new MapiAdministrationSession(databaseLocationInfo.ServerLegacyDN, Fqdn.Parse(text));
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        if (this.Permanent)
                        {
                            base.WriteError(ex, ExchangeErrorCategory.ServerOperation, this.Identity);
                        }
                        else
                        {
                            TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                            {
                                ex
                            });
                        }
                    }
                    catch (MapiRetryableException ex2)
                    {
                        if (this.Permanent)
                        {
                            base.WriteError(ex2, ExchangeErrorCategory.ServerTransient, this.Identity);
                        }
                        else
                        {
                            TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                            {
                                ex2
                            });
                        }
                    }
                    try
                    {
                        if (dataObject != null && base.ForReconciliation)
                        {
                            base.DataObject.ExternalDirectoryObjectId = string.Empty;
                        }
                        base.DataObject.PreviousDatabase = base.DataObject.Database;
                        base.DataSession.Save(base.DataObject);
                    }
                    catch (DataSourceTransientException exception2)
                    {
                        base.WriteError(exception2, ExchangeErrorCategory.ServerTransient, null);
                    }
                    catch (InvalidObjectOperationException)
                    {
                    }
                    catch (DataValidationException)
                    {
                    }
                    catch (ADOperationException)
                    {
                    }
                }
                base.InternalProcessRecord();
                this.LogRemoveMailboxDetails(dataObject);
            }
            if (this.StoreMailboxIdentity != null || this.Permanent)
            {
                if (this.Permanent)
                {
                    if (!(guid != Guid.Empty) || adobjectId == null)
                    {
                        goto IL_5A0;
                    }
                    try
                    {
                        base.WriteVerbose(Strings.VerboseDeleteMailboxInStore(guid.ToString(), adobjectId.ToString()));
                        this.mapiSession.DeleteMailbox(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(adobjectId), guid));
                        goto IL_5A0;
                    }
                    catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException ex3)
                    {
                        TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                        {
                            ex3
                        });
                        base.WriteVerbose(ex3.LocalizedString);
                        goto IL_5A0;
                    }
                    catch (DataSourceOperationException exception3)
                    {
                        base.WriteError(exception3, ExchangeErrorCategory.ServerOperation, base.DataObject);
                        goto IL_5A0;
                    }
                }
                try
                {
                    base.WriteVerbose(Strings.VerboseDeleteMailboxInStore(this.mailboxStatistics.MailboxGuid.ToString(), this.mailboxStatistics.Database.ToString()));
                    ((IConfigDataProvider)this.mapiSession).Delete(this.mailboxStatistics);
                    goto IL_5A0;
                }
                catch (DataSourceOperationException exception4)
                {
                    base.WriteError(exception4, ExchangeErrorCategory.ServerOperation, (this.Identity == null) ? this.StoreMailboxIdentity : this.Identity);
                    goto IL_5A0;
                }
            }
            if (this.mapiSession != null)
            {
                try
                {
                    TIdentity identity = this.Identity;
                    base.WriteVerbose(Strings.VerboseSyncMailboxWithDS(identity.ToString(), base.DataObject.Database.ToString(), text));
                    bool flag3 = true;
                    if (base.DataObject.Database == null || Guid.Empty == base.DataObject.Database.ObjectGuid)
                    {
                        flag3 = false;
                        TaskLogger.Trace("Cannot get the database for mailbox '{0}'", new object[]
                        {
                            base.DataObject.Identity
                        });
                    }
                    if (Guid.Empty == base.DataObject.ExchangeGuid)
                    {
                        flag3 = false;
                        TaskLogger.Trace("Cannot get the mailbox guid for mailbox '{0}'", new object[]
                        {
                            base.DataObject.Identity
                        });
                    }
                    if (flag3)
                    {
                        this.mapiSession.SyncMailboxWithDS(new MailboxId(MapiTaskHelper.ConvertDatabaseADObjectIdToDatabaseId(base.DataObject.Database), base.DataObject.ExchangeGuid));
                    }
                }
                catch (Microsoft.Exchange.Data.Mapi.Common.MailboxNotFoundException ex4)
                {
                    TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                    {
                        ex4
                    });
                    base.WriteVerbose(ex4.LocalizedString);
                }
                catch (DataSourceTransientException ex5)
                {
                    TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                    {
                        ex5
                    });
                    this.WriteWarning(ex5.LocalizedString);
                }
                catch (DataSourceOperationException ex6)
                {
                    TaskLogger.Trace("Swallowing exception {0} from mapi.net", new object[]
                    {
                        ex6
                    });
                    this.WriteWarning(ex6.LocalizedString);
                }
            }
IL_5A0:
            if (!flag && this.mailboxStatistics != null)
            {
                this.mailboxStatistics.Dispose();
                this.mailboxStatistics = null;
            }
            this.DisposeMapiSession();
            TaskLogger.LogExit();
        }
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            ADObjectId  adobjectId  = null;
            ADRecipient adrecipient = (ADRecipient)base.GetDataObject <ADRecipient>(this.Identity, this.recipientSession, null, new LocalizedString?(Strings.ErrorMailboxNotFound(this.Identity.ToString())), new LocalizedString?(Strings.ErrorMailboxNotUnique(this.Identity.ToString())));
            ADUser      aduser      = adrecipient as ADUser;

            if (aduser != null)
            {
                this.exchangeGuid = aduser.ExchangeGuid;
                adobjectId        = aduser.Database;
            }
            else
            {
                ADSystemMailbox adsystemMailbox = adrecipient as ADSystemMailbox;
                if (adsystemMailbox != null)
                {
                    this.exchangeGuid = adsystemMailbox.ExchangeGuid;
                    adobjectId        = adsystemMailbox.Database;
                }
            }
            if (adobjectId == null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorInvalidObjectMissingCriticalProperty(adrecipient.GetType().Name, this.Identity.ToString(), IADMailStorageSchema.Database.Name)), ErrorCategory.InvalidArgument, adrecipient);
            }
            DatabaseIdParameter id = new DatabaseIdParameter(adobjectId);

            this.database = (MailboxDatabase)base.GetDataObject <MailboxDatabase>(id, this.systemConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(adobjectId.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(adobjectId.ToString())));
            try
            {
                this.dbLocationInfo = ActiveManager.GetActiveManagerInstance().GetServerForDatabase(this.database.Id.ObjectGuid);
                this.server         = this.DbLocationInfo.ServerFqdn.Split(new char[]
                {
                    '.'
                })[0];
            }
            catch (DatabaseNotFoundException exception)
            {
                base.WriteError(exception, ExchangeErrorCategory.ServerOperation, null);
            }
            catch (ObjectNotFoundException exception2)
            {
                base.WriteError(exception2, ExchangeErrorCategory.ServerOperation, null);
            }
            try
            {
                if (this.registryKeyHive == null)
                {
                    this.registryKeyHive = this.OpenHive(this.dbLocationInfo.ServerFqdn);
                }
            }
            catch (IOException ex)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex.ToString()), ErrorCategory.ObjectNotFound, null);
            }
            catch (SecurityException ex2)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex2.ToString()), ErrorCategory.SecurityError, null);
            }
            catch (UnauthorizedAccessException ex3)
            {
                base.WriteError(new FailedMailboxQuarantineException(this.Identity.ToString(), ex3.ToString()), ErrorCategory.PermissionDenied, null);
            }
            TaskLogger.LogExit();
        }
 private void SetTargetParameters()
 {
     if (base.Task.AutoDiscoverTargetMailboxServer.IsPresent)
     {
         base.Task.TargetMailboxServer = this.AutoDiscoverTargetServer();
     }
     if (base.Task.TargetMailboxServer != null)
     {
         this.targetMailboxServer = this.GetServerFromId(base.Task.TargetMailboxServer);
         ADSystemMailbox adsystemMailbox = null;
         try
         {
             this.targetSystemMailboxMdb = base.GetServerMdb(this.targetMailboxServer);
             adsystemMailbox             = base.GetSystemMailboxFromMdb(this.targetSystemMailboxMdb);
             this.targetServerHasMdb     = true;
         }
         catch (MailboxServerNotHostingMdbException)
         {
             this.targetServerHasMdb = false;
         }
         if (this.targetServerHasMdb)
         {
             this.targetMailboxAddress  = adsystemMailbox.PrimarySmtpAddress.ToString();
             this.friendlyTargetAddress = base.Task.TargetMailboxServer.ToString() + "\\" + this.targetMailboxAddress;
             return;
         }
     }
     else if (base.Task.TargetDatabase != null)
     {
         MailboxDatabase      mailboxDatabase       = (MailboxDatabase)base.Task.GetAdDataObject <MailboxDatabase>(base.Task.TargetDatabase, base.Task.GlobalConfigSession, null, new LocalizedString?(Strings.ErrorDatabaseNotFound(base.Task.TargetDatabase.ToString())), new LocalizedString?(Strings.ErrorDatabaseNotUnique(base.Task.TargetDatabase.ToString())));
         ActiveManager        activeManagerInstance = ActiveManager.GetActiveManagerInstance();
         DatabaseLocationInfo serverForDatabase     = activeManagerInstance.GetServerForDatabase(mailboxDatabase.Guid);
         if (serverForDatabase != null && !string.IsNullOrEmpty(serverForDatabase.ServerFqdn))
         {
             base.Task.TargetMailboxServer = ServerIdParameter.Parse(serverForDatabase.ServerFqdn);
             this.targetMailboxServer      = this.GetServerFromId(base.Task.TargetMailboxServer);
             ADSystemMailbox systemMailboxFromMdb = base.GetSystemMailboxFromMdb(mailboxDatabase);
             this.targetSystemMailboxMdb = mailboxDatabase;
             this.targetMailboxAddress   = systemMailboxFromMdb.PrimarySmtpAddress.ToString();
             this.friendlyTargetAddress  = base.Task.TargetMailboxServer.ToString() + "\\" + this.targetMailboxAddress;
             return;
         }
         base.WriteErrorAndMonitoringEvent(new MdbServerNotFoundException(mailboxDatabase.ToString()), ErrorCategory.InvalidData, 1011);
         return;
     }
     else if (base.Task.TargetEmailAddress != null)
     {
         this.targetMailboxAddress = base.Task.TargetEmailAddress;
         if (string.IsNullOrEmpty(base.Task.TargetEmailAddressDisplayName))
         {
             this.friendlyTargetAddress = base.Task.TargetEmailAddress;
         }
         else
         {
             this.friendlyTargetAddress = base.Task.TargetEmailAddressDisplayName + "(" + base.Task.TargetEmailAddress + ")";
         }
         RoutingAddress routingAddress = new RoutingAddress(base.Task.TargetEmailAddress);
         if (!routingAddress.IsValid)
         {
             base.WriteErrorAndMonitoringEvent(new RecipientTaskException(Strings.TestMailflowInvalidTargetEmailAddress(base.Task.TargetEmailAddress)), ErrorCategory.InvalidData, 1008);
         }
     }
 }