public IEnumerable <ItemType> GetItemsToCollect(OVAL.Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var variableEvaluator         = new VariableEntityEvaluator(variables);
            var fileEffectiveRightsObject = (fileeffectiverights53_object)objectType;

            var paths     = new List <String>();
            var filenames = new List <String>();

            if (fileEffectiveRightsObject.IsFilePathDefined())
            {
                var filepathEntity = (EntitySimpleBaseType)fileEffectiveRightsObject.GetItemValue(fileeffectiverights53_object_ItemsChoices.filepath);
                var filepathValues = variableEvaluator.EvaluateVariableForEntity(filepathEntity);
                filepathValues = this.ProcessOperationForFilepathEntity(filepathEntity.operation, filepathValues);


                paths.AddRange(filepathValues.Select(filepath => Path.GetDirectoryName(filepath)).Distinct());
                filenames.AddRange(filepathValues.Select(filepath => Path.GetFileName(filepath)).Distinct());
            }
            else
            {
                var pathEntity       = (EntitySimpleBaseType)fileEffectiveRightsObject.GetItemValue(fileeffectiverights53_object_ItemsChoices.path);
                var pathEntityValues = variableEvaluator.EvaluateVariableForEntity(pathEntity);
                pathEntityValues = ProcessOperationForFilepathEntity(pathEntity.operation, pathEntityValues);
                paths.AddRange(pathEntityValues);

                var filenameEntity = (EntitySimpleBaseType)fileEffectiveRightsObject.GetItemValue(fileeffectiverights53_object_ItemsChoices.filename);
                if (filenameEntity == null)
                {
                    filenames.Add(string.Empty);
                }
                else
                {
                    var filenameEntityValues = variableEvaluator.EvaluateVariableForEntity(filenameEntity);
                    filenameEntityValues = ProcessOperationForFilenameEntity(filenameEntity.operation, filenameEntityValues, pathEntityValues);
                    filenames.AddRange(filenameEntityValues.Distinct());
                }
            }

            var trusteeSidEntity       = (EntitySimpleBaseType)fileEffectiveRightsObject.GetItemValue(fileeffectiverights53_object_ItemsChoices.trustee_sid);
            var trusteeSidEntityValues = variableEvaluator.EvaluateVariableForEntity(trusteeSidEntity);

            var itemsToCollect = new List <ItemType>();

            foreach (var path in paths)
            {
                foreach (var filename in filenames)
                {
                    foreach (var trusteeSID in trusteeSidEntityValues)
                    {
                        var newItems = ProcessOperationForTrusteeSidEntity(path, filename, trusteeSID, trusteeSidEntity.operation);
                        itemsToCollect.AddRange(newItems);
                    }
                }
            }

            return(itemsToCollect);
        }
Exemplo n.º 2
0
        public void When_there_is_no_variable_reference_the_entity_variable_evaluation_must_return_the_own_entity_value()
        {
            var objectType = (fileeffectiverights53_object)ProbeHelper.GetDefinitionObjectTypeByID(DEFINITIONS_SIMPLE, OBJECT_ID_1010);
            var variableEntityEvaluator = new VariableEntityEvaluator(VariableHelper.CreateEmptyEvaluatedVariables());
            var trusteeSIDEntity        = objectType.GetAllObjectEntities()[fileeffectiverights53_object_ItemsChoices.trustee_sid.ToString()];
            var evaluationResult        = variableEntityEvaluator.EvaluateVariableForEntity(trusteeSIDEntity);

            this.DoBasicAssertForEntityVariableEvaluation(evaluationResult.ToArray(), 1);
            Assert.AreEqual(trusteeSIDEntity.Value, evaluationResult.First(), MSG_FOR_INVALID_EVALUATION_RESULT);
        }
Exemplo n.º 3
0
        public override void PrepareCollectionOfObjects(IEnumerable <ObjectType> allItemsToCollect, VariablesEvaluated variables)
        {
            base.PrepareCollectionOfObjects(allItemsToCollect, variables);
            if (allItemsToCollect.Count() > 0)
            {
                var variableEvaluator = new VariableEntityEvaluator(variables);

                var allSapObjects = allItemsToCollect.OfType <sapcode_object>().ToList();
                var issues        = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)(x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.issue)])))).Distinct();
                var systemNames   = allSapObjects.SelectMany(x => variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)x.Items[x.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.system_name)]))).Distinct();

                var systemIds = systemNames.Select(x => Convert.ToInt32(x));
                if (systemIds.Count() > 1)
                {
                    throw new NotSupportedException("Only concurrent collections of a single system is supported!");
                }

                ExecutionLogBuilder.AddInfo(string.Format("Authenticating at code control with user '{0}'.", AuthUser));
                var authResult = connectionProvider.authenticate(AuthUser, AuthPassword);
                if (authResult.error)
                {
                    ExecutionLogBuilder.AnErrorOccurred(string.Format("Error authenticating at code control : {0}.", authResult.errorMessage));
                }
                else
                {
                    ExecutionLogBuilder.AddInfo(string.Format("Successfully authenticated.", AuthUser));
                    int nSystem   = systemIds.Single();
                    var allIssues = issues.Select(x => (long)Convert.ToInt32(x)).ToArray();
                    ExecutionLogBuilder.AddInfo(
                        string.Format("Starting scan request for system {0} and issues '{1}'.", nSystem, string.Join(",", allIssues)));
                    issueResult = connectionProvider.scanIssueListBySystem(authResult.token, nSystem, allIssues);

                    var scanCriteria = new ScanCriteriaDTO()
                    {
                        scanIdList = new[] { issueResult.scanId ?? 0 }
                    };

                    var waitTime = 0L;
                    //const int timeOut = 3600000; // 1 hour
                    //const int timeOut = 10800000; // 3 hs
                    const int timeOut = 18000000;
                    while (((issueResult.status == "AWAITING") || (issueResult.status == "PROCESSING")) &&
                           (waitTime <= timeOut)
                           )
                    {
                        Thread.Sleep(40000);
                        issueResult = connectionProvider.findScan(authResult.token, scanCriteria).FirstOrDefault();
                        // Wait time is desconsidering remote call duration,
                        // should be done with a stop watch
                        waitTime += 40000;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public IEnumerable <ItemType> GetItemsToCollect(OVAL.Definitions.ObjectType objectType, OVAL.Definitions.variableEvaluator.VariablesEvaluated variables)
        {
            var metabaseObject = (metabase_object)objectType;

            var variableEvaluator     = new VariableEntityEvaluator(variables);
            var idEntityValues        = variableEvaluator.EvaluateVariableForEntity(metabaseObject.GetIdEntity());
            var keyEntityValues       = variableEvaluator.EvaluateVariableForEntity(metabaseObject.GetKeyEntity());
            var allIdsAfterOperation  = this.ProcessOperationForIdEntity(metabaseObject.GetIdEntity(), idEntityValues);
            var allKeysAfterOperation = this.ProcessOperationForKeyEntity(metabaseObject.GetKeyEntity(), keyEntityValues);

            return(CreateMetabaseItems(allKeysAfterOperation, allIdsAfterOperation));
        }
Exemplo n.º 5
0
        public IEnumerable <OVAL.SystemCharacteristics.ItemType> GetItemsToCollect(ObjectType objectType, VariablesEvaluated variables)
        {
            var processObject       = (OVAL.Definitions.Unix.process_object)objectType;
            var commandEntity       = (EntityObjectStringType)processObject.Item;
            var commandEntityValues = new VariableEntityEvaluator(variables).EvaluateVariableForEntity(commandEntity);

            var itemsToCollect = new List <OVAL.SystemCharacteristics.ItemType>();

            foreach (var commandValue in commandEntityValues)
            {
                itemsToCollect.AddRange(ProcessEntityOperation(commandValue, commandEntity));
            }

            return(itemsToCollect);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public IEnumerable <OVAL.SystemCharacteristics.ItemType> GetItemsToCollect(OVAL.Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var showSubcommandEntity = ((line_object)objectType).GetShowSubcommandEntity();
            var showSubcommandValues =
                new VariableEntityEvaluator(variables)
                .EvaluateVariableForEntity(showSubcommandEntity);

            return
                (showSubcommandValues
                 .Select(v =>
                         new line_item()
            {
                show_subcommand = new EntityItemStringType()
                {
                    Value = v
                }
            }));
        }
Exemplo n.º 8
0
        private IEnumerable <string> processVariablesForEntity(EntityObjectStringType entity)
        {
            List <string> variables = new List <string>();

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

            VariableEntityEvaluator variableEvaluator = new VariableEntityEvaluator(this.variablesEvaluated);

            variables.AddRange(variableEvaluator.EvaluateVariableForEntity(entity));
            if (variables.Count() == 0)
            {
                variables.Add(entity.Value);
            }
            return(variables);
        }
Exemplo n.º 9
0
        public IEnumerable <ItemType> GetItemsToCollect(OVAL.Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var usernameEntity = ((password_object)objectType).Items.OfType <EntityObjectStringType>().FirstOrDefault();

            if (usernameEntity != null)
            {
                var usernames = new VariableEntityEvaluator(variables).EvaluateVariableForEntity(usernameEntity);
                return
                    (usernames
                     .Select(
                         user =>
                         new password_item()
                {
                    username = OvalHelper.CreateItemEntityWithStringValue(user)
                }));
            }

            return(null);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public virtual IEnumerable <ItemType> GetItemsToCollect(Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var variableEvaluator = new VariableEntityEvaluator(variables);
            var namespaceEntity   = (EntityObjectStringType)((wmi_object)objectType).GetItemValue(wmi_object_ItemsChoices.@namespace);
            var wqlEntity         = (EntityObjectStringType)((wmi_object)objectType).GetItemValue(wmi_object_ItemsChoices.wql);

            var namespaces = variableEvaluator.EvaluateVariableForEntity(namespaceEntity);
            var wqls       = variableEvaluator.EvaluateVariableForEntity(wqlEntity);

            var itemsToCollect = new List <ItemType>();

            foreach (var ns in namespaces)
            {
                foreach (var wql in wqls)
                {
                    itemsToCollect.Add(this.CreateWmiItem(ns, wql));
                }
            }
            return(itemsToCollect);
        }
Exemplo n.º 12
0
        public IEnumerable <ItemType> GetItemsToCollect(Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var sapcodeObjectType = (sapcode_object)objectType;
            var variableEvaluator = new VariableEntityEvaluator(variables);
            var issues            = variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)sapcodeObjectType.Items[sapcodeObjectType.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.issue)]));
            var systemNames       = variableEvaluator.EvaluateVariableForEntity(((EntitySimpleBaseType)sapcodeObjectType.Items[sapcodeObjectType.ItemsElementName.ToList().IndexOf(SapCodeObjectItemsChoices.system_name)]));
            var itemList          = new List <ItemType>();

            foreach (var systemName in systemNames)
            {
                foreach (var issueNumber in issues)
                {
                    itemList.Add(new sapcode_item()
                    {
                        issue       = OvalHelper.CreateItemEntityWithIntegerValue(issueNumber),
                        system_name = OvalHelper.CreateItemEntityWithIntegerValue(systemName)
                    });
                }
            }

            return(itemList.ToArray());
        }
Exemplo n.º 13
0
        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");
        }
Exemplo n.º 14
0
        public IEnumerable <ItemType> GetItemsToCollect(OVAL.Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var fmriEntity = ((OVAL.Definitions.Solaris.smf_object)objectType).GetFmriEntity();

            if (fmriEntity.operation != OperationEnumeration.equals)
            {
                return(CreateSmfItemWithErrorStatus(fmriEntity));
            }


            var fmriValues     = new VariableEntityEvaluator(variables).EvaluateVariableForEntity(fmriEntity);
            var itemsToCollect = new List <ItemType>();

            foreach (var fmriValue in fmriValues)
            {
                var newSmfItem = new smf_item()
                {
                    fmri = OvalHelper.CreateItemEntityWithStringValue(fmriValue)
                };
                itemsToCollect.Add(newSmfItem);
            }

            return(itemsToCollect);
        }
 public XmlFileContentVariableEvaluator(VariablesEvaluated variables)
 {
     this.VariableEntityEvaluator = new VariableEntityEvaluator(variables);
 }
Exemplo n.º 16
0
        public IEnumerable <ItemType> GetItemsToCollect(Definitions.ObjectType objectType, VariablesEvaluated variables)
        {
            var fileObject        = ((textfilecontent54_object)objectType);
            var variableEvaluator = new VariableEntityEvaluator(variables);

            IList <string> filepaths = new List <string>();
            IList <string> paths     = new List <string>();
            IList <string> filenames = new List <string>();

            if (fileObject.IsFilePathDefined())
            {
                filepaths =
                    variableEvaluator
                    .EvaluateVariableForEntity(
                        (EntitySimpleBaseType)fileObject.GetItemValue(
                            textfilecontent54_ItemsChoices.filepath)).ToList();

                foreach (var filepath in filepaths)
                {
                    var indexOfLastSlash = filepath.LastIndexOf("/");
                    var path             = filepath.Substring(0, indexOfLastSlash + 1);
                    var filename         = filepath.Replace(path, string.Empty);

                    paths.Add(path);
                    filenames.Add(filename);
                }
            }
            else
            {
                paths =
                    variableEvaluator
                    .EvaluateVariableForEntity(
                        (EntitySimpleBaseType)fileObject.GetItemValue(
                            textfilecontent54_ItemsChoices.path)).ToList();
                filenames =
                    variableEvaluator
                    .EvaluateVariableForEntity(
                        (EntitySimpleBaseType)fileObject.GetItemValue(
                            textfilecontent54_ItemsChoices.filename)).ToList();

                foreach (var path in paths)
                {
                    foreach (var filename in filenames)
                    {
                        filepaths.Add(string.Format("{0}/{1}", path, filename).Replace("//", "/"));
                    }
                }
            }

            var entityPattern = (EntitySimpleBaseType)fileObject.GetItemValue(textfilecontent54_ItemsChoices.pattern);
            var pattern       = variableEvaluator.EvaluateVariableForEntity(entityPattern).SingleOrDefault();

            var entityInstance = (EntitySimpleBaseType)fileObject.GetItemValue(textfilecontent54_ItemsChoices.instance);
            var instance       = variableEvaluator.EvaluateVariableForEntity(entityInstance).SingleOrDefault();

            var itemsToCollect = new List <ItemType>();

            foreach (var filepath in filepaths)
            {
                if (string.IsNullOrWhiteSpace(pattern))
                {
                    continue;
                }

                var fileContentSearchParameters =
                    TextFileContentObjectCollector
                    .GetDictionaryWithParametersToSearchTextFileConten(
                        filepath, pattern, int.Parse(instance), fileObject.IsMultiline());

                try
                {
                    var matchLines = ObjectCollector.GetValues(fileContentSearchParameters);
                    if (matchLines == null || matchLines.Count <= 0)
                    {
                        var newNotExistsItem = CreateTextFileContentItem(filepath, "", "", pattern, instance, null);
                        newNotExistsItem.status = StatusEnumeration.doesnotexist;
                        itemsToCollect.Add(newNotExistsItem);
                    }
                    else
                    {
                        var newCollectedItem = CreateTextFileContentItem(filepath, "", "", pattern, instance, null);
                        var result           = string.Join(System.Environment.NewLine, matchLines);
                        ((textfilecontent_item)newCollectedItem).text = new EntityItemAnySimpleType()
                        {
                            Value = result
                        };
                        itemsToCollect.Add(newCollectedItem);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    var newNotCollectedItem = CreateTextFileContentItem(filepath, "", "", pattern, instance, null);
                    newNotCollectedItem.status = StatusEnumeration.notcollected;
                    itemsToCollect.Add(newNotCollectedItem);
                }
            }

            //IList<ItemType> itemsToCollect = new List<ItemType>();
            //for (int i = 0; i < filepaths.Count; i++)
            //{
            //    if ((filepaths[i] != null) && (paths[i] != null) && (filenames[i] != null) && (pattern != null) && (instance != null))
            //    {
            //        var fileContents = this.FileContentCollector.GetTextFileFullContentInLines(filepaths[i]); //this.FileContentCollector.GetTextFileContent(filepaths[i], pattern);
            //        if ((fileContents == null) || (fileContents.Count() <= 0))
            //        {
            //            var newFileContentItem = CreateTextFileContentItem(filepaths[i], "", "", "", "", "");
            //            newFileContentItem.status = StatusEnumeration.doesnotexist;
            //            itemsToCollect.Add(newFileContentItem);
            //            continue;
            //        }

            //        var matchLines = new Dictionary<int, string>();
            //        for (int currentInstance = 1; currentInstance <= fileContents.Count(); currentInstance++)
            //        {
            //            var comparator = new OvalComparatorFactory().GetComparator(entityInstance.datatype);
            //            if (comparator.Compare(instance, currentInstance.ToString(), entityInstance.operation))
            //            {
            //                var instanceNumber = currentInstance - 1;
            //                var matchLine = fileContents[instanceNumber].Text;
            //                matchLines.Add(currentInstance, matchLine);
            //            }
            //        }

            //        foreach (var matchLine in matchLines)
            //        {
            //            var newTextFileContent =
            //                CreateTextFileContentItem(
            //                    filepaths[i],
            //                    paths[i],
            //                    filenames[i],
            //                    pattern,
            //                    matchLine.Key.ToString(),
            //                    matchLine.Value);

            //            itemsToCollect.Add(newTextFileContent);
            //        }
            //    }
            //}

            return(itemsToCollect);
        }
Exemplo n.º 17
0
        private IEnumerable <string> EvaluateVariable(Modulo.Collect.OVAL.Definitions.EntityObjectStringType variableNameEntity, VariablesEvaluated variables)
        {
            var variableEvaluator = new VariableEntityEvaluator(variables);

            return(variableEvaluator.EvaluateVariableForEntity(variableNameEntity));
        }
 public FileEffectiveRights53EntityVariableEvaluator(VariablesEvaluated variables)
 {
     this.VariableEntityEvaluator = new VariableEntityEvaluator(variables);
 }
 public FileAuditedPermissionsVariableEvaluator(VariablesEvaluated variables)
 {
     this.VariableEntityEvaluator = new VariableEntityEvaluator(variables);
 }
Exemplo n.º 20
0
        private IEnumerable <string> EvaluateVariable(EntityObjectStringType variableNameEntity, VariablesEvaluated variables)
        {
            var variableEvaluator = new VariableEntityEvaluator(variables);

            return(variableEvaluator.EvaluateVariableForEntity(variableNameEntity));
        }
Exemplo n.º 21
0
 public FileEffectiveRightsVariableEvaluator(VariablesEvaluated variable)
 {
     this.variables    = variable;
     variableEvaluator = new VariableEntityEvaluator(this.variables);
 }