Example #1
0
        // Token: 0x06000555 RID: 1365 RVA: 0x0001ED04 File Offset: 0x0001CF04
        public static List <Exception> ResetAutoBlockedDevices(MailboxSession mailboxSession)
        {
            List <Exception> list       = new List <Exception>();
            IEnumerator      enumerator = SyncStateStorage.GetEnumerator(mailboxSession, null);

            using (enumerator as IDisposable)
            {
                while (enumerator.MoveNext())
                {
                    object           obj = enumerator.Current;
                    SyncStateStorage syncStateStorage = (SyncStateStorage)obj;
                    if (syncStateStorage.DeviceIdentity.IsProtocol("AirSync"))
                    {
                        try
                        {
                            using (GlobalInfo globalInfo = GlobalInfo.LoadFromMailbox(mailboxSession, syncStateStorage, null))
                            {
                                if (globalInfo.DeviceBehavior.AutoBlockReason != DeviceAccessStateReason.Unknown)
                                {
                                    globalInfo.DeviceBehavior.UnblockDevice();
                                    globalInfo.IsDirty = true;
                                    globalInfo.SaveToMailbox();
                                }
                            }
                        }
                        catch (LocalizedException item)
                        {
                            list.Add(item);
                        }
                    }
                }
            }
            return(list);
        }
        // Token: 0x06000D1B RID: 3355 RVA: 0x000478C8 File Offset: 0x00045AC8
        public static IAutdStatusData Load(GlobalInfo globalInfo, SyncStateStorage syncStateStorage)
        {
            NewAutdStatusData newAutdStatusData = new NewAutdStatusData();

            newAutdStatusData.globalInfo     = globalInfo;
            newAutdStatusData.deviceMetadata = syncStateStorage.DeviceMetadata;
            if (!globalInfo.HasNewAutdData)
            {
                using (AutdStatusData autdStatusData = AutdStatusData.Load(syncStateStorage, false, false))
                {
                    if (autdStatusData != null)
                    {
                        newAutdStatusData.lastPingHeartbeat = autdStatusData.LastPingHeartbeat;
                        newAutdStatusData.DPFolderList      = ((autdStatusData.DPFolderList == null) ? null : new Dictionary <string, PingCommand.DPFolderInfo>(autdStatusData.DPFolderList));
                    }
                }
                newAutdStatusData.deviceMetadataStateChanged = true;
                newAutdStatusData.globalStateModified        = true;
            }
            else
            {
                newAutdStatusData.lastPingHeartbeat = globalInfo.LastPingHeartbeat;
                if (newAutdStatusData.deviceMetadata.PingFolderList != null)
                {
                    newAutdStatusData.DPFolderList = ((newAutdStatusData.deviceMetadata.PingFolderList == null) ? null : new Dictionary <string, PingCommand.DPFolderInfo>((Dictionary <string, PingCommand.DPFolderInfo>)newAutdStatusData.deviceMetadata.PingFolderList));
                }
                newAutdStatusData.deviceMetadataStateChanged = false;
                newAutdStatusData.globalStateModified        = false;
            }
            return(newAutdStatusData);
        }
 // Token: 0x06000585 RID: 1413 RVA: 0x00020C18 File Offset: 0x0001EE18
 internal static bool DeviceSupportedForMdm(GlobalInfo globalInfo)
 {
     if (globalInfo != null && !string.IsNullOrEmpty(globalInfo.DeviceOS))
     {
         string[] array = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).ActiveSync.MdmSupportedPlatforms.PlatformsSupported.Split(new char[]
         {
             ','
         });
         foreach (string pattern in array)
         {
             if (Regex.IsMatch(globalInfo.DeviceOS, pattern, RegexOptions.IgnoreCase))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 // Token: 0x06000AAD RID: 2733 RVA: 0x0003B52C File Offset: 0x0003972C
 internal static void CopyValuesFromGlobalInfo(MobileDevice mobileDevice, GlobalInfo globalInfo)
 {
     if (globalInfo != null)
     {
         mobileDevice.FriendlyName            = globalInfo.DeviceFriendlyName;
         mobileDevice.DeviceImei              = globalInfo.DeviceImei;
         mobileDevice.DeviceOS                = globalInfo.DeviceOS;
         mobileDevice.DeviceOSLanguage        = globalInfo.DeviceOSLanguage;
         mobileDevice.DeviceTelephoneNumber   = DeviceInfo.ObfuscatePhoneNumber(globalInfo.DevicePhoneNumber);
         mobileDevice.DeviceUserAgent         = globalInfo.UserAgent;
         mobileDevice.DeviceModel             = globalInfo.DeviceModel;
         mobileDevice.DeviceMobileOperator    = globalInfo.DeviceMobileOperator;
         mobileDevice.DeviceAccessState       = globalInfo.DeviceAccessState;
         mobileDevice.DeviceAccessStateReason = globalInfo.DeviceAccessStateReason;
         mobileDevice.ClientVersion           = globalInfo.DeviceActiveSyncVersion;
         mobileDevice.DeviceAccessControlRule = globalInfo.DeviceAccessControlRule;
     }
 }
        // Token: 0x060000BC RID: 188 RVA: 0x000086B8 File Offset: 0x000068B8
        private MobileDevice InternalCreateDevice(GlobalInfo globalInfo, ExDateTime syncStorageCreationTime)
        {
            MobileDevice mobileDevice = new MobileDevice();

            mobileDevice.FirstSyncTime  = new DateTime?((DateTime)syncStorageCreationTime.ToUtc());
            mobileDevice.ClientType     = this.clientType;
            mobileDevice.DeviceId       = this.deviceIdentity.DeviceId;
            mobileDevice.DeviceType     = this.deviceIdentity.DeviceType;
            mobileDevice.OrganizationId = this.organizationId;
            if (mobileDevice.ClientType == MobileClientType.EAS)
            {
                mobileDevice.SetExchangeVersion(this.exchangeVersion);
            }
            AirSyncDiagnostics.TraceDebug <string, OrganizationId>(this.tracer, this, "Creating device with DeviceId {0} and OrganizationId {1}.", mobileDevice.DeviceId, mobileDevice.OrganizationId);
            if (this.user != null)
            {
                mobileDevice.UserDisplayName = this.user.ToString();
            }
            GlobalInfo.CopyValuesFromGlobalInfo(mobileDevice, globalInfo);
            return(mobileDevice);
        }
 // Token: 0x060000B0 RID: 176 RVA: 0x0000716C File Offset: 0x0000536C
 internal void UpdateMobileDevice(MobileDevice mobileDevice, GlobalInfo globalInfo)
 {
     if (mobileDevice == null)
     {
         throw new ArgumentNullException("mobileDevice");
     }
     GlobalInfo.CopyValuesFromGlobalInfo(mobileDevice, globalInfo);
     try
     {
         if (this.user != null)
         {
             mobileDevice.UserDisplayName = this.user.ToString();
         }
         ADNotificationAdapter.RunADOperation(delegate()
         {
             this.session.Save(mobileDevice);
         });
         if (this.protocolLogger != null)
         {
             this.protocolLogger.SetValue(ProtocolLoggerData.DomainController, this.session.LastUsedDc);
         }
     }
     catch (ADOperationException ex)
     {
         DirectoryOperationException ex2 = ex.InnerException as DirectoryOperationException;
         if (ex2 != null && ex2.Response != null && ex2.Response.ResultCode == ResultCode.InsufficientAccessRights)
         {
             AirSyncDiagnostics.TraceDebug <string, ADOperationException>(this.tracer, this, "Failed to save MobileDevice data to Active Directory for \"{0}\". \r\nException:\r\n{1}", this.userName, ex);
             AirSyncDiagnostics.LogEvent(this.directoryAccessDeniedEventTuple, new string[]
             {
                 this.userName
             });
             throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, ex, false)
                   {
                       ErrorStringForProtocolLogger = ex2.GetType().FullName + ":ADDeviceSaveAccessDenied"
                   };
         }
         throw;
     }
 }
        // Token: 0x06000AAB RID: 2731 RVA: 0x0003B38C File Offset: 0x0003958C
        internal static int ComputeADDeviceInfoHash(GlobalInfo globalInfo)
        {
            if (globalInfo == null)
            {
                return(0);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(globalInfo.DeviceFriendlyName);
            stringBuilder.Append(globalInfo.DeviceImei);
            stringBuilder.Append(globalInfo.DeviceOS);
            stringBuilder.Append(globalInfo.DeviceOSLanguage);
            stringBuilder.Append(DeviceInfo.ObfuscatePhoneNumber(globalInfo.DevicePhoneNumber));
            stringBuilder.Append(globalInfo.UserAgent);
            stringBuilder.Append(globalInfo.DeviceModel);
            stringBuilder.Append(globalInfo.DeviceMobileOperator);
            stringBuilder.Append(globalInfo.DeviceAccessState);
            stringBuilder.Append(globalInfo.DeviceAccessStateReason);
            stringBuilder.Append(globalInfo.DeviceActiveSyncVersion);
            stringBuilder.Append(globalInfo.DeviceAccessControlRule);
            return(stringBuilder.ToString().GetHashCode());
        }
        public static ISyncStatusData Load(GlobalInfo globalInfo, SyncStateStorage syncStateStorage)
        {
            NewSyncStatusData newSyncStatusData = new NewSyncStatusData();

            newSyncStatusData.globalInfo     = globalInfo;
            newSyncStatusData.deviceMetadata = syncStateStorage.DeviceMetadata;
            if (!globalInfo.HasNewSyncData)
            {
                using (SyncStatusData syncStatusData = SyncStatusData.Load(syncStateStorage) as SyncStatusData)
                {
                    newSyncStatusData.clientCategoryList           = ((syncStatusData.ClientCategoryList == null) ? null : new List <int>(syncStatusData.ClientCategoryList));
                    newSyncStatusData.lastClientIdsSent            = ((syncStatusData.LastClientIdsSeen == null) ? null : new List <string>(syncStatusData.LastClientIdsSeen));
                    newSyncStatusData.lastSyncRequestRandomString  = syncStatusData.LastSyncRequestRandomString;
                    newSyncStatusData.lastCachableWbxmlDocument    = syncStatusData.LastCachableWbxmlDocument;
                    newSyncStatusData.ClientCanSendUpEmptyRequests = syncStatusData.ClientCanSendUpEmptyRequests;
                    newSyncStatusData.lastSyncAttemptTime          = syncStatusData.LastSyncAttemptTime;
                    newSyncStatusData.lastSyncSuccessTime          = syncStatusData.LastSyncSuccessTime;
                    newSyncStatusData.lastSyncUserAgent            = syncStatusData.LastSyncUserAgent;
                }
                newSyncStatusData.deviceMetadataStateChanged = true;
                newSyncStatusData.globalStateModified        = NewSyncStatusData.GlobalInfoStateModified.All;
            }
            else
            {
                newSyncStatusData.clientCategoryList           = ((globalInfo.ClientCategoryHashList == null) ? null : new List <int>(globalInfo.ClientCategoryHashList));
                newSyncStatusData.lastClientIdsSent            = ((globalInfo.LastClientIdsSeen == null) ? null : new List <string>(globalInfo.LastClientIdsSeen));
                newSyncStatusData.lastSyncRequestRandomString  = newSyncStatusData.deviceMetadata.LastSyncRequestRandomString;
                newSyncStatusData.lastCachableWbxmlDocument    = newSyncStatusData.deviceMetadata.LastCachedSyncRequest;
                newSyncStatusData.ClientCanSendUpEmptyRequests = newSyncStatusData.deviceMetadata.ClientCanSendUpEmptyRequests;
                newSyncStatusData.lastSyncAttemptTime          = globalInfo.LastSyncAttemptTime;
                newSyncStatusData.lastSyncSuccessTime          = globalInfo.LastSyncSuccessTime;
                newSyncStatusData.lastSyncUserAgent            = globalInfo.LastSyncUserAgent;
                newSyncStatusData.deviceMetadataStateChanged   = false;
                newSyncStatusData.globalStateModified          = NewSyncStatusData.GlobalInfoStateModified.None;
            }
            return(newSyncStatusData);
        }
Example #9
0
        // Token: 0x06000556 RID: 1366 RVA: 0x0001EDD0 File Offset: 0x0001CFD0
        public static DeviceBehavior GetDeviceBehavior(Guid userGuid, DeviceIdentity deviceIdentity, GlobalInfo globalInfo, object traceObject, ProtocolLogger protocolLogger)
        {
            string token = DeviceBehaviorCache.GetToken(userGuid, deviceIdentity);

            globalInfo.DeviceBehavior.ProtocolLogger = protocolLogger;
            globalInfo.DeviceBehavior.CacheToken     = token;
            DeviceBehavior deviceBehavior;

            if (globalInfo.DeviceADObjectId == null || !DeviceBehaviorCache.TryGetAndRemoveValue(userGuid, deviceIdentity, out deviceBehavior))
            {
                if (protocolLogger != null)
                {
                    protocolLogger.SetValue(ProtocolLoggerData.DeviceBehaviorLoaded, 7);
                }
                AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, traceObject, "No device in cache, return GlobalInfo.DeviceBehavior");
                return(globalInfo.DeviceBehavior);
            }
            if (deviceBehavior.AutoBlockReason != globalInfo.DeviceBehavior.AutoBlockReason)
            {
                if (protocolLogger != null)
                {
                    protocolLogger.SetValue(ProtocolLoggerData.DeviceBehaviorLoaded, 1);
                }
                AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, traceObject, "AutoBlockReason changed, return GlobalInfo.DeviceBehavior");
                return(globalInfo.DeviceBehavior);
            }
            int num = globalInfo.DeviceBehavior.IsNewerThan(deviceBehavior.WhenLoaded);

            if (num > -1)
            {
                string arg = DeviceBehavior.dateCollections[num];
                if (protocolLogger != null)
                {
                    protocolLogger.SetValue(ProtocolLoggerData.DeviceBehaviorLoaded, num + 2);
                }
                AirSyncDiagnostics.TraceInfo <string>(ExTraceGlobals.RequestsTracer, traceObject, "{0} is newer, return GlobalInfo.DeviceBehavior", arg);
                return(globalInfo.DeviceBehavior);
            }
            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, traceObject, "Return cached DeviceBehavior");
            deviceBehavior.Owner          = globalInfo;
            deviceBehavior.ProtocolLogger = protocolLogger;
            return(deviceBehavior);
        }
Example #10
0
 public override void SetFolderSyncOptions(IAirSyncVersionFactory versionFactory, bool isQuarantineMailAvailable, GlobalInfo globalInfo)
 {
 }
        public override void ConvertServerToClientObject(ISyncItem syncItem, XmlNode airSyncParentNode, SyncOperation changeObject, GlobalInfo globalInfo)
        {
            RecipientInfoCacheEntry entry = (RecipientInfoCacheEntry)syncItem.NativeItem;

            this.recipientInfoCacheDataObject.Bind(entry);
            base.AirSyncDataObject.Bind(airSyncParentNode);
            base.AirSyncDataObject.CopyFrom(this.recipientInfoCacheDataObject);
            base.AirSyncDataObject.Unbind();
            if (changeObject != null && (changeObject.ChangeType == ChangeType.Add || changeObject.ChangeType == ChangeType.Change))
            {
                changeObject.ChangeTrackingInformation = base.ChangeTrackFilter.Filter(airSyncParentNode, changeObject.ChangeTrackingInformation);
            }
            if (changeObject != null && (changeObject.ChangeType == ChangeType.Add || changeObject.ChangeType == ChangeType.Change))
            {
                base.HasAddsOrChangesToReturnToClientImmediately = true;
            }
            base.HasServerChanges = true;
        }
 public override bool GenerateResponsesXmlNode(XmlDocument xmlResponse, IAirSyncVersionFactory versionFactory, string deviceType, GlobalInfo globalInfo, ProtocolLogger protocolLogger, MailboxLogger mailboxLogger)
 {
     return(false);
 }
 // Token: 0x060000AF RID: 175 RVA: 0x0000713B File Offset: 0x0000533B
 internal MobileDevice CreateMobileDevice(GlobalInfo globalInfo, ExDateTime syncStorageCreationTime, bool checkForMaxDevices, MailboxSession mailboxSession = null)
 {
     return(this.CreateMobileDevice(globalInfo, syncStorageCreationTime, checkForMaxDevices, true, mailboxSession));
 }
 public override void SetFolderSyncOptions(IAirSyncVersionFactory versionFactory, bool isQuarantineMailAvailable, GlobalInfo globalInfo)
 {
     base.FilterType = AirSyncV25FilterTypes.NoFilter;
     base.SyncState[CustomStateDatumType.FilterType] = new Int32Data((int)base.FilterType);
     base.SyncState[CustomStateDatumType.MaxItems]   = new Int32Data(base.MaxItems);
 }
        // Token: 0x06000AA9 RID: 2729 RVA: 0x0003B150 File Offset: 0x00039350
        public static GlobalInfo LoadFromMailbox(MailboxSession mailboxSession, SyncStateStorage syncStateStorage, ProtocolLogger protocolLogger)
        {
            bool flag;

            return(GlobalInfo.LoadFromMailbox(mailboxSession, syncStateStorage, protocolLogger, out flag));
        }
        // Token: 0x06000AAA RID: 2730 RVA: 0x0003B168 File Offset: 0x00039368
        public static GlobalInfo LoadFromMailbox(MailboxSession mailboxSession, SyncStateStorage syncStateStorage, ProtocolLogger protocolLogger, out bool updateUserHasPartnership)
        {
            if (mailboxSession == null)
            {
                throw new ArgumentNullException("mailboxSession");
            }
            if (syncStateStorage == null)
            {
                throw new ArgumentNullException("syncStateStorage");
            }
            updateUserHasPartnership = false;
            CustomSyncState customSyncState         = null;
            GlobalInfo      globalInfo              = null;
            bool            isDirty                 = false;
            bool            hasNewSyncData          = false;
            bool            hasNewAutdData          = false;
            bool            isSyncStateJustUpgraded = false;
            bool            flag = false;
            GlobalInfo      result;

            try
            {
                GlobalSyncStateInfo syncStateInfo = new GlobalSyncStateInfo();
                customSyncState = syncStateStorage.GetCustomSyncState(syncStateInfo, GlobalInfo.ExtraGlobalInfoPropertiesToFetch);
                if (customSyncState == null)
                {
                    isDirty = true;
                    using (CustomSyncState customSyncState2 = syncStateStorage.GetCustomSyncState(new FolderIdMappingSyncStateInfo(), new PropertyDefinition[0]))
                    {
                        if (customSyncState2 == null)
                        {
                            updateUserHasPartnership = true;
                            syncStateStorage.DeleteAllSyncStates();
                        }
                    }
                    customSyncState = syncStateStorage.CreateCustomSyncState(syncStateInfo);
                    isDirty         = true;
                }
                else
                {
                    try
                    {
                        object obj = customSyncState.StoreObject.TryGetProperty(AirSyncStateSchema.LastSyncAttemptTime);
                        hasNewSyncData = (obj != null && !(obj is PropertyError));
                    }
                    catch (Exception arg)
                    {
                        AirSyncDiagnostics.TraceError <Exception>(ExTraceGlobals.RequestsTracer, null, "[GlobalInfo.LoadFromMailbox] Encountered exception when checking for new syncStatus properties.  Exception: {0}", arg);
                    }
                    try
                    {
                        object obj2 = customSyncState.StoreObject.TryGetProperty(AirSyncStateSchema.LastPingHeartbeatInterval);
                        hasNewAutdData = (obj2 != null && !(obj2 is PropertyError));
                    }
                    catch (Exception arg2)
                    {
                        AirSyncDiagnostics.TraceError <Exception>(ExTraceGlobals.RequestsTracer, null, "[GlobalInfo.LoadFromMailbox] Encountered exception when checking for new syncStatus properties.  Exception: {0}", arg2);
                    }
                    if (customSyncState.BackendVersion != null && customSyncState.BackendVersion.Value != customSyncState.Version)
                    {
                        isDirty = true;
                        isSyncStateJustUpgraded = true;
                        if (protocolLogger != null)
                        {
                            protocolLogger.SetValue(ProtocolLoggerData.Ssu, "2007");
                        }
                    }
                }
                globalInfo                         = new GlobalInfo(customSyncState);
                globalInfo.IsDirty                 = isDirty;
                globalInfo.HasNewSyncData          = hasNewSyncData;
                globalInfo.HasNewAutdData          = hasNewAutdData;
                globalInfo.IsSyncStateJustUpgraded = isSyncStateJustUpgraded;
                if (Command.CurrentCommand != null)
                {
                    globalInfo.WriteNewSyncData = Command.CurrentCommand.User.Features.IsEnabled(EasFeature.SyncStatusOnGlobalInfo);
                }
                flag   = true;
                result = globalInfo;
            }
            finally
            {
                if (!flag)
                {
                    if (globalInfo != null)
                    {
                        globalInfo.Dispose();
                    }
                    else if (customSyncState != null)
                    {
                        customSyncState.Dispose();
                    }
                }
            }
            return(result);
        }
Example #17
0
        public override void ConvertServerToClientObject(ISyncItem syncItem, XmlNode airSyncParentNode, SyncOperation changeObject, GlobalInfo globalInfo)
        {
            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.RequestsTracer, this, "EntitySyncCollection.ConvertServerToClientObject");
            IItem item  = ((EntitySyncItem)syncItem).Item;
            Item  item2 = ((EntitySyncItem)syncItem).NativeItem as Item;

            if (item2 == null || !this.EntityDataObject.CanConvertItemClassUsingCurrentSchema(item2.ClassName))
            {
                throw new ConversionException(string.Format("Cannot convert item '{0}' of .NET type \"{1}\" using current schema.  ClassName: '{2}'", item.Id, item.GetType().FullName, (item2 == null) ? "<NULL>" : item2.ClassName));
            }
            try
            {
                base.AirSyncDataObject.Bind(airSyncParentNode);
                this.EntityDataObject.Bind(item);
                AirSyncDiagnostics.FaultInjectionTracer.TraceTest(2170957117U);
                base.AirSyncDataObject.CopyFrom(this.EntityDataObject);
            }
            finally
            {
                this.EntityDataObject.Unbind();
                base.AirSyncDataObject.Unbind();
            }
            base.ApplyChangeTrackFilter(changeObject, airSyncParentNode);
            base.SetHasChanges(changeObject);
        }
        private void ProcessSet(XmlNode setNode)
        {
            using (this.command.Context.Tracker.Start(TimeId.DeviceInfoProcessSet))
            {
                AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Processing DeviceInformation - Set");
                foreach (object obj in setNode.ChildNodes)
                {
                    XmlNode xmlNode   = (XmlNode)obj;
                    string  innerText = xmlNode.InnerText;
                    string  localName;
                    switch (localName = xmlNode.LocalName)
                    {
                    case "Model":
                        this.deviceModel = DeviceClassCache.NormalizeDeviceClass(innerText);
                        break;

                    case "IMEI":
                        this.deviceImei = innerText;
                        break;

                    case "FriendlyName":
                        this.deviceFriendlyName = innerText;
                        break;

                    case "OS":
                        this.deviceOS = innerText;
                        break;

                    case "OSLanguage":
                        this.deviceOSLanguage = innerText;
                        break;

                    case "PhoneNumber":
                        this.devicePhoneNumber = innerText;
                        break;

                    case "UserAgent":
                        this.deviceUserAgent = innerText;
                        break;

                    case "EnableOutboundSMS":
                    {
                        string a;
                        if (this.command.User.IsConsumerOrganizationUser)
                        {
                            this.deviceEnableOutboundSMS = false;
                        }
                        else if ((a = innerText) != null)
                        {
                            if (!(a == "0"))
                            {
                                if (a == "1")
                                {
                                    this.deviceEnableOutboundSMS = true;
                                }
                            }
                            else
                            {
                                this.deviceEnableOutboundSMS = false;
                            }
                        }
                        break;
                    }

                    case "MobileOperator":
                        this.deviceMobileOperator = innerText;
                        break;

                    case "Annotations":
                        this.command.RequestAnnotations.ParseWLAnnotations(xmlNode, "DeviceInformation");
                        break;
                    }
                }
                if (this.command.RequestAnnotations.ContainsAnnotation("CreateChatsFolder", "DeviceInformation"))
                {
                    this.CreateSmsAndChatsSyncFolder();
                }
                bool       flag       = false;
                GlobalInfo globalInfo = this.command.GlobalInfo;
                globalInfo.DeviceModel        = this.deviceModel;
                globalInfo.DeviceImei         = this.deviceImei;
                globalInfo.DeviceFriendlyName = this.deviceFriendlyName;
                globalInfo.UserAgent          = this.deviceUserAgent;
                string text;
                if (this.command.Context.Request.DeviceIdentity.DeviceType.ToUpper().Contains("SAMSUNG") && this.command.TryParseDeviceOSFromUserAgent(out text))
                {
                    this.deviceOS = text;
                }
                globalInfo.DeviceOS          = this.deviceOS;
                globalInfo.DeviceOSLanguage  = this.deviceOSLanguage;
                globalInfo.DevicePhoneNumber = this.devicePhoneNumber;
                string text2 = string.IsNullOrEmpty(this.devicePhoneNumber) ? globalInfo.DevicePhoneNumberForSms : this.devicePhoneNumber;
                if (string.IsNullOrEmpty(text2))
                {
                    text2 = Guid.NewGuid().GetHashCode().ToString("D3", CultureInfo.InvariantCulture);
                    globalInfo.DevicePhoneNumberForSms = text2;
                }
                else
                {
                    flag |= (string.Compare(text2, globalInfo.DevicePhoneNumberForSms, StringComparison.Ordinal) != 0);
                }
                flag |= (this.deviceEnableOutboundSMS != globalInfo.DeviceEnableOutboundSMS);
                globalInfo.DeviceMobileOperator      = this.deviceMobileOperator;
                globalInfo.DeviceInformationReceived = true;
                SmsSqmDataPointHelper.AddDeviceInfoReceivedDataPoint(SmsSqmSession.Instance, this.mailboxSession.MailboxOwner.ObjectId, this.mailboxSession.MailboxOwner.LegacyDn, this.command.Request.DeviceIdentity.DeviceType, this.command.Request.VersionString);
                if (flag)
                {
                    try
                    {
                        using (VersionedXmlDataProvider versionedXmlDataProvider = new VersionedXmlDataProvider(this.mailboxSession))
                        {
                            TextMessagingAccount textMessagingAccount = (TextMessagingAccount)versionedXmlDataProvider.Read <TextMessagingAccount>(this.mailboxSession.MailboxOwner.ObjectId);
                            IRecipientSession    adrecipientSession   = this.mailboxSession.GetADRecipientSession(false, ConsistencyMode.FullyConsistent);
                            ADRecipient          adrecipient          = adrecipientSession.Read(this.mailboxSession.MailboxOwner.ObjectId);
                            this.command.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, adrecipientSession.LastUsedDc);
                            if (adrecipient == null)
                            {
                                throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerError, new LocalizedString("Cannot find AD Recipient correlated to the text messaging account"), false)
                                      {
                                          ErrorStringForProtocolLogger = "NoUserAccountForSms"
                                      };
                            }
                            E164Number e164Number = null;
                            E164Number.TryParse(text2, out e164Number);
                            if (this.deviceEnableOutboundSMS)
                            {
                                if (e164Number == null)
                                {
                                    throw new AirSyncPermanentException(StatusCode.Sync_ServerError, new LocalizedString(string.Format("Cannot parse phone number {0} into a E164 number.", text2)), false)
                                          {
                                              ErrorStringForProtocolLogger = "BadSmsPhoneNum"
                                          };
                                }
                                bool notificationEnabled = textMessagingAccount.NotificationPhoneNumber != null && textMessagingAccount.NotificationPhoneNumberVerified;
                                textMessagingAccount.SetEasEnabled(e164Number, this.syncStateStorage.DeviceIdentity.Protocol, this.syncStateStorage.DeviceIdentity.DeviceType, this.syncStateStorage.DeviceIdentity.DeviceId, this.deviceFriendlyName);
                                TextMessagingHelper.SaveTextMessagingAccount(textMessagingAccount, versionedXmlDataProvider, adrecipient, adrecipientSession);
                                this.command.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, adrecipientSession.LastUsedDc);
                                SmsSqmDataPointHelper.AddEasConfigurationDataPoint(SmsSqmSession.Instance, this.mailboxSession.MailboxOwner.ObjectId, this.mailboxSession.MailboxOwner.LegacyDn, this.command.Request.DeviceIdentity.DeviceType, notificationEnabled, this.command.Request.VersionString);
                            }
                            else if (textMessagingAccount.EasEnabled && textMessagingAccount.EasPhoneNumber == e164Number)
                            {
                                textMessagingAccount.SetEasDisabled();
                                TextMessagingHelper.SaveTextMessagingAccount(textMessagingAccount, versionedXmlDataProvider, adrecipient, adrecipientSession);
                                this.command.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, adrecipientSession.LastUsedDc);
                            }
                        }
                        globalInfo.DevicePhoneNumberForSms = text2;
                        globalInfo.DeviceEnableOutboundSMS = this.deviceEnableOutboundSMS;
                    }
                    catch (StoragePermanentException innerException)
                    {
                        throw new AirSyncPermanentException(StatusCode.ServerError, new LocalizedString("Server Error when trying to update SMS settings."), innerException, false)
                              {
                                  ErrorStringForProtocolLogger = "SmsSettingsSaveError"
                              };
                    }
                }
                this.OutputToIISLog();
            }
        }
        // Token: 0x060000B8 RID: 184 RVA: 0x00007D00 File Offset: 0x00005F00
        private MobileDevice CreateMobileDevice(GlobalInfo globalInfo, ExDateTime syncStorageCreationTime, bool checkForMaxDevices, bool retryIfFailed, MailboxSession mailboxSession)
        {
            ActiveSyncDevices activeSyncDevices = this.GetActiveSyncDeviceContainer();

            if (activeSyncDevices == null)
            {
                activeSyncDevices = this.CreateActiveSyncDeviceContainer(true);
            }
            AirSyncDiagnostics.TraceInfo <MobileClientType, DeviceIdentity, string>(ExTraceGlobals.RequestsTracer, null, "ADDeviceManager::CreateMobileDevice - ClientType: {0}, DeviceIdentity: {1}, mailboxSession from: {2}", this.clientType, this.deviceIdentity, (mailboxSession == null) ? "CurrentCommand" : "parameter");
            this.CleanUpOldDevices(mailboxSession ?? Command.CurrentCommand.MailboxSession);
            MobileDevice      mobileDevice     = this.InternalCreateDevice(globalInfo, syncStorageCreationTime);
            IThrottlingPolicy throttlingPolicy = (this.budget != null) ? this.budget.ThrottlingPolicy : null;

            if (checkForMaxDevices && throttlingPolicy != null)
            {
                if (!throttlingPolicy.EasMaxDevices.IsUnlimited)
                {
                    MobileDevice[] easDevices = null;
                    ADNotificationAdapter.RunADOperation(delegate()
                    {
                        easDevices = this.session.Find <MobileDevice>(MobileDevice.GetRootId(this.userId), QueryScope.OneLevel, new ComparisonFilter(ComparisonOperator.LessThanOrEqual, ADObjectSchema.ExchangeVersion, ExchangeObjectVersion.Exchange2012), null, 0);
                    });
                    if (this.protocolLogger != null)
                    {
                        this.protocolLogger.SetValue(ProtocolLoggerData.DomainController, this.session.LastUsedDc);
                    }
                    if (easDevices != null && (long)easDevices.Length >= (long)((ulong)throttlingPolicy.EasMaxDevices.Value))
                    {
                        this.SendMaxDevicesExceededMailIfNeeded(easDevices.Length, throttlingPolicy.EasMaxDevices.Value);
                        throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.MaximumDevicesReached, null, false)
                              {
                                  ErrorStringForProtocolLogger = "MaxDevicesExceeded"
                              };
                    }
                }
                else
                {
                    AirSyncDiagnostics.TraceDebug(this.tracer, this, "throttlingPolicy.EasMaxDevices is unlimited. Skipping max devices check.");
                }
            }
            else
            {
                AirSyncDiagnostics.TraceDebug(this.tracer, this, "No throttling policy is found. Skipping max devices check.");
            }
            switch (mobileDevice.ClientType)
            {
            case MobileClientType.EAS:
                mobileDevice.SetId(activeSyncDevices.Id.GetChildId(ADDeviceManager.EasDeviceCnString(mobileDevice)));
                break;

            case MobileClientType.MOWA:
                mobileDevice.SetId(activeSyncDevices.Id.GetChildId(ADDeviceManager.MowaDeviceCnString(mobileDevice)));
                break;

            default:
                throw new PlatformNotSupportedException("New MobileClientType is not supported.");
            }
            try
            {
                ADNotificationAdapter.RunADOperation(delegate()
                {
                    this.session.Save(mobileDevice);
                });
            }
            catch (ADObjectAlreadyExistsException)
            {
                mobileDevice = this.GetMobileDevice();
                if (mobileDevice == null)
                {
                    throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerErrorRetryLater, EASServerStrings.FailedToCreateNewActiveDevice(this.deviceIdentity.DeviceId, this.deviceIdentity.DeviceType, this.userName), true)
                          {
                              ErrorStringForProtocolLogger = "CreateActiveSyncDevice:ADObjectAlreadyExistsException"
                          };
                }
                if (globalInfo != null)
                {
                    this.UpdateMobileDevice(mobileDevice, globalInfo);
                }
            }
            catch (ADOperationException ex)
            {
                DirectoryOperationException ex2 = ex.InnerException as DirectoryOperationException;
                if (retryIfFailed)
                {
                    if (ex.ErrorCode != 5)
                    {
                        if (ex2 == null || ex2.Response == null || ex2.Response.ResultCode != ResultCode.InsufficientAccessRights)
                        {
                            goto IL_308;
                        }
                    }
                    try
                    {
                        this.SetActiveSyncDeviceContainerPermissions(activeSyncDevices);
                    }
                    catch (ADOperationException ex3)
                    {
                        throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerErrorRetryLater, EASServerStrings.FailedToApplySecurityToContainer(activeSyncDevices.DistinguishedName), ex3, true)
                              {
                                  ErrorStringForProtocolLogger = "SetEASDevContainerPerms:ADOperationException:" + ex3.Message
                              };
                    }
                    return(this.CreateMobileDevice(globalInfo, syncStorageCreationTime, checkForMaxDevices, false, mailboxSession));
                }
IL_308:
                AirSyncDiagnostics.LogEvent(this.unableToCreateADDeviceEventTuple, new string[]
                {
                    mobileDevice.DeviceType,
                    mobileDevice.DeviceId,
                    activeSyncDevices.Id.ToDNString(),
                    ex.Message
                });
                throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerErrorRetryLater, ex, false)
                      {
                          ErrorStringForProtocolLogger = "CreateActiveSyncDevice:ADOperationException" + ex.Message
                      };
            }
            return(mobileDevice);
        }
        // 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);
        }
Example #21
0
 internal DevicePasswordSetting(XmlNode request, XmlNode response, IAirSyncUser user, GlobalInfo globalInfo, ProtocolLogger protocolLogger) : base(request, response, protocolLogger)
 {
     this.user = user;
     if (globalInfo == null)
     {
         throw new ArgumentNullException("globalInfo should not be null here!");
     }
     this.globalInfo = globalInfo;
 }