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,38 @@ struct xccdf_policy *xccdf_policy_model_get_existing_policy_by_id(struct xccdf_p
46
47
return NULL ;
47
48
}
48
49
50
+ static inline void _add_selectors_for_all_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
+ }
56
+ else if (xccdf_item_get_type (item ) == XCCDF_GROUP ) {
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
+ }
65
+ else if (xccdf_item_get_type (item ) == XCCDF_RULE ) {
66
+ struct xccdf_select * select = xccdf_select_new ();
67
+ xccdf_select_set_item (select , xccdf_item_get_id (item ));
68
+ xccdf_select_set_selected (select , true);
69
+ xccdf_profile_add_select (profile , select );
70
+ printf ("r: %s\n" , xccdf_item_get_id (item ));
71
+ }
72
+
73
+ if (children ) {
74
+ while (xccdf_item_iterator_has_more (children )) {
75
+ struct xccdf_item * current = xccdf_item_iterator_next (children );
76
+ _add_selectors_for_all_items (profile , current );
77
+ }
78
+ xccdf_item_iterator_free (children );
79
+ }
80
+ }
81
+
49
82
struct xccdf_policy * xccdf_policy_model_create_policy_by_id (struct xccdf_policy_model * policy_model , const char * id )
50
83
{
51
84
struct xccdf_profile * profile = NULL ;
@@ -71,9 +104,22 @@ struct xccdf_policy *xccdf_policy_model_create_policy_by_id(struct xccdf_policy_
71
104
assert (benchmark != NULL );
72
105
return NULL ;
73
106
}
74
- profile = xccdf_benchmark_get_profile_by_id (benchmark , id );
75
- if (profile == NULL )
76
- return NULL ;
107
+
108
+ if (strcmp (id , "(all)" ) == 0 ) {
109
+ profile = xccdf_profile_new ();
110
+ xccdf_profile_set_id (profile , "(all)" );
111
+ struct oscap_text * title = oscap_text_new ();
112
+ oscap_text_set_text (title , "(all) profile (all rules selected)" );
113
+ oscap_text_set_lang (title , "en" );
114
+ xccdf_profile_add_title (profile , title );
115
+
116
+ _add_selectors_for_all_items (profile , XITEM (benchmark ));
117
+ }
118
+ else {
119
+ profile = xccdf_benchmark_get_profile_by_id (benchmark , id );
120
+ if (profile == NULL )
121
+ return NULL ;
122
+ }
77
123
}
78
124
}
79
125
0 commit comments