Example #1
0
        private bool IsRemoteWipePending()
        {
            bool result;

            try
            {
                this.OpenMailboxSession();
                DeviceInfo deviceInfo = MobileDeviceTaskHelper.GetDeviceInfo(this.mailboxSession, this.Identity);
                if (deviceInfo == null)
                {
                    result = false;
                }
                else
                {
                    result = ((deviceInfo.WipeRequestTime != null || deviceInfo.WipeSentTime != null) && deviceInfo.WipeAckTime == null);
                }
            }
            catch
            {
                if (this.mailboxSession != null)
                {
                    this.mailboxSession.Dispose();
                    this.mailboxSession = null;
                }
                throw;
            }
            return(result);
        }
        private void GetExchangePrincipal(IRecipientSession recipientSession)
        {
            Exception ex = null;

            if (this.Mailbox != null)
            {
                this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, this.Mailbox, "Get-MobileDeviceStatistics", out ex);
            }
            else if (this.Identity != null)
            {
                TIdentity          identity  = this.Identity;
                MailboxIdParameter mailboxId = identity.GetMailboxId();
                if (mailboxId == null && this.DataObject != null)
                {
                    this.Identity = (TIdentity)((object)this.CreateIdentityObject());
                    TIdentity identity2 = this.Identity;
                    mailboxId = identity2.GetMailboxId();
                }
                if (mailboxId == null)
                {
                    TIdentity identity3 = this.Identity;
                    base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(identity3.ToString())), ErrorCategory.InvalidArgument, null);
                }
                this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, mailboxId, base.CommandRuntime.ToString(), out ex);
            }
            if (ex != null)
            {
                base.WriteError(ex, ErrorCategory.InvalidArgument, null);
            }
        }
Example #3
0
        protected override IConfigDataProvider CreateSession()
        {
            IConfigurationSession configurationSession;

            if (!MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                configurationSession = (IConfigurationSession)base.CreateSession();
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 133, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\AirSync\\RemoveMobileDevice.cs");
            }
            configurationSession.UseConfigNC      = false;
            configurationSession.UseGlobalCatalog = (base.DomainController == null && base.ServerSettings.ViewEntireForest);
            return(configurationSession);
        }
        protected override IConfigDataProvider CreateSession()
        {
            IConfigurationSession configurationSession;

            if (!this.IgnoreDehydratedFlag && SharedConfiguration.IsDehydratedConfiguration(base.CurrentOrganizationId))
            {
                configurationSession = SharedConfiguration.CreateScopedToSharedConfigADSession(base.CurrentOrganizationId);
                return(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, configurationSession.SessionSettings, 527, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxPolicies\\RetentionPolicyTasks.cs"));
            }
            if (!MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                configurationSession = (IConfigurationSession)base.CreateSession();
            }
            else
            {
                ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(base.RootOrgContainerId, base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true);
                configurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(base.DomainController, false, ConsistencyMode.PartiallyConsistent, sessionSettings, 546, "CreateSession", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\MailboxPolicies\\RetentionPolicyTasks.cs");
            }
            return(configurationSession);
        }
Example #5
0
        protected override void InternalValidate()
        {
            MailboxIdParameter mailboxIdParameter = null;

            try
            {
                base.InternalValidate();
            }
            catch (ManagementObjectNotFoundException)
            {
                if (this.Identity == null || !this.TryGetMailboxIdFromIdentity(this.Identity.ToString(), out mailboxIdParameter))
                {
                    throw;
                }
                this.deviceExistsinAD = false;
            }
            if (base.HasErrors)
            {
                return;
            }
            if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
            {
                ADObjectId adobjectId;
                if (!base.TryGetExecutingUserId(out adobjectId))
                {
                    throw new ExecutingUserPropertyNotFoundException("executingUserid");
                }
                if (!base.DataObject.Id.Parent.Parent.Equals(adobjectId) || (mailboxIdParameter != null && !mailboxIdParameter.Equals(adobjectId)))
                {
                    base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
                }
            }
            Exception ex = null;

            if (mailboxIdParameter == null)
            {
                mailboxIdParameter = this.Identity.GetMailboxId();
            }
            if (mailboxIdParameter == null && base.DataObject != null)
            {
                this.Identity      = new MobileDeviceIdParameter(base.DataObject);
                mailboxIdParameter = this.Identity.GetMailboxId();
            }
            if (mailboxIdParameter == null)
            {
                base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
            }
            this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, this.CreateTenantGlobalCatalogSession(base.SessionSettings), mailboxIdParameter, "Remove-MobileDevice", out ex);
            if (ex != null)
            {
                base.WriteError(ex, ErrorCategory.InvalidArgument, null);
            }
            if (DeviceInfo.IsThrottlingLimitsExceeded((IConfigurationSession)base.DataSession, this.principal, out this.activeSyncDevices))
            {
                uint maxDeviceDeleteCount = 0U;
                using (IBudget budget = StandardBudget.Acquire(this.principal.Sid, BudgetType.Eas, this.principal.MailboxInfo.OrganizationId.ToADSessionSettings()))
                {
                    IThrottlingPolicy throttlingPolicy = budget.ThrottlingPolicy;
                    maxDeviceDeleteCount = throttlingPolicy.EasMaxDeviceDeletesPerMonth.Value;
                }
                base.WriteError(new LocalizedException(Strings.MaxDeviceDeletesPerMonthReached(this.activeSyncDevices.ObjectsDeletedThisPeriod, maxDeviceDeleteCount)), ErrorCategory.WriteError, null);
            }
        }
Example #6
0
        internal static List <string> ValidateAddresses(IRecipientSession recipientSession, ADObjectId executingUserId, MultiValuedProperty <string> notificationEmailAddresses, out IList <LocalizedString> localizedWarnings)
        {
            if (recipientSession == null)
            {
                throw new ArgumentNullException("recipientSession");
            }
            List <string> list = new List <string>(((notificationEmailAddresses != null) ? notificationEmailAddresses.Count : 0) + 1);

            localizedWarnings = new List <LocalizedString>(list.Count);
            if (executingUserId != null)
            {
                ADRecipient adrecipient = recipientSession.Read(executingUserId);
                if (adrecipient == null || !MobileDeviceTaskHelper.IsUserMailboxEnabled(adrecipient))
                {
                    localizedWarnings.Add(Strings.LogonUserIsNotAValidADRecipient(executingUserId.ToString()));
                }
                else
                {
                    list.Add(adrecipient.PrimarySmtpAddress.ToString());
                }
            }
            if (notificationEmailAddresses != null)
            {
                foreach (string text in notificationEmailAddresses)
                {
                    if (!SmtpAddress.IsValidSmtpAddress(text))
                    {
                        ADRecipient[] array = recipientSession.FindByANR(text, 2, null);
                        if (array == null || array.Length != 1 || !MobileDeviceTaskHelper.IsUserMailboxEnabled(array[0]))
                        {
                            localizedWarnings.Add(Strings.InvalidSmtpAddressOrAlias(text));
                        }
                        else
                        {
                            list.Add(array[0].PrimarySmtpAddress.ToString());
                        }
                    }
                    else
                    {
                        IRecipientSession recipientSession2 = recipientSession;
                        if (GlobalSettings.IsMultiTenancyEnabled)
                        {
                            try
                            {
                                ADSessionSettings sessionSettings = ADSessionSettings.FromTenantAcceptedDomain(SmtpAddress.Parse(text).Domain);
                                recipientSession2 = DirectorySessionFactory.Default.CreateTenantRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 240, "ValidateAddresses", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\AirSync\\MobileDeviceTaskHelper.cs");
                            }
                            catch (CannotResolveTenantNameException)
                            {
                                localizedWarnings.Add(Strings.InvalidSmtpAddressOrAlias(text));
                                recipientSession2 = null;
                            }
                        }
                        if (recipientSession2 != null)
                        {
                            ADRecipient adrecipient2 = recipientSession2.FindByProxyAddress(ProxyAddress.Parse(text));
                            if (adrecipient2 == null)
                            {
                                localizedWarnings.Add(Strings.InvalidSmtpAddressOrAlias(text));
                            }
                            else
                            {
                                list.Add(adrecipient2.PrimarySmtpAddress.ToString());
                            }
                        }
                    }
                }
            }
            return(list);
        }
Example #7
0
        internal static ExchangePrincipal GetExchangePrincipal(ADSessionSettings sessionSettings, IRecipientSession recipientSession, MailboxIdParameter mailbox, string cmdletName, out Exception localizedError)
        {
            ADUser aduser = null;

            return(MobileDeviceTaskHelper.GetExchangePrincipal(sessionSettings, recipientSession, mailbox, cmdletName, out localizedError, out aduser));
        }
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         if (base.ParameterSetName == "Identity")
         {
             base.InternalValidate();
             if (base.HasErrors)
             {
                 return;
             }
             if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
             {
                 ADObjectId id;
                 if (!base.TryGetExecutingUserId(out id))
                 {
                     throw new ExecutingUserPropertyNotFoundException("executingUserid");
                 }
                 TDataObject dataObject = this.DataObject;
                 if (!dataObject.Id.Parent.Parent.Equals(id))
                 {
                     TIdentity identity = this.Identity;
                     base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(identity.ToString())), ErrorCategory.InvalidArgument, null);
                 }
             }
         }
         IRecipientSession recipientSession = this.CreateTenantGlobalCatalogSession(base.SessionSettings);
         this.GetExchangePrincipal(recipientSession);
         if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
         {
             ADObjectId id2;
             if (!base.TryGetExecutingUserId(out id2))
             {
                 throw new ExecutingUserPropertyNotFoundException("executingUserid");
             }
             if (!this.principal.ObjectId.Equals(id2))
             {
                 base.WriteError(new RecipientNotFoundException(this.Mailbox.ToString()), ErrorCategory.InvalidArgument, null);
             }
         }
         if (this.GetMailboxLog)
         {
             IList <LocalizedString> list = null;
             ADObjectId executingUserId   = null;
             base.TryGetExecutingUserId(out executingUserId);
             this.validatedAddresses = MobileDeviceTaskHelper.ValidateAddresses(recipientSession, executingUserId, this.NotificationEmailAddresses, out list);
             if (list != null)
             {
                 foreach (LocalizedString text in list)
                 {
                     this.WriteWarning(text);
                 }
             }
         }
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
 protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         base.InternalValidate();
         if (!base.HasErrors)
         {
             if (MobileDeviceTaskHelper.IsRunningUnderMyOptionsRole(this, base.TenantGlobalCatalogSession, base.SessionSettings))
             {
                 ADObjectId id;
                 if (!base.TryGetExecutingUserId(out id))
                 {
                     throw new ExecutingUserPropertyNotFoundException("executingUserid");
                 }
                 if (!this.DataObject.Id.Parent.Parent.Equals(id))
                 {
                     base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
                 }
             }
             IRecipientSession  recipientSession = this.CreateTenantGlobalCatalogSession(base.SessionSettings);
             Exception          ex        = null;
             MailboxIdParameter mailboxId = this.Identity.GetMailboxId();
             if (mailboxId == null && this.DataObject != null)
             {
                 this.Identity = new MobileDeviceIdParameter(this.DataObject);
                 mailboxId     = this.Identity.GetMailboxId();
             }
             if (mailboxId == null)
             {
                 base.WriteError(new LocalizedException(Strings.ErrorObjectNotFound(this.Identity.ToString())), ErrorCategory.InvalidArgument, null);
             }
             ADUser adObject = null;
             this.principal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, mailboxId, "Clear-MobileDevice", out ex, out adObject);
             if (ex != null)
             {
                 base.WriteError(ex, ErrorCategory.InvalidArgument, null);
             }
             IList <LocalizedString> list = null;
             ADObjectId adobjectId        = null;
             base.TryGetExecutingUserId(out adobjectId);
             this.validatedAddresses = MobileDeviceTaskHelper.ValidateAddresses(recipientSession, adobjectId, this.NotificationEmailAddresses, out list);
             if (list != null)
             {
                 foreach (LocalizedString text in list)
                 {
                     this.WriteWarning(text);
                 }
             }
             base.VerifyIsWithinScopes((IDirectorySession)base.DataSession, adObject, true, new DataAccessTask <MobileDevice> .ADObjectOutOfScopeString(Strings.ErrorCannotChangeMailboxOutOfWriteScope));
             if (adobjectId != null)
             {
                 ExchangePrincipal exchangePrincipal = MobileDeviceTaskHelper.GetExchangePrincipal(base.SessionSettings, recipientSession, new MailboxIdParameter(adobjectId), "Clear-MobileDevice", out ex);
                 if (ex != null)
                 {
                     base.WriteWarning(ex.ToString());
                 }
                 if (exchangePrincipal != null)
                 {
                     this.wipeRequestorSMTP = exchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString();
                 }
                 else
                 {
                     this.wipeRequestorSMTP = null;
                 }
             }
         }
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            MailboxSession mailboxSession = null;

            try
            {
                mailboxSession = MailboxSession.OpenAsAdmin(this.principal, CultureInfo.InvariantCulture, "Client=Management;Action=Get-ActiveSyncDeviceStatistics");
                DeviceInfo deviceInfo = MobileDeviceTaskHelper.GetDeviceInfo(mailboxSession, this.Identity);
                if (deviceInfo == null)
                {
                    base.WriteError(new MobileDeviceNotExistException(this.Identity.ToString()), ErrorCategory.InvalidOperation, this.Identity);
                }
                using (SyncStateStorage syncStateStorage = SyncStateStorage.Bind(mailboxSession, deviceInfo.DeviceIdentity, null))
                {
                    if (syncStateStorage == null)
                    {
                        base.WriteError(new MobileDeviceNotExistException(this.Identity.ToString()), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    using (CustomSyncState orCreateGlobalSyncState = AirSyncUtility.GetOrCreateGlobalSyncState(syncStateStorage))
                    {
                        if (this.Cancel)
                        {
                            if (!DeviceInfo.CancelRemoteWipeFromMailbox(orCreateGlobalSyncState))
                            {
                                this.WriteWarning(Strings.CannotCancelWipe(this.Identity.ToString()));
                            }
                        }
                        else
                        {
                            DeviceInfo.StartRemoteWipeFromMailbox(syncStateStorage, orCreateGlobalSyncState, ExDateTime.UtcNow, this.validatedAddresses, this.wipeRequestorSMTP);
                        }
                        orCreateGlobalSyncState.Commit();
                    }
                }
                base.InternalProcessRecord();
            }
            catch (FolderSaveException exception)
            {
                base.WriteError(exception, ErrorCategory.WriteError, this.Identity);
            }
            catch (CorruptSyncStateException ex)
            {
                TaskLogger.LogError(ex);
                base.WriteError(ex, ErrorCategory.ReadError, this.principal);
            }
            catch (InvalidSyncStateVersionException ex2)
            {
                TaskLogger.LogError(ex2);
                base.WriteError(ex2, ErrorCategory.ReadError, this.principal);
            }
            catch (StorageTransientException ex3)
            {
                TaskLogger.LogError(ex3);
                base.WriteError(ex3, ErrorCategory.ReadError, this.principal);
            }
            catch (StoragePermanentException ex4)
            {
                TaskLogger.LogError(ex4);
                base.WriteError(ex4, ErrorCategory.InvalidOperation, this.principal);
            }
            catch (InvalidOperationException ex5)
            {
                TaskLogger.LogError(ex5);
                base.WriteError(ex5, ErrorCategory.InvalidOperation, this.principal);
            }
            finally
            {
                if (mailboxSession != null)
                {
                    mailboxSession.Dispose();
                }
                TaskLogger.LogExit();
            }
        }