@@ -47,33 +47,29 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
47
47
return NULL ;
48
48
}
49
49
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 )
51
51
{
52
52
struct xccdf_item_iterator * children = NULL ;
53
53
if (xccdf_item_get_type (item ) == XCCDF_BENCHMARK ) {
54
54
children = xccdf_benchmark_get_content (XBENCHMARK (item ));
55
55
}
56
56
else if (xccdf_item_get_type (item ) == XCCDF_GROUP ) {
57
57
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 ));
64
58
}
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
+ {
66
63
struct xccdf_select * select = xccdf_select_new ();
67
64
xccdf_select_set_item (select , xccdf_item_get_id (item ));
68
65
xccdf_select_set_selected (select , true);
69
66
xccdf_profile_add_select (profile , select );
70
- printf ("r: %s\n" , xccdf_item_get_id (item ));
71
67
}
72
68
73
69
if (children ) {
74
70
while (xccdf_item_iterator_has_more (children )) {
75
71
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 );
77
73
}
78
74
xccdf_item_iterator_free (children );
79
75
}
@@ -89,6 +85,9 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
89
85
profile = xccdf_tailoring_get_profile_by_id (tailoring , id );
90
86
}
91
87
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
+
92
91
if (!profile ) {
93
92
if (id == NULL ) {
94
93
profile = xccdf_profile_new ();
@@ -113,7 +112,7 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
113
112
oscap_text_set_lang (title , "en" );
114
113
xccdf_profile_add_title (profile , title );
115
114
116
- _add_selectors_for_all_items (profile , XITEM (benchmark ));
115
+ _add_selectors_for_all_xccdf_items (profile , XITEM (benchmark ));
117
116
}
118
117
else {
119
118
profile = xccdf_benchmark_get_profile_by_id (benchmark , id );
0 commit comments