Esempio n. 1
0
void TailoringWindow::setItemSelected(struct xccdf_item* xccdfItem, bool selected)
{
    struct xccdf_select* newSelect = xccdf_select_new();
    xccdf_select_set_item(newSelect, xccdf_item_get_id(xccdfItem));
    xccdf_select_set_selected(newSelect, selected);

    xccdf_profile_add_select(mProfile, newSelect);
    xccdf_policy_add_select(mPolicy, xccdf_select_clone(newSelect));

    if (getXccdfItemInternalSelected(mPolicy, xccdfItem) != selected)
        throw TailoringWindowException(
             QString(
                 "Even though xccdf_select was added to both profile and policy "
                 "to make '%1' selected=%2, it remains selected=%3."
             ).arg(QString::fromUtf8(xccdf_item_get_id(xccdfItem))).arg(selected).arg(!selected)
        );
}
Esempio n. 2
0
void TailoringWindow::syncCollapsedItem(QTreeWidgetItem* item, QSet<QString>& usedCollapsedIds)
{
    struct xccdf_item* xccdfItem = getXccdfItemFromTreeItem(item);
    const QString id = QString::fromUtf8(xccdf_item_get_id(xccdfItem));

    if (mCollapsedItemIds.contains(id))
    {
        mUI.itemsTree->collapseItem(item);
        usedCollapsedIds.insert(id);
    }
    else
    {
        mUI.itemsTree->expandItem(item);
    }

    for (int i = 0; i < item->childCount(); ++i)
        syncCollapsedItem(item->child(i), usedCollapsedIds);
}
Esempio n. 3
0
void TailoringWindow::itemCollapsed(QTreeWidgetItem* item)
{
    struct xccdf_item* xccdfItem = getXccdfItemFromTreeItem(item);
    const QString id = QString::fromUtf8(xccdf_item_get_id(xccdfItem));
    mCollapsedItemIds.insert(id);
}
Esempio n. 4
0
void TailoringWindow::synchronizeTreeItem(QTreeWidgetItem* treeItem, struct xccdf_item* xccdfItem, bool recursive)
{
    ++mSynchronizeItemLock;

    const QString title = oscapTextIteratorGetPreferred(xccdf_item_get_title(xccdfItem));
    treeItem->setText(0, title);

    QString searchable = QString("%1 %2").arg(title, QString::fromUtf8(xccdf_item_get_id(xccdfItem)));
    switch (xccdf_item_get_type(xccdfItem))
    {
        case XCCDF_BENCHMARK:
            treeItem->setIcon(0, getShareIcon("benchmark.png"));
            break;

        case XCCDF_GROUP:
            treeItem->setIcon(0, getShareIcon("group.png"));
            break;

        case XCCDF_RULE:
            treeItem->setIcon(0, getShareIcon("rule.png"));
            {
                struct xccdf_ident_iterator* idents = xccdf_rule_get_idents(xccdf_item_to_rule(xccdfItem));
                while (xccdf_ident_iterator_has_more(idents))
                {
                    struct xccdf_ident* ident = xccdf_ident_iterator_next(idents);
                    searchable += " " + QString::fromUtf8(xccdf_ident_get_id(ident));
                }
                xccdf_ident_iterator_free(idents);
            }
            break;

        case XCCDF_VALUE:
            treeItem->setIcon(0, getShareIcon("value.png"));
            break;

        default:
            treeItem->setIcon(0, QIcon());
            break;
    }

    treeItem->setText(1, searchable);

    treeItem->setData(0, Qt::UserRole, QVariant::fromValue(reinterpret_cast<void*>(xccdfItem)));

    xccdf_type_t xccdfItemType = xccdf_item_get_type(xccdfItem);
    switch (xccdfItemType)
    {
        case XCCDF_RULE:
        case XCCDF_GROUP:
        {
            treeItem->setFlags(treeItem->flags() | Qt::ItemIsUserCheckable);
            treeItem->setCheckState(0,
                    getXccdfItemInternalSelected(mPolicy, xccdfItem) ? Qt::Checked : Qt::Unchecked);
            _syncXCCDFItemChildrenDisabledState(treeItem, treeItem->checkState(0));
            break;
        }
        case XCCDF_VALUE:
            treeItem->setFlags(treeItem->flags() & ~Qt::ItemIsUserCheckable);
        default:
            break;
    }

    if (recursive)
    {
        typedef std::vector<struct xccdf_item*> XCCDFItemVector;
        typedef std::map<struct xccdf_item*, QTreeWidgetItem*> XCCDFToQtItemMap;

        XCCDFItemVector itemsToAdd;
        XCCDFToQtItemMap existingItemsMap;

        // valuesIt contains Values
        struct xccdf_value_iterator* valuesIt = NULL;
        // itemsIt contains Rules and Groups
        struct xccdf_item_iterator* itemsIt = NULL;

        switch (xccdfItemType)
        {
            case XCCDF_GROUP:
                valuesIt = xccdf_group_get_values(xccdf_item_to_group(xccdfItem));
                itemsIt = xccdf_group_get_content(xccdf_item_to_group(xccdfItem));
                break;
            case XCCDF_BENCHMARK:
                valuesIt = xccdf_benchmark_get_values(xccdf_item_to_benchmark(xccdfItem));
                itemsIt = xccdf_benchmark_get_content(xccdf_item_to_benchmark(xccdfItem));
                break;
            default:
                break;
        }

        if (valuesIt != NULL)
        {
            while (xccdf_value_iterator_has_more(valuesIt))
            {
                struct xccdf_value* childItem = xccdf_value_iterator_next(valuesIt);
                itemsToAdd.push_back(xccdf_value_to_item(childItem));
            }
            xccdf_value_iterator_free(valuesIt);
        }

        if (itemsIt != NULL)
        {
            while (xccdf_item_iterator_has_more(itemsIt))
            {
                struct xccdf_item* childItem = xccdf_item_iterator_next(itemsIt);
                itemsToAdd.push_back(childItem);
            }
            xccdf_item_iterator_free(itemsIt);
        }

        for (int i = 0; i < treeItem->childCount(); ++i)
        {
            QTreeWidgetItem* childTreeItem = treeItem->child(i);
            struct xccdf_item* childXccdfItem = getXccdfItemFromTreeItem(childTreeItem);

            if (std::find(itemsToAdd.begin(), itemsToAdd.end(), childXccdfItem) == itemsToAdd.end())
            {
                // this will remove it from the tree as well, see ~QTreeWidgetItem()
                delete childTreeItem;
            }
            else
            {
                existingItemsMap[childXccdfItem] = childTreeItem;
            }
        }

        unsigned int idx = 0;
        for (XCCDFItemVector::const_iterator it = itemsToAdd.begin();
                it != itemsToAdd.end(); ++it, ++idx)
        {
            struct xccdf_item* childXccdfItem = *it;
            QTreeWidgetItem* childTreeItem = 0;

            XCCDFToQtItemMap::iterator mapIt = existingItemsMap.find(childXccdfItem);

            if (mapIt == existingItemsMap.end())
            {
                childTreeItem = new QTreeWidgetItem();

                childTreeItem->setFlags(
                        Qt::ItemIsSelectable |
                        Qt::ItemIsEnabled);

                treeItem->insertChild(idx, childTreeItem);
            }
            else
            {
                childTreeItem = mapIt->second;
            }

            synchronizeTreeItem(childTreeItem, childXccdfItem, true);
        }
    }

    --mSynchronizeItemLock;
}
Esempio n. 5
0
inline bool getXccdfItemInternalSelected(struct xccdf_policy* policy, struct xccdf_item* item)
{
    struct xccdf_select* select = xccdf_policy_get_select_by_id(policy, xccdf_item_get_id(item));
    return select ? xccdf_select_get_selected(select) : xccdf_item_get_selected(item);
}
struct xccdf_refine_rule_internal* xccdf_policy_get_refine_rule_by_item(struct xccdf_policy* policy, struct xccdf_item* rule)
{
	const char* item_id = xccdf_item_get_id(rule);
	return oscap_htable_get(policy->refine_rules_internal, item_id);
}