private void EnrichEntity(OwnerInformationReferences EntityData) { if (EntityData == null) { return; } foreach (var entity in EntityData) { foreach (GraphNode node in data.Values) { if (entity.Domain == node.Domain) { node.Entity = entity; } } } }
public ReportHealthCheckMapBuilder(PingCastleReportCollection <HealthcheckData> consolidation, OwnerInformationReferences ownerInformationReferences) { this.Report = consolidation; EntityData = ownerInformationReferences; FullNodeMap = true; }
static public GraphNodeCollection BuildModel(PingCastleReportCollection <HealthcheckData> consolidation, OwnerInformationReferences EntityData) { GraphNodeCollection nodes = new GraphNodeCollection(); // build links based on the most to the less reliable information Trace.WriteLine("Building model"); int nodeNumber = 0; Trace.WriteLine("domain reports"); // enumerate official domains foreach (HealthcheckData data in consolidation) { GraphNode node = nodes.CreateNodeIfNeeded(ref nodeNumber, data.Domain, data.NetBIOSName, data.GenerationDate); node.HealthCheckData = data; node.SetForest(data.Forest); } Trace.WriteLine("direct trust"); // get trust map based on direct trusts data foreach (HealthcheckData data in consolidation) { GraphNode source = nodes.Locate(data); foreach (var trust in data.Trusts) { GraphNode destination = nodes.CreateNodeIfNeeded(ref nodeNumber, trust.Domain, trust.NetBiosName, data.GenerationDate); source.Link(destination, trust); } } Trace.WriteLine("forest trust"); foreach (HealthcheckData data in consolidation) { foreach (var trust in data.Trusts) { // do not examine if we have more accurate information (aka the forest report) if (consolidation.GetDomain(trust.Domain) != null) { continue; } if (trust.KnownDomains != null) { GraphNode source = nodes.Locate(trust); foreach (var domainInfo in trust.KnownDomains) { GraphNode destination = nodes.CreateNodeIfNeeded(ref nodeNumber, domainInfo.Domain, domainInfo.NetbiosName, data.GenerationDate); source.LinkInsideAForest(destination, domainInfo.CreationDate); destination.SetForest(domainInfo.Forest); } } } } Trace.WriteLine("Building reachable links"); // make links based on reachable domains. Information is less reliable. foreach (HealthcheckData data in consolidation) { // ignore report without reachable domains if (data.ReachableDomains == null) { continue; } // ignore reachable links if we have the forest domain report if (consolidation.GetDomain(data.Forest) != null) { continue; } foreach (HealthCheckTrustDomainInfoData di in data.ReachableDomains) { // domain info can contain only netbios name (not FQDN) // enrich it if (di.NetbiosName.Equals(di.DnsName, StringComparison.InvariantCultureIgnoreCase)) { EnrichDomainInfo(consolidation, di); } // if no information was given (only Netbios name!) fallback to a forest trust if (String.IsNullOrEmpty(di.ForestName) || di.ForestName == di.DnsName) { GraphNode childDomain = nodes.CreateNodeIfNeeded(ref nodeNumber, di.Domain, di.NetbiosName, data.GenerationDate); GraphNode myForestRoot = nodes.CreateNodeIfNeeded(ref nodeNumber, data.Forest, null, data.GenerationDate); myForestRoot.LinkTwoForests(childDomain); myForestRoot.SetForest(myForestRoot.Domain); } else { // ignore the domain if the forest trust is known (information should be already there) if (consolidation.GetDomain(di.Forest) != null) { continue; } // add the forest trust if needed GraphNode remoteForestRoot = nodes.CreateNodeIfNeeded(ref nodeNumber, di.Forest, di.ForestNetbios, data.GenerationDate); remoteForestRoot.SetForest(remoteForestRoot.Domain); // add the forest root if needed GraphNode myForestRoot = nodes.CreateNodeIfNeeded(ref nodeNumber, data.Forest, null, data.GenerationDate); myForestRoot.LinkTwoForests(remoteForestRoot); myForestRoot.SetForest(myForestRoot.Domain); // add the trust if the domain is a child of the forest) // (ignore the trust if forest root = trust) GraphNode childDomain = nodes.CreateNodeIfNeeded(ref nodeNumber, di.Domain, di.NetbiosName, data.GenerationDate); remoteForestRoot.LinkInsideAForest(childDomain); childDomain.SetForest(remoteForestRoot.Domain); } } } Trace.WriteLine("enrich forest information"); nodes.EnrichForestInformation(); Trace.WriteLine("done"); nodes.EnrichEntity(EntityData); nodes.RemoveDeletedNodes(); return(nodes); }
public HealthCheckReportMapBuilder(HealthcheckDataCollection consolidation, OwnerInformationReferences ownerInformationReferences) { this.consolidation = consolidation; EntityData = ownerInformationReferences; FullNodeMap = true; }