private fileeffectiverights53_object CreateFileObject(EntityObjectStringType filePath, EntityObjectStringType fileName, EntityObjectStringType path, EntityObjectStringType trusteeSID) { var newFileEffectiveRights53Object = new fileeffectiverights53_object(); var items = new List<object>(); var itemChoices = new List<fileeffectiverights53_object_ItemsChoices>(); if (filePath == null) { itemChoices.Add(fileeffectiverights53_object_ItemsChoices.path); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.filename); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.trustee_sid); items.Add(path); items.Add(fileName); items.Add(trusteeSID); } else { itemChoices.Add(fileeffectiverights53_object_ItemsChoices.filepath); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.trustee_sid); items.Add(filePath); items.Add(trusteeSID); } newFileEffectiveRights53Object.Items = items.ToArray(); newFileEffectiveRights53Object.Fileeffectiverights53ObjectItemsElementName = itemChoices.ToArray(); return newFileEffectiveRights53Object; }
private IEnumerable <String> ProcessOperationForKeyEntity( EntityObjectStringType keyEntity, IEnumerable <string> currentKeyValues) { if (keyEntity.operation.Equals(OperationEnumeration.equals)) { return(currentKeyValues); } var result = new List <String>(); var allMetabaseKeys = this.ObjectCollector.GetAllMetabaseKeys(); var ovalComparator = new OvalComparatorFactory().GetComparator(keyEntity.datatype); foreach (var keyValue in currentKeyValues) { foreach (var metabaseKey in allMetabaseKeys) { if (ovalComparator.Compare(metabaseKey, keyValue, keyEntity.operation)) { result.Add(metabaseKey); } } } return(result); }
private IEnumerable<string> ProcessOperationForEntity( EntityObjectStringType nameEntity, IEnumerable<string> alreadyProcessedNames) { if (nameEntity.operation.Equals(OperationEnumeration.equals)) return alreadyProcessedNames; var newNames = new List<string>(); var allRpmInfos = GetAllRpmInfoOnTarget(); if (nameEntity.operation.Equals(OperationEnumeration.patternmatch)) { foreach (var processedName in alreadyProcessedNames) foreach (var rpmInfo in allRpmInfos) if (Regex.IsMatch(rpmInfo, processedName)) newNames.Add(rpmInfo); } if (nameEntity.operation.Equals(OperationEnumeration.notequal)) { foreach (var processedName in alreadyProcessedNames) foreach (var rpmInfo in allRpmInfos) if (!rpmInfo.Equals(processedName)) newNames.Add(rpmInfo); } return newNames; }
private fileeffectiverights53_object CreateFileObject(EntityObjectStringType filePath, EntityObjectStringType fileName, EntityObjectStringType path, EntityObjectStringType trusteeSID) { var newFileEffectiveRights53Object = new fileeffectiverights53_object(); var items = new List <object>(); var itemChoices = new List <fileeffectiverights53_object_ItemsChoices>(); if (filePath == null) { itemChoices.Add(fileeffectiverights53_object_ItemsChoices.path); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.filename); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.trustee_sid); items.Add(path); items.Add(fileName); items.Add(trusteeSID); } else { itemChoices.Add(fileeffectiverights53_object_ItemsChoices.filepath); itemChoices.Add(fileeffectiverights53_object_ItemsChoices.trustee_sid); items.Add(filePath); items.Add(trusteeSID); } newFileEffectiveRights53Object.Items = items.ToArray(); newFileEffectiveRights53Object.Fileeffectiverights53ObjectItemsElementName = itemChoices.ToArray(); return(newFileEffectiveRights53Object); }
private file_object CreateFileObject(EntityObjectStringType filePath, EntityObjectStringType path, EntityObjectStringType fileName) { file_object fileObject = new file_object(); EntityObjectStringType[] items; file_object_ItemsChoices[] itemChoices; if (filePath != null) { items = new EntityObjectStringType[1]; itemChoices = new file_object_ItemsChoices[1]; items[0] = filePath; itemChoices[0] = file_object_ItemsChoices.filepath; } else { items = new EntityObjectStringType[2]; itemChoices = new file_object_ItemsChoices[2]; items[0] = path; items[1] = fileName; itemChoices[0] = file_object_ItemsChoices.path; itemChoices[1] = file_object_ItemsChoices.filename; } fileObject.Items = items; fileObject.FileObjectItemsElementName = itemChoices; return(fileObject); }
private file_object CreateFileObject(EntityObjectStringType filePath, EntityObjectStringType path, EntityObjectStringType fileName) { file_object fileObject = new file_object(); EntityObjectStringType[] items; file_object_ItemsChoices[] itemChoices; if (filePath != null) { items = new EntityObjectStringType[1]; itemChoices = new file_object_ItemsChoices[1]; items[0] = filePath; itemChoices[0] = file_object_ItemsChoices.filepath; } else { items = new EntityObjectStringType[2]; itemChoices = new file_object_ItemsChoices[2]; items[0] = path; items[1] = fileName; itemChoices[0] = file_object_ItemsChoices.path; itemChoices[1] = file_object_ItemsChoices.filename; } fileObject.Items = items; fileObject.FileObjectItemsElementName = itemChoices; return fileObject; }
private IEnumerable <ItemType> ProcessOperationFilePath(OVAL.Definitions.ObjectType objectType) { var itemTypes = new List <ItemType>(); EntityObjectStringType filePath = null; String path = null; String fileName = null; if (objectType is OVAL.Definitions.Windows.file_object) { filePath = (EntityObjectStringType)((OVAL.Definitions.Windows.file_object)objectType).GetItemValue(file_object_ItemsChoices.filepath); path = Path.GetDirectoryName(filePath.Value); fileName = Path.GetFileName(filePath.Value); } else if (objectType is OVAL.Definitions.Unix.file_object) { filePath = (EntityObjectStringType)((OVAL.Definitions.Unix.file_object)objectType).GetItemValue(OVAL.Definitions.Unix.ItemsChoiceType3.filepath); path = GetUnixPath(filePath.Value); fileName = GetUnixFilename(filePath.Value); } if (filePath == null || filePath.Value == null) { return(itemTypes); } var filePathInformation = new FilePathRegexInformation(path); var operationForPath = filePath.operation; if (this.operatorHelper.IsRegularExpression(operationForPath)) { if (filePathInformation.GetPathWithFirstRegex() == null) { operationForPath = OperationEnumeration.equals; } } else if (this.operatorHelper.IsNotEqualsOperation(operationForPath)) { operationForPath = OperationEnumeration.equals; } var pathEntity = new EntityObjectStringType() { Value = path, operation = operationForPath }; var fileNameEntity = new EntityObjectStringType() { Value = fileName, operation = filePath.operation }; var fileEntities = new Dictionary <string, EntityObjectStringType>(); fileEntities.Add("path", pathEntity); fileEntities.Add("filename", fileNameEntity); var paths = this.ProcessOperationsPaths(fileEntities); var fileNames = this.ProcessOperationFileName(fileEntities, paths, true); var family = GetFamilyEnumerationForObjectType(objectType); return(new FileItemTypeFactory(family).CreateFileItemTypesWithFilePathsByCombinationFrom(paths, fileNames)); }
public void Should_be_possible_to_create_a_instance_of_EntityBaseType_based_on_another_EntityBaseType() { EntityObjectStringType entitySource = new EntityObjectStringType() { datatype = Common.SimpleDatatypeEnumeration.@string, operation = Common.OperationEnumeration.equals, Value = "file.txt" }; EntityBaseTypeFactory factory = new EntityBaseTypeFactory(); EntityObjectStringType newEntity = factory.CreateEntityBasedOn <EntityObjectStringType>(entitySource); Assert.IsNotNull(newEntity); Assert.IsInstanceOfType(newEntity, typeof(EntityObjectStringType)); Assert.AreEqual(Common.SimpleDatatypeEnumeration.@string, newEntity.datatype); Assert.AreEqual(Common.OperationEnumeration.equals, newEntity.operation); Assert.AreEqual("file.txt", newEntity.Value); EntityObjectBoolType entityBoolSource = new EntityObjectBoolType() { datatype = Common.SimpleDatatypeEnumeration.boolean, operation = Common.OperationEnumeration.notequal, var_ref = "oval:modulo:19" }; EntityObjectBoolType newEntityBoolType = factory.CreateEntityBasedOn <EntityObjectBoolType>(entityBoolSource); Assert.IsNotNull(newEntityBoolType); Assert.IsInstanceOfType(newEntityBoolType, typeof(EntityObjectBoolType)); }
private OVAL.Definitions.Unix.file_object CreateUnixFileObject(EntityObjectStringType filePath, EntityObjectStringType path, EntityObjectStringType fileName) { var fileObject = new OVAL.Definitions.Unix.file_object(); EntityObjectStringType[] items; OVAL.Definitions.Unix.ItemsChoiceType3[] itemChoices; if (filePath != null) { items = new EntityObjectStringType[1]; itemChoices = new OVAL.Definitions.Unix.ItemsChoiceType3[1]; items[0] = filePath; itemChoices[0] = OVAL.Definitions.Unix.ItemsChoiceType3.filepath; } else { items = new EntityObjectStringType[2]; itemChoices = new OVAL.Definitions.Unix.ItemsChoiceType3[2]; items[0] = path; items[1] = fileName; itemChoices[0] = OVAL.Definitions.Unix.ItemsChoiceType3.path; itemChoices[1] = OVAL.Definitions.Unix.ItemsChoiceType3.filename; } fileObject.Items = items; fileObject.ItemsElementName = itemChoices; return(fileObject); }
/// <summary> /// Verifies if is there variable defined in some entity. /// </summary> public bool HasVariableDefined() { EntityObjectStringType fileName = (EntityObjectStringType)this.GetItemValue(fileeffectiverights_object_ItemsChoices.filename); EntityObjectStringType path = (EntityObjectStringType)this.GetItemValue(fileeffectiverights_object_ItemsChoices.path); EntityObjectStringType trustee_name = (EntityObjectStringType)this.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name); return((!string.IsNullOrEmpty(path.var_ref)) || (!string.IsNullOrEmpty(fileName.var_ref)) || (!string.IsNullOrEmpty(trustee_name.var_ref))); }
public bool HasVariableDefined() { EntityObjectStringType fileName = (EntityObjectStringType)this.GetItemValue(textfilecontent_ItemsChoices.filename); EntityObjectStringType path = (EntityObjectStringType)this.GetItemValue(textfilecontent_ItemsChoices.path); EntityObjectStringType line = (EntityObjectStringType)this.GetItemValue(textfilecontent_ItemsChoices.line); return((!string.IsNullOrEmpty(path.var_ref)) || (!string.IsNullOrEmpty(fileName.var_ref)) || (!string.IsNullOrEmpty(line.var_ref))); }
private void ConfigureObjectEntities(regkeyeffectiverights53_object regKeyEffectiveRightsObject) { var allObjectEntities = regKeyEffectiveRightsObject.GetAllObjectEntities(); this.HiveObjectEntity = allObjectEntities[regkeyeffectiverights53_object_ItemsChoices.hive.ToString()]; this.KeyObjectEntity = allObjectEntities[regkeyeffectiverights53_object_ItemsChoices.key.ToString()]; this.TrusteeSIDObjectEntity = allObjectEntities[regkeyeffectiverights53_object_ItemsChoices.trustee_sid.ToString()]; }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType) { EntityObjectStringType newObjectStringType = new EntityObjectStringType(); newObjectStringType.datatype = objectStringType.datatype; newObjectStringType.mask = objectStringType.mask; newObjectStringType.operation = objectStringType.operation; newObjectStringType.var_ref = objectStringType.var_ref; newObjectStringType.Value = objectStringType.Value; return newObjectStringType; }
private IEnumerable <string> processOperationPatternMatchForTrustName(EntityObjectStringType trustName) { var operationResult = new List <string>(); string[] valuesToApply = this.searchUsers(); var multiLevelOperation = new MultiLevelPatternMatchOperation(FamilyEnumeration.windows); operationResult.AddRange(multiLevelOperation.applyPatternMatch(trustName.Value, valuesToApply)); return(operationResult); }
private IEnumerable <string> processVariablesFromEntity(fileeffectiverights_object fileEffectiveRights, fileeffectiverights_object_ItemsChoices itemChoice) { List <string> values = new List <string>(); EntityObjectStringType entity = (EntityObjectStringType)fileEffectiveRights.GetItemValue(itemChoice); if (entity != null) { values.AddRange(this.processVariableForEntity(entity)); } return(values); }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType) { return(new EntityObjectStringType() { datatype = objectStringType.datatype, mask = objectStringType.mask, operation = objectStringType.operation, var_ref = objectStringType.var_ref, Value = objectStringType.Value }); }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType) { EntityObjectStringType newObjectStringType = new EntityObjectStringType(); newObjectStringType.datatype = objectStringType.datatype; newObjectStringType.mask = objectStringType.mask; newObjectStringType.operation = objectStringType.operation; newObjectStringType.var_ref = objectStringType.var_ref; newObjectStringType.Value = objectStringType.Value; return(newObjectStringType); }
private EntityObjectStringType CopyEntityObjectStringType(EntityObjectStringType sourceEntityObject) { return(new EntityObjectStringType() { datatype = sourceEntityObject.datatype, mask = sourceEntityObject.mask, operation = sourceEntityObject.operation, var_ref = sourceEntityObject.var_ref, Value = sourceEntityObject.Value }); }
public user_object NewObjectWithVariable( string variableReference, OperationEnumeration operation = OperationEnumeration.equals) { var userEntity = new EntityObjectStringType() { operation = operation, var_ref = variableReference }; return this.CreateUserObject(userEntity); }
public user_object NewObjectWithVariable( string variableReference, OperationEnumeration operation = OperationEnumeration.equals) { var userEntity = new EntityObjectStringType() { operation = operation, var_ref = variableReference }; return(this.CreateUserObject(userEntity)); }
public user_object NewObject( string userEntityValue, OperationEnumeration operation = OperationEnumeration.equals) { var userEntity = new EntityObjectStringType() { operation = operation, Value = userEntityValue }; return(this.CreateUserObject(userEntity)); }
private Dictionary <string, EntityObjectStringType> CreateFileEntities(string valueForFilepathEntity) { var filePathEntity = new EntityObjectStringType() { Value = valueForFilepathEntity, operation = OperationEnumeration.patternmatch }; var fileEntities = new Dictionary <string, EntityObjectStringType>(); fileEntities.Add("filepath", filePathEntity); return(fileEntities); }
public user_object NewObject( string userEntityValue, OperationEnumeration operation = OperationEnumeration.equals) { var userEntity = new EntityObjectStringType() { operation = operation, Value = userEntityValue }; return this.CreateUserObject(userEntity); }
private IEnumerable<String> processObjectEntity(EntityObjectStringType entity) { if (this.Variables == null) return null; string variableID = this.getVariableId(entity); VariableValue variableValue = this.Variables.GetVariableValueForVariableId(variableID).FirstOrDefault(); bool hasVariableValues = ((variableValue != null) && (variableValue.values != null) && (variableValue.values.Count() > 0)); if (hasVariableValues) return variableValue.values; else return string.IsNullOrEmpty(entity.Value) ? null : new string[] { entity.Value }; }
private IEnumerable <string> processVariableForEntity(EntityObjectStringType entity) { List <string> variables = new List <string>(); if (entity == null) { return(variables); } variables.AddRange(variableEvaluator.EvaluateVariableForEntity(entity)); if (variables.Count() == 0) { variables.Add(entity.Value); } return(variables); }
private IEnumerable<OVAL.SystemCharacteristics.ItemType> ProcessEntityOperation(String entityValue, EntityObjectStringType entity) { var allTargetProcesses = this.ProcessCollector.getProcessInfo(); var processResult = new List<OVAL.SystemCharacteristics.ItemType>(); var comparator = new OvalComparatorFactory().GetComparator(SimpleDatatypeEnumeration.@string); foreach (var targetProcess in allTargetProcesses) { if (comparator.Compare(targetProcess.Command, entityValue, entity.operation)) { var newProcessItem = CreateProcessItem(targetProcess); processResult.Add(newProcessItem); } } return processResult; }
public void Should_be_possible_to_apply_NotEqual_operation_on_OvalObjectEntity() { string definitionFileName = "fdcc_xpfirewall_oval_regex_on_value.xml"; registry_object obj50006 = (registry_object)this.getFakeObj(definitionFileName, "oval:modulo:obj:50006"); Dictionary <string, EntityObjectStringType> entities = OvalHelper.GetRegistryEntitiesFromObjectType(obj50006); EntityObjectStringType nameEntity = entities[registry_object_ItemsChoices.name.ToString()]; Dictionary <string, object> operationParameters = getOperationParameters("CSDVersion", new string[] { "BuildVersion", "CSDVersion", "XPTO" }); OvalEntityOperationBase notEqualsOperation = OvalEntityOperationFactory.CreateOperationForOvalEntity(nameEntity.operation); IEnumerable <string> resultAfterApplyOperation = notEqualsOperation.Apply(operationParameters); Assert.IsInstanceOfType(notEqualsOperation, typeof(NotEqualsEntityOperation), MSG_INVALID_OPERATION_TYPE); Assert.AreEqual(2, resultAfterApplyOperation.Count(), MSG_INVALID_OPERATION_RESULT_COUNT); Assert.AreEqual("BuildVersion", resultAfterApplyOperation.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM); Assert.AreEqual("XPTO", resultAfterApplyOperation.ElementAt(1), MSG_UNEXPECTED_FOUND_ITEM); }
public void Should_be_possible_to_apply_Equals_operation_on_RegistryObjectEntities() { registry_object registryObject = (registry_object)this.getFakeObj(DEFINITIONS_FILENAME, REGISTRY_OBJECT_ID); EntityObjectStringType keyEntity = this.getRegistryObjectEntity(registryObject, registry_object_ItemsChoices.key.ToString()); // Assert Key Entity Operation OvalEntityOperationBase operationForKeyEntity = OvalEntityOperationFactory.CreateOperationForOvalEntity(keyEntity.operation); Dictionary <string, object> keyOperationParameters = this.getOperationParameters(keyEntity.Value, new string[] { REGISTRY_KEY_NAME }); IEnumerable <string> derivedKeys = operationForKeyEntity.Apply(keyOperationParameters); Assert.IsInstanceOfType(operationForKeyEntity, typeof(EqualsEntityOperation), MSG_INVALID_OPERATION_TYPE); Assert.IsNotNull(derivedKeys); Assert.AreEqual(1, derivedKeys.Count(), MSG_INVALID_OPERATION_RESULT_COUNT); Assert.AreEqual(keyEntity.Value, derivedKeys.ElementAt(0), MSG_UNEXPECTED_FOUND_ITEM); }
private IEnumerable<String> ProcessOperationForKeyEntity( EntityObjectStringType keyEntity, IEnumerable<string> currentKeyValues) { if (keyEntity.operation.Equals(OperationEnumeration.equals)) return currentKeyValues; var result = new List<String>(); var allMetabaseKeys = this.ObjectCollector.GetAllMetabaseKeys(); var ovalComparator = new OvalComparatorFactory().GetComparator(keyEntity.datatype); foreach (var keyValue in currentKeyValues) foreach (var metabaseKey in allMetabaseKeys) if (ovalComparator.Compare(metabaseKey, keyValue, keyEntity.operation)) result.Add(metabaseKey); return result; }
private ObjectType CreateObjectTypeFrom(ObjectType fileObject, string filePath, string path, string fileName) { //EntityObjectStringType filePathFrom = (EntityObjectStringType) fileObject.GetItemValue(file_object_ItemsChoices.filepath); //EntityObjectStringType pathFrom = (EntityObjectStringType) fileObject.GetItemValue(file_object_ItemsChoices.path); //EntityObjectStringType fileNameFrom = (EntityObjectStringType)fileObject.GetItemValue(file_object_ItemsChoices.filename); var filePathFrom = (EntityObjectStringType)GetFileEntity(fileObject, "filepath"); var pathFrom = (EntityObjectStringType)GetFileEntity(fileObject, "path"); var fileNameFrom = (EntityObjectStringType)GetFileEntity(fileObject, "filename"); EntityObjectStringType newfilePath = null; EntityObjectStringType newPath = null; EntityObjectStringType newFileName = null; //if (fileObject.IsFilePathSet()) if (filePathFrom != null) { newfilePath = this.CreateObjectStringTypeFrom(filePathFrom); newfilePath.Value = !string.IsNullOrEmpty(filePath) ? filePath : newfilePath.Value; } else { newPath = this.CreateObjectStringTypeFrom(pathFrom); newPath.Value = !string.IsNullOrEmpty(path) ? path : newPath.Value; if (fileNameFrom == null) { newFileName = new EntityObjectStringType() { Value = string.Empty }; } else { newFileName = this.CreateObjectStringTypeFrom(fileNameFrom); newFileName.Value = fileName == null ? newFileName.Value : fileName; } } if (fileObject is OVAL.Definitions.Unix.file_object) { return(this.CreateUnixFileObject(newfilePath, newPath, newFileName)); } return(this.CreateFileObject(newfilePath, newPath, newFileName)); }
private textfilecontent_object CreateFileObject(EntityObjectStringType fileName, EntityObjectStringType line, EntityObjectStringType path) { textfilecontent_object fileContentObject = new textfilecontent_object(); var items = new List<object>(); var itemChoices = new List<textfilecontent_ItemsChoices>(); items.Add(fileName); items.Add(line); items.Add(path); itemChoices.Add(textfilecontent_ItemsChoices.filename); itemChoices.Add(textfilecontent_ItemsChoices.line); itemChoices.Add(textfilecontent_ItemsChoices.path); fileContentObject.Items = items.ToArray(); fileContentObject.TextfilecontentItemsElementName = itemChoices.ToArray(); return fileContentObject; }
public void Should_be_possible_to_evaluate_a_constant_variables_of_an_entitytype() { oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("oval_definitions.oval.org.mitre.oval.def.5921.xml"); Assert.IsNotNull(definitions, "the definitios is not created"); EntityObjectStringType entityType = new EntityObjectStringType(); entityType.var_ref = "oval:org.mitre.oval:var:932"; VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, null, null); IEnumerable <string> values = variableEvaluator.Evaluate(entityType); Assert.IsNotNull(values, "the valueToMatch of variable is null"); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == "1", "the valueToMatch is not expected"); }
private ObjectType CreateObjectTypeFrom(textfilecontent54_object fileContentObject, string filePath, string fileName, string path, string pattern, string instance) { EntityObjectStringType filePathFrom = null; EntityObjectStringType pathFrom = null; EntityObjectStringType fileNameFrom = null; EntityObjectStringType newFilePath = null; EntityObjectStringType newPath = null; EntityObjectStringType newFileName = null; var patternFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.pattern); var instanceFrom = (EntityObjectIntType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.instance); var newPattern = this.CopyEntityObjectStringType(patternFrom); newPattern.Value = !string.IsNullOrEmpty(pattern) ? pattern : newPattern.Value; var newInstance = this.CopyEntityObjectIntType(instanceFrom); newInstance.Value = !string.IsNullOrEmpty(instance) ? instance : newInstance.Value; var behaviors = fileContentObject.Items.OfType <Textfilecontent54Behaviors>().ToArray(); if (fileContentObject.IsFilePathDefined()) { filePathFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.filepath); newFilePath = this.CopyEntityObjectStringType(filePathFrom); newFilePath.Value = !string.IsNullOrEmpty(filePath) ? filePath : newFilePath.Value; return(this.CreateTextFileContentObject(newFilePath, null, null, newPattern, newInstance, behaviors)); } else { pathFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.path); fileNameFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.filename); newPath = this.CopyEntityObjectStringType(pathFrom); newPath.Value = !string.IsNullOrEmpty(path) ? path : newPath.Value; newFileName = this.CopyEntityObjectStringType(fileNameFrom); newFileName.Value = !string.IsNullOrEmpty(fileName) ? fileName : newFileName.Value; return(this.CreateTextFileContentObject(null, newFileName, newPath, newPattern, newInstance, behaviors)); } }
private ObjectType CreateObjectTypeFrom(fileeffectiverights_object fileEffectiveRights, string path, string fileName, string trustee_name) { EntityObjectStringType fileNameFrom = (EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.filename); EntityObjectStringType pathFrom = (EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.path); EntityObjectStringType trustee_nameFrom = (EntityObjectStringType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name); EntityObjectStringType newFileName = entityBaseTypeFactory.CreateEntityBasedOn <EntityObjectStringType>(fileNameFrom); newFileName.Value = !string.IsNullOrEmpty(fileName) ? fileName : newFileName.Value; EntityObjectStringType newPath = entityBaseTypeFactory.CreateEntityBasedOn <EntityObjectStringType>(pathFrom); newPath.Value = !string.IsNullOrEmpty(path) ? path : newPath.Value; EntityObjectStringType newTrustee_name = entityBaseTypeFactory.CreateEntityBasedOn <EntityObjectStringType>(trustee_nameFrom); newTrustee_name.Value = !string.IsNullOrEmpty(trustee_name) ? trustee_name : newTrustee_name.Value; return(this.CreateFileEffectiveRights(newFileName, newPath, newTrustee_name)); }
private ObjectType CreateFileEffectiveRights(EntityObjectStringType newFileName, EntityObjectStringType newPath, EntityObjectStringType newTrustee_name) { List<EntityObjectStringType> items = new List<EntityObjectStringType>(); List<fileeffectiverights_object_ItemsChoices> choices = new List<fileeffectiverights_object_ItemsChoices>(); items.Add(newFileName); choices.Add(fileeffectiverights_object_ItemsChoices.filename); items.Add(newPath); choices.Add(fileeffectiverights_object_ItemsChoices.path); items.Add(newTrustee_name); choices.Add(fileeffectiverights_object_ItemsChoices.trustee_name); fileeffectiverights_object newFileEffectiveRights = new fileeffectiverights_object(); newFileEffectiveRights.Items = items.ToArray(); newFileEffectiveRights.FileeffectiverightsObjectItemsElementName = choices.ToArray(); return newFileEffectiveRights; }
private textfilecontent_object CreateFileObject(EntityObjectStringType fileName, EntityObjectStringType line, EntityObjectStringType path) { textfilecontent_object fileContentObject = new textfilecontent_object(); var items = new List <object>(); var itemChoices = new List <textfilecontent_ItemsChoices>(); items.Add(fileName); items.Add(line); items.Add(path); itemChoices.Add(textfilecontent_ItemsChoices.filename); itemChoices.Add(textfilecontent_ItemsChoices.line); itemChoices.Add(textfilecontent_ItemsChoices.path); fileContentObject.Items = items.ToArray(); fileContentObject.TextfilecontentItemsElementName = itemChoices.ToArray(); return(fileContentObject); }
private ObjectType CreateObjectTypeFrom(textfilecontent_object fileContentObject, string fileName, string line, string path) { EntityObjectStringType pathFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent_ItemsChoices.path); EntityObjectStringType fileNameFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent_ItemsChoices.filename); EntityObjectStringType lineFrom = (EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent_ItemsChoices.line); EntityObjectStringType newPath = this.CreateObjectStringTypeFrom(pathFrom); newPath.Value = !string.IsNullOrEmpty(path) ? path : newPath.Value; EntityObjectStringType newFileName = this.CreateObjectStringTypeFrom(fileNameFrom); newFileName.Value = !string.IsNullOrEmpty(fileName) ? fileName : newFileName.Value; EntityObjectStringType newLine = this.CreateObjectStringTypeFrom(lineFrom); newLine.Value = !string.IsNullOrEmpty(line) ? line : newLine.Value; return(this.CreateFileObject(newFileName, newLine, newPath)); }
public void Equals_operation_should_be_CaseSensitive() { #region User Object // <user_object id="oval:modulo:obj:5" version="1" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows"> // <user>lfernandes</user> // </user_object> #endregion user_object userObject = (user_object)this.getFakeObj("definitionsSimple.xml", "oval:modulo:obj:5"); EntityObjectStringType userEntity = (EntityObjectStringType)userObject.User; Dictionary <string, object> operationParameters; OvalEntityOperationBase equalsOperation = OvalEntityOperationFactory.CreateOperationForOvalEntity(userEntity.operation); operationParameters = this.getOperationParameters(userEntity.Value, new string[] { "LFernandes" }); IEnumerable <string> operationResult = equalsOperation.Apply(operationParameters); Assert.IsInstanceOfType(equalsOperation, typeof(EqualsEntityOperation), MSG_INVALID_OPERATION_TYPE); Assert.AreEqual(0, operationResult.Count(), MSG_INVALID_OPERATION_RESULT_COUNT); }
private ObjectType CreateFileEffectiveRights(EntityObjectStringType newFileName, EntityObjectStringType newPath, EntityObjectStringType newTrustee_name) { List <EntityObjectStringType> items = new List <EntityObjectStringType>(); List <fileeffectiverights_object_ItemsChoices> choices = new List <fileeffectiverights_object_ItemsChoices>(); items.Add(newFileName); choices.Add(fileeffectiverights_object_ItemsChoices.filename); items.Add(newPath); choices.Add(fileeffectiverights_object_ItemsChoices.path); items.Add(newTrustee_name); choices.Add(fileeffectiverights_object_ItemsChoices.trustee_name); fileeffectiverights_object newFileEffectiveRights = new fileeffectiverights_object(); newFileEffectiveRights.Items = items.ToArray(); newFileEffectiveRights.FileeffectiverightsObjectItemsElementName = choices.ToArray(); return(newFileEffectiveRights); }
private IEnumerable <string> ProcessOperationForEntity( EntityObjectStringType nameEntity, IEnumerable <string> alreadyProcessedNames) { if (nameEntity.operation.Equals(OperationEnumeration.equals)) { return(alreadyProcessedNames); } var newNames = new List <string>(); var allRpmInfos = GetAllRpmInfoOnTarget(); if (nameEntity.operation.Equals(OperationEnumeration.patternmatch)) { foreach (var processedName in alreadyProcessedNames) { foreach (var rpmInfo in allRpmInfos) { if (Regex.IsMatch(rpmInfo, processedName)) { newNames.Add(rpmInfo); } } } } if (nameEntity.operation.Equals(OperationEnumeration.notequal)) { foreach (var processedName in alreadyProcessedNames) { foreach (var rpmInfo in allRpmInfos) { if (!rpmInfo.Equals(processedName)) { newNames.Add(rpmInfo); } } } } return(newNames); }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType, bool isNilEntity = false) { if (isNilEntity) { return new EntityObjectStringType() { Value = string.Empty } } ; return(new EntityObjectStringType() { datatype = objectStringType.datatype, mask = objectStringType.mask, operation = objectStringType.operation, var_ref = objectStringType.var_ref, Value = objectStringType.Value }); }
private IEnumerable<string> EvaluateVariable(EntityObjectStringType variableNameEntity, VariablesEvaluated variables) { var variableEvaluator = new VariableEntityEvaluator(variables); return variableEvaluator.EvaluateVariableForEntity(variableNameEntity); }
public void Should_be_possible_to_create_a_instance_of_EntityBaseType_based_on_another_EntityBaseType() { EntityObjectStringType entitySource = new EntityObjectStringType() { datatype = Common.SimpleDatatypeEnumeration.@string, operation = Common.OperationEnumeration.equals, Value = "file.txt" }; EntityBaseTypeFactory factory = new EntityBaseTypeFactory(); EntityObjectStringType newEntity = factory.CreateEntityBasedOn<EntityObjectStringType>(entitySource); Assert.IsNotNull(newEntity); Assert.IsInstanceOfType(newEntity,typeof(EntityObjectStringType)); Assert.AreEqual(Common.SimpleDatatypeEnumeration.@string, newEntity.datatype); Assert.AreEqual(Common.OperationEnumeration.equals, newEntity.operation); Assert.AreEqual("file.txt", newEntity.Value); EntityObjectBoolType entityBoolSource = new EntityObjectBoolType() { datatype = Common.SimpleDatatypeEnumeration.boolean, operation = Common.OperationEnumeration.notequal, var_ref = "oval:modulo:19" }; EntityObjectBoolType newEntityBoolType = factory.CreateEntityBasedOn<EntityObjectBoolType>(entityBoolSource); Assert.IsNotNull(newEntityBoolType); Assert.IsInstanceOfType(newEntityBoolType, typeof(EntityObjectBoolType)); }
private IList<String> ProcessOperation(IEnumerable<string> entityValuesAlreadyProcessed, EntityObjectStringType entity) { if (entity.operation == OperationEnumeration.equals) return entityValuesAlreadyProcessed.ToList(); var newResult = new List<String>(); foreach (var entityValueAlreadyProcessed in entityValuesAlreadyProcessed) ((List<String>)newResult).AddRange(ProcessOperationDifferentOfEquals(entity.operation, entityValueAlreadyProcessed)); return newResult; }
private OVAL.Definitions.Unix.file_object CreateUnixFileObject(EntityObjectStringType filePath, EntityObjectStringType path, EntityObjectStringType fileName) { var fileObject = new OVAL.Definitions.Unix.file_object(); EntityObjectStringType[] items; OVAL.Definitions.Unix.ItemsChoiceType3[] itemChoices; if (filePath != null) { items = new EntityObjectStringType[1]; itemChoices = new OVAL.Definitions.Unix.ItemsChoiceType3[1]; items[0] = filePath; itemChoices[0] = OVAL.Definitions.Unix.ItemsChoiceType3.filepath; } else { items = new EntityObjectStringType[2]; itemChoices = new OVAL.Definitions.Unix.ItemsChoiceType3[2]; items[0] = path; items[1] = fileName; itemChoices[0] = OVAL.Definitions.Unix.ItemsChoiceType3.path; itemChoices[1] = OVAL.Definitions.Unix.ItemsChoiceType3.filename; } fileObject.Items = items; fileObject.ItemsElementName = itemChoices; return fileObject; }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType) { return new EntityObjectStringType() { datatype = objectStringType.datatype, mask = objectStringType.mask, operation = objectStringType.operation, var_ref = objectStringType.var_ref, Value = objectStringType.Value }; }
public static bool IsOvalObjectPatternMatch(EntityObjectStringType ovalObject) { return (ovalObject.operation == OperationEnumeration.patternmatch); }
private EntityObjectStringType CopyEntityObjectStringType(EntityObjectStringType sourceEntityObject) { return new EntityObjectStringType() { datatype = sourceEntityObject.datatype, mask = sourceEntityObject.mask, operation = sourceEntityObject.operation, var_ref = sourceEntityObject.var_ref, Value = sourceEntityObject.Value }; }
public void Should_be_possible_to_evaluate_a_constant_variables_of_an_entitytype() { oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("oval_definitions.oval.org.mitre.oval.def.5921.xml"); Assert.IsNotNull(definitions, "the definitios is not created"); EntityObjectStringType entityType = new EntityObjectStringType(); entityType.var_ref = "oval:org.mitre.oval:var:932"; VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, null, null); IEnumerable<string> values = variableEvaluator.Evaluate(entityType); Assert.IsNotNull(values, "the valueToMatch of variable is null"); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == "1", "the valueToMatch is not expected"); }
public void Should_be_evaluate_a_local_Variables_of_an_entityType() { OvalDocumentLoader ovalDocument = new OvalDocumentLoader(); oval_definitions definitions = ovalDocument.GetFakeOvalDefinitions("definitionsWithLocalVariable.xml"); Assert.IsNotNull(definitions, "the definitios is not created"); oval_system_characteristics systemCharacteristics = ovalDocument.GetFakeOvalSystemCharacteristics("system_characteristics_with_local_variable.xml"); Assert.IsNotNull(definitions, "the system Characteristics is not was created"); EntityObjectStringType entityType = new EntityObjectStringType(); entityType.var_ref = "oval:org.mitre.oval:var:4000"; VariableEvaluator variableEvaluator = new VariableEvaluator(definitions.variables, systemCharacteristics, null); IEnumerable<string> values = variableEvaluator.Evaluate(entityType); Assert.IsNotNull(values, "the valueToMatch of variable is null"); Assert.IsTrue(values.Count() == 1, "the quantity of values is not expected"); Assert.IsTrue(values.ElementAt(0) == @"Software\Microsoft\Windows NT\CurrentVersion", "the value is not expected"); }
private IEnumerable<string> processVariableForEntity(EntityObjectStringType entity) { List<string> variables = new List<string>(); if (entity == null) return variables; variables.AddRange(variableEvaluator.EvaluateVariableForEntity(entity)); if (variables.Count() == 0) variables.Add(entity.Value); return variables; }
private ObjectType CreateObjectTypeFrom(ObjectType fileObject, string filePath, string path, string fileName) { //EntityObjectStringType filePathFrom = (EntityObjectStringType) fileObject.GetItemValue(file_object_ItemsChoices.filepath); //EntityObjectStringType pathFrom = (EntityObjectStringType) fileObject.GetItemValue(file_object_ItemsChoices.path); //EntityObjectStringType fileNameFrom = (EntityObjectStringType)fileObject.GetItemValue(file_object_ItemsChoices.filename); var filePathFrom = (EntityObjectStringType)GetFileEntity(fileObject, "filepath"); var pathFrom = (EntityObjectStringType)GetFileEntity(fileObject, "path"); var fileNameFrom = (EntityObjectStringType)GetFileEntity(fileObject, "filename"); EntityObjectStringType newfilePath = null; EntityObjectStringType newPath = null; EntityObjectStringType newFileName = null; //if (fileObject.IsFilePathSet()) if (filePathFrom != null) { newfilePath = this.CreateObjectStringTypeFrom(filePathFrom); newfilePath.Value = !string.IsNullOrEmpty(filePath) ? filePath : newfilePath.Value; } else { newPath = this.CreateObjectStringTypeFrom(pathFrom); newPath.Value = !string.IsNullOrEmpty(path) ? path : newPath.Value; if (fileNameFrom == null) { newFileName = new EntityObjectStringType() { Value = string.Empty }; } else { newFileName = this.CreateObjectStringTypeFrom(fileNameFrom); newFileName.Value = fileName == null ? newFileName.Value : fileName; } } if (fileObject is OVAL.Definitions.Unix.file_object) return this.CreateUnixFileObject(newfilePath, newPath, newFileName); return this.CreateFileObject(newfilePath,newPath, newFileName); }
public void Should_be_possible_to_process_a_variable_given_EntityBaseType() { List<string> variableValues = new List<string>() { "Multiprocessor Free" }; VariableValue variable = new VariableValue("oval:org.mitre.oval:obj:6000", "oval:com.hp:var:1", variableValues); IEnumerable<VariableValue> variables = new List<VariableValue>() { variable }; VariablesEvaluated variablesEvaluated = new VariablesEvaluated(variables); VariableEntityEvaluator variableEntityEvaluator = new VariableEntityEvaluator(variablesEvaluated); EntityObjectStringType entity = new EntityObjectStringType(); entity.var_ref = "oval:com.hp:var:1"; IEnumerable<string> values = variableEntityEvaluator.EvaluateVariableForEntity(entity); Assert.IsTrue(values.Count() > 0 , "the quantity of entities is not expected"); Assert.AreEqual(values.ElementAt(0), variableValues.ElementAt(0), "the value is not expected"); }
private Dictionary<string, EntityObjectStringType> CreateFileEntities(string valueForFilepathEntity) { var filePathEntity = new EntityObjectStringType() { Value = valueForFilepathEntity, operation = OperationEnumeration.patternmatch }; var fileEntities = new Dictionary<string, EntityObjectStringType>(); fileEntities.Add("filepath", filePathEntity); return fileEntities; }
public virtual FilePathOperationResult ProcessOperationFilePath(Dictionary<string, EntityObjectStringType> fileEntities) { FilePathOperationResult filePathOperationResult = new FilePathOperationResult(); if (!this.IsThereFilePathEntity(fileEntities)) return filePathOperationResult; EntityObjectStringType filePath; if (!fileEntities.TryGetValue("filepath", out filePath)) return filePathOperationResult; string path = Path.GetDirectoryName(filePath.Value); string fileName = Path.GetFileName(filePath.Value); FilePathRegexInformation filePathInformation = new FilePathRegexInformation(path); OperationEnumeration operationForPath = filePath.operation; OperationEnumeration operationForFileName = operationForPath; if (this.operatorHelper.IsRegularExpression(operationForPath)) { PathLevelWithRegex pathWithRegex = filePathInformation.GetPathWithFirstRegex(); if (pathWithRegex == null) operationForPath = OperationEnumeration.equals; PathLevelWithRegex filenameWithRegex = new FilePathRegexInformation(fileName.Replace(".", "")).GetPathWithFirstRegex(); if (filenameWithRegex == null) operationForFileName = OperationEnumeration.equals; } else if (this.operatorHelper.IsNotEqualsOperation(operationForPath)) { operationForPath = OperationEnumeration.equals; operationForFileName = operationForPath; } //RegexHelper.IsPathLevelARegexPattern(fileName) ? OperationEnumeration.patternmatch : OperationEnumeration.equals; Dictionary<string, EntityObjectStringType> pathAndFileNameEntities = new Dictionary<string, EntityObjectStringType>(); EntityObjectStringType pathEntity = new EntityObjectStringType() { Value = path, operation = operationForPath }; EntityObjectStringType fileNameEntity = new EntityObjectStringType() { Value = fileName, operation = operationForFileName }; pathAndFileNameEntities.Add("path", pathEntity); pathAndFileNameEntities.Add("filename", fileNameEntity); IEnumerable<string> paths = this.ProcessOperationsPaths(pathAndFileNameEntities); IEnumerable<string> fileNames = this.ProcessOperationFileName(pathAndFileNameEntities, paths, true); filePathOperationResult.FileNames.AddRange(fileNames); filePathOperationResult.Paths.AddRange(paths); return filePathOperationResult; }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType, bool isNilEntity = false) { if (isNilEntity) return new EntityObjectStringType() { Value = string.Empty }; return new EntityObjectStringType() { datatype = objectStringType.datatype, mask = objectStringType.mask, operation = objectStringType.operation, var_ref = objectStringType.var_ref, Value = objectStringType.Value }; }
private EntityObjectStringType CreateObjectStringTypeFrom(EntityObjectStringType objectStringType) { EntityBaseTypeFactory factory = new EntityBaseTypeFactory(); return factory.CreateEntityBasedOn<EntityObjectStringType>(objectStringType); }
private textfilecontent54_object CreateTextFileContentObject( EntityObjectStringType filePath, EntityObjectStringType fileName, EntityObjectStringType path, EntityObjectStringType pattern, EntityObjectIntType instance, Object[] behaviors) { var fileContentObject = new textfilecontent54_object(); object[] items; textfilecontent54_ItemsChoices[] itemChoices; var hasBehaviors = (behaviors != null) && (behaviors.Count() > 0); var behaviorCount = behaviors.Count(); if (filePath == null) { if (hasBehaviors) { var entityCount = behaviorCount + 4; items = new object[entityCount]; itemChoices = new textfilecontent54_ItemsChoices[entityCount]; for (int i = 0; i < behaviorCount; i++) { itemChoices[i] = textfilecontent54_ItemsChoices.behaviors; items[i] = behaviors.ElementAt(i); } itemChoices[behaviorCount] = textfilecontent54_ItemsChoices.path; itemChoices[behaviorCount + 1] = textfilecontent54_ItemsChoices.filename; itemChoices[behaviorCount + 2] = textfilecontent54_ItemsChoices.pattern; itemChoices[behaviorCount + 3] = textfilecontent54_ItemsChoices.instance; items[behaviorCount] = path; items[behaviorCount + 1] = fileName; items[behaviorCount + 2] = pattern; items[behaviorCount + 3] = instance; } else { items = new EntitySimpleBaseType[4]; itemChoices = new textfilecontent54_ItemsChoices[4]; itemChoices[0] = textfilecontent54_ItemsChoices.path; itemChoices[1] = textfilecontent54_ItemsChoices.filename; itemChoices[2] = textfilecontent54_ItemsChoices.pattern; itemChoices[3] = textfilecontent54_ItemsChoices.instance; items[0] = path; items[1] = fileName; items[2] = pattern; items[3] = instance; } } else { if (hasBehaviors) { var entityCount = behaviorCount + 3; items = new object[entityCount]; itemChoices = new textfilecontent54_ItemsChoices[entityCount]; for (int i = 0; i < behaviorCount; i++) { itemChoices[i] = textfilecontent54_ItemsChoices.behaviors; items[i] = behaviors.ElementAt(i); } itemChoices[behaviorCount] = textfilecontent54_ItemsChoices.filepath; itemChoices[behaviorCount + 1] = textfilecontent54_ItemsChoices.pattern; itemChoices[behaviorCount + 2] = textfilecontent54_ItemsChoices.instance; items[behaviorCount] = filePath; items[behaviorCount + 1] = pattern; items[behaviorCount + 2] = instance; } else { items = new EntitySimpleBaseType[3]; itemChoices = new textfilecontent54_ItemsChoices[3]; itemChoices[0] = textfilecontent54_ItemsChoices.filepath; itemChoices[1] = textfilecontent54_ItemsChoices.pattern; itemChoices[2] = textfilecontent54_ItemsChoices.instance; items[0] = filePath; items[1] = pattern; items[2] = instance; } } fileContentObject.Items = items; fileContentObject.Textfilecontent54ItemsElementName = itemChoices; return fileContentObject; }
private string getVariableId(EntityObjectStringType entity) { string varReference = entity.var_ref; return string.IsNullOrEmpty(varReference) ? string.Empty : varReference; }