internal static IEnumerable <string> ParseStream(Stream data) { IEnumerable <string> result; try { XDocument xdocument = XDocument.Load(data); IEnumerable <string> ruleNames = from rule in xdocument.Elements("rules").Elements("rule") select rule.Attribute("name").Value; string duplicateRuleName = PowershellTransportRuleSerializer.GetDuplicateRuleName(ruleNames); if (duplicateRuleName != null) { throw new ParserException(RulesStrings.RuleNameExists(duplicateRuleName)); } IEnumerable <string> enumerable = from version in xdocument.Elements("rules").Elements("rule").Elements("version") where PowershellTransportRuleSerializer.IsSupportedVersion(version.Attribute("requiredMinVersion").Value) select version.Element("commandBlock").Value.Trim(); result = enumerable; } catch (NullReferenceException ex) { throw new XmlException("Malformed XML: " + ex.Message); } return(result); }
public override Property CreateProperty(string propertyName, string typeName) { if (propertyName != null) { if (propertyName == "ClientIpProperty") { return(new ClientAccessRulesClientIpProperty(propertyName, Argument.GetTypeForName(typeName))); } if (propertyName == "SourceTcpPortNumberProperty") { return(new ClientAccessRulesSourcePortNumberProperty(propertyName, Argument.GetTypeForName(typeName))); } if (propertyName == "ProtocolProperty") { return(new ClientAccessRulesProtocolProperty(propertyName, Argument.GetTypeForName(typeName))); } if (propertyName == "UsernamePatternProperty") { return(new ClientAccessRulesUsernamePatternProperty(propertyName, Argument.GetTypeForName(typeName))); } if (propertyName == "AuthenticationTypeProperty") { return(new ClientAccessRulesAuthenticationTypeProperty(propertyName, Argument.GetTypeForName(typeName))); } if (propertyName == "UserRecipientFilterProperty") { return(new ClientAccessRulesUserRecipientFilterProperty(propertyName, Argument.GetTypeForName(typeName))); } } throw new RulesValidationException(RulesStrings.InvalidPropertyName(propertyName)); }
public override Action CreateAction(string actionName, ShortList <Argument> arguments, string externalName = null) { if (actionName != null && actionName == "RightsProtectMessage") { return(new RightsProtectMessageAction(arguments)); } throw new ParserException(RulesStrings.InvalidActionName(actionName)); }
private static ClientAccessRuleAction CreateAction(string actionName, ShortList <Argument> arguments) { if (string.Compare(actionName, "AllowAccess", StringComparison.OrdinalIgnoreCase) == 0) { return(new ClientAccessRuleAllowAccessAction(arguments)); } if (string.Compare(actionName, "DenyAccess", StringComparison.OrdinalIgnoreCase) == 0) { return(new ClientAccessRuleDenyAccessAction(arguments)); } throw new RulesValidationException(RulesStrings.InvalidActionName(actionName)); }
internal static Exception TryParseVersion(Stream contentStream, out bool isE14Format) { isE14Format = false; try { contentStream.Position = 0L; XDocument xdocument = XDocument.Load(contentStream); IEnumerable <XElement> source = from rule in xdocument.Elements("rules").Elements("rule") select rule; if (!source.Any <XElement>()) { return(null); } IEnumerable <string> enumerable = from rule in source let formatAttribute = rule.Attribute("format") where formatAttribute != null && !string.IsNullOrWhiteSpace(formatAttribute.Value) select formatAttribute.Value; if (!enumerable.Any <string>()) { isE14Format = true; return(null); } if (source.Count <XElement>() > enumerable.Count <string>()) { throw new ParseException(RulesStrings.InvalidAttribute("format", "rule", enumerable.First <string>())); } foreach (string text in enumerable) { if (string.Compare(text, "cmdlet", true) != 0) { throw new ParseException(RulesStrings.InvalidAttribute("format", "rule", text)); } } isE14Format = false; } catch (ParseException result) { return(result); } catch (XmlException result2) { return(result2); } return(null); }
public override PredicateCondition CreatePredicate(string name, Property property, ShortList <string> valueEntries, RulesCreationContext creationContext) { if (name != null) { if (!(name == "recipientIs")) { if (!(name == "allInternal")) { if (name == "is") { if (property == null || !string.Equals(property.Name, "Message.Sender.Department", StringComparison.OrdinalIgnoreCase)) { throw new ParserException(RulesStrings.InvalidPropertyName((property != null) ? property.Name : string.Empty)); } return(base.CreatePredicate(name, property, valueEntries, creationContext)); } } else { if (property == null || !string.Equals(property.Name, "Message.ToCcBcc", StringComparison.OrdinalIgnoreCase)) { throw new ParserException(RulesStrings.InvalidPropertyName((property != null) ? property.Name : string.Empty)); } return(new AllInternalPredicate()); } } else { if (property == null || !string.Equals(property.Name, "Message.ToCcBcc", StringComparison.OrdinalIgnoreCase)) { throw new ParserException(RulesStrings.InvalidPropertyName((property != null) ? property.Name : string.Empty)); } return(new RecipientIsPredicate(valueEntries, creationContext)); } } return(base.CreatePredicate(name, property, valueEntries, creationContext)); }