Beispiel #1
0
        internal static void CheckLegacyDNNotInUse(MailboxId disconnectedMailboxIdentity, string disconnectedMailboxLegacyDN, IRecipientSession globalCatalogSession, Task.ErrorLoggerDelegate errorLogger)
        {
            ADRecipient adrecipient = ConnectMailbox.FindMailboxByLegacyDN(disconnectedMailboxLegacyDN, globalCatalogSession);

            if (adrecipient != null)
            {
                errorLogger(new MdbAdminTaskException(Strings.ErrorMailboxLegacyDNInUse(disconnectedMailboxLegacyDN, disconnectedMailboxIdentity.ToString(), adrecipient.DisplayName)), ExchangeErrorCategory.ServerOperation, disconnectedMailboxIdentity);
            }
        }
Beispiel #2
0
        private ADUser FindArchiveUser(MailboxStatistics storeMailbox, IRecipientSession globalCatalogSession, Task.TaskErrorLoggingDelegate errorLogger)
        {
            ADRecipient adrecipient = ConnectMailbox.FindMailboxByLegacyDN(storeMailbox.LegacyDN, globalCatalogSession);

            if (adrecipient == null)
            {
                errorLogger(new MdbAdminTaskException(Strings.ErrorRecipientNotFound(storeMailbox.LegacyDN)), ErrorCategory.InvalidArgument, storeMailbox);
            }
            return((ADUser)adrecipient);
        }
Beispiel #3
0
 private static void ConnectArchiveCore(ADUser userToConnect, Guid deletedMailboxGuid, string parameterSetName, IRecipientSession recipientSession, IConfigurationSession configSession, MapiAdministrationSession mapiAdministrationSession, string alias, SecurityIdentifier linkedUserSid, DatabaseLocationInfo databaseLocationInfo, MailboxDatabase database, Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger)
 {
     userToConnect.ArchiveDatabase = (ADObjectId)database.Identity;
     userToConnect.ArchiveGuid     = deletedMailboxGuid;
     userToConnect.ArchiveName     = new MultiValuedProperty <string>(Strings.ArchiveNamePrefix + userToConnect.DisplayName);
     if (MailboxTaskHelper.SupportsMailboxReleaseVersioning(userToConnect))
     {
         userToConnect.ArchiveRelease = databaseLocationInfo.MailboxRelease;
     }
     userToConnect.ArchiveQuota        = ProvisioningHelper.DefaultArchiveQuota;
     userToConnect.ArchiveWarningQuota = ProvisioningHelper.DefaultArchiveWarningQuota;
     MailboxTaskHelper.ApplyDefaultArchivePolicy(userToConnect, configSession);
     recipientSession.Save(userToConnect);
     verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
     ConnectMailbox.UpdateSDAndRefreshMailbox(mapiAdministrationSession, userToConnect, database, deletedMailboxGuid, parameterSetName, verboseLogger, warningLogger);
 }
Beispiel #4
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);
     }
 }
Beispiel #5
0
 internal static void ConnectMailboxCore(ADUser userToConnect, Guid deletedMailboxGuid, StoreMailboxType mailboxType, string deletedMailboxLegacyDN, string parameterSetName, bool clearPropertiesBeforeConnecting, IRecipientSession recipientSession, MapiAdministrationSession mapiAdministrationSession, string alias, SecurityIdentifier linkedUserSid, DatabaseLocationInfo databaseLocationInfo, MailboxDatabase database, ADObjectId elcPolicyId, ADObjectId retentionPolicyId, ADObjectId mobilePolicyId, ADObjectId addressBookPolicyId, Task.TaskVerboseLoggingDelegate verboseLogger, Task.TaskWarningLoggingDelegate warningLogger, ADObjectId roleAssignmentPolicyId, Task task)
 {
     if (userToConnect.ExchangeVersion.IsOlderThan(ExchangeObjectVersion.Exchange2012))
     {
         verboseLogger(Strings.VerboseUpdatingVersion(userToConnect.Identity.ToString(), userToConnect.ExchangeVersion.ToString(), ExchangeObjectVersion.Exchange2012.ToString()));
         userToConnect.SetExchangeVersion(ExchangeObjectVersion.Exchange2012);
         recipientSession.Save(userToConnect);
         verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
         bool useGlobalCatalog = recipientSession.UseGlobalCatalog;
         try
         {
             recipientSession.UseGlobalCatalog = false;
             userToConnect = (ADUser)recipientSession.Read(userToConnect.Id);
         }
         finally
         {
             recipientSession.UseGlobalCatalog = useGlobalCatalog;
         }
     }
     if (clearPropertiesBeforeConnecting)
     {
         List <PropertyDefinition> list = new List <PropertyDefinition>(RecipientConstants.DisableMailbox_PropertiesToReset);
         MailboxTaskHelper.RemovePersistentProperties(list);
         list.Remove(ADObjectSchema.ExchangeVersion);
         MailboxTaskHelper.ClearExchangeProperties(userToConnect, list);
     }
     userToConnect.Alias = alias;
     if ("Linked" == parameterSetName)
     {
         userToConnect.MasterAccountSid = linkedUserSid;
     }
     else if ("Shared" == parameterSetName)
     {
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     else if ("Room" == parameterSetName)
     {
         userToConnect.ResourceType     = new ExchangeResourceType?(ExchangeResourceType.Room);
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     else if ("Equipment" == parameterSetName)
     {
         userToConnect.ResourceType     = new ExchangeResourceType?(ExchangeResourceType.Equipment);
         userToConnect.MasterAccountSid = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
     }
     userToConnect.ServerLegacyDN             = databaseLocationInfo.ServerLegacyDN;
     userToConnect.ExchangeGuid               = deletedMailboxGuid;
     userToConnect.Database                   = (ADObjectId)database.Identity;
     userToConnect.LegacyExchangeDN           = deletedMailboxLegacyDN.ToLowerInvariant();
     userToConnect.ManagedFolderMailboxPolicy = elcPolicyId;
     userToConnect.RetentionPolicy            = retentionPolicyId;
     userToConnect.ActiveSyncMailboxPolicy    = mobilePolicyId;
     userToConnect.UseDatabaseQuotaDefaults   = new bool?(true);
     userToConnect.AddressBookPolicy          = addressBookPolicyId;
     if (roleAssignmentPolicyId != null)
     {
         userToConnect.RoleAssignmentPolicy = roleAssignmentPolicyId;
     }
     if (mailboxType == StoreMailboxType.PublicFolderPrimary || mailboxType == StoreMailboxType.PublicFolderSecondary)
     {
         userToConnect.MasterAccountSid            = new SecurityIdentifier(WellKnownSidType.SelfSid, null);
         userToConnect.UserAccountControl          = (UserAccountControlFlags.AccountDisabled | UserAccountControlFlags.NormalAccount);
         userToConnect.ExchangeUserAccountControl |= UserAccountControlFlags.AccountDisabled;
         MailboxTaskHelper.StampMailboxRecipientTypes(userToConnect, "PublicFolder");
     }
     else
     {
         MailboxTaskHelper.StampMailboxRecipientTypes(userToConnect, parameterSetName);
     }
     if (MailboxTaskHelper.SupportsMailboxReleaseVersioning(userToConnect))
     {
         userToConnect.MailboxRelease = databaseLocationInfo.MailboxRelease;
     }
     userToConnect.EmailAddressPolicyEnabled = true;
     ProvisioningLayer.UpdateAffectedIConfigurable(task, RecipientTaskHelper.ConvertRecipientToPresentationObject(userToConnect), false);
     recipientSession.Save(userToConnect);
     verboseLogger(Strings.VerboseADOperationSucceeded(userToConnect.Identity.ToString()));
     ConnectMailbox.UpdateSDAndRefreshMailbox(mapiAdministrationSession, userToConnect, database, deletedMailboxGuid, parameterSetName, verboseLogger, warningLogger);
 }
Beispiel #6
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter(new object[]
     {
         this.DataObject
     });
     if (base.ParameterSetName == "ValidateOnly" || this.needListMatchingUser)
     {
         base.WriteObject(this.matchedUsers, true);
     }
     else if (this.Archive)
     {
         if (!this.Force && this.User == null && !base.ShouldContinue(Strings.ComfirmConnectToMatchingUser(this.userToConnect.Identity.ToString(), this.userToConnect.Alias)))
         {
             TaskLogger.LogExit();
             return;
         }
         ConnectMailbox.ConnectArchiveCore(this.userToConnect, this.DataObject.MailboxGuid, base.ParameterSetName, this.RecipientSession, this.TenantConfigurationSession, (MapiAdministrationSession)base.DataSession, this.alias, this.linkedUserSid, this.databaseLocationInfo, this.OwnerMailboxDatabase, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning));
     }
     else
     {
         Organization orgContainer = this.TenantConfigurationSession.GetOrgContainer();
         if (this.DataObject.MailboxType != StoreMailboxType.Private)
         {
             if (orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid == Guid.Empty)
             {
                 if (this.DataObject.MailboxType == StoreMailboxType.PublicFolderSecondary)
                 {
                     this.WriteWarning(Strings.WarningPromotingSecondaryToPrimary);
                 }
             }
             else if (this.DataObject.MailboxType == StoreMailboxType.PublicFolderPrimary)
             {
                 this.WriteWarning(Strings.WarningConnectingPrimaryAsSecondary);
             }
         }
         if (!this.Force && this.User == null && !base.ShouldContinue(Strings.ComfirmConnectToMatchingUser(this.userToConnect.Identity.ToString(), this.alias)))
         {
             TaskLogger.LogExit();
             return;
         }
         if (this.elcPolicyId != null && !this.Force && !this.ManagedFolderMailboxPolicyAllowed.IsPresent && !base.ShouldContinue(Strings.ConfirmManagedFolderMailboxPolicyAllowed(this.userToConnect.Identity.ToString())))
         {
             TaskLogger.LogExit();
             return;
         }
         if (!base.IsProvisioningLayerAvailable)
         {
             base.WriteError(new InvalidOperationException(Strings.ErrorNoProvisioningHandlerAvailable), ErrorCategory.InvalidOperation, null);
         }
         ADObjectId           roleAssignmentPolicyId = null;
         RoleAssignmentPolicy roleAssignmentPolicy   = RecipientTaskHelper.FindDefaultRoleAssignmentPolicy(this.TenantConfigurationSession, new Task.ErrorLoggerDelegate(base.WriteError), Strings.ErrorDefaultRoleAssignmentPolicyNotUnique, Strings.ErrorDefaultRoleAssignmentPolicyNotFound);
         if (roleAssignmentPolicy != null)
         {
             roleAssignmentPolicyId = (ADObjectId)roleAssignmentPolicy.Identity;
         }
         ConnectMailbox.ConnectMailboxCore(this.userToConnect, this.DataObject.MailboxGuid, this.DataObject.MailboxType, this.DataObject.LegacyDN, base.ParameterSetName, true, this.RecipientSession, (MapiAdministrationSession)base.DataSession, this.alias, this.linkedUserSid, this.databaseLocationInfo, this.OwnerMailboxDatabase, this.elcPolicyId, this.retentionPolicyId, this.mobilePolicyId, this.addressBookPolicyId, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning), roleAssignmentPolicyId, this);
         if (this.DataObject.MailboxType != StoreMailboxType.Private && orgContainer.DefaultPublicFolderMailbox.HierarchyMailboxGuid == Guid.Empty)
         {
             orgContainer.DefaultPublicFolderMailbox = orgContainer.DefaultPublicFolderMailbox.Clone();
             orgContainer.DefaultPublicFolderMailbox.SetHierarchyMailbox(this.DataObject.MailboxGuid, PublicFolderInformation.HierarchyType.MailboxGuid);
             this.TenantConfigurationSession.Save(orgContainer);
             MailboxTaskHelper.PrepopulateCacheForMailbox(this.OwnerMailboxDatabase, this.databaseLocationInfo.ServerFqdn, this.userToConnect.OrganizationId, this.DataObject.LegacyDN, this.DataObject.MailboxGuid, this.TenantConfigurationSession.LastUsedDc, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
         }
     }
     TaskLogger.LogExit();
 }
Beispiel #7
0
        protected override void InternalValidate()
        {
            TaskLogger.LogEnter();
            base.InternalValidate();
            if ("Linked" == base.ParameterSetName)
            {
                try
                {
                    NetworkCredential userForestCredential = (this.LinkedCredential == null) ? null : this.LinkedCredential.GetNetworkCredential();
                    this.linkedUserSid = MailboxTaskHelper.GetAccountSidFromAnotherForest(this.LinkedMasterAccount, this.LinkedDomainController, userForestCredential, this.ResourceForestSession, new MailboxTaskHelper.GetUniqueObject(base.GetDataObject <ADUser>), new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
                }
                catch (PSArgumentException exception)
                {
                    base.ThrowTerminatingError(exception, ErrorCategory.InvalidArgument, this.LinkedCredential);
                }
            }
            if (this.ManagedFolderMailboxPolicy != null)
            {
                ManagedFolderMailboxPolicy managedFolderMailboxPolicy = (ManagedFolderMailboxPolicy)base.GetDataObject <ManagedFolderMailboxPolicy>(this.ManagedFolderMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotFound(this.ManagedFolderMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorManagedFolderMailboxPolicyNotUnique(this.ManagedFolderMailboxPolicy.ToString())));
                this.elcPolicyId = (ADObjectId)managedFolderMailboxPolicy.Identity;
            }
            if (this.RetentionPolicy != null)
            {
                if (SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
                {
                    base.WriteError(new LocalizedException(Strings.ErrorLinkOpOnDehydratedTenant("RetentionPolicy")), ExchangeErrorCategory.Client, null);
                }
                RetentionPolicy retentionPolicy = (RetentionPolicy)base.GetDataObject <RetentionPolicy>(this.RetentionPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorRetentionPolicyNotFound(this.RetentionPolicy.ToString())), new LocalizedString?(Strings.ErrorRetentionPolicyNotUnique(this.RetentionPolicy.ToString())));
                this.retentionPolicyId = retentionPolicy.Id;
            }
            if (this.ActiveSyncMailboxPolicy != null)
            {
                MobileMailboxPolicy mobileMailboxPolicy = (MobileMailboxPolicy)base.GetDataObject <MobileMailboxPolicy>(this.ActiveSyncMailboxPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotFound(this.ActiveSyncMailboxPolicy.ToString())), new LocalizedString?(Strings.ErrorMobileMailboxPolicyNotUnique(this.ActiveSyncMailboxPolicy.ToString())));
                this.mobilePolicyId = (ADObjectId)mobileMailboxPolicy.Identity;
            }
            if (this.AddressBookPolicy != null)
            {
                AddressBookMailboxPolicy addressBookMailboxPolicy = (AddressBookMailboxPolicy)base.GetDataObject <AddressBookMailboxPolicy>(this.AddressBookPolicy, this.TenantConfigurationSession, null, new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotFound(this.AddressBookPolicy.ToString())), new LocalizedString?(Strings.ErrorAddressBookMailboxPolicyNotUnique(this.AddressBookPolicy.ToString())), ExchangeErrorCategory.Client);
                this.addressBookPolicyId = (ADObjectId)addressBookMailboxPolicy.Identity;
            }
            MailboxTaskHelper.ValidateMailboxIsDisconnected(this.GlobalCatalogSession, this.DataObject.MailboxGuid, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.ErrorLoggerDelegate(base.WriteError));
            if (!this.Archive)
            {
                ConnectMailbox.CheckLegacyDNNotInUse(this.DataObject.Identity, this.DataObject.LegacyDN, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError));
            }
            if (this.User != null)
            {
                this.userToConnect = (ADUser)base.GetDataObject <ADUser>(this.User, this.RecipientSession, null, new LocalizedString?(Strings.ErrorRecipientNotFound(this.User.ToString())), new LocalizedString?(Strings.ErrorRecipientNotUnique(this.User.ToString())));
                if (this.Archive)
                {
                    ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                }
                else if (RecipientType.User != this.userToConnect.RecipientType)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorNoMatchedUserTypeFound(RecipientType.User.ToString(), this.User.ToString(), this.userToConnect.RecipientType.ToString())), ErrorCategory.InvalidArgument, this.User);
                }
            }
            else if (!this.Archive)
            {
                if ("ValidateOnly" == base.ParameterSetName)
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, null);
                }
                else
                {
                    this.matchedUsers = this.FindMatchedUser(this.DataObject, new bool?("User" == base.ParameterSetName));
                }
                if ("ValidateOnly" != base.ParameterSetName)
                {
                    if (this.matchedUsers.Length == 0)
                    {
                        base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                    }
                    else if (this.matchedUsers.Length > 1)
                    {
                        this.WriteWarning(Strings.ErrorMultipleMatchedUser(this.Identity.ToString()));
                        this.needListMatchingUser = true;
                    }
                    else
                    {
                        this.userToConnect = (ADUser)this.matchedUsers[0];
                        this.userToConnect = (ADUser)this.RecipientSession.Read(this.userToConnect.Id);
                        if (this.userToConnect == null)
                        {
                            base.WriteError(new MdbAdminTaskException(Strings.ErrorNoMatchedUserFound), ErrorCategory.InvalidArgument, this.Identity);
                        }
                        if (this.Archive)
                        {
                            ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
                        }
                    }
                }
            }
            else
            {
                this.userToConnect = this.FindArchiveUser(this.DataObject, this.RecipientSession, new Task.TaskErrorLoggingDelegate(base.WriteError));
                ConnectMailbox.CheckUserForArchive(this.DataObject, this.GlobalCatalogSession, new Task.ErrorLoggerDelegate(base.WriteError), this.userToConnect, this.OwnerMailboxDatabase, this.AllowLegacyDNMismatch);
            }
            if (this.userToConnect != null && !this.Archive)
            {
                if ("User" == base.ParameterSetName)
                {
                    if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) != UserAccountControlFlags.None && this.DataObject.MailboxType == StoreMailboxType.Private)
                    {
                        base.WriteError(new RecipientTaskException(Strings.ErrorAccountDisabledForUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                    }
                }
                else if ((this.userToConnect.UserAccountControl & UserAccountControlFlags.AccountDisabled) == UserAccountControlFlags.None)
                {
                    base.WriteError(new RecipientTaskException(Strings.ErrorAccountEnabledForNonUserMailbox), ErrorCategory.InvalidArgument, this.userToConnect);
                }
                if (!string.IsNullOrEmpty(this.Alias))
                {
                    this.alias = this.Alias;
                }
                else
                {
                    this.alias = RecipientTaskHelper.GenerateUniqueAlias(this.globalCatalogSession, this.userToConnect.OrganizationId, this.userToConnect.Name, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose));
                }
            }
            if (this.Archive && this.userToConnect.ManagedFolderMailboxPolicy != null)
            {
                base.WriteError(new MdbAdminTaskException(Strings.ErrorNoArchiveWithManagedFolder(this.userToConnect.Name)), ErrorCategory.InvalidData, this.Identity);
            }
            if (this.DataObject.IsArchiveMailbox != null && this.Archive != this.DataObject.IsArchiveMailbox.Value)
            {
                if (this.Archive)
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotArchive(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
                else
                {
                    base.WriteError(new MdbAdminTaskException(Strings.ErrorDisconnectedMailboxNotPrimary(this.Identity.ToString(), this.userToConnect.Name)), ErrorCategory.InvalidArgument, this.Identity);
                }
            }
            ADSessionSettings sessionSettings = ADSessionSettings.FromCustomScopeSet(base.ScopeSet, ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);

            MapiTaskHelper.VerifyDatabaseIsWithinScope(sessionSettings, this.OwnerMailboxDatabase, new Task.ErrorLoggerDelegate(base.WriteError));
            TaskLogger.LogExit();
        }