Exemple #1
0
 private void ValidateLinkedMasterAccount()
 {
     if (string.IsNullOrEmpty(this.LinkedDomainController))
     {
         base.WriteError(new RecipientTaskException(Strings.ErrorMissLinkedDomainController), ErrorCategory.InvalidArgument, this.Identity);
     }
     try
     {
         NetworkCredential userForestCredential = (this.LinkedCredential == null) ? null : this.LinkedCredential.GetNetworkCredential();
         this.linkedUserSid = MailboxTaskHelper.GetAccountSidFromAnotherForest(this.LinkedMasterAccount, this.LinkedDomainController, userForestCredential, base.GlobalConfigSession, new MailboxTaskHelper.GetUniqueObject(base.GetDataObject <ADUser>), new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
     }
     catch (PSArgumentException exception)
     {
         base.ThrowTerminatingError(exception, ErrorCategory.InvalidArgument, this.LinkedCredential);
     }
 }
Exemple #2
0
		protected override void InternalBeginProcessing()
		{
			TaskLogger.LogEnter();
			if (this.RemoveManagedFolderAndPolicy)
			{
				this.RetentionPolicy = null;
			}
			base.InternalBeginProcessing();
			base.CheckExclusiveParameters(new object[]
			{
				ADRecipientSchema.MailboxPlan,
				"SKUCapability"
			});
			Mailbox mailbox = (Mailbox)this.GetDynamicParameters();
			this.needChangeMailboxSubtype = base.Fields.IsModified("Type");
			if (this.needChangeMailboxSubtype)
			{
				if (ConvertibleMailboxSubType.Equipment != this.Type && ConvertibleMailboxSubType.Room != this.Type && (mailbox.ResourceCustom.Changed || mailbox.ResourceCapacity != null))
				{
					base.ThrowTerminatingError(new TaskArgumentException(Strings.ErrorCannotChangeResourceProperties, null), ExchangeErrorCategory.Client, null);
				}
				if (base.Fields.IsModified("LinkedCredential") || base.Fields.IsModified("LinkedDomainController") || base.Fields.IsModified(MailboxSchema.LinkedMasterAccount))
				{
					base.ThrowTerminatingError(new TaskArgumentException(Strings.ErrorCannotChangeLinkedProperty, null), ExchangeErrorCategory.Client, null);
				}
			}
			if (mailbox.IsModified(MailboxSchema.UseDatabaseRetentionDefaults) && mailbox.IsModified(MailboxSchema.RetainDeletedItemsUntilBackup) && mailbox.UseDatabaseRetentionDefaults && mailbox.RetainDeletedItemsUntilBackup)
			{
				base.ThrowTerminatingError(new RecipientTaskException(Strings.ErrorOnlyOneParameterMayBeUsed), ExchangeErrorCategory.Client, this);
			}
			if (mailbox.IsModified(MailboxSchema.AuditOwner))
			{
				MultiValuedProperty<MailboxAuditOperations> auditOwner = mailbox.AuditOwner;
				foreach (MailboxAuditOperations mailboxAuditOperations in auditOwner)
				{
					if ((mailboxAuditOperations & SetMailboxBase<TIdentity, TPublicObject>.UnsupportedOwnerOperations) != MailboxAuditOperations.None)
					{
						base.ThrowTerminatingError(new RecipientTaskException(Strings.ErrorInvalidAuditOwnerOperationType), ExchangeErrorCategory.Client, this);
					}
				}
			}
			if (mailbox.IsModified(MailboxSchema.AuditDelegate))
			{
				MultiValuedProperty<MailboxAuditOperations> auditDelegate = mailbox.AuditDelegate;
				foreach (MailboxAuditOperations mailboxAuditOperations2 in auditDelegate)
				{
					if ((mailboxAuditOperations2 & SetMailboxBase<TIdentity, TPublicObject>.UnsupportedDelegateOperations) != MailboxAuditOperations.None)
					{
						base.ThrowTerminatingError(new RecipientTaskException(Strings.ErrorInvalidAuditDelegateOperationType), ExchangeErrorCategory.Client, this);
					}
				}
			}
			if (mailbox.IsModified(MailboxSchema.AuditAdmin))
			{
				MultiValuedProperty<MailboxAuditOperations> auditAdmin = mailbox.AuditAdmin;
				foreach (MailboxAuditOperations mailboxAuditOperations3 in auditAdmin)
				{
					if ((mailboxAuditOperations3 & SetMailboxBase<TIdentity, TPublicObject>.UnsupportedAdminOperations) != MailboxAuditOperations.None)
					{
						base.ThrowTerminatingError(new RecipientTaskException(Strings.ErrorInvalidAuditAdminOperationType), ExchangeErrorCategory.Client, this);
					}
				}
			}
			if (this.LinkedMasterAccount != null)
			{
				if (string.IsNullOrEmpty(this.LinkedDomainController))
				{
					base.ThrowTerminatingError(new TaskArgumentException(Strings.ErrorMissLinkedDomainController), ExchangeErrorCategory.Client, this);
				}
				try
				{
					NetworkCredential userForestCredential = (this.LinkedCredential == null) ? null : this.LinkedCredential.GetNetworkCredential();
					mailbox[ADRecipientSchema.MasterAccountSid] = MailboxTaskHelper.GetAccountSidFromAnotherForest(this.LinkedMasterAccount, this.LinkedDomainController, userForestCredential, base.GlobalConfigSession, new MailboxTaskHelper.GetUniqueObject(base.GetDataObject<ADUser>), new Task.ErrorLoggerDelegate(base.ThrowTerminatingError));
				}
				catch (PSArgumentException exception)
				{
					base.ThrowNonLocalizedTerminatingError(exception, ExchangeErrorCategory.Client, this.LinkedCredential);
				}
			}
			TaskLogger.LogExit();
		}
Exemple #3
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();
        }