@@ -667,19 +667,28 @@ struct blueprint_entries {
667
667
oscap_pcre_t * re ;
668
668
};
669
669
670
- static inline int _parse_blueprint_fix (const char * fix_text , struct oscap_list * generic , struct oscap_list * services_enable , struct oscap_list * services_disable , struct oscap_list * kernel_append )
670
+ struct blueprint_customizations {
671
+ struct oscap_list * generic ;
672
+ struct oscap_list * services_enable ;
673
+ struct oscap_list * services_disable ;
674
+ struct oscap_list * services_mask ;
675
+ struct oscap_list * kernel_append ;
676
+ };
677
+
678
+ static inline int _parse_blueprint_fix (const char * fix_text , struct blueprint_customizations * customizations )
671
679
{
672
680
char * err ;
673
681
int errofs ;
674
682
int ret = 0 ;
675
683
676
684
struct blueprint_entries tab [] = {
677
- {"\\[customizations\\.services\\]\\s+enabled[=\\s]+\\[([^\\]]+)\\]\\s+" , services_enable , NULL },
678
- {"\\[customizations\\.services\\]\\s+disabled[=\\s]+\\[([^\\]]+)\\]\\s+" , services_disable , NULL },
679
- {"\\[customizations\\.kernel\\]\\s+append[=\\s\"]+([^\"]+)[\\s\"]+" , kernel_append , NULL },
685
+ {"\\[customizations\\.services\\]\\s+enabled[=\\s]+\\[([^\\]]+)\\]\\s+" , customizations -> services_enable , NULL },
686
+ {"\\[customizations\\.services\\]\\s+disabled[=\\s]+\\[([^\\]]+)\\]\\s+" , customizations -> services_disable , NULL },
687
+ {"\\[customizations\\.services\\]\\s+masked[=\\s]+\\[([^\\]]+)\\]\\s+" , customizations -> services_mask , NULL },
688
+ {"\\[customizations\\.kernel\\]\\s+append[=\\s\"]+([^\"]+)[\\s\"]+" , customizations -> kernel_append , NULL },
680
689
// We do this only to pop the 'distro' entry to the top of the generic list,
681
690
// effectively placing it to the root of the TOML document.
682
- {"\\s+(distro[=\\s\"]+[^\"]+[\\s\"]+)" , generic , NULL },
691
+ {"\\s+(distro[=\\s\"]+[^\"]+[\\s\"]+)" , customizations -> generic , NULL },
683
692
{NULL , NULL , NULL }
684
693
};
685
694
@@ -714,7 +723,7 @@ static inline int _parse_blueprint_fix(const char *fix_text, struct oscap_list *
714
723
memcpy (val , & fix_text [ovector [2 ]], ovector [3 ] - ovector [2 ]);
715
724
val [ovector [3 ] - ovector [2 ]] = '\0' ;
716
725
717
- if (!oscap_list_contains (kernel_append , val , (oscap_cmp_func ) oscap_streq )) {
726
+ if (!oscap_list_contains (customizations -> kernel_append , val , (oscap_cmp_func ) oscap_streq )) {
718
727
oscap_list_prepend (tab [i ].list , val );
719
728
} else {
720
729
free (val );
@@ -725,7 +734,7 @@ static inline int _parse_blueprint_fix(const char *fix_text, struct oscap_list *
725
734
}
726
735
727
736
if (start_offset < fix_text_len - 1 ) {
728
- oscap_list_add (generic , strdup (fix_text + start_offset ));
737
+ oscap_list_add (customizations -> generic , strdup (fix_text + start_offset ));
729
738
}
730
739
731
740
exit :
@@ -872,14 +881,14 @@ static int _xccdf_policy_rule_generate_fix(struct xccdf_policy *policy, struct x
872
881
return ret ;
873
882
}
874
883
875
- static int _xccdf_policy_rule_generate_blueprint_fix (struct xccdf_policy * policy , struct xccdf_rule * rule , const char * template , struct oscap_list * generic , struct oscap_list * services_enable , struct oscap_list * services_disable , struct oscap_list * kernel_append )
884
+ static int _xccdf_policy_rule_generate_blueprint_fix (struct xccdf_policy * policy , struct xccdf_rule * rule , const char * template , struct blueprint_customizations * customizations )
876
885
{
877
886
char * fix_text = NULL ;
878
887
int ret = _xccdf_policy_rule_get_fix_text (policy , rule , template , & fix_text );
879
888
if (fix_text == NULL ) {
880
889
return ret ;
881
890
}
882
- ret = _parse_blueprint_fix (fix_text , generic , services_enable , services_disable , kernel_append );
891
+ ret = _parse_blueprint_fix (fix_text , customizations );
883
892
free (fix_text );
884
893
return ret ;
885
894
}
@@ -1161,67 +1170,68 @@ static int _write_script_header_to_fd(struct xccdf_policy *policy, struct xccdf_
1161
1170
}
1162
1171
}
1163
1172
1173
+ static inline void _format_and_write_list_into_blueprint_fd (struct oscap_list * list_ , const char * separator , int output_fd )
1174
+ {
1175
+ struct oscap_iterator * it = oscap_iterator_new (list_ );
1176
+ while (oscap_iterator_has_more (it )) {
1177
+ char * var_line = (char * )oscap_iterator_next (it );
1178
+ _write_text_to_fd (output_fd , var_line );
1179
+ if (oscap_iterator_has_more (it ))
1180
+ _write_text_to_fd (output_fd , separator );
1181
+ }
1182
+ oscap_iterator_free (it );
1183
+ }
1184
+
1164
1185
static int _xccdf_policy_generate_fix_blueprint (struct oscap_list * rules_to_fix , struct xccdf_policy * policy , const char * sys , int output_fd )
1165
1186
{
1166
1187
int ret = 0 ;
1167
- struct oscap_list * generic = oscap_list_new ();
1168
- struct oscap_list * services_enable = oscap_list_new ();
1169
- struct oscap_list * services_disable = oscap_list_new ();
1170
- struct oscap_list * kernel_append = oscap_list_new ();
1188
+ struct blueprint_customizations customizations = {
1189
+ .generic = oscap_list_new (),
1190
+ .services_enable = oscap_list_new (),
1191
+ .services_disable = oscap_list_new (),
1192
+ .services_mask = oscap_list_new (),
1193
+ .kernel_append = oscap_list_new ()
1194
+ };
1195
+
1171
1196
struct oscap_iterator * rules_to_fix_it = oscap_iterator_new (rules_to_fix );
1172
1197
while (oscap_iterator_has_more (rules_to_fix_it )) {
1173
1198
struct xccdf_rule * rule = (struct xccdf_rule * )oscap_iterator_next (rules_to_fix_it );
1174
- ret = _xccdf_policy_rule_generate_blueprint_fix (policy , rule , sys , generic , services_enable , services_disable , kernel_append );
1199
+ ret = _xccdf_policy_rule_generate_blueprint_fix (policy , rule , sys , & customizations );
1175
1200
if (ret != 0 )
1176
1201
break ;
1177
1202
}
1178
1203
oscap_iterator_free (rules_to_fix_it );
1179
1204
1180
- struct oscap_iterator * generic_it = oscap_iterator_new (generic );
1205
+ struct oscap_iterator * generic_it = oscap_iterator_new (customizations . generic );
1181
1206
while (oscap_iterator_has_more (generic_it )) {
1182
1207
char * var_line = (char * ) oscap_iterator_next (generic_it );
1183
1208
_write_text_to_fd (output_fd , var_line );
1184
1209
}
1185
1210
_write_text_to_fd (output_fd , "\n" );
1186
1211
oscap_iterator_free (generic_it );
1187
- oscap_list_free (generic , free );
1188
1212
1189
1213
_write_text_to_fd (output_fd , "[customizations.kernel]\nappend = \"" );
1190
- struct oscap_iterator * kernel_append_it = oscap_iterator_new (kernel_append );
1191
- while (oscap_iterator_has_more (kernel_append_it )) {
1192
- char * var_line = (char * ) oscap_iterator_next (kernel_append_it );
1193
- _write_text_to_fd (output_fd , var_line );
1194
- if (oscap_iterator_has_more (kernel_append_it ))
1195
- _write_text_to_fd (output_fd , " " );
1196
- }
1214
+ _format_and_write_list_into_blueprint_fd (customizations .kernel_append , " " , output_fd );
1197
1215
_write_text_to_fd (output_fd , "\"\n\n" );
1198
- oscap_iterator_free (kernel_append_it );
1199
- oscap_list_free (kernel_append , free );
1200
1216
1201
1217
_write_text_to_fd (output_fd , "[customizations.services]\n" );
1202
1218
_write_text_to_fd (output_fd , "enabled = [" );
1203
- struct oscap_iterator * services_enable_it = oscap_iterator_new (services_enable );
1204
- while (oscap_iterator_has_more (services_enable_it )) {
1205
- char * var_line = (char * ) oscap_iterator_next (services_enable_it );
1206
- _write_text_to_fd (output_fd , var_line );
1207
- if (oscap_iterator_has_more (services_enable_it ))
1208
- _write_text_to_fd (output_fd , "," );
1209
- }
1219
+ _format_and_write_list_into_blueprint_fd (customizations .services_enable , "," , output_fd );
1210
1220
_write_text_to_fd (output_fd , "]\n" );
1211
- oscap_iterator_free (services_enable_it );
1212
- oscap_list_free (services_enable , free );
1213
1221
1214
1222
_write_text_to_fd (output_fd , "disabled = [" );
1215
- struct oscap_iterator * services_disable_it = oscap_iterator_new (services_disable );
1216
- while (oscap_iterator_has_more (services_disable_it )) {
1217
- char * var_line = (char * ) oscap_iterator_next (services_disable_it );
1218
- _write_text_to_fd (output_fd , var_line );
1219
- if (oscap_iterator_has_more (services_disable_it ))
1220
- _write_text_to_fd (output_fd , "," );
1221
- }
1223
+ _format_and_write_list_into_blueprint_fd (customizations .services_disable , "," , output_fd );
1224
+ _write_text_to_fd (output_fd , "]\n" );
1225
+
1226
+ _write_text_to_fd (output_fd , "masked = [" );
1227
+ _format_and_write_list_into_blueprint_fd (customizations .services_mask , "," , output_fd );
1222
1228
_write_text_to_fd (output_fd , "]\n\n" );
1223
- oscap_iterator_free (services_disable_it );
1224
- oscap_list_free (services_disable , free );
1229
+
1230
+ oscap_list_free (customizations .services_mask , free );
1231
+ oscap_list_free (customizations .services_disable , free );
1232
+ oscap_list_free (customizations .kernel_append , free );
1233
+ oscap_list_free (customizations .services_enable , free );
1234
+ oscap_list_free (customizations .generic , free );
1225
1235
1226
1236
return ret ;
1227
1237
}
0 commit comments