private void RegisterExchangeTopologyNotification()
        {
            Exception ex = null;

            try
            {
                lock (this.registeredExchangeTopologyNotificationLock)
                {
                    this.registeredExchangeTopologyNotification = ServiceDiscovery.ExchangeTopologyBridge.RegisterExchangeTopologyNotification(new ADNotificationCallback(this.ADNotificationCallback), this.scope);
                }
            }
            catch (ServiceDiscoveryPermanentException ex2)
            {
                ex = ex2;
            }
            catch (ServiceDiscoveryTransientException ex3)
            {
                ex = ex3;
            }
            if (ex == null)
            {
                ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug(0L, "ADNotificationHandler::RegisterExchangeTopologyNotification. Successfully registered for ExchangeTopologyNotification.");
                ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_RegisteredForTopologyChangedNotification, null, new object[0]);
                return;
            }
            string text = ex.ToString().TruncateToUseInEventLog();

            ExTraceGlobals.ServiceDiscoveryTracer.TraceError <string>(0L, "ADNotificationHandler::RegisterExchangeTopologyNotification. Failed to Failed to register for ExchangeTopologyNotification. Error = {0}", text);
            ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorRegisteringForTopologyChangedNotification, null, new object[]
            {
                text
            });
        }
Пример #2
0
 private void RefreshCache()
 {
     try
     {
         IRecipientSession recipientSession  = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, true, ConsistencyMode.IgnoreInvalid, null, this.adSettings, ConfigScopes.TenantSubTree, 208, "RefreshCache", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Auditing\\AuditCaches.cs");
         QueryFilter       filter            = new ComparisonFilter(ComparisonOperator.Equal, ADRecipientSchema.AuditBypassEnabled, true);
         ADRawEntry[]      recipients        = null;
         ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
         {
             recipients = recipientSession.Find(null, QueryScope.SubTree, filter, null, 0, BypassAuditCache.OrganizationCache.queryProperties);
         });
         if (adoperationResult.Succeeded)
         {
             HashSet <SecurityIdentifier> hashSet = null;
             if (recipients != null && recipients.Length > 0)
             {
                 hashSet = new HashSet <SecurityIdentifier>();
                 foreach (ADRawEntry adrawEntry in recipients)
                 {
                     SecurityIdentifier securityIdentifier = adrawEntry[IADSecurityPrincipalSchema.Sid] as SecurityIdentifier;
                     if (null != securityIdentifier && !hashSet.Contains(securityIdentifier))
                     {
                         hashSet.Add(securityIdentifier);
                     }
                 }
             }
             Interlocked.Exchange <HashSet <SecurityIdentifier> >(ref this.bypassingUserSid, hashSet);
         }
         else
         {
             ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorReadingBypassAudit, this.adSettings.CurrentOrganizationId.ToString(), new object[]
             {
                 this.adSettings.CurrentOrganizationId,
                 adoperationResult.Exception
             });
         }
     }
     finally
     {
         this.refreshTimer.Change(this.RefreshInterval, new TimeSpan(0, 0, 0, 0, -1));
     }
 }
Пример #3
0
        private ExternalAccessCache.OrganizationInfo GetOrganizationInfo(SecurityIdentifier logonSid)
        {
            Util.ThrowOnNullArgument(logonSid, "logonSid");
            ADRecipient       recipient         = null;
            ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                recipient = this.recipientSession.FindBySid(logonSid);
            });

            if (adoperationResult.Succeeded && recipient != null)
            {
                return(new ExternalAccessCache.OrganizationInfo
                {
                    OrgIdGuid = ((recipient.OrganizationId.OrganizationalUnit == null) ? Guid.Empty : recipient.OrganizationId.OrganizationalUnit.ObjectGuid),
                    LastAccessed = DateTime.UtcNow
                });
            }
            ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorResolvingLogonUser, logonSid.ToString(), new object[]
            {
                logonSid,
                adoperationResult.Exception
            });
            return(null);
        }
Пример #4
0
        private void PopulateServiceCache(object obj)
        {
            ServiceCache.CachePopulateReason cachePopulateReason = (ServiceCache.CachePopulateReason)obj;
            Exception ex = null;

            try
            {
                try
                {
                    DateTime dateTime     = (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || this.serviceTopologyInstance == null) ? DateTime.MinValue : this.serviceTopologyInstance.DiscoveryStarted;
                    bool     forceRefresh = false;
                    if (this.dropCacheOnInactivity && dateTime != DateTime.MinValue && this.serviceTopologyInstance.TopologyRequestCount <= 1)
                    {
                        this.DropCache();
                        return;
                    }
                    if (cachePopulateReason == ServiceCache.CachePopulateReason.CacheMissDetected || (cachePopulateReason == ServiceCache.CachePopulateReason.CacheNotPresent && this.isFirstLoad))
                    {
                        forceRefresh = true;
                    }
                    ExchangeTopology exchangeTopology = ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology(dateTime, ExchangeTopologyScope.Complete, forceRefresh);
                    if (exchangeTopology != null)
                    {
                        this.serviceTopologyInstance = new ServiceTopology(exchangeTopology, "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\ServiceDiscovery\\ServiceCache.cs", "PopulateServiceCache", 426);
                    }
                    else if (this.serviceTopologyInstance != null)
                    {
                        this.serviceTopologyInstance.CreationTime = ExDateTime.Now;
                    }
                    this.isFirstLoad = false;
                    if (this.serviceTopologyInstance != null)
                    {
                        this.cachePresentEvent.Set();
                    }
                    else
                    {
                        ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug(0L, "ServiceCache::ServiceDiscovery.ExchangeTopologyBridge.ReadExchangeTopology returned null. This is unexpected");
                    }
                }
                catch (ServiceDiscoveryPermanentException ex2)
                {
                    ex = ex2;
                }
                catch (ServiceDiscoveryTransientException ex3)
                {
                    ex = ex3;
                }
                this.StartCacheRefreshTimer();
            }
            finally
            {
                this.semaphore.Release();
            }
            if (ex == null)
            {
                ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <ServiceCache.CachePopulateReason>(0L, "ServiceCache::PopulateServiceCache. Successfully populated ServiceTopology. Reason to populate cache = {0}", cachePopulateReason);
                ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_PopulatedServiceTopology, null, new object[]
                {
                    cachePopulateReason
                });
                return;
            }
            string text = ex.ToString().TruncateToUseInEventLog();

            ExTraceGlobals.ServiceDiscoveryTracer.TraceError <ServiceCache.CachePopulateReason, string>(0L, "ServiceCache::PopulateServiceCache. Failed to populate a ServiceTopology. Reason to populate cache = {0}. Error = {1}.", cachePopulateReason, text);
            ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorPopulatingServiceTopology, null, new object[]
            {
                cachePopulateReason,
                text
            });
        }
Пример #5
0
        public void UpdateHistory(CallbackContext callbackContext)
        {
            if (this.ShouldSkipAudit)
            {
                return;
            }
            MailboxSession mailboxSession = (MailboxSession)this.currentFolder.Session;
            CoreFolder     coreFolder     = null;
            StoreObjectId  objectId       = this.currentFolder.Id.ObjectId;

            if (mailboxSession.LogonType == LogonType.Delegated || mailboxSession.LogonType == LogonType.DelegatedAdmin)
            {
                Exception ex = null;
                try
                {
                    coreFolder         = CoreFolder.Bind(callbackContext.SessionWithBestAccess, objectId);
                    this.currentFolder = coreFolder;
                }
                catch (StoragePermanentException ex2)
                {
                    ex = ex2;
                }
                catch (StorageTransientException ex3)
                {
                    ex = ex3;
                }
                if (ex != null)
                {
                    ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, Exception>((long)this.currentFolder.Session.GetHashCode(), "Failed to rebind folder {0} with Admin logon. The cached RecentBindingHistory data will not be updated. Error: {1}", objectId, ex);
                    ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorBindingFolderForFolderBindHistory, objectId.ToString(), new object[]
                    {
                        objectId,
                        mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                        mailboxSession.MailboxGuid,
                        mailboxSession.LogonType,
                        IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                        COWTriggerAction.FolderBind,
                        ex
                    });
                    this.currentFolder = null;
                }
            }
            if (this.currentFolder != null)
            {
                try
                {
                    this.currentFolder.PropertyBag.SetProperty(FolderSchema.RecentBindingHistory, this.bindingHistory.ToArray());
                    FolderSaveResult folderSaveResult = this.currentFolder.Save(SaveMode.NoConflictResolutionForceSave);
                    if (coreFolder == null)
                    {
                        this.currentFolder.PropertyBag.Load(null);
                    }
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, LocalizedException>((long)this.currentFolder.Session.GetHashCode(), "Failed to save RecentBindingHistory on folder {0}. Error: {1}.", objectId, folderSaveResult.Exception);
                        ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorSavingFolderBindHistory, objectId.ToString(), new object[]
                        {
                            objectId,
                            mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                            mailboxSession.MailboxGuid,
                            mailboxSession.LogonType,
                            IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                            COWTriggerAction.FolderBind,
                            folderSaveResult.Exception
                        });
                    }
                }
                finally
                {
                    if (coreFolder != null)
                    {
                        coreFolder.Dispose();
                    }
                }
            }
        }