Skip to content

Commit 884e855

Browse files
author
Martin Preisler
committed
Comments, refactoring of the (all) profile feature
1 parent ff5d42d commit 884e855

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/XCCDF_POLICY/xccdf_policy_model.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,29 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
4747
return NULL;
4848
}
4949

50-
static inline void _add_selectors_for_all_items(struct xccdf_profile *profile, struct xccdf_item *item)
50+
static void _add_selectors_for_all_xccdf_items(struct xccdf_profile *profile, struct xccdf_item *item)
5151
{
5252
struct xccdf_item_iterator *children = NULL;
5353
if (xccdf_item_get_type(item) == XCCDF_BENCHMARK) {
5454
children = xccdf_benchmark_get_content(XBENCHMARK(item));
5555
}
5656
else if (xccdf_item_get_type(item) == XCCDF_GROUP) {
5757
children = xccdf_group_get_content(XGROUP(item));
58-
59-
struct xccdf_select *select = xccdf_select_new();
60-
xccdf_select_set_item(select, xccdf_item_get_id(item));
61-
xccdf_select_set_selected(select, true);
62-
xccdf_profile_add_select(profile, select);
63-
printf("g: %s\n", xccdf_item_get_id(item));
6458
}
65-
else if (xccdf_item_get_type(item) == XCCDF_RULE) {
59+
60+
if (xccdf_item_get_type(item) == XCCDF_RULE ||
61+
xccdf_item_get_type(item) == XCCDF_GROUP)
62+
{
6663
struct xccdf_select *select = xccdf_select_new();
6764
xccdf_select_set_item(select, xccdf_item_get_id(item));
6865
xccdf_select_set_selected(select, true);
6966
xccdf_profile_add_select(profile, select);
70-
printf("r: %s\n", xccdf_item_get_id(item));
7167
}
7268

7369
if (children) {
7470
while (xccdf_item_iterator_has_more(children)) {
7571
struct xccdf_item *current = xccdf_item_iterator_next(children);
76-
_add_selectors_for_all_items(profile, current);
72+
_add_selectors_for_all_xccdf_items(profile, current);
7773
}
7874
xccdf_item_iterator_free(children);
7975
}
@@ -89,6 +85,9 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
8985
profile = xccdf_tailoring_get_profile_by_id(tailoring, id);
9086
}
9187

88+
// The (default) and (all) profiles are de-facto owned by the xccdf_policy
89+
// and will be freed by it when it's freed. See xccdf_policy_free.
90+
9291
if (!profile) {
9392
if (id == NULL) {
9493
profile = xccdf_profile_new();
@@ -113,7 +112,7 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
113112
oscap_text_set_lang(title, "en");
114113
xccdf_profile_add_title(profile, title);
115114

116-
_add_selectors_for_all_items(profile, XITEM(benchmark));
115+
_add_selectors_for_all_xccdf_items(profile, XITEM(benchmark));
117116
}
118117
else {
119118
profile = xccdf_benchmark_get_profile_by_id(benchmark, id);

0 commit comments

Comments
 (0)