Пример #1
0
        protected void ValidateConfiguration()
        {
            // if no AntimalwareConfiguration XmlDocument was provided, use the AntimalwareConfigFile parameter
            if ((AntimalwareConfiguration == null) && (AntimalwareConfigFile != null))
            {
                if ((!string.IsNullOrWhiteSpace(AntimalwareConfigFile)) && File.Exists(AntimalwareConfigFile))
                {
                    AntimalwareConfiguration             = new XmlDocument();
                    AntimalwareConfiguration.XmlResolver = null;
                    AntimalwareConfiguration.Load(AntimalwareConfigFile);
                }
                else
                {
                    ThrowTerminatingError(new ErrorRecord(
                                              new Exception("ServiceExtensionCannotFindAntimalwareConfigFile"),
                                              string.Empty,
                                              ErrorCategory.InvalidData,
                                              null));
                }
            }

            // read values from xml file if provided
            if (AntimalwareConfiguration != null)
            {
                // check for antimalware enabled
                XmlNode antimalwareEnabledNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/AntimalwareEnabled");
                if ((antimalwareEnabledNode != null) && (antimalwareEnabledNode.InnerText != null))
                {
                    isAntimalwareEnabled = antimalwareEnabledNode.InnerText.ToUpperInvariant().Equals("TRUE");
                }

                // check for monitoring enabled
                XmlNode monitoringNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/Monitoring");
                if (monitoringNode != null)
                {
                    if (monitoringNode.InnerText != null)
                    {
                        switch (monitoringNode.InnerText.ToUpperInvariant())
                        {
                        case "ON": monitoringAction = MonitoringActionType.Enable; break;

                        case "OFF": monitoringAction = MonitoringActionType.Disable; break;

                        default: break;
                        }
                    }

                    // now remove the monitoring node from the xml document since it
                    // is not recognized by the schema used by the antimalware extension
                    monitoringNode.ParentNode.RemoveChild(monitoringNode);
                }

                // check for storage account name if present in the config file
                XmlNode storageAccountNameNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/StorageAccountName");
                if (storageAccountNameNode != null)
                {
                    if (storageAccountNameNode.InnerText != null)
                    {
                        monitoringStorageAccountName = storageAccountNameNode.InnerText;
                    }
                    // strip this node from the xml prior to passing to antimalware extension
                    storageAccountNameNode.ParentNode.RemoveChild(storageAccountNameNode);
                }
            }

            // error no configuration was provided - error if this is not a case of disable or uninstall
            if (!isAntimalwareEnabled &&
                ((!((Disable.IsPresent && Disable.ToBool()) || (Uninstall.IsPresent && Uninstall.ToBool())))))
            {
                ThrowTerminatingError(new ErrorRecord(
                                          new Exception("Configuration is required and must specify AntimalwareEnabled=true"),
                                          string.Empty,
                                          ErrorCategory.InvalidData,
                                          null));
            }

            // process Monitoring parameter if specified (will override any setting in xml config)
            if (Monitoring != null)
            {
                switch (Monitoring.ToUpperInvariant())
                {
                case "ON": monitoringAction = MonitoringActionType.Enable; break;

                case "OFF": monitoringAction = MonitoringActionType.Disable; break;

                default: break;
                }
            }
        }
Пример #2
0
        protected override void ValidateConfiguration()
        {
            // read values from xml file if provided
            if (AntimalwareConfiguration != null)
            {
                // check for antimalware enabled
                XmlNode antimalwareEnabledNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/AntimalwareEnabled");
                if ((antimalwareEnabledNode != null) && (antimalwareEnabledNode.InnerText != null))
                {
                    isAntimalwareEnabled = antimalwareEnabledNode.InnerText.ToUpperInvariant().Equals("TRUE");
                }

                // check for monitoring enabled
                XmlNode monitoringNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/Monitoring");
                if (monitoringNode != null)
                {
                    if (monitoringNode.InnerText != null)
                    {
                        switch (monitoringNode.InnerText.ToUpperInvariant())
                        {
                        case "ON": monitoringAction = MonitoringActionType.Enable; break;

                        case "OFF": monitoringAction = MonitoringActionType.Disable; break;

                        default: break;
                        }
                    }

                    // now remove the monitoring node from the xml document since it
                    // is not recognized by the schema used by the antimalware extension
                    monitoringNode.ParentNode.RemoveChild(monitoringNode);
                }

                // check for storage account name if present in the config file
                XmlNode storageAccountNameNode = AntimalwareConfiguration.SelectSingleNode("//AntimalwareConfig/StorageAccountName");
                if (storageAccountNameNode != null)
                {
                    if (storageAccountNameNode.InnerText != null)
                    {
                        monitoringStorageAccountName = storageAccountNameNode.InnerText;
                    }
                    // strip this node from the xml prior to passing to antimalware extension
                    storageAccountNameNode.ParentNode.RemoveChild(storageAccountNameNode);
                }
            }

            // process Monitoring parameter if specified (will override any setting in xml config)
            if (Monitoring != null)
            {
                switch (Monitoring.ToUpperInvariant())
                {
                case "ON": monitoringAction = MonitoringActionType.Enable; break;

                case "OFF": monitoringAction = MonitoringActionType.Disable; break;

                default: break;
                }
            }

            // always error if user has not opted in to enable antimalware
            if (!isAntimalwareEnabled)
            {
                ThrowTerminatingError(new ErrorRecord(
                                          new Exception(Resources.ServiceExtensionCannotFindAntimalwareEnableSetting),
                                          string.Empty,
                                          ErrorCategory.InvalidData,
                                          null));
            }
        }