private fileeffectiverights53_object CreateFileEffectiveRightsObject(
            IEnumerable <EntitySimpleBaseType> entities, bool useFilepathEntity = true)
        {
            var itemsElementName = new List <fileeffectiverights53_object_ItemsChoices>();

            if (useFilepathEntity)
            {
                itemsElementName.Add(fileeffectiverights53_object_ItemsChoices.filepath);
            }
            else
            {
                itemsElementName.Add(fileeffectiverights53_object_ItemsChoices.path);
                if (entities.ElementAt(1) == null)
                {
                    entities = new EntitySimpleBaseType[] { entities.First(), entities.Last() }
                }
                ;
                else
                {
                    itemsElementName.Add(fileeffectiverights53_object_ItemsChoices.filename);
                }
            }
            itemsElementName.Add(fileeffectiverights53_object_ItemsChoices.trustee_sid);

            return(new fileeffectiverights53_object()
            {
                id = "oval:modsic.fakeobject:obj:1",
                version = "1",
                Fileeffectiverights53ObjectItemsElementName = itemsElementName.ToArray(),
                Items = entities.ToArray()
            });
        }
Esempio n. 2
0
        public bool IsAllEntitiesSet()
        {
            EntitySimpleBaseType key  = (EntitySimpleBaseType)this.GetItemValue(registry_object_ItemsChoices.key);
            EntitySimpleBaseType name = (EntitySimpleBaseType)this.GetItemValue(registry_object_ItemsChoices.name);

            return((key != null) && (name != null));
        }
        private xmlfilecontent_object CreateFileObject(
            EntitySimpleBaseType filePath, EntitySimpleBaseType fileName, EntitySimpleBaseType path, EntitySimpleBaseType xpath)
        {
            var newXmlFileContentObject = new xmlfilecontent_object();

            EntitySimpleBaseType[]        items;
            xmlfilecontent_ItemsChoices[] itemChoices;
            if (filePath == null)
            {
                items          = new EntitySimpleBaseType[4];
                itemChoices    = new xmlfilecontent_ItemsChoices[3];
                itemChoices[0] = xmlfilecontent_ItemsChoices.path;
                itemChoices[1] = xmlfilecontent_ItemsChoices.filename;
                itemChoices[2] = xmlfilecontent_ItemsChoices.xpath;
                items[0]       = path;
                items[1]       = fileName;
                items[2]       = xpath;
            }
            else
            {
                items          = new EntitySimpleBaseType[3];
                itemChoices    = new xmlfilecontent_ItemsChoices[2];
                itemChoices[0] = xmlfilecontent_ItemsChoices.filepath;
                itemChoices[1] = xmlfilecontent_ItemsChoices.xpath;
                items[0]       = filePath;
                items[1]       = xpath;
            }

            newXmlFileContentObject.Items = items;
            newXmlFileContentObject.XmlfilecontentItemsElementName = itemChoices;

            return(newXmlFileContentObject);
        }
        private fileauditedpermissions53_object CreateFileObject(
            EntitySimpleBaseType filePath, EntitySimpleBaseType fileName, EntitySimpleBaseType path, EntitySimpleBaseType xpath)
        {
            EntitySimpleBaseType[] items;
            fileauditedpermissions53_objectItemsChoices[] itemChoices;
            if (filePath == null)
            {
                items          = new EntitySimpleBaseType[4];
                itemChoices    = new fileauditedpermissions53_objectItemsChoices[3];
                itemChoices[0] = fileauditedpermissions53_objectItemsChoices.path;
                itemChoices[1] = fileauditedpermissions53_objectItemsChoices.filename;
                itemChoices[2] = fileauditedpermissions53_objectItemsChoices.trustee_sid;
                items[0]       = path;
                items[1]       = fileName;
                items[2]       = xpath;
            }
            else
            {
                items          = new EntitySimpleBaseType[3];
                itemChoices    = new fileauditedpermissions53_objectItemsChoices[2];
                itemChoices[0] = fileauditedpermissions53_objectItemsChoices.filepath;
                itemChoices[1] = fileauditedpermissions53_objectItemsChoices.trustee_sid;
                items[0]       = filePath;
                items[1]       = xpath;
            }

            return(new fileauditedpermissions53_object()
            {
                Items = items, Fileauditedpermissions53ObjectItemsElementName = itemChoices
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Determines whether the object type has some entity that references a variable id.
        /// </summary>
        /// <param name="variableId">The variable id.</param>
        /// <returns></returns>
        public virtual bool HasReferenceForVariable(string variableId)
        {
            IEnumerable <EntitySimpleBaseType> entities = this.GetEntityBaseTypes();
            EntitySimpleBaseType entity = entities.Where <EntitySimpleBaseType>(e => e.var_ref == variableId).FirstOrDefault <EntitySimpleBaseType>();

            return(entity != null);
        }
Esempio n. 6
0
        private bool Compare(EntityItemSimpleBaseType valueOfFieldItemType, EntitySimpleBaseType valueOfFieldStateType)
        {
            string itemValue  = valueOfFieldItemType.Value;
            string stateValue = valueOfFieldStateType.Value;

            if ((itemValue == null) && (stateValue == null))
            {
                return(true);
            }

            // If one of objects to compare is null and another one is not null the compare result must be false.
            if (this.IsOneOfTheseObjectsNullAndAnotherOneNotNull(itemValue, stateValue) &&
                string.IsNullOrEmpty(valueOfFieldStateType.var_ref) &&
                valueOfFieldStateType.datatype != SimpleDatatypeEnumeration.@string)
            {
                return(false);
            }

            var value = valueOfFieldStateType.Value;

            if (IsThereDefinedVariable(valueOfFieldStateType))
            {
                value = ProcessVariableById(valueOfFieldStateType.var_ref);
            }

            IOvalComparator comparator    = new OvalComparatorFactory().GetComparator(valueOfFieldStateType.datatype);
            string          firstElement  = itemValue;
            string          secondElement = value;

            return(comparator.Compare(firstElement, secondElement, valueOfFieldStateType.operation));
        }
Esempio n. 7
0
        private IEnumerable <string> ReturnTheSameValue(EntitySimpleBaseType entityType)
        {
            List <String> values = new List <string>();

            values.Add(entityType.Value);
            return(values);
        }
Esempio n. 8
0
 private IEnumerable<string> processEntityVariable(EntitySimpleBaseType entity)
 {
     List<string> values = new List<string>();
     IEnumerable<VariableValue> variablesOfEntity = variables.GetVariableValueForVariableId(entity.var_ref);
     if (variablesOfEntity.Count() > 0)
         values.AddRange(variablesOfEntity.FirstOrDefault().values);            
     return values;
 }
Esempio n. 9
0
        private void assertGeneratedEntityItem(EntityItemStringType createdEntity, EntitySimpleBaseType sourceEntity, string entityName)
        {
            if (sourceEntity == null)
            {
                return;
            }

            Assert.AreEqual(sourceEntity.Value, createdEntity.Value, string.Format(UNEXPECTED_ENTITY_VALUE_FOUND, entityName));
        }
Esempio n. 10
0
        private IEnumerable <string> processEntityVariable(EntitySimpleBaseType entity)
        {
            List <string> values = new List <string>();
            IEnumerable <VariableValue> variablesOfEntity = variables.GetVariableValueForVariableId(entity.var_ref);

            if (variablesOfEntity.Count() > 0)
            {
                values.AddRange(variablesOfEntity.FirstOrDefault().values);
            }
            return(values);
        }
Esempio n. 11
0
 /// <summary>
 /// This method evaluates variables specified in entityType.
 /// If is not exists any variables, the return value is the same value defined in entityType.
 /// </summary>
 /// <param name="entityType">EntityType.</param>
 /// <returns></returns>
 public IEnumerable <string> Evaluate(EntitySimpleBaseType entityType)
 {
     if (this.ExistsVariableDefined(entityType))
     {
         return(EvaluateVariable(entityType.var_ref));
     }
     else
     {
         return(this.ReturnTheSameValue(entityType));
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Set the variable value in the Entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public IEnumerable<string> EvaluateVariableForEntity(EntitySimpleBaseType entity)
        {
            List<string> variableValues = new List<string>();
            if (entity == null)
                return variableValues;

            if (this.isVariableSet(entity))
                variableValues.AddRange(this.processEntityVariable(entity));
            else
                variableValues.Add(entity.Value);

            return variableValues;
        }        
Esempio n. 13
0
        public IEnumerable <string> EvaluateEntityVariable(EntitySimpleBaseType entity)
        {
            if (entity == null)
            {
                return(null);
            }

            VariableEntityEvaluator variableEvaluator = new VariableEntityEvaluator(this.EvaluatedVariables);
            var variables = variableEvaluator.EvaluateVariableForEntity(entity);

            if ((variables.Count() == 0) && (entity.Value != null))
            {
                ((IList)variables).Add(entity.Value);
            }

            return(variables);
        }
Esempio n. 14
0
        public void Should_not_evaluate_a_variable_if_the_entityType_not_have_a_variable_reference()
        {
            oval_definitions definitions = new OvalDocumentLoader().GetFakeOvalDefinitions("definitionsSimple.xml");

            Assert.IsNotNull(definitions, "the definitios is not created");

            registry_object registryObject = (registry_object)definitions.objects[1];

            Dictionary <String, EntityObjectStringType> registryEntities = this.GetRegistryEntitiesFromName(registryObject);
            EntitySimpleBaseType keyName = registryEntities[registry_object_ItemsChoices.key.ToString()];

            VariableEvaluator    variableEvaluator = new VariableEvaluator(definitions.variables, null, null);
            IEnumerable <string> values            = variableEvaluator.Evaluate(keyName);

            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 valueToMatch is not expected");
        }
Esempio n. 15
0
        private bool MustCheckIfFileExists(xmlfilecontent_object xmlFileContentObject)
        {
            var allObjectEntities = xmlFileContentObject.GetAllObjectEntities();
            EntitySimpleBaseType filepathEntity = null;

            allObjectEntities.TryGetValue(xmlfilecontent_ItemsChoices.filepath.ToString(), out filepathEntity);
            if (filepathEntity != null)
            {
                return(filepathEntity.var_check.Equals(CheckEnumeration.all));
            }

            EntitySimpleBaseType pathEntity     = null;
            EntitySimpleBaseType filenameEntity = null;

            allObjectEntities.TryGetValue(xmlfilecontent_ItemsChoices.path.ToString(), out pathEntity);
            allObjectEntities.TryGetValue(xmlfilecontent_ItemsChoices.filename.ToString(), out filenameEntity);
            return(((pathEntity != null) && string.IsNullOrWhiteSpace(pathEntity.var_ref) && pathEntity.var_check.Equals(CheckEnumeration.all)) ||
                   ((filenameEntity != null) && string.IsNullOrWhiteSpace(filenameEntity.var_ref) && filenameEntity.var_check.Equals(CheckEnumeration.all)));
        }
Esempio n. 16
0
        private IEnumerable <string> processVariablesForEntity(EntitySimpleBaseType entity)
        {
            var variables = new List <string>();

            if (entity == null)
            {
                return(variables);
            }

            var variableEvaluator = new VariableEntityEvaluator(this.variablesEvaluated);

            variables.AddRange(variableEvaluator.EvaluateVariableForEntity(entity));
            if ((variables.Count() == 0) && (!string.IsNullOrEmpty(entity.Value)))
            {
                variables.Add(entity.Value);
            }

            return(variables);
        }
Esempio n. 17
0
        /// <summary>
        /// Set the variable value in the Entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public IEnumerable <string> EvaluateVariableForEntity(EntitySimpleBaseType entity)
        {
            List <string> variableValues = new List <string>();

            if (entity == null)
            {
                return(variableValues);
            }

            if (this.isVariableSet(entity))
            {
                variableValues.AddRange(this.processEntityVariable(entity));
            }
            else
            {
                variableValues.Add(entity.Value);
            }

            return(variableValues);
        }
Esempio n. 18
0
        private IEnumerable <ItemType> ProcessOperation(EntitySimpleBaseType userEntity, IEnumerable <String> evalutedVariables)
        {
            var entityOperation = userEntity.operation;
            var entityValue     = userEntity.Value;

            var userNames = string.IsNullOrEmpty(userEntity.var_ref) ? new string[] { entityValue } : evalutedVariables;

            var result = new List <ItemType>();

            foreach (var userName in userNames)
            {
                if (IsEqualsOperation(userEntity))
                {
                    result.Add(CreateUserItem(userName));
                }
                else
                {
                    foreach (var collectedUser in WindowsAccountProvider.GetAllGroupByUsers())//WindowsAccountProvider.GetAllUsersByGroup())
                    {
                        if (this.Compare(userName, collectedUser.Name, entityOperation))
                        {
                            result.Add(CreateUserItemFromWindowsAccount(collectedUser));
                        }
                    }
                }
            }

            if (result.IsEmpty())
            {
                var newNotExistsItem = CreateUserItem(userNames.FirstOrDefault());

                newNotExistsItem.status = StatusEnumeration.doesnotexist;
                result.Add(newNotExistsItem);
            }

            return(result);
        }
Esempio n. 19
0
        private bool IsVariablesWasProcessed(fileeffectiverights_object fileEffectiveRights, IEnumerable <string> fileNames, IEnumerable <string> paths, IEnumerable <string> trustee_names)
        {
            EntitySimpleBaseType path         = (EntitySimpleBaseType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.path);
            EntitySimpleBaseType fileName     = (EntitySimpleBaseType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.filename);
            EntitySimpleBaseType trustee_name = (EntitySimpleBaseType)fileEffectiveRights.GetItemValue(fileeffectiverights_object_ItemsChoices.trustee_name);
            bool result = true;

            if (!string.IsNullOrEmpty(path.var_ref))
            {
                result = result && ((paths.Count() > 0) && (!string.IsNullOrEmpty(paths.First())));
            }

            if (!string.IsNullOrEmpty(fileName.var_ref))
            {
                result = result && ((fileNames.Count() > 0) && (!string.IsNullOrEmpty(fileNames.First())));
            }

            if (!string.IsNullOrEmpty(trustee_name.var_ref))
            {
                result = result && ((trustee_names.Count() > 0) && (!string.IsNullOrEmpty(trustee_names.First())));
            }

            return(result);
        }
Esempio n. 20
0
 private bool CheckNullForEntities(EntityItemSimpleBaseType valueOfFieldItemType, EntitySimpleBaseType valueOfFieldStateType)
 {
     return((valueOfFieldItemType == null) && (valueOfFieldStateType == null));
 }
Esempio n. 21
0
 private static bool IsThereDefinedVariable(EntitySimpleBaseType valueOfFieldStateType)
 {
     return(!String.IsNullOrEmpty(valueOfFieldStateType.var_ref));
 }
Esempio n. 22
0
 private bool isVariableSet(EntitySimpleBaseType entity)
 {
     return ((entity.var_ref != null) && (entity.var_ref != ""));
 }
Esempio n. 23
0
 private bool ExistsVariableDefined(EntitySimpleBaseType entityType)
 {
     return(entityType.var_ref != null);
 }
Esempio n. 24
0
 private void AssertObjectEntity(EntitySimpleBaseType entityToAssert, string expectedEntiyValue)
 {
     Assert.IsNotNull(entityToAssert);
     Assert.IsNotNull(entityToAssert.Value);
     Assert.AreEqual(expectedEntiyValue, entityToAssert.Value);
 }
Esempio n. 25
0
 private bool isVariableSet(EntitySimpleBaseType entity)
 {
     return((entity.var_ref != null) && (entity.var_ref != ""));
 }
Esempio n. 26
0
 private bool IsEqualsOperation(EntitySimpleBaseType entity)
 {
     return
         (entity.operation.Equals(OperationEnumeration.equals) ||
          entity.operation.Equals(OperationEnumeration.caseinsensitiveequals));
 }
        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);
        }