|
|
d7b4b6 |
From ff5d42dc9164c71d36bb7a3b21d961773d3e22d6 Mon Sep 17 00:00:00 2001
|
|
|
d7b4b6 |
From: Martin Preisler <mpreisle@redhat.com>
|
|
|
d7b4b6 |
Date: Mon, 17 Sep 2018 08:09:45 -0400
|
|
|
d7b4b6 |
Subject: [PATCH 1/4] Introduce a "virtual" "(all)" profile that will select
|
|
|
d7b4b6 |
all groups and all rules
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
This is useful for testing and debugging. It will use default values but
|
|
|
d7b4b6 |
will select everything in the benchmark.
|
|
|
d7b4b6 |
---
|
|
|
d7b4b6 |
src/XCCDF_POLICY/xccdf_policy.c | 6 ++--
|
|
|
d7b4b6 |
src/XCCDF_POLICY/xccdf_policy_model.c | 52 +++++++++++++++++++++++++--
|
|
|
d7b4b6 |
2 files changed, 53 insertions(+), 5 deletions(-)
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
diff --git a/src/XCCDF_POLICY/xccdf_policy.c b/src/XCCDF_POLICY/xccdf_policy.c
|
|
|
d7b4b6 |
index b984d0273..c35fa8dfd 100644
|
|
|
d7b4b6 |
--- a/src/XCCDF_POLICY/xccdf_policy.c
|
|
|
d7b4b6 |
+++ b/src/XCCDF_POLICY/xccdf_policy.c
|
|
|
d7b4b6 |
@@ -2283,8 +2283,10 @@ void xccdf_policy_free(struct xccdf_policy * policy) {
|
|
|
d7b4b6 |
/* A policy which is set to use default profile has its profile member set to NULL,
|
|
|
d7b4b6 |
* check it so we don't try to get the ID from a NULL profile.
|
|
|
d7b4b6 |
* */
|
|
|
d7b4b6 |
- if (policy->profile && xccdf_profile_get_id(policy->profile) == NULL)
|
|
|
d7b4b6 |
- /* If ID of policy's profile is NULL then this
|
|
|
d7b4b6 |
+ if (policy->profile && (
|
|
|
d7b4b6 |
+ (xccdf_profile_get_id(policy->profile) == NULL) ||
|
|
|
d7b4b6 |
+ (strcmp(xccdf_profile_get_id(policy->profile), "(all)") == 0)))
|
|
|
d7b4b6 |
+ /* If ID of policy's profile is NULL or "(all)" then this
|
|
|
d7b4b6 |
* profile is created by Policy layer and need
|
|
|
d7b4b6 |
* to be freed
|
|
|
d7b4b6 |
*/
|
|
|
d7b4b6 |
diff --git a/src/XCCDF_POLICY/xccdf_policy_model.c b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
index 2ec913bbd..37187bc92 100644
|
|
|
d7b4b6 |
--- a/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
+++ b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
@@ -31,6 +31,7 @@
|
|
|
d7b4b6 |
#include "xccdf_policy_model_priv.h"
|
|
|
d7b4b6 |
#include "xccdf_policy_priv.h"
|
|
|
d7b4b6 |
#include "XCCDF/item.h"
|
|
|
d7b4b6 |
+#include "XCCDF/helpers.h"
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_policy_model *policy_model, const char *profile_id)
|
|
|
d7b4b6 |
{
|
|
|
d7b4b6 |
@@ -46,6 +47,38 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
|
|
|
d7b4b6 |
return NULL;
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
+static inline void _add_selectors_for_all_items(struct xccdf_profile *profile, struct xccdf_item *item)
|
|
|
d7b4b6 |
+{
|
|
|
d7b4b6 |
+ struct xccdf_item_iterator *children = NULL;
|
|
|
d7b4b6 |
+ if (xccdf_item_get_type(item) == XCCDF_BENCHMARK) {
|
|
|
d7b4b6 |
+ children = xccdf_benchmark_get_content(XBENCHMARK(item));
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+ else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
|
|
|
d7b4b6 |
+ children = xccdf_group_get_content(XGROUP(item));
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
+ struct xccdf_select *select = xccdf_select_new();
|
|
|
d7b4b6 |
+ xccdf_select_set_item(select, xccdf_item_get_id(item));
|
|
|
d7b4b6 |
+ xccdf_select_set_selected(select, true);
|
|
|
d7b4b6 |
+ xccdf_profile_add_select(profile, select);
|
|
|
d7b4b6 |
+ printf("g: %s\n", xccdf_item_get_id(item));
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+ else if (xccdf_item_get_type(item) == XCCDF_RULE) {
|
|
|
d7b4b6 |
+ struct xccdf_select *select = xccdf_select_new();
|
|
|
d7b4b6 |
+ xccdf_select_set_item(select, xccdf_item_get_id(item));
|
|
|
d7b4b6 |
+ xccdf_select_set_selected(select, true);
|
|
|
d7b4b6 |
+ xccdf_profile_add_select(profile, select);
|
|
|
d7b4b6 |
+ printf("r: %s\n", xccdf_item_get_id(item));
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
+ if (children) {
|
|
|
d7b4b6 |
+ while (xccdf_item_iterator_has_more(children)) {
|
|
|
d7b4b6 |
+ struct xccdf_item *current = xccdf_item_iterator_next(children);
|
|
|
d7b4b6 |
+ _add_selectors_for_all_items(profile, current);
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+ xccdf_item_iterator_free(children);
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+}
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_model *policy_model, const char *id)
|
|
|
d7b4b6 |
{
|
|
|
d7b4b6 |
struct xccdf_profile *profile = NULL;
|
|
|
d7b4b6 |
@@ -71,9 +104,22 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
|
|
|
d7b4b6 |
assert(benchmark != NULL);
|
|
|
d7b4b6 |
return NULL;
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
- profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
|
|
|
d7b4b6 |
- if (profile == NULL)
|
|
|
d7b4b6 |
- return NULL;
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
+ if (strcmp(id, "(all)") == 0) {
|
|
|
d7b4b6 |
+ profile = xccdf_profile_new();
|
|
|
d7b4b6 |
+ xccdf_profile_set_id(profile, "(all)");
|
|
|
d7b4b6 |
+ struct oscap_text *title = oscap_text_new();
|
|
|
d7b4b6 |
+ oscap_text_set_text(title, "(all) profile (all rules selected)");
|
|
|
d7b4b6 |
+ oscap_text_set_lang(title, "en");
|
|
|
d7b4b6 |
+ xccdf_profile_add_title(profile, title);
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
+ _add_selectors_for_all_items(profile, XITEM(benchmark));
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
+ else {
|
|
|
d7b4b6 |
+ profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
|
|
|
d7b4b6 |
+ if (profile == NULL)
|
|
|
d7b4b6 |
+ return NULL;
|
|
|
d7b4b6 |
+ }
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
From 884e8558dac6f8442e81a081f261cbd114931c31 Mon Sep 17 00:00:00 2001
|
|
|
d7b4b6 |
From: Martin Preisler <mpreisle@redhat.com>
|
|
|
d7b4b6 |
Date: Mon, 17 Sep 2018 09:11:37 -0400
|
|
|
d7b4b6 |
Subject: [PATCH 2/4] Comments, refactoring of the (all) profile feature
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
---
|
|
|
d7b4b6 |
src/XCCDF_POLICY/xccdf_policy_model.c | 21 ++++++++++-----------
|
|
|
d7b4b6 |
1 file changed, 10 insertions(+), 11 deletions(-)
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
diff --git a/src/XCCDF_POLICY/xccdf_policy_model.c b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
index 37187bc92..552229947 100644
|
|
|
d7b4b6 |
--- a/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
+++ b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
@@ -47,7 +47,7 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
|
|
|
d7b4b6 |
return NULL;
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
-static inline void _add_selectors_for_all_items(struct xccdf_profile *profile, struct xccdf_item *item)
|
|
|
d7b4b6 |
+static void _add_selectors_for_all_xccdf_items(struct xccdf_profile *profile, struct xccdf_item *item)
|
|
|
d7b4b6 |
{
|
|
|
d7b4b6 |
struct xccdf_item_iterator *children = NULL;
|
|
|
d7b4b6 |
if (xccdf_item_get_type(item) == XCCDF_BENCHMARK) {
|
|
|
d7b4b6 |
@@ -55,25 +55,21 @@ static inline void _add_selectors_for_all_items(struct xccdf_profile *profile, s
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
|
|
|
d7b4b6 |
children = xccdf_group_get_content(XGROUP(item));
|
|
|
d7b4b6 |
-
|
|
|
d7b4b6 |
- struct xccdf_select *select = xccdf_select_new();
|
|
|
d7b4b6 |
- xccdf_select_set_item(select, xccdf_item_get_id(item));
|
|
|
d7b4b6 |
- xccdf_select_set_selected(select, true);
|
|
|
d7b4b6 |
- xccdf_profile_add_select(profile, select);
|
|
|
d7b4b6 |
- printf("g: %s\n", xccdf_item_get_id(item));
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
- else if (xccdf_item_get_type(item) == XCCDF_RULE) {
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
+ if (xccdf_item_get_type(item) == XCCDF_RULE ||
|
|
|
d7b4b6 |
+ xccdf_item_get_type(item) == XCCDF_GROUP)
|
|
|
d7b4b6 |
+ {
|
|
|
d7b4b6 |
struct xccdf_select *select = xccdf_select_new();
|
|
|
d7b4b6 |
xccdf_select_set_item(select, xccdf_item_get_id(item));
|
|
|
d7b4b6 |
xccdf_select_set_selected(select, true);
|
|
|
d7b4b6 |
xccdf_profile_add_select(profile, select);
|
|
|
d7b4b6 |
- printf("r: %s\n", xccdf_item_get_id(item));
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
if (children) {
|
|
|
d7b4b6 |
while (xccdf_item_iterator_has_more(children)) {
|
|
|
d7b4b6 |
struct xccdf_item *current = xccdf_item_iterator_next(children);
|
|
|
d7b4b6 |
- _add_selectors_for_all_items(profile, current);
|
|
|
d7b4b6 |
+ _add_selectors_for_all_xccdf_items(profile, current);
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
xccdf_item_iterator_free(children);
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
@@ -89,6 +85,9 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
|
|
|
d7b4b6 |
profile = xccdf_tailoring_get_profile_by_id(tailoring, id);
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
+ // The (default) and (all) profiles are de-facto owned by the xccdf_policy
|
|
|
d7b4b6 |
+ // and will be freed by it when it's freed. See xccdf_policy_free.
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
if (!profile) {
|
|
|
d7b4b6 |
if (id == NULL) {
|
|
|
d7b4b6 |
profile = xccdf_profile_new();
|
|
|
d7b4b6 |
@@ -113,7 +112,7 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
|
|
|
d7b4b6 |
oscap_text_set_lang(title, "en");
|
|
|
d7b4b6 |
xccdf_profile_add_title(profile, title);
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
- _add_selectors_for_all_items(profile, XITEM(benchmark));
|
|
|
d7b4b6 |
+ _add_selectors_for_all_xccdf_items(profile, XITEM(benchmark));
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
else {
|
|
|
d7b4b6 |
profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
From 6496649d6aaf8ccea3c5560f2492f294645378eb Mon Sep 17 00:00:00 2001
|
|
|
d7b4b6 |
From: Martin Preisler <mpreisle@redhat.com>
|
|
|
d7b4b6 |
Date: Mon, 17 Sep 2018 09:13:24 -0400
|
|
|
d7b4b6 |
Subject: [PATCH 3/4] Mention (all) profile in the man page
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
---
|
|
|
d7b4b6 |
utils/oscap.8 | 2 +-
|
|
|
d7b4b6 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
diff --git a/utils/oscap.8 b/utils/oscap.8
|
|
|
d7b4b6 |
index 5af83ec3b..25724155c 100644
|
|
|
d7b4b6 |
--- a/utils/oscap.8
|
|
|
d7b4b6 |
+++ b/utils/oscap.8
|
|
|
d7b4b6 |
@@ -83,7 +83,7 @@ You may specify OVAL Definition files as the last parameter, XCCDF evaluation wi
|
|
|
d7b4b6 |
.TP
|
|
|
d7b4b6 |
\fB\-\-profile PROFILE\fR
|
|
|
d7b4b6 |
.RS
|
|
|
d7b4b6 |
-Select a particular profile from XCCDF document.
|
|
|
d7b4b6 |
+Select a particular profile from XCCDF document. If "(all)" is given a virtual profile that selects all groups and rules will be used.
|
|
|
d7b4b6 |
.RE
|
|
|
d7b4b6 |
.TP
|
|
|
d7b4b6 |
\fB\-\-rule RULE\fR
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
From a7e1395ca912b375c4702250dfde6026e1c54d6c Mon Sep 17 00:00:00 2001
|
|
|
d7b4b6 |
From: Martin Preisler <mpreisle@redhat.com>
|
|
|
d7b4b6 |
Date: Tue, 18 Sep 2018 07:58:08 -0400
|
|
|
d7b4b6 |
Subject: [PATCH 4/4] Fixed coding style issues
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
---
|
|
|
d7b4b6 |
src/XCCDF_POLICY/xccdf_policy_model.c | 9 +++------
|
|
|
d7b4b6 |
1 file changed, 3 insertions(+), 6 deletions(-)
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
diff --git a/src/XCCDF_POLICY/xccdf_policy_model.c b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
index 552229947..55f09fb03 100644
|
|
|
d7b4b6 |
--- a/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
+++ b/src/XCCDF_POLICY/xccdf_policy_model.c
|
|
|
d7b4b6 |
@@ -52,8 +52,7 @@ static void _add_selectors_for_all_xccdf_items(struct xccdf_profile *profile, st
|
|
|
d7b4b6 |
struct xccdf_item_iterator *children = NULL;
|
|
|
d7b4b6 |
if (xccdf_item_get_type(item) == XCCDF_BENCHMARK) {
|
|
|
d7b4b6 |
children = xccdf_benchmark_get_content(XBENCHMARK(item));
|
|
|
d7b4b6 |
- }
|
|
|
d7b4b6 |
- else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
|
|
|
d7b4b6 |
+ } else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
|
|
|
d7b4b6 |
children = xccdf_group_get_content(XGROUP(item));
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
@@ -96,8 +95,7 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
|
|
|
d7b4b6 |
oscap_text_set_text(title, "No profile (default benchmark)");
|
|
|
d7b4b6 |
oscap_text_set_lang(title, "en");
|
|
|
d7b4b6 |
xccdf_profile_add_title(profile, title);
|
|
|
d7b4b6 |
- }
|
|
|
d7b4b6 |
- else {
|
|
|
d7b4b6 |
+ } else {
|
|
|
d7b4b6 |
struct xccdf_benchmark *benchmark = xccdf_policy_model_get_benchmark(policy_model);
|
|
|
d7b4b6 |
if (benchmark == NULL) {
|
|
|
d7b4b6 |
assert(benchmark != NULL);
|
|
|
d7b4b6 |
@@ -113,8 +111,7 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
|
|
|
d7b4b6 |
xccdf_profile_add_title(profile, title);
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
_add_selectors_for_all_xccdf_items(profile, XITEM(benchmark));
|
|
|
d7b4b6 |
- }
|
|
|
d7b4b6 |
- else {
|
|
|
d7b4b6 |
+ } else {
|
|
|
d7b4b6 |
profile = xccdf_benchmark_get_profile_by_id(benchmark, id);
|
|
|
d7b4b6 |
if (profile == NULL)
|
|
|
d7b4b6 |
return NULL;
|