@@ -63,6 +63,7 @@ static int _rule_add_info_message(struct xccdf_rule_result *rr, ...)
63
63
64
64
msg = xccdf_message_new ();
65
65
xccdf_message_set_content (msg , text );
66
+ dI ("[%s]->msg: %s" , xccdf_rule_result_get_idref (rr ), text );
66
67
free (text );
67
68
xccdf_message_set_severity (msg , XCCDF_MSG_INFO );
68
69
xccdf_rule_result_add_message (rr , msg );
@@ -379,9 +380,11 @@ static inline int _xccdf_fix_decode_xml(struct xccdf_fix *fix, char **result)
379
380
#if defined(unix ) || defined(__unix__ ) || defined(__unix )
380
381
static inline int _xccdf_fix_execute (struct xccdf_rule_result * rr , struct xccdf_fix * fix )
381
382
{
382
- if (fix == NULL || rr == NULL || oscap_streq (xccdf_fix_get_content (fix ), NULL ))
383
+ if (fix == NULL || rr == NULL || oscap_streq (xccdf_fix_get_content (fix ), NULL )) {
384
+ _rule_add_info_message (rr , "No fix available." );
383
385
return 1 ;
384
-
386
+ }
387
+
385
388
const char * interpret = NULL ;
386
389
if ((interpret = _get_supported_interpret (xccdf_fix_get_system (fix ), NULL )) == NULL ) {
387
390
_rule_add_info_message (rr , "Not supported xccdf:fix/@system='%s' or missing interpreter." ,
@@ -478,10 +481,13 @@ static inline int _xccdf_fix_execute(struct xccdf_rule_result *rr, struct xccdf_
478
481
#else
479
482
static inline int _xccdf_fix_execute (struct xccdf_rule_result * rr , struct xccdf_fix * fix )
480
483
{
481
- if (fix == NULL || rr == NULL || oscap_streq (xccdf_fix_get_content (fix ), NULL ))
484
+ if (fix == NULL || rr == NULL || oscap_streq (xccdf_fix_get_content (fix ), NULL )) {
485
+ _rule_add_info_message (rr , "No fix available." );
482
486
return 1 ;
483
- else
487
+ } else {
484
488
_rule_add_info_message (rr , "Cannot execute the fix script: not implemented" );
489
+ }
490
+
485
491
return 1 ;
486
492
}
487
493
#endif
@@ -493,39 +499,48 @@ int xccdf_policy_rule_result_remediate(struct xccdf_policy *policy, struct xccdf
493
499
if (xccdf_rule_result_get_result (rr ) != XCCDF_RESULT_FAIL )
494
500
return 0 ;
495
501
502
+ // if a miscellaneous error happens (fix unsuitable or if we want to skip it for any reason
503
+ // we set misc_error to one, and the fix will be reported as error (and not skipped without log like before)
504
+ int misc_error = 0 ;
505
+
496
506
if (fix == NULL ) {
497
507
fix = _find_suitable_fix (policy , rr );
498
- if (fix == NULL )
499
- // We may want to append xccdf:message about missing fix.
500
- return 0 ;
508
+ if (fix == NULL ) {
509
+ // We want to append xccdf:message about missing fix.
510
+ _rule_add_info_message (rr , "No suitable fix found." );
511
+ xccdf_rule_result_set_result (rr , XCCDF_RESULT_FAIL );
512
+ misc_error = 1 ;
513
+ }
501
514
}
502
515
503
516
struct xccdf_check * check = NULL ;
504
517
struct xccdf_check_iterator * check_it = xccdf_rule_result_get_checks (rr );
505
518
while (xccdf_check_iterator_has_more (check_it ))
506
519
check = xccdf_check_iterator_next (check_it );
507
520
xccdf_check_iterator_free (check_it );
508
- if (check != NULL && xccdf_check_get_multicheck (check ))
509
- // Do not try to apply fix for multi-check.
510
- return 0 ;
511
-
512
- /* Initialize the fix. */
513
- struct xccdf_fix * cfix = xccdf_fix_clone (fix );
514
- int res = xccdf_policy_resolve_fix_substitution (policy , cfix , rr , test_result );
515
- xccdf_rule_result_add_fix (rr , cfix );
516
- if (res != 0 ) {
517
- _rule_add_info_message (rr , "Fix execution was aborted: Text substitution failed." );
518
- return res ;
519
- }
520
521
521
- /* Execute the fix. */
522
- res = _xccdf_fix_execute (rr , cfix );
523
- if (res != 0 ) {
524
- _rule_add_info_message (rr , "Fix was not executed. Execution was aborted." );
525
- return res ;
522
+ if (misc_error == 0 ){
523
+ /* Initialize the fix. */
524
+ struct xccdf_fix * cfix = xccdf_fix_clone (fix );
525
+ int res = xccdf_policy_resolve_fix_substitution (policy , cfix , rr , test_result );
526
+ xccdf_rule_result_add_fix (rr , cfix );
527
+ if (res != 0 ) {
528
+ _rule_add_info_message (rr , "Fix execution was aborted: Text substitution failed." );
529
+ xccdf_rule_result_set_result (rr , XCCDF_RESULT_ERROR );
530
+ misc_error = 1 ;
531
+ }else {
532
+
533
+ /* Execute the fix. */
534
+ res = _xccdf_fix_execute (rr , cfix );
535
+ if (res != 0 ) {
536
+ _rule_add_info_message (rr , "Fix was not executed. Execution was aborted." );
537
+ xccdf_rule_result_set_result (rr , XCCDF_RESULT_ERROR );
538
+ misc_error = 1 ;
539
+ }
540
+ }
526
541
}
527
542
528
- /* We report rule during remediation only when the fix was actually executed */
543
+ /* We report rule during remediation even if fix isn't executed due to a miscellaneous error */
529
544
int report = 0 ;
530
545
struct xccdf_rule * rule = _lookup_rule_by_rule_result (policy , rr );
531
546
if (rule == NULL ) {
@@ -538,18 +553,20 @@ int xccdf_policy_rule_result_remediate(struct xccdf_policy *policy, struct xccdf
538
553
return report ;
539
554
}
540
555
541
- /* Verify applied fix by calling OVAL again */
542
- if (check == NULL ) {
543
- xccdf_rule_result_set_result (rr , XCCDF_RESULT_ERROR );
544
- _rule_add_info_message (rr , "Failed to verify applied fix: Missing xccdf:check." );
545
- } else {
546
- int new_result = xccdf_policy_check_evaluate (policy , check );
547
- if (new_result == XCCDF_RESULT_PASS )
548
- xccdf_rule_result_set_result (rr , XCCDF_RESULT_FIXED );
549
- else {
556
+ if (misc_error == 0 ){
557
+ /* Verify fix if applied by calling OVAL again */
558
+ if (check == NULL ) {
550
559
xccdf_rule_result_set_result (rr , XCCDF_RESULT_ERROR );
551
- _rule_add_info_message (rr , "Failed to verify applied fix: Checking engine returns: %s" ,
552
- new_result <= 0 ? "internal error" : xccdf_test_result_type_get_text (new_result ));
560
+ _rule_add_info_message (rr , "Failed to verify applied fix: Missing xccdf:check." );
561
+ } else {
562
+ int new_result = xccdf_policy_check_evaluate (policy , check );
563
+ if (new_result == XCCDF_RESULT_PASS )
564
+ xccdf_rule_result_set_result (rr , XCCDF_RESULT_FIXED );
565
+ else {
566
+ xccdf_rule_result_set_result (rr , XCCDF_RESULT_ERROR );
567
+ _rule_add_info_message (rr , "Failed to verify applied fix: Checking engine returns: %s" ,
568
+ new_result <= 0 ? "internal error" : xccdf_test_result_type_get_text (new_result ));
569
+ }
553
570
}
554
571
}
555
572
0 commit comments