private static void HandleMissingSchemaVersionDirectory(Exception ex, string directoryPath) { bool watsonReportEnabled = true; if (ex == null || ex is ArgumentNullException || ex is SecurityException || ex is ArgumentException || ex is PathTooLongException) { watsonReportEnabled = false; } AirSyncDiagnostics.TraceError <string, string>(ExTraceGlobals.RequestsTracer, null, "SchemaDirectory with path '{0}' is missing or not accessible. Exception '{1}' ", directoryPath, (ex == null) ? string.Empty : ex.ToString()); throw new AirSyncFatalException(EASServerStrings.SchemaDirectoryVersionNotAccessible(directoryPath), "SchemaDirectoryVersionNotAccessible", watsonReportEnabled, ex); }
private static void HandleBadSchemaFile(Exception ex, string dirPath) { if (ex is XmlSchemaException) { XmlSchemaException ex2 = (XmlSchemaException)ex; string text = (ex2.SourceUri != null) ? ex2.SourceUri : string.Empty; AirSyncDiagnostics.TraceError <string, string>(ExTraceGlobals.RequestsTracer, null, "Schema file with path '{0}' is corrupted. Exception '{1}'", text, ex2.ToString()); throw new AirSyncFatalException(EASServerStrings.SchemaFileCorrupted(text), "SchemaFileCorrupted", false, ex2); } AirSyncDiagnostics.TraceError <string, string>(ExTraceGlobals.RequestsTracer, null, "Unable to compile the XSD SchemaSet under the folder '{0}'. Exception '{1}' ", dirPath, (ex == null) ? string.Empty : ex.ToString()); throw new AirSyncFatalException(EASServerStrings.SchemaUnknownCompilationError(dirPath), "SchemaUnknownCompilationError", true, ex); }
private void ConstructAdminNotificationMail(MessageItem messageToAdmin) { StringBuilder stringBuilder = new StringBuilder("<html>"); stringBuilder.Append("<style>\r\n body\r\n {\r\n font-family: Tahoma;\r\n background-color: rgb(255,255,255);\r\n color: #000000; font-size:x-small;\r\n width: 600px;\r\n }\r\n p\r\n {\r\n margin-left:0px ;\r\n margin-bottom:8px\r\n }\r\n table\r\n {\r\n font-family: Tahoma;\r\n background-color: rgb(255,255,255);\r\n color: #000000;\r\n font-size:x-small;\r\n border:0px ;\r\n text-align:left;\r\n margin-left:20px\r\n }\r\n </style>"); stringBuilder.Append("<body>"); messageToAdmin.Subject = EASServerStrings.AdminMailSubject(this.context.User.ADUser.DisplayName, this.context.User.ADUser.Alias); stringBuilder.AppendFormat("<p>{0}</p>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBody1, false)); Uri userActiveSyncOptionsPageUrl = this.GetUserActiveSyncOptionsPageUrl(); if (userActiveSyncOptionsPageUrl == null) { stringBuilder.AppendFormat("<p>{0}</p>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBody2, false)); } else { string arg = string.Format("<a href=\"{0}\">{1}</a>", userActiveSyncOptionsPageUrl.AbsoluteUri, userActiveSyncOptionsPageUrl.AbsoluteUri); string arg2 = string.Format(AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBody4, false), arg); stringBuilder.AppendFormat("<p>{0}</p>", arg2); } stringBuilder.Append("<p>"); stringBuilder.Append(AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailDeviceInformation, false)); stringBuilder.Append("<table>"); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailUser, false), AirSyncUtility.HtmlEncode(this.context.User.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(), false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceModel, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceModel, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceType, false), AirSyncUtility.HtmlEncode(this.context.DeviceIdentity.DeviceType, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceID, false), AirSyncUtility.HtmlEncode(this.context.DeviceIdentity.DeviceId, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceOS, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceOS, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceUserAgent, false), AirSyncUtility.HtmlEncode(this.globalInfo.UserAgent, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailDevicePhoneNumber, false), AirSyncUtility.HtmlEncode(DeviceInfo.ObfuscatePhoneNumber(this.globalInfo.DevicePhoneNumber), false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceIMEI, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceImei, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyEASVersion, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceActiveSyncVersion, false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailDevicePolicyApplied, false), (this.globalInfo.DevicePolicyApplied != null) ? AirSyncUtility.HtmlEncode(this.globalInfo.DevicePolicyApplied.ToString(), false) : null); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailDevicePolicyStatus, false), AirSyncUtility.HtmlEncode(this.globalInfo.DevicePolicyApplicationStatus.ToString(), false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceAccessState, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceAccessState.ToString(), false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodyDeviceAccessStateReason, false), AirSyncUtility.HtmlEncode(this.globalInfo.DeviceAccessStateReason.ToString(), false)); stringBuilder.AppendFormat("<tr><td>{0}</td><td>{1}</td></tr>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailDeviceAccessControlRule, false), (this.globalInfo.DeviceAccessControlRule != null) ? AirSyncUtility.HtmlEncode(this.globalInfo.DeviceAccessControlRule.ToString(), false) : null); stringBuilder.Append("</table></p>"); StringBuilder stringBuilder2 = new StringBuilder(); foreach (SmtpAddress smtpAddress in this.organizationSettings.AdminMailRecipients) { stringBuilder2.AppendFormat("{0},", smtpAddress.ToString()); } stringBuilder.AppendFormat("<p>{0}</p>", AirSyncUtility.HtmlEncode(EASServerStrings.AdminMailBodySentAt(ExDateTime.Now.ToString(), stringBuilder2.ToString()), false)); stringBuilder.Append("</body></html>"); using (TextWriter textWriter = messageToAdmin.Body.OpenTextWriter(BodyFormat.TextHtml)) { textWriter.Write(stringBuilder.ToString()); } }
// Token: 0x060005BB RID: 1467 RVA: 0x000221F0 File Offset: 0x000203F0 private static bool IsRuleValueMatch(ActiveSyncDeviceFilterRule rule, string actualValue) { switch (rule.Operator) { case DeviceFilterOperator.Equals: return(string.Equals(actualValue, rule.Value, StringComparison.OrdinalIgnoreCase)); case DeviceFilterOperator.Contains: return(AirSyncUtility.AreNotNullOrEmptyAndContains(actualValue, rule.Value)); case DeviceFilterOperator.StartsWith: return(AirSyncUtility.AreNotNullOrEmptyAndStartsWith(actualValue, rule.Value)); case DeviceFilterOperator.Regex: return(AirSyncUtility.AreNotNullOrEmptyAndRegexMatches(actualValue, rule.Value, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant)); default: throw new DeviceFilterInvalidException(EASServerStrings.InvalidDeviceFilterOperatorError(rule.Operator.ToString())); } }
// Token: 0x060000BB RID: 187 RVA: 0x0000858C File Offset: 0x0000678C private void SetActiveSyncDeviceContainerPermissions(ActiveSyncDevices container) { ADDeviceManager.ReadStaticADData(this.protocolLogger); RawSecurityDescriptor rawSecurityDescriptor = null; ADNotificationAdapter.RunADOperation(delegate() { rawSecurityDescriptor = this.session.ReadSecurityDescriptor(container.Id); }); if (rawSecurityDescriptor == null) { if (this.protocolLogger != null) { this.protocolLogger.SetValue(ProtocolLoggerData.Error, "ADObjectWithNoSecurityDescriptor"); } AirSyncPermanentException ex = new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerError, EASServerStrings.NullNTSD(container.Id.DistinguishedName), true); throw ex; } AirSyncDiagnostics.TraceDebug <string>(this.tracer, this, "Setting ACL on device container for user \"{0}\".", this.userName); ActiveDirectorySecurity acl = new ActiveDirectorySecurity(); byte[] array = new byte[rawSecurityDescriptor.BinaryLength]; rawSecurityDescriptor.GetBinaryForm(array, 0); acl.SetSecurityDescriptorBinaryForm(array); acl.AddAccessRule(new ActiveDirectoryAccessRule(ADDeviceManager.exchangeServersGroupSid, ActiveDirectoryRights.CreateChild | ActiveDirectoryRights.DeleteChild | ActiveDirectoryRights.ListChildren | ActiveDirectoryRights.ReadProperty | ActiveDirectoryRights.WriteProperty | ActiveDirectoryRights.ListObject, AccessControlType.Allow, ADDeviceManager.activeSyncDeviceClass, ActiveDirectorySecurityInheritance.None)); acl.AddAccessRule(new ActiveDirectoryAccessRule(ADDeviceManager.exchangeServersGroupSid, ActiveDirectoryRights.Delete | ActiveDirectoryRights.ReadProperty | ActiveDirectoryRights.WriteProperty | ActiveDirectoryRights.ListObject, AccessControlType.Allow, ActiveDirectorySecurityInheritance.Children, ADDeviceManager.activeSyncDeviceClass)); ADNotificationAdapter.RunADOperation(delegate() { this.session.SaveSecurityDescriptor(container, new RawSecurityDescriptor(acl.GetSecurityDescriptorBinaryForm(), 0)); }); }
// 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: 0x060000B6 RID: 182 RVA: 0x000077F0 File Offset: 0x000059F0 private static void ReadStaticADData(ProtocolLogger logger) { if (!ADDeviceManager.initialized) { lock (ADDeviceManager.syncLock) { if (!ADDeviceManager.initialized) { ITopologyConfigurationSession configSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 587, "ReadStaticADData", "f:\\15.00.1497\\sources\\dev\\AirSync\\src\\AirSync\\ADDeviceManager.cs"); configSession.UseConfigNC = false; configSession.UseGlobalCatalog = true; ADGroup exchangeServersGroup = null; ADNotificationAdapter.RunADOperation(delegate() { exchangeServersGroup = configSession.ResolveWellKnownGuid <ADGroup>(WellKnownGuid.ExSWkGuid, configSession.ConfigurationNamingContext); }); if (exchangeServersGroup == null) { throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerError, EASServerStrings.FailedToResolveWellKnownGuid(WellKnownGuid.ExSWkGuid.ToString(), "Exchange Server Security Group"), true) { ErrorStringForProtocolLogger = "ExSrvGrpSchemaGuidNotFound" }; } ADDeviceManager.exchangeServersGroupSid = exchangeServersGroup.Sid; if (logger != null) { logger.SetValue(ProtocolLoggerData.DomainController, configSession.LastUsedDc); } configSession.UseGlobalCatalog = false; ADSchemaClassObject[] objClass = null; ADNotificationAdapter.RunADOperation(delegate() { objClass = configSession.Find <ADSchemaClassObject>(configSession.SchemaNamingContext, QueryScope.OneLevel, new ComparisonFilter(ComparisonOperator.Equal, ADSchemaObjectSchema.DisplayName, "msExchActiveSyncDevice"), ADDeviceManager.defaultSortOrder, 2); }); if (objClass == null || objClass.Length == 0 || objClass[0].SchemaIDGuid == Guid.Empty) { throw new AirSyncPermanentException(HttpStatusCode.InternalServerError, StatusCode.ServerError, EASServerStrings.CannotFindSchemaClassException("msExchActiveSyncDevice", configSession.SchemaNamingContext.DistinguishedName), true); } if (objClass.Length > 1 && logger != null) { logger.SetValue(ProtocolLoggerData.Error, "DisplayNameIsNotUniqueForClassMsExchActiveSyncDevice"); } ADDeviceManager.activeSyncDeviceClass = objClass[0].SchemaIDGuid; if (logger != null) { logger.SetValue(ProtocolLoggerData.DomainController, configSession.LastUsedDc); } ADDeviceManager.initialized = true; } } } }