コード例 #1
0
        protected ImportResults PerformComputerDiscovery(IComputerPrincipalProvider provider)
        {
            OUPrincipalMapping ou = new OUPrincipalMapping($"LDAP://{settings.ImportOU}", settings.ImportOU);

            ImportResults results = new ImportResults
            {
                DiscoveryErrors = new List <DiscoveryError>(),
            };

            principalCache = new ConcurrentDictionary <SecurityIdentifier, ISecurityPrincipal>();

            this.PerformComputerDiscovery(ou, provider, results.DiscoveryErrors);

            principalCache.Clear();

            results.Targets = this.ConvertToTargets(ou);

            return(results);
        }
コード例 #2
0
        public ImportResults Import()
        {
            ImportResults results         = new ImportResults();
            string        globalChannelId = null;
            bool          onSuccessGlobal = false;
            bool          onFailureGlobal = false;
            Dictionary <string, SmtpNotificationChannelDefinition> notificationDefinitions = null;

            string      xml = File.ReadAllText(settings.ImportFile);
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            XmlNode appRootNode = doc.SelectSingleNode("/configuration/lithnet-laps");

            if (appRootNode == null)
            {
                throw new ImportException("The specified file did not appear to be a Lithnet LAPS Web App config file");
            }

            if (settings.ImportNotifications)
            {
                notificationDefinitions = CreateNotificationChannelDefinitions(appRootNode);

                foreach (KeyValuePair <string, SmtpNotificationChannelDefinition> item in notificationDefinitions)
                {
                    results.NotificationChannels.Smtp.Add(item.Value);
                }

                globalChannelId = this.GetNotificationChannelDefinitionId(appRootNode, notificationDefinitions, out onSuccessGlobal, out onFailureGlobal);
            }

            XmlNodeList targetNodes = doc.SelectNodes("/configuration/lithnet-laps/targets/target");

            if (targetNodes == null || targetNodes.Count == 0)
            {
                return(results);
            }

            foreach (XmlElement targetNode in targetNodes.OfType <XmlElement>())
            {
                this.OnItemProcessStart?.Invoke(this, new ImportProcessingEventArgs($"Processing {targetNode.SelectSingleNode("@name")?.Value}"));

                SecurityDescriptorTarget target = this.ConvertToSecurityDescriptorTarget(targetNode, out List <DiscoveryError> discoveryErrors);

                if (discoveryErrors.Count > 0)
                {
                    results.DiscoveryErrors.AddRange(discoveryErrors);
                }

                if (target == null)
                {
                    continue;
                }

                if (settings.ImportNotifications)
                {
                    string channelId = this.GetNotificationChannelDefinitionId(targetNode, notificationDefinitions, out bool onSuccess, out bool onFailure);

                    if (channelId != null)
                    {
                        if (onSuccess)
                        {
                            target.Notifications.OnSuccess.Add(channelId);
                        }

                        if (onFailure)
                        {
                            target.Notifications.OnFailure.Add(channelId);
                        }
                    }

                    if (onSuccessGlobal && globalChannelId != null)
                    {
                        target.Notifications.OnSuccess.Add(globalChannelId);
                    }

                    if (onFailureGlobal && globalChannelId != null)
                    {
                        target.Notifications.OnFailure.Add(globalChannelId);
                    }
                }

                results.Targets.Add(target);

                this.OnItemProcessFinish?.Invoke(this, new ImportProcessingEventArgs($"Processing {targetNode.SelectSingleNode("@name")?.Value}"));
            }

            return(results);
        }