Beispiel #1
0
        private void RecalculateAccessRules()
        {
            if (this.m_accessRules == null)
            {
                this.m_accessRules = new List <FileSystemAccessRule>();
            }
            string text = NativeHelpers.GetDomainName();
            int    num  = text.IndexOf('.');

            if (num > -1)
            {
                text = text.Substring(0, num);
            }
            ComparisonFilter filter = new ComparisonFilter(ComparisonOperator.Equal, DatabaseAvailabilityGroupSchema.Name, this.m_dagName);

            DatabaseAvailabilityGroup[] array = this.m_adSession.Find <DatabaseAvailabilityGroup>(null, QueryScope.SubTree, filter, null, 1);
            if (array == null || array.Length == 0)
            {
                this.m_accessRules.Clear();
                TaskLogger.Trace("Account {0}$ for witness share \\\\{1}\\{2} does not exist yet, assuming we are working with empty dag, fsw will be created with current user {3} permissions and removed.", new object[]
                {
                    this.m_dagName,
                    this.WitnessServer,
                    this.ShareName,
                    WindowsIdentity.GetCurrent().User
                });
                FileSystemAccessRule item = new FileSystemAccessRule(WindowsIdentity.GetCurrent().User.Translate(typeof(NTAccount)) as NTAccount, FileSystemRights.FullControl, AccessControlType.Allow);
                this.m_accessRules.Add(item);
                return;
            }
            MultiValuedProperty <IPAddress> databaseAvailabilityGroupIpAddresses = array[0].DatabaseAvailabilityGroupIpAddresses;
            bool flag = databaseAvailabilityGroupIpAddresses == null || databaseAvailabilityGroupIpAddresses.Count != 1 || !IPAddress.None.Equals(databaseAvailabilityGroupIpAddresses[0]);

            if (flag)
            {
                bool flag2 = true;
                if (this.m_accessRules.Count == 1)
                {
                    if (this.m_accessRules[0].IdentityReference.Value.Contains(this.m_dagName))
                    {
                        flag2 = false;
                    }
                    else
                    {
                        this.m_accessRules.Clear();
                    }
                }
                if (flag2)
                {
                    ITopologyConfigurationSession topologyConfigurationSession = this.CreateRootSession();
                    DateTime   t = DateTime.UtcNow.AddMinutes(6.0);
                    ADComputer adcomputer;
                    for (adcomputer = topologyConfigurationSession.FindComputerByHostName(this.m_dagName); adcomputer == null; adcomputer = topologyConfigurationSession.FindComputerByHostName(this.m_dagName))
                    {
                        if (DateTime.UtcNow > t)
                        {
                            throw new DagUnableToFindCnoException(this.m_dagName);
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(20.0));
                    }
                    IdentityReference    identity = adcomputer.Sid.Translate(typeof(NTAccount));
                    FileSystemAccessRule item2    = new FileSystemAccessRule(identity, FileSystemRights.FullControl, AccessControlType.Allow);
                    this.m_accessRules.Add(item2);
                    return;
                }
            }
            else
            {
                bool       flag3     = false;
                IAmCluster amCluster = null;
                DatabaseAvailabilityGroup databaseAvailabilityGroup = array[0];
                List <AmServerName>       list = new List <AmServerName>();
                try
                {
                    if (!this.m_clusterReference.TryGetTarget(out amCluster) || (amCluster is AmCluster && ((AmCluster)amCluster).IsDisposed))
                    {
                        amCluster = null;
                        foreach (ADObjectId adobjectId in databaseAvailabilityGroup.Servers)
                        {
                            AmServerName amServerName = new AmServerName(adobjectId);
                            if (!databaseAvailabilityGroup.StoppedMailboxServers.Contains(amServerName.Fqdn) && (databaseAvailabilityGroup.ServersInMaintenance == null || !databaseAvailabilityGroup.ServersInMaintenance.Contains(adobjectId)))
                            {
                                amCluster = ClusterFactory.Instance.OpenByName(amServerName);
                                if (amCluster != null)
                                {
                                    flag3 = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (amCluster != null)
                    {
                        using (IEnumerator <IAmClusterNode> enumerator2 = amCluster.EnumerateNodes().GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                IAmClusterNode amClusterNode = enumerator2.Current;
                                list.Add(amClusterNode.Name);
                            }
                            goto IL_352;
                        }
                    }
                    foreach (ADObjectId serverId in databaseAvailabilityGroup.Servers)
                    {
                        list.Add(new AmServerName(serverId));
                    }
                    IL_352 :;
                }
                finally
                {
                    if (flag3 && amCluster != null)
                    {
                        amCluster.Dispose();
                    }
                }
                this.m_accessRules.Clear();
                ITopologyConfigurationSession topologyConfigurationSession2 = this.CreateRootSession();
                foreach (AmServerName amServerName2 in list)
                {
                    ADComputer           adcomputer2 = topologyConfigurationSession2.FindComputerByHostName(amServerName2.NetbiosName);
                    IdentityReference    identity2   = adcomputer2.Sid.Translate(typeof(NTAccount));
                    FileSystemAccessRule item3       = new FileSystemAccessRule(identity2, FileSystemRights.FullControl, AccessControlType.Allow);
                    this.m_accessRules.Add(item3);
                }
            }
        }