Exemple #1
0
 public bool HasDomainAmbigiousName(DomainKey domainKey)
 {
     if (AmbigiousNameReference.ContainsKey(domainKey.DomainName))
     {
         return(AmbigiousNameReference[domainKey.DomainName].Count > 1);
     }
     return(true);
 }
 public bool HasDomainAmbigiousName(DomainKey domainKey)
 {
     if (domainKey == null || string.IsNullOrEmpty(domainKey.DomainName))
     {
         return(false);
     }
     if (AmbigiousNameReference.ContainsKey(domainKey.DomainName))
     {
         return(AmbigiousNameReference[domainKey.DomainName].Count > 1);
     }
     return(true);
 }
        public void EnrichInformation()
        {
            // complete domain information
            // indeed, data can be FQDN only (trust with remote deleted)
            // NetBIOS + SID (SID History and unable to locate a server)
            // SID Only (SID History from removed domain)
            AmbigiousNameReference.Clear();

            var sidreference = new Dictionary <string, DomainKey>();

            // first pass - build reference based on SID
            foreach (var item in data.Values)
            {
                foreach (var domainKey in item.DomainKnown)
                {
                    if (domainKey.IsComplete && !sidreference.ContainsKey(domainKey.DomainSID))
                    {
                        sidreference.Add(domainKey.DomainSID, domainKey);
                    }
                }
            }
            // second pass, build AmbigiousNameReference
            foreach (var domain in sidreference.Values)
            {
                if (!AmbigiousNameReference.ContainsKey(domain.DomainName))
                {
                    AmbigiousNameReference[domain.DomainName] = new List <string> {
                        domain.DomainSID
                    }
                }
                ;
                else if (!string.IsNullOrEmpty(domain.DomainSID))
                {
                    if (!AmbigiousNameReference[domain.DomainName].Contains(domain.DomainSID))
                    {
                        AmbigiousNameReference[domain.DomainName].Add(domain.DomainSID);
                    }
                }
            }
            // third pass, update incomplete information based on the information we have
            foreach (var item in data.Values)
            {
                foreach (var domainKey in item.DomainKnown)
                {
                    if (domainKey.IsComplete)
                    {
                        continue;
                    }
                    // try to complete based on sid
                    if (!String.IsNullOrEmpty(domainKey.DomainSID) && sidreference.ContainsKey(domainKey.DomainSID))
                    {
                        var reference = sidreference[domainKey.DomainSID];
                        if (string.IsNullOrEmpty(domainKey.DomainNetBIOS))
                        {
                            domainKey.DomainNetBIOS = reference.DomainNetBIOS;
                        }
                        if (string.IsNullOrEmpty(domainKey.DomainName))
                        {
                            domainKey.DomainName = reference.DomainName;
                        }
                    }
                    else if (!String.IsNullOrEmpty(domainKey.DomainName))
                    {
                        foreach (var reference in sidreference.Values)
                        {
                            if (reference.DomainName == domainKey.DomainName)
                            {
                                if (string.IsNullOrEmpty(domainKey.DomainNetBIOS))
                                {
                                    domainKey.DomainNetBIOS = reference.DomainNetBIOS;
                                }
                                break;
                            }
                        }
                    }
                    else if (!String.IsNullOrEmpty(domainKey.DomainNetBIOS))
                    {
                        foreach (var reference in sidreference.Values)
                        {
                            if (reference.DomainNetBIOS == domainKey.DomainNetBIOS)
                            {
                                if (string.IsNullOrEmpty(domainKey.DomainName))
                                {
                                    domainKey.DomainName = reference.DomainName;
                                }
                                if (string.IsNullOrEmpty(domainKey.DomainName))
                                {
                                    domainKey.DomainName = reference.DomainName;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }