/// <summary> /// This method executes the process of a setElement in the ObjectType. /// For the objectType that has a setElement the process is a some different. /// Actually, the setElement uses the objectType already was collected. /// In this process the setElement process uses a systemCharacteristics for the get a reference for the objectType /// collected and makes the references are used in the new CollectedObject of the process. /// </summary> /// <param name="ovalObject">The Oval Object.</param> /// <param name="collectInfo">The collect info.</param> /// <returns></returns> private CollectedObject ProcessSet(Definitions.ObjectType ovalObject, CollectInfo collectInfo) { CollectedObject collectedObject = null; try { var setElement = this.GetSetElement(ovalObject); var setEvaluator = new SetEvaluator(collectInfo.SystemCharacteristics, collectInfo.States, collectInfo.Variables); var resultOfSet = setEvaluator.Evaluate(setElement); var objectReferences = resultOfSet.Result; if (objectReferences.Count() > 0) { collectedObject = new CollectedObject(ovalObject.id); foreach (string reference in objectReferences) { var itemType = collectInfo.SystemCharacteristics.GetSystemDataByReferenceId(reference); collectedObject.AddItemToSystemData(itemType); } collectedObject.SetEspecificObjectStatus(resultOfSet.ObjectFlag); } return collectedObject; } catch (Exception ex) { collectedObject = new CollectedObject(ovalObject.id); collectedObject.SetEspecificObjectStatus(FlagEnumeration.error); collectedObject.ObjectType.message = MessageType.FromErrorString(String.Format("An error occurred while set processing: '{0}'", ex.Message)); return collectedObject; } }
private static CollectedObject CreateRegistryCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType currentVersion = CreateRegistryItem("HKEY_LOCAL_MACHINE", "1", "", "Microsoft\\WindowsNT\\", "CDSVersion", "Service Pack 1"); collectedObject.AddItemToSystemData(currentVersion); ItemType systemRoot = CreateRegistryItem("HKEY_LOCAL_MACHINE", "2", "", "Microsoft\\WindowsNT\\", "SystemRoot", @"c:\Windows"); collectedObject.AddItemToSystemData(systemRoot); return collectedObject; }
/// <summary> /// Executes a normal collect, using the system datasource for data collecting. /// </summary> /// <param name="ovalComponent">The oval component.</param> /// <param name="collectInfo">The collect info.</param> /// <param name="id">The id parameter is 'a sequencial number controlled by external scope.</param> /// <returns></returns> private CollectedObject ProcessCollect(Definitions.ObjectType ovalComponent, CollectInfo collectInfo, ProbeResultBuilder probeResultBuilder, ref int id) { CollectedObject collectedObject = null; var allItemsToCollect = this.TryToGetItemsToCollect(ovalComponent, collectInfo.Variables); if (allItemsToCollect.Count() > 0) { collectedObject = new CollectedObject(ovalComponent.id); foreach (var itemToCollect in allItemsToCollect) { var collectedItems = ObjectCollector.CollectDataForSystemItem(itemToCollect); foreach (var collectedItem in collectedItems) { var itemType = probeResultBuilder.GetItemType(collectedItem.ItemType); if (itemType == null) { collectedItem.ItemType.id = id.ToString(); id++; } else { collectedItem.ItemType = itemType; } collectedObject.AddItemToSystemData(collectedItem.ItemType); var variables = collectInfo.GetVariableValueForOvalComponent(collectedObject.ObjectType.id); collectedObject.AddVariableReference(variables); ExecutionLogBuilder.AddDetailInformation(collectedItem.ExecutionLog); } } collectedObject.UpdateCollectedObjectStatus(); } return collectedObject; }
private static IEnumerable<CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable<definitions.ObjectType> objectTypes, List<string> resultsForObjects) { List<CollectedObject> collectedObjects = new List<CollectedObject>(); IEnumerable<registry_object> registryObjects = objectTypes.OfType<registry_object>(); int id = 1; foreach (var registryObject in registryObjects) { CollectedObject collectedObject = new CollectedObject(registryObject.id); string existId = resultsForObjects.Where(x => x.Equals(registryObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { ItemType registryItem = CreateRegistryItem( registryObject.GetItemValue(registry_object_ItemsChoices.hive).ToString(), id.ToString(), "", registryObject.GetItemValue(registry_object_ItemsChoices.key).ToString(), registryObject.GetItemValue(registry_object_ItemsChoices.name).ToString(), "default" ); collectedObject.AddItemToSystemData(registryItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return collectedObjects; }
private static CollectedObject CreateFamilyCollectedObject(string ovalId, int quantidadeDeItems) { CollectedObject collectedObject = new CollectedObject(ovalId); ItemType familyItem = CreateFamilyItem("windows"); collectedObject.AddItemToSystemData(familyItem); return collectedObject; }
private static IEnumerable<CollectedObject> CreateCollectedObjectsForSpecificObjectTypes(IEnumerable<OVAL.Definitions.ObjectType> objectTypes, List<string> resultsForObjects) { List<CollectedObject> collectedObjects = new List<CollectedObject>(); IEnumerable<family_object> familyObjects = objectTypes.OfType<family_object>(); int id = 1; foreach (var familyObject in familyObjects) { string existId = resultsForObjects.Where(x => x.Equals(familyObject.id)).SingleOrDefault(); if (string.IsNullOrEmpty(existId)) { CollectedObject collectedObject = new CollectedObject(familyObject.id); ItemType familyItem = CreateFamilySpecificItem(id.ToString()); collectedObject.AddItemToSystemData(familyItem); collectedObjects.Add(collectedObject); id++; } else { resultsForObjects.Remove(existId); } } return collectedObjects; }
public void Should_be_possible_to_create_a_relation_between_objectType_and_systemData_through_of_referenceData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); Assert.AreEqual(2, collectObject.ObjectType.reference.Count(), "the quantity of reference is not expected"); Assert.AreEqual("1", collectObject.ObjectType.reference[0].item_ref, "the first element of reference not has the id expected"); Assert.AreEqual("2", collectObject.ObjectType.reference[1].item_ref, "the second element of reference not has the id expected"); CollectedObject otherCollectedObject = new CollectedObject("oval:org.mitre.oval:obj:6001"); ItemType registryItem3 = new registry_item() { status = StatusEnumeration.exists, id = "3" }; otherCollectedObject.AddItemToSystemData(registryItem3); Assert.AreEqual(1, otherCollectedObject.ObjectType.reference.Count(), "the quantity of reference is not expected for the second collectedObject"); Assert.AreEqual("3", otherCollectedObject.ObjectType.reference[0].item_ref, "the referece id of element is not expected"); }
public void Should_be_possible_to_update_status_of_an_objectType_to_error_based_on_in_systemData() { CollectedObject collectObject = new CollectedObject("oval:org.mitre.oval:obj:6000"); ItemType registryItem1 = new registry_item() { status = StatusEnumeration.exists, id = "1" }; ItemType registryItem2 = new registry_item() { status = StatusEnumeration.doesnotexist, id = "2" }; ItemType registryItem3 = new registry_item() { status = StatusEnumeration.error, id = "3" }; collectObject.AddItemToSystemData(registryItem1); collectObject.AddItemToSystemData(registryItem2); collectObject.AddItemToSystemData(registryItem3); collectObject.UpdateCollectedObjectStatus(); Assert.AreEqual(FlagEnumeration.error, collectObject.ObjectType.flag); }