// Token: 0x06000558 RID: 1368 RVA: 0x0001F11C File Offset: 0x0001D31C public void RecordNewUserAgent(string newUserAgent) { EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.UserAgentsChanges).BehaviorTypeIncidenceDuration; lock (this.instanceLock) { if (newUserAgent != null && !this.userAgentStrings.Contains(newUserAgent)) { ExDateTime utcNow = ExDateTime.UtcNow; ExDateTime windowStartTime = utcNow - behaviorTypeIncidenceDuration; DeviceBehavior.ClearOldRecords(windowStartTime, this.userAgentTimes, this.userAgentStrings); this.userAgentTimes.Add(utcNow); this.userAgentStrings.Add(newUserAgent); this.SaveDeviceBehavior(false); int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.UserAgentsChanges).BehaviorTypeIncidenceLimit; if (behaviorTypeIncidenceLimit > 0 && this.userAgentTimes.Count > behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.UserAgentsChanges); } else if (utcNow > this.blockTime && utcNow < this.nextUnblockTime) { this.UnblockDevice(); } } } }
// Token: 0x06000562 RID: 1378 RVA: 0x0001F9A8 File Offset: 0x0001DBA8 private BackOffValue GetAutoBlockBackOffTimeForSyncCommands() { int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceLimit; EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceDuration; if (behaviorTypeIncidenceDuration.TotalSeconds == 0.0) { return(BackOffValue.NoBackOffValue); } if (this.syncTimes == null || this.syncTimes.Count == 0 || this.syncTimes.Count <= behaviorTypeIncidenceLimit / 2) { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: Skip calculating backOff time."); return(new BackOffValue { BackOffDuration = -1.0 * behaviorTypeIncidenceDuration.TotalSeconds, BackOffType = BackOffType.Low, BackOffReason = AutoblockThresholdType.SyncCommands.ToString() }); } TimeSpan currentDuration = ExDateTime.UtcNow.Subtract(this.syncTimes[0]); BackOffValue backOffValue = this.CalculateAutoBlockBackOffTime(behaviorTypeIncidenceLimit, behaviorTypeIncidenceDuration, this.syncTimes.Count, currentDuration, AutoblockThresholdType.SyncCommands.ToString()); AirSyncDiagnostics.TraceInfo <int, double>(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: SyncCommandLimit:{0}, backOffDuration:{1}", behaviorTypeIncidenceLimit, backOffValue.BackOffDuration); return(backOffValue); }
private static PolicyData LoadDefaultPolicySetting(IConfigurationSession scopedSession, ProtocolLogger protocolLogger) { MobileMailboxPolicy[] mobileMaiboxPolicies = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { mobileMaiboxPolicies = scopedSession.Find <MobileMailboxPolicy>(scopedSession.GetOrgContainerId().GetDescendantId(new ADObjectId("CN=Mobile Mailbox Policies")), QueryScope.OneLevel, ADNotificationManager.filter, ADNotificationManager.sortBy, 3); }); if (!adoperationResult.Succeeded) { AirSyncDiagnostics.TraceDebug <ADObjectId, string>(ExTraceGlobals.RequestsTracer, null, "Exception occurred during AD Operation during LoadDefaultPolicySettings for OrgID {0}. Message - {1}", scopedSession.GetOrgContainerId(), adoperationResult.Exception.Message); throw adoperationResult.Exception; } protocolLogger.SetValue(ProtocolLoggerData.DomainController, scopedSession.LastUsedDc); if (mobileMaiboxPolicies == null || mobileMaiboxPolicies.Length == 0) { AirSyncDiagnostics.TraceInfo <ADObjectId>(ExTraceGlobals.RequestsTracer, null, "no default policy setting found for OrgId {0}", scopedSession.GetOrgContainerId()); return(null); } AirSyncDiagnostics.TraceInfo <ADObjectId>(ExTraceGlobals.RequestsTracer, null, "LoadDefaultPolicySetting from AD.Policy Id {0}", mobileMaiboxPolicies[0].Id); if (mobileMaiboxPolicies.Length > 1) { ADNotificationManager.HandleMultipleDefaultPolicies(mobileMaiboxPolicies, scopedSession.GetOrgContainerId(), protocolLogger); protocolLogger.SetValue(ProtocolLoggerData.DomainController, scopedSession.LastUsedDc); } return(ADNotificationManager.AddPolicyToCache(mobileMaiboxPolicies[0], scopedSession.SessionSettings.CurrentOrganizationId.PartitionId)); }
public static IOrganizationSettingsData GetOrganizationSettingsData(OrganizationId organizationId, IAirSyncContext context) { if (organizationId == null) { throw new ArgumentException("OrganizationId is null"); } if (!ADNotificationManager.started) { throw new InvalidOperationException("ADNotificationManager should be started first!"); } IConfigurationSession scopedSession = null; ADObjectId configurationUnit = organizationId.ConfigurationUnit; if (configurationUnit == null) { if (ADNotificationManager.enterpriseConfigurationID == null) { scopedSession = ADNotificationManager.CreateScopedADSession(organizationId, ConsistencyMode.IgnoreInvalid); ADNotificationManager.enterpriseConfigurationID = scopedSession.GetOrgContainerId(); if (context != null) { context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, scopedSession.LastUsedDc); } } configurationUnit = ADNotificationManager.enterpriseConfigurationID; } ADNotificationManager.ADSettingsInfo <IOrganizationSettingsData> adsettingsInfo = null; AirSyncDiagnostics.TraceDebug <ADObjectId>(ExTraceGlobals.RequestsTracer, null, "Loaded ConfigurationUnit {0}", configurationUnit); Func <IOrganizationSettingsData> loadDataAction = () => ADNotificationManager.LoadOrganizationSettings(scopedSession ?? ADNotificationManager.CreateScopedADSession(organizationId, ConsistencyMode.PartiallyConsistent), context); ADNotificationManager.LoadADSettingsData <IOrganizationSettingsData>(ADNotificationManager.organizationSettingsCache, configurationUnit.DistinguishedName, loadDataAction, organizationId.PartitionId, out adsettingsInfo); return(adsettingsInfo.ADSettingsData); }
// Token: 0x0600056A RID: 1386 RVA: 0x000200D0 File Offset: 0x0001E2D0 private void BlockDevice(AutoblockThresholdType autoblockThresholdType) { AirSyncDiagnostics.TraceInfo <AutoblockThresholdType>(ExTraceGlobals.RequestsTracer, this, "BlockDevice {0}", autoblockThresholdType); EnhancedTimeSpan deviceBlockDuration = ADNotificationManager.GetAutoBlockThreshold(autoblockThresholdType).DeviceBlockDuration; ExDateTime utcNow = ExDateTime.UtcNow; lock (this.instanceLock) { if (this.blockTime > utcNow || this.nextUnblockTime < utcNow) { this.blockTime = utcNow; this.nextUnblockTime = utcNow + deviceBlockDuration; this.autoBlockReason = DeviceAccessStateReason.UserAgentsChanges + (int)autoblockThresholdType; this.timeToUpdateAD = utcNow; this.SaveDeviceBehavior(true); if (deviceBlockDuration != EnhancedTimeSpan.Zero) { AirSyncCounters.AutoBlockedDevices.Increment(); } if (this.ProtocolLogger != null) { this.ProtocolLogger.SetValue(ProtocolLoggerData.AutoBlockEvent, autoblockThresholdType.ToString()); } } } }
// Token: 0x06000759 RID: 1881 RVA: 0x00028D5C File Offset: 0x00026F5C public static bool IsWssAccessEnabled(IAirSyncUser user) { AirSyncDiagnostics.Assert(user != null); PolicyData policyData = ADNotificationManager.GetPolicyData(user); return(policyData == null || policyData.WSSAccessEnabled); }
private static PolicyData GetDefaultPolicySetting(IAirSyncUser user) { ADObjectId configurationUnit = user.ADUser.ConfigurationUnit; if (configurationUnit == null) { if (ADNotificationManager.enterpriseConfigurationID == null) { IConfigurationSession configurationSession = ADNotificationManager.CreateScopedADSession(user); ADNotificationManager.enterpriseConfigurationID = configurationSession.GetOrgContainerId(); user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, configurationSession.LastUsedDc); } configurationUnit = ADNotificationManager.enterpriseConfigurationID; } Func <PolicyData> loadDataAction = () => ADNotificationManager.LoadDefaultPolicySetting(ADNotificationManager.CreateScopedADSession(user), user.Context.ProtocolLogger); ADNotificationManager.ADSettingsInfo <PolicyData> adsettingsInfo; bool flag = ADNotificationManager.LoadADSettingsData <PolicyData>(ADNotificationManager.policies, configurationUnit.DistinguishedName, loadDataAction, user.OrganizationId.PartitionId, out adsettingsInfo); if (flag && adsettingsInfo.ADSettingsData == null) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Default PolicySettings not found. Save null in cache.Policy DN {0}", configurationUnit.DistinguishedName); ADNotificationManager.policies.Add(configurationUnit.DistinguishedName, new ADNotificationManager.ADSettingsInfo <PolicyData>(user.OrganizationId.PartitionId, null, ExDateTime.UtcNow)); } AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Returning Default PolicySettings data. DN {0}", configurationUnit.DistinguishedName); return(adsettingsInfo.ADSettingsData); }
public static IOrganizationSettingsData GetOrganizationSettingsData(IAirSyncUser user) { if (user == null) { throw new ArgumentNullException("user"); } return(ADNotificationManager.GetOrganizationSettingsData(user.OrganizationId, user.Context)); }
private static PolicyData GetPolicySetting(IAirSyncUser user) { ADObjectId policyId = user.ADUser.ActiveSyncMailboxPolicy; AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Loading user PolicySettings data.Policy DN {0}", policyId.DistinguishedName); Func <PolicyData> loadDataAction = () => ADNotificationManager.LoadPolicySetting(ADNotificationManager.CreateScopedADSession(user), user, policyId, true); ADNotificationManager.ADSettingsInfo <PolicyData> adsettingsInfo; ADNotificationManager.LoadADSettingsData <PolicyData>(ADNotificationManager.policies, policyId.DistinguishedName, loadDataAction, user.OrganizationId.PartitionId, out adsettingsInfo); return(adsettingsInfo.ADSettingsData); }
// Token: 0x06000D92 RID: 3474 RVA: 0x0004AE00 File Offset: 0x00049000 internal static bool NeedToSendBootstrapMailForWM61(IAirSyncContext airSyncContext, GlobalInfo globalInfo) { if (airSyncContext == null) { throw new ArgumentNullException("airSyncContext"); } if (globalInfo == null) { throw new ArgumentNullException("globalInfo"); } PolicyData policyData = ADNotificationManager.GetPolicyData(airSyncContext.User); if (policyData == null || !policyData.AllowMobileOTAUpdate) { return(false); } if (airSyncContext.Request.Version != 121) { return(false); } if (globalInfo.HaveSentBoostrapMailForWM61) { return(false); } if (globalInfo.BootstrapMailForWM61TriggeredTime != null) { return(false); } string deviceOS = globalInfo.DeviceOS; if (deviceOS == null || !deviceOS.StartsWith("Windows CE", StringComparison.OrdinalIgnoreCase)) { return(false); } try { Version v = new Version(deviceOS.Substring("Windows CE".Length).Trim()); if (v < OTABootstrapMail.WM61VersionStartRange || v > OTABootstrapMail.WM61VersionEndRange) { return(false); } } catch (Exception ex) { if (ex is ArgumentException || ex is ArgumentOutOfRangeException || ex is FormatException || ex is OverflowException) { return(false); } throw ex; } return(GlobalSettings.BootstrapCABForWM61HostingURL != null && GlobalSettings.MobileUpdateInformationURL != null); }
// Token: 0x0600055D RID: 1373 RVA: 0x0001F608 File Offset: 0x0001D808 public void AddSyncKey(ExDateTime syncAttemptTime, string collectionId, uint syncKey) { AirSyncDiagnostics.TraceInfo <string, uint>(ExTraceGlobals.RequestsTracer, this, "AddSyncKey collectionId:{0} syncKey:{1}", collectionId, syncKey); DeviceAutoBlockThreshold autoBlockThreshold = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands); lock (this.instanceLock) { int num = this.syncTimes.Count - 1; while (num > -1 && !(this.syncTimes[num] == syncAttemptTime)) { num--; } if (num == -1) { this.RecordSyncCommand(syncAttemptTime); num = this.syncTimes.Count - 1; if (this.syncTimes[num] != syncAttemptTime) { throw new InvalidOperationException("Recently added sync record is not the last one!"); } if (this.BlockOnFrequency()) { return; } } int num2 = this.syncKeys[num] ^ ((collectionId != null) ? collectionId.GetHashCode() : 0) ^ syncKey.GetHashCode(); this.syncKeys[num] = num2; AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "AddSyncKey new hashcode {0}", num2); if (this.ProtocolLogger != null) { this.ProtocolLogger.SetValue(ProtocolLoggerData.SyncHashCode, num2); } int num3 = 0; ExDateTime t = syncAttemptTime - autoBlockThreshold.BehaviorTypeIncidenceDuration; for (int i = 0; i < this.syncTimes.Count; i++) { if (!(this.syncTimes[i] < t) && this.syncKeys[i] == num2) { num3++; } } int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit; if (behaviorTypeIncidenceLimit > 0 && num3 >= behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.SyncCommands); } else if (this.AutoBlockReason != DeviceAccessStateReason.Unknown) { this.UnblockDevice(); } } }
// Token: 0x060005B9 RID: 1465 RVA: 0x00021F98 File Offset: 0x00020198 public static bool IsDeviceInFilter(string filterName) { if (Command.CurrentCommand != null && Command.CurrentCommand.Context != null) { IOrganizationSettingsData organizationSettingsData = ADNotificationManager.GetOrganizationSettingsData(Command.CurrentCommand.Context.User); if (organizationSettingsData == null || organizationSettingsData.DeviceFiltering == null || organizationSettingsData.DeviceFiltering.Count == 0) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, "There are no device filters or failed to get device filters"); return(false); } ActiveSyncDeviceFilter filter = organizationSettingsData.DeviceFiltering.GetFilter(filterName); if (filter == null) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "There are no device filters by given name:{0}", filterName); return(false); } if (filter.ApplyForAllDevices) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Device filter name:{0} has been set to apply for all devices", filterName); return(true); } if (filter.Rules == null) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "There are no rules for the given device filters name:{0}", filterName); return(false); } string text; string text2; string text3; string text4; string text5; DeviceFilterManager.GetActualValues(out text, out text2, out text3, out text4, out text5); foreach (ActiveSyncDeviceFilterRule activeSyncDeviceFilterRule in filter.Rules) { if ((activeSyncDeviceFilterRule.Characteristic == DeviceAccessCharacteristic.DeviceType && DeviceFilterManager.IsRuleValueMatch(activeSyncDeviceFilterRule, text)) || (activeSyncDeviceFilterRule.Characteristic == DeviceAccessCharacteristic.DeviceModel && DeviceFilterManager.IsRuleValueMatch(activeSyncDeviceFilterRule, text2)) || (activeSyncDeviceFilterRule.Characteristic == DeviceAccessCharacteristic.DeviceOS && DeviceFilterManager.IsRuleValueMatch(activeSyncDeviceFilterRule, text3)) || (activeSyncDeviceFilterRule.Characteristic == DeviceAccessCharacteristic.UserAgent && DeviceFilterManager.IsRuleValueMatch(activeSyncDeviceFilterRule, text4)) || (activeSyncDeviceFilterRule.Characteristic == DeviceAccessCharacteristic.XMSWLHeader && DeviceFilterManager.IsRuleValueMatch(activeSyncDeviceFilterRule, text5))) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, "The current request with DeviceType:{0} DeviceModel:{1} DeviceOS:{2} UserAgent:{3} XMSWLHeader:{4} has a matching filter:{5}", new object[] { text, text2, text3, text4, text5, filterName }); return(true); } } return(false); } return(false); }
private static IOrganizationSettingsData LoadOrganizationSettings(IConfigurationSession scopedSession, IAirSyncContext context) { ADObjectId organizationId = scopedSession.GetOrgContainerId(); ActiveSyncOrganizationSettings organizationSettings = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { organizationSettings = scopedSession.Read <ActiveSyncOrganizationSettings>(organizationId.GetDescendantId(new ADObjectId("CN=Mobile Mailbox Settings"))); }); if (!adoperationResult.Succeeded) { AirSyncDiagnostics.TraceDebug <ADObjectId, string>(ExTraceGlobals.RequestsTracer, null, "Exception occurred during AD Operation during LoadOrganizationSettings {0}. Exception Message- {1}", organizationId, adoperationResult.Exception.Message); } ValidationError[] array = organizationSettings.Validate(); bool flag = false; if (array != null) { foreach (ValidationError validationError in array) { if (string.Equals(validationError.PropertyName, "ConfigurationXMLRaw", StringComparison.OrdinalIgnoreCase)) { flag = true; } } } if (flag) { organizationSettings.DeviceFiltering = null; } ADRawEntry adrawEntry = scopedSession.ReadADRawEntry(organizationId, new PropertyDefinition[] { OrganizationSchema.IntuneManagedStatus }); organizationSettings.IsIntuneManaged = (adrawEntry != null && (bool)adrawEntry[OrganizationSchema.IntuneManagedStatus]); AirSyncDiagnostics.TraceInfo <bool>(ExTraceGlobals.RequestsTracer, null, "LoadOrganizationSettings from AD.IntuneManagedStatus {0}.", organizationSettings.IsIntuneManaged); if (context != null) { context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, scopedSession.LastUsedDc); } if (organizationSettings != null) { AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, null, "LoadOrganizationSettings from AD. Found {0} OrganizationSettings.", 1); return(ADNotificationManager.AddOrganizationSettingsToCache(organizationSettings, scopedSession)); } AirSyncDiagnostics.TraceError <ADObjectId>(ExTraceGlobals.RequestsTracer, null, "Cannot find ActiveSyncOrganizationSettings object in AD for organization {0}", organizationId); return(null); }
// Token: 0x0600056B RID: 1387 RVA: 0x000201B4 File Offset: 0x0001E3B4 private void UnblockDevice() { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "UnblockDevice"); TimeSpan timeSpan = ADNotificationManager.Started ? (ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).BehaviorTypeIncidenceDuration *(long)GlobalSettings.AutoBlockADWriteDelay) : TimeSpan.Zero; lock (this.instanceLock) { switch (this.autoBlockReason) { case DeviceAccessStateReason.UserAgentsChanges: this.userAgentTimes.Clear(); this.userAgentStrings.Clear(); break; case DeviceAccessStateReason.RecentCommands: this.recentCommandTimes.Clear(); this.recentCommandHashCodes.Clear(); break; case DeviceAccessStateReason.Watsons: this.watsons.Clear(); break; case DeviceAccessStateReason.OutOfBudgets: this.outOfBudgets.Clear(); break; case DeviceAccessStateReason.SyncCommands: this.syncTimes.Clear(); this.syncKeys.Clear(); break; case DeviceAccessStateReason.CommandFrequency: this.recentCommandTimes.Clear(); this.recentCommandHashCodes.Clear(); this.syncTimes.Clear(); this.syncKeys.Clear(); break; } if (timeSpan > DeviceBehavior.MaxADUpdateDelay) { timeSpan = DeviceBehavior.MaxADUpdateDelay; } this.timeToUpdateAD = ExDateTime.UtcNow + timeSpan; this.nextUnblockTime = ExDateTime.MinValue; this.autoBlockReason = DeviceAccessStateReason.Unknown; this.SaveDeviceBehavior(true); } }
public static void Start(IAirSyncContext context) { lock (ADNotificationManager.startLock) { if (!ADNotificationManager.started) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, "ADNotificationManager is being started ..."); ADNotificationManager.topoSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 189, "Start", "f:\\15.00.1497\\sources\\dev\\AirSync\\src\\AirSync\\ADNotificationManager.cs"); ADNotificationManager.LoadAutoBlockThresholds(); ADNotificationManager.started = true; context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, ADNotificationManager.topoSession.LastUsedDc); AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, "ADNotificationManager is started."); int expireTimeInMinutes = (GlobalSettings.ADCacheExpirationTimeout.TotalMinutes < 1.0) ? 1 : ((int)GlobalSettings.ADCacheExpirationTimeout.TotalMinutes); ADNotificationManager.policies = new MruDictionaryCache <string, ADNotificationManager.ADSettingsInfo <PolicyData> >(GlobalSettings.ADCacheMaxOrgCount, GlobalSettings.ADCacheMaxOrgCount, expireTimeInMinutes); ADNotificationManager.organizationSettingsCache = new MruDictionaryCache <string, ADNotificationManager.ADSettingsInfo <IOrganizationSettingsData> >(GlobalSettings.ADCacheMaxOrgCount, GlobalSettings.ADCacheMaxOrgCount, expireTimeInMinutes); ADNotificationManager.vDirSettingsCache = new ADObjIdToVDirMap(); } } }
// Token: 0x0600055C RID: 1372 RVA: 0x0001F55C File Offset: 0x0001D75C public void RecordOutOfBudget() { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "RecordOutOfBudget"); ExDateTime utcNow = ExDateTime.UtcNow; DeviceAutoBlockThreshold autoBlockThreshold = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.OutOfBudgets); ExDateTime windowStartTime = utcNow - autoBlockThreshold.BehaviorTypeIncidenceDuration; lock (this.instanceLock) { DeviceBehavior.ClearOldRecords(windowStartTime, this.outOfBudgets); this.outOfBudgets.Add(utcNow); this.SaveDeviceBehavior(false); int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit; if (behaviorTypeIncidenceLimit > 0 && this.outOfBudgets.Count > behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.OutOfBudgets); } } }
// Token: 0x06000563 RID: 1379 RVA: 0x0001FAA8 File Offset: 0x0001DCA8 private BackOffValue GetAutoBlockBackOffTimeForCommandsFrequency() { EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration; if (behaviorTypeIncidenceDuration.TotalSeconds == 0.0) { return(BackOffValue.NoBackOffValue); } BackOffValue backOffValue; if ((this.recentCommandTimes != null && this.recentCommandTimes.Count >= 0) || (this.syncTimes != null && this.syncTimes.Count >= 0)) { int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceLimit; ExDateTime exDateTime = ExDateTime.MaxValue; ExDateTime exDateTime2 = ExDateTime.MaxValue; int num = 0; if (this.syncTimes != null && this.syncKeys.Count > 0) { num += this.syncTimes.Count; exDateTime = this.syncTimes[0]; } if (this.recentCommandTimes != null && this.recentCommandTimes.Count > 0) { num += this.recentCommandTimes.Count; exDateTime2 = this.recentCommandTimes[0]; } TimeSpan currentDuration = (exDateTime < exDateTime2) ? ExDateTime.UtcNow.Subtract(exDateTime) : ExDateTime.UtcNow.Subtract(exDateTime2); backOffValue = this.CalculateAutoBlockBackOffTime(behaviorTypeIncidenceLimit, behaviorTypeIncidenceDuration, num, currentDuration, AutoblockThresholdType.CommandFrequency.ToString()); AirSyncDiagnostics.TraceInfo <int, double>(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: SyncCommandLimit:{0}, backOffDuration:{1}", behaviorTypeIncidenceLimit, backOffValue.BackOffDuration); } else { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "GetAutoblockBackOffTime: Skip calculating backOff time."); backOffValue = new BackOffValue { BackOffType = BackOffType.Low, BackOffReason = AutoblockThresholdType.CommandFrequency.ToString(), BackOffDuration = -1.0 * behaviorTypeIncidenceDuration.TotalSeconds }; } return(backOffValue); }
// Token: 0x06000569 RID: 1385 RVA: 0x0001FF98 File Offset: 0x0001E198 private bool BlockOnFrequency() { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "BlockOnFrequency"); int behaviorTypeIncidenceLimit = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceLimit; if (behaviorTypeIncidenceLimit == 0) { return(false); } ExDateTime utcNow = ExDateTime.UtcNow; ExDateTime t = utcNow - ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration; int num = 0; lock (this.instanceLock) { foreach (ExDateTime t2 in this.recentCommandTimes) { if (t2 > t) { num++; } } if (num >= behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.CommandFrequency); return(true); } foreach (ExDateTime t3 in this.syncTimes) { if (t3 > t) { num++; } } if (num >= behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.CommandFrequency); return(true); } } return(false); }
// Token: 0x0600055A RID: 1370 RVA: 0x0001F358 File Offset: 0x0001D558 public void RecordCommand(int commandHashcode) { AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.RequestsTracer, this, "RecordCommand HC:{0}", commandHashcode); ExDateTime utcNow = ExDateTime.UtcNow; DeviceAutoBlockThreshold autoBlockThreshold = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.RecentCommands); EnhancedTimeSpan behaviorTypeIncidenceDuration = autoBlockThreshold.BehaviorTypeIncidenceDuration; if (behaviorTypeIncidenceDuration < ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration) { behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration; } ExDateTime exDateTime = utcNow - behaviorTypeIncidenceDuration; lock (this.instanceLock) { DeviceBehavior.ClearOldRecords(exDateTime, this.recentCommandTimes, this.recentCommandHashCodes); this.recentCommandTimes.Add(utcNow); this.recentCommandHashCodes.Add(commandHashcode); this.SaveDeviceBehavior(false); if (this.ProtocolLogger != null) { this.ProtocolLogger.SetValue(ProtocolLoggerData.CommandHashCode, commandHashcode); } if (!this.BlockOnFrequency()) { exDateTime = utcNow - autoBlockThreshold.BehaviorTypeIncidenceDuration; int num = 0; for (int i = 0; i < this.recentCommandTimes.Count; i++) { if (!(this.recentCommandTimes[i] < exDateTime) && this.recentCommandHashCodes[i] == commandHashcode) { num++; } } int behaviorTypeIncidenceLimit = autoBlockThreshold.BehaviorTypeIncidenceLimit; if (behaviorTypeIncidenceLimit > 0 && num > behaviorTypeIncidenceLimit) { this.BlockDevice(AutoblockThresholdType.RecentCommands); } } } }
// Token: 0x06000568 RID: 1384 RVA: 0x0001FEDC File Offset: 0x0001E0DC private void RecordSyncCommand(ExDateTime syncAttemptTime) { AirSyncDiagnostics.TraceInfo <ExDateTime>(ExTraceGlobals.RequestsTracer, this, "RecordSyncCommand syncAttemptTime:{0:o}", syncAttemptTime); ExDateTime utcNow = ExDateTime.UtcNow; EnhancedTimeSpan behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.SyncCommands).BehaviorTypeIncidenceDuration; if (behaviorTypeIncidenceDuration < ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration) { behaviorTypeIncidenceDuration = ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.CommandFrequency).BehaviorTypeIncidenceDuration; } ExDateTime windowStartTime = utcNow - behaviorTypeIncidenceDuration; lock (this.instanceLock) { DeviceBehavior.ClearOldRecords(windowStartTime, this.syncTimes, this.syncKeys); this.syncTimes.Add(syncAttemptTime); this.syncKeys.Add(0); this.SaveDeviceBehavior(false); } }
// Token: 0x06000D93 RID: 3475 RVA: 0x0004AF14 File Offset: 0x00049114 internal static void SendBootstrapMailForWM61(IAirSyncUser user) { if (user == null) { throw new ArgumentNullException("user"); } if (user.ExchangePrincipal == null) { throw new ArgumentNullException("user.ExchangePrincipal"); } using (MailboxSession mailboxSession = MailboxSession.OpenAsSystemService(user.ExchangePrincipal, CultureInfo.InvariantCulture, "Client=ActiveSync")) { CultureInfo preferedCulture = mailboxSession.PreferedCulture; string subject = Strings.BootstrapMailForWM61Subject.ToString(preferedCulture); string text = string.Format("<a href=\"{0}\">{1}</a>", GlobalSettings.MobileUpdateInformationURL, AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body7.ToString(preferedCulture), false)); string text2 = string.Format("<a href=\"{0}\">{1}</a>", GlobalSettings.BootstrapCABForWM61HostingURL, AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body8.ToString(preferedCulture), false)); string text3 = string.Empty; IOrganizationSettingsData organizationSettingsData = ADNotificationManager.GetOrganizationSettingsData(user); if (organizationSettingsData != null && !string.IsNullOrEmpty(organizationSettingsData.OtaNotificationMailInsert)) { text3 = string.Format("<p>{0}</p><hr>", organizationSettingsData.OtaNotificationMailInsert); } string body = string.Format("<html><head><style>p, li {{font-size:10pt; font-family:Tahoma;}}</style></head><body><p style=\"font-size:12pt; color:darkblue;\"><b>{0}</b></p><p>{1}</p><ul><li>{2}</li><li>{3}</li><li>{4}</li><li>{5}</li><li>{6}</li></ul><p><span style=\"font-size:12pt;\"><b>{7}</b></span><br>{8}</p><hr>{9}<p style=\"font-size:8pt; color:gray;\">{10}</p></body></html>", new object[] { AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body1.ToString(preferedCulture), false), AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body2.ToString(preferedCulture), false), AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body3.ToString(preferedCulture), false), AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body4.ToString(preferedCulture), false), AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body5.ToString(preferedCulture), false), AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body6.ToString(preferedCulture), false), text, text2, AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body9.ToString(preferedCulture), false), text3, AirSyncUtility.HtmlEncode(Strings.BootstrapMailForWM61Body10.ToString(preferedCulture), false) }); SystemMessageHelper.PostMessage(mailboxSession, subject, body, "IPM.Note", Importance.High); } }
public static PolicyData GetPolicyData(IAirSyncUser user) { if (user == null) { throw new ArgumentNullException("user"); } if (!ADNotificationManager.started) { throw new InvalidOperationException("ADNotificationManager should be started first!"); } PolicyData policyData = null; if (user.ADUser.ActiveSyncMailboxPolicy != null) { policyData = ADNotificationManager.GetPolicySetting(user); } if (policyData == null) { policyData = ADNotificationManager.GetDefaultPolicySetting(user); } return(policyData); }
private void ProcessSet(XmlNode setNode) { using (this.user.Context.Tracker.Start(TimeId.DevicePasswordProcessSet)) { if (setNode.ChildNodes.Count != 1) { this.status = SettingsBase.ErrorCode.ProtocolError; } else { string innerText = setNode.FirstChild.InnerText; if (innerText.Length > 255) { this.status = SettingsBase.ErrorCode.InvalidArguments; } else { PolicyData policyData = ADNotificationManager.GetPolicyData(this.user); bool flag = policyData != null && policyData.PasswordRecoveryEnabled; if (innerText.Length > 0 && flag) { this.globalInfo.RecoveryPassword = innerText; } else { this.globalInfo.RecoveryPassword = null; } if (innerText.Length > 0 && !flag) { this.status = SettingsBase.ErrorCode.DeniedByPolicy; } else { this.status = SettingsBase.ErrorCode.Success; } } } } }
private static PolicyData AddPolicyToCache(MobileMailboxPolicy mobileMaiboxPolicy, PartitionId partitionId) { PolicyData policyData = null; if (mobileMaiboxPolicy != null) { policyData = new PolicyData(mobileMaiboxPolicy); string defaultPolicyKey = ADNotificationManager.GetDefaultPolicyKey(mobileMaiboxPolicy.Id); if (policyData.IsDefault) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Adding policy {0} as default.", mobileMaiboxPolicy.Id.DistinguishedName); ADNotificationManager.policies.Add(defaultPolicyKey, new ADNotificationManager.ADSettingsInfo <PolicyData>(partitionId, policyData, ExDateTime.UtcNow)); } else if (ADNotificationManager.IsOrgDefaultPolicyEquals(mobileMaiboxPolicy.Id, defaultPolicyKey)) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Removing policy {0} as default.", mobileMaiboxPolicy.Id.DistinguishedName); ADNotificationManager.policies.Remove(defaultPolicyKey); } AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, null, "Adding policy to location {0}.", mobileMaiboxPolicy.Id.DistinguishedName); ADNotificationManager.policies.Add(mobileMaiboxPolicy.Id.DistinguishedName, new ADNotificationManager.ADSettingsInfo <PolicyData>(partitionId, policyData, ExDateTime.UtcNow)); } return(policyData); }
public static DeviceAutoBlockThreshold GetAutoBlockThreshold(AutoblockThresholdType type) { AirSyncDiagnostics.TraceDebug <AutoblockThresholdType>(ExTraceGlobals.RequestsTracer, null, "GetAutoblockThreshold data.AutoblockThresholdType {0}", type); if (!Enum.IsDefined(typeof(AutoblockThresholdType), type)) { AirSyncDiagnostics.TraceError(ExTraceGlobals.RequestsTracer, null, "InvalidAutoblockReason"); throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.SyncStateCorrupt, null, false) { ErrorStringForProtocolLogger = "InvalidAutoblockReason" }; } if (ADNotificationManager.autoBlockThresholds == null || ADNotificationManager.autoBlockThresholds.DeviceAutoBlockThresholds == null || ADNotificationManager.autoBlockThresholds.WhenCreated.Add(GlobalSettings.ADCacheExpirationTimeout) < ExDateTime.UtcNow) { lock (ADNotificationManager.startLock) { if (ADNotificationManager.autoBlockThresholds == null || ADNotificationManager.autoBlockThresholds.DeviceAutoBlockThresholds == null || ADNotificationManager.autoBlockThresholds.WhenCreated.Add(GlobalSettings.ADCacheExpirationTimeout) < ExDateTime.UtcNow) { AirSyncDiagnostics.TraceDebug <AutoblockThresholdType>(ExTraceGlobals.RequestsTracer, null, "refresh AutoblockThreshold data from AD.AutoblockThresholdType {0}", type); ADNotificationManager.LoadAutoBlockThresholds(); } } } return(ADNotificationManager.autoBlockThresholds.DeviceAutoBlockThresholds[(int)type]); }
private static PolicyData LoadPolicySetting(IConfigurationSession scopedSession, IAirSyncUser user, ADObjectId policyId, bool forceLoad) { MobileMailboxPolicy mobileMailboxPolicy = null; ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate() { mobileMailboxPolicy = scopedSession.Read <MobileMailboxPolicy>(policyId); }); if (!adoperationResult.Succeeded) { AirSyncDiagnostics.TraceDebug <ADObjectId, string>(ExTraceGlobals.RequestsTracer, null, "Exception occurred during AD Operation during LoadPolicySettings {0}. Exception Message - {1}", policyId, adoperationResult.Exception.Message); throw adoperationResult.Exception; } if (user != null) { user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, scopedSession.LastUsedDc); } if (mobileMailboxPolicy != null && (forceLoad || mobileMailboxPolicy.IsDefault)) { AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, null, "LoadPolicySetting from AD"); return(ADNotificationManager.AddPolicyToCache(mobileMailboxPolicy, scopedSession.SessionSettings.CurrentOrganizationId.PartitionId)); } return(null); }
// Token: 0x06000285 RID: 645 RVA: 0x0000E88C File Offset: 0x0000CA8C private bool TarpitErrorResponse(int httpStatusCode) { if (httpStatusCode != 441 && httpStatusCode != 449) { return(true); } if (httpStatusCode == 451) { return(!DeviceCapability.DeviceCanHandleRedirect(this.context)); } if (ADNotificationManager.GetAutoBlockThreshold(AutoblockThresholdType.RecentCommands).BehaviorTypeIncidenceDuration == EnhancedTimeSpan.Zero) { return(false); } DeviceBehavior deviceBehavior = this.context.DeviceBehavior; if (deviceBehavior == null) { Guid userGuid = AirSyncResponse.UnknownUserGuid; if (httpStatusCode != 441) { switch (httpStatusCode) { case 449: if (Command.CurrentCommand != null && Command.CurrentCommand.GlobalInfo != null && Command.CurrentCommand.GlobalInfo.DeviceADObjectId != null) { userGuid = Command.CurrentCommand.GlobalInfo.DeviceADObjectId.ObjectGuid; goto IL_136; } goto IL_136; case 451: if (this.context.User != null && this.context.User.ADUser != null && this.context.User.ADUser.Id != null) { userGuid = this.context.User.ADUser.Id.ObjectGuid; goto IL_136; } goto IL_136; } throw new ApplicationException("Unexpected HTTP status code " + httpStatusCode); } IL_136: if (!DeviceBehaviorCache.TryGetValue(userGuid, this.context.DeviceIdentity, out deviceBehavior)) { deviceBehavior = new DeviceBehavior(true); DeviceBehaviorCache.AddOrReplace(userGuid, this.context.DeviceIdentity, deviceBehavior); } } if (deviceBehavior != null) { lock (deviceBehavior) { if (deviceBehavior.IsDeviceAutoBlocked(null) != DeviceAccessStateReason.Unknown) { return(true); } deviceBehavior.RecordCommand(httpStatusCode); if (deviceBehavior.IsDeviceAutoBlocked(null) != DeviceAccessStateReason.Unknown) { return(true); } } return(false); } return(false); }
internal override Command.ExecutionState ExecuteCommand() { string attachmentName = this.AttachmentName; string value = string.Empty; FolderSyncState folderSyncState = null; AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "GetAttachmentCommand.Execute(). AttachmentName: '{0}'", attachmentName); try { int incBy = 0; if (base.Request.ContentType != null && !string.Equals(base.Request.ContentType, "message/rfc822", StringComparison.OrdinalIgnoreCase)) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidContentType"); throw new AirSyncPermanentException(HttpStatusCode.BadRequest, StatusCode.First140Error, null, false); } int num = attachmentName.IndexOf(':'); ItemIdMapping itemIdMapping = null; if (num != -1 && num != attachmentName.LastIndexOf(':')) { folderSyncState = base.SyncStateStorage.GetFolderSyncState(new MailboxSyncProviderFactory(base.MailboxSession), attachmentName.Substring(0, num)); if (folderSyncState == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentName)); } itemIdMapping = (ItemIdMapping)folderSyncState[CustomStateDatumType.IdMapping]; if (itemIdMapping == null) { throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenAttachmentId(attachmentName)); } } PolicyData policyData = ADNotificationManager.GetPolicyData(base.User); if (policyData != null && !policyData.AttachmentsEnabled) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentsNotEnabledGetAttCmd"); throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false); } Unlimited <ByteQuantifiedSize> maxAttachmentSize = (policyData != null) ? policyData.MaxAttachmentSize : Unlimited <ByteQuantifiedSize> .UnlimitedValue; value = AttachmentHelper.GetAttachment(base.MailboxSession, attachmentName, base.OutputStream, maxAttachmentSize, itemIdMapping, out incBy); base.ProtocolLogger.IncrementValue(ProtocolLoggerData.Attachments); base.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.AttachmentBytes, incBy); } catch (FormatException innerException) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "InvalidAttachmentName"); AirSyncPermanentException ex = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.InvalidIDs, innerException, false); throw ex; } catch (ObjectNotFoundException innerException2) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentNotFound"); AirSyncPermanentException ex2 = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.None, innerException2, false); throw ex2; } catch (IOException innerException3) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOException"); throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.None, innerException3, false); } catch (DataTooLargeException innerException4) { base.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AttachmentIsTooLarge"); PolicyData policyData2 = ADNotificationManager.GetPolicyData(base.User); if (policyData2 != null) { policyData2.MaxAttachmentSize.ToString(); } else { GlobalSettings.MaxDocumentDataSize.ToString(CultureInfo.InvariantCulture); } throw new AirSyncPermanentException(HttpStatusCode.RequestEntityTooLarge, StatusCode.AttachmentIsTooLarge, innerException4, false); } finally { if (folderSyncState != null) { folderSyncState.Dispose(); folderSyncState = null; } } base.Context.Response.AppendHeader("Content-Type", value); return(Command.ExecutionState.Complete); }
// Token: 0x06000560 RID: 1376 RVA: 0x0001F884 File Offset: 0x0001DA84 public DeviceAccessStateReason IsDeviceAutoBlocked(ExDateTime requestTime, out TimeSpan blockTime) { blockTime = TimeSpan.Zero; ExDateTime t = (this.AutoBlockReason != DeviceAccessStateReason.Unknown) ? ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).LastChangeTime : ExDateTime.MinValue; DeviceAccessStateReason result; lock (this.instanceLock) { if (this.AutoBlockReason != DeviceAccessStateReason.Unknown) { if (this.blockTime < t) { this.UnblockDevice(); } else if (ExDateTime.UtcNow >= this.nextUnblockTime) { this.UnblockDevice(); } else { blockTime = this.nextUnblockTime - requestTime; } } result = this.AutoBlockReason; } return(result); }
// Token: 0x0600055F RID: 1375 RVA: 0x0001F7CC File Offset: 0x0001D9CC public DeviceAccessStateReason IsDeviceAutoBlocked(string userAgent, out TimeSpan blockTime) { blockTime = TimeSpan.Zero; DeviceAccessStateReason result; lock (this.instanceLock) { if ((string.IsNullOrEmpty(userAgent) || this.userAgentStrings.Contains(userAgent)) && this.AutoBlockReason >= DeviceAccessStateReason.UserAgentsChanges && this.nextUnblockTime > ExDateTime.UtcNow && this.blockTime > ADNotificationManager.GetAutoBlockThreshold(this.AutoBlockReason).LastChangeTime) { blockTime = this.nextUnblockTime - ExDateTime.UtcNow; result = this.AutoBlockReason; } else { result = DeviceAccessStateReason.Unknown; } } return(result); }