31
31
#include "xccdf_policy_model_priv.h"
32
32
#include "xccdf_policy_priv.h"
33
33
#include "XCCDF/item.h"
34
+ #include "XCCDF/helpers.h"
34
35
35
36
struct xccdf_policy * xccdf_policy_model_get_existing_policy_by_id (struct xccdf_policy_model * policy_model , const char * profile_id )
36
37
{
@@ -46,6 +47,33 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
46
47
return NULL ;
47
48
}
48
49
50
+ static void _add_selectors_for_all_xccdf_items (struct xccdf_profile * profile , struct xccdf_item * item )
51
+ {
52
+ struct xccdf_item_iterator * children = NULL ;
53
+ if (xccdf_item_get_type (item ) == XCCDF_BENCHMARK ) {
54
+ children = xccdf_benchmark_get_content (XBENCHMARK (item ));
55
+ } else if (xccdf_item_get_type (item ) == XCCDF_GROUP ) {
56
+ children = xccdf_group_get_content (XGROUP (item ));
57
+ }
58
+
59
+ if (xccdf_item_get_type (item ) == XCCDF_RULE ||
60
+ xccdf_item_get_type (item ) == XCCDF_GROUP )
61
+ {
62
+ struct xccdf_select * select = xccdf_select_new ();
63
+ xccdf_select_set_item (select , xccdf_item_get_id (item ));
64
+ xccdf_select_set_selected (select , true);
65
+ xccdf_profile_add_select (profile , select );
66
+ }
67
+
68
+ if (children ) {
69
+ while (xccdf_item_iterator_has_more (children )) {
70
+ struct xccdf_item * current = xccdf_item_iterator_next (children );
71
+ _add_selectors_for_all_xccdf_items (profile , current );
72
+ }
73
+ xccdf_item_iterator_free (children );
74
+ }
75
+ }
76
+
49
77
struct xccdf_policy * xccdf_policy_model_create_policy_by_id (struct xccdf_policy_model * policy_model , const char * id )
50
78
{
51
79
struct xccdf_profile * profile = NULL ;
@@ -56,6 +84,9 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
56
84
profile = xccdf_tailoring_get_profile_by_id (tailoring , id );
57
85
}
58
86
87
+ // The (default) and (all) profiles are de-facto owned by the xccdf_policy
88
+ // and will be freed by it when it's freed. See xccdf_policy_free.
89
+
59
90
if (!profile ) {
60
91
if (id == NULL ) {
61
92
profile = xccdf_profile_new ();
@@ -64,16 +95,27 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
64
95
oscap_text_set_text (title , "No profile (default benchmark)" );
65
96
oscap_text_set_lang (title , "en" );
66
97
xccdf_profile_add_title (profile , title );
67
- }
68
- else {
98
+ } else {
69
99
struct xccdf_benchmark * benchmark = xccdf_policy_model_get_benchmark (policy_model );
70
100
if (benchmark == NULL ) {
71
101
assert (benchmark != NULL );
72
102
return NULL ;
73
103
}
74
- profile = xccdf_benchmark_get_profile_by_id (benchmark , id );
75
- if (profile == NULL )
76
- return NULL ;
104
+
105
+ if (strcmp (id , "(all)" ) == 0 ) {
106
+ profile = xccdf_profile_new ();
107
+ xccdf_profile_set_id (profile , "(all)" );
108
+ struct oscap_text * title = oscap_text_new ();
109
+ oscap_text_set_text (title , "(all) profile (all rules selected)" );
110
+ oscap_text_set_lang (title , "en" );
111
+ xccdf_profile_add_title (profile , title );
112
+
113
+ _add_selectors_for_all_xccdf_items (profile , XITEM (benchmark ));
114
+ } else {
115
+ profile = xccdf_benchmark_get_profile_by_id (benchmark , id );
116
+ if (profile == NULL )
117
+ return NULL ;
118
+ }
77
119
}
78
120
}
79
121
0 commit comments