Skip to content

Commit 3f00d7b

Browse files
committed
Move error at the beginning of evaluation
We don't like the current behavior when user needs to wait for the initial scan results just to see the error. We will move the error so it is printed right away and the initial scan is not even performed.
1 parent e433f36 commit 3f00d7b

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

src/XCCDF/xccdf_session.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,32 +1906,6 @@ struct xccdf_rule_result_iterator *xccdf_session_get_rule_results(const struct x
19061906
return xccdf_result_get_rule_results(session->xccdf.result);
19071907
}
19081908

1909-
static bool _system_is_in_bootc_mode(void)
1910-
{
1911-
#ifdef OS_WINDOWS
1912-
return false;
1913-
#else
1914-
#define BOOTC_PATH "/usr/bin/bootc"
1915-
struct stat statbuf;
1916-
if (stat(BOOTC_PATH, &statbuf) == -1) {
1917-
return false;
1918-
}
1919-
FILE *output = popen(BOOTC_PATH " status --format json 2>/dev/null", "r");
1920-
if (output == NULL) {
1921-
return false;
1922-
}
1923-
char buf[1024] = {0};
1924-
int c;
1925-
size_t i = 0;
1926-
while (i < sizeof(buf) && (c = fgetc(output)) != EOF) {
1927-
buf[i] = c;
1928-
i++;
1929-
}
1930-
pclose(output);
1931-
return *buf != '\0' && strstr(buf, "\"booted\":null") == NULL;
1932-
#endif
1933-
}
1934-
19351909
int xccdf_session_remediate(struct xccdf_session *session)
19361910
{
19371911
int res = 0;
@@ -1943,14 +1917,6 @@ int xccdf_session_remediate(struct xccdf_session *session)
19431917
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Can't perform remediation in offline mode: not implemented");
19441918
return 1;
19451919
}
1946-
if (_system_is_in_bootc_mode()) {
1947-
oscap_seterr(OSCAP_EFAMILY_OSCAP,
1948-
"Detected running Image Mode operating system. OpenSCAP can't "
1949-
"perform remediation of this system because majority of the "
1950-
"system is read-only. Please apply remediation during bootable "
1951-
"container image build using 'oscap-im' instead.");
1952-
return 1;
1953-
}
19541920
xccdf_policy_model_unregister_engines(session->xccdf.policy_model, oval_sysname);
19551921
if ((res = xccdf_session_load_oval(session)) != 0)
19561922
return res;

utils/oscap-xccdf.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,33 @@ int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char
586586
return return_code;
587587
}
588588

589+
590+
static bool _system_is_in_bootc_mode(void)
591+
{
592+
#ifdef OS_WINDOWS
593+
return false;
594+
#else
595+
#define BOOTC_PATH "/usr/bin/bootc"
596+
struct stat statbuf;
597+
if (stat(BOOTC_PATH, &statbuf) == -1) {
598+
return false;
599+
}
600+
FILE *output = popen(BOOTC_PATH " status --format json 2>/dev/null", "r");
601+
if (output == NULL) {
602+
return false;
603+
}
604+
char buf[1024] = {0};
605+
int c;
606+
size_t i = 0;
607+
while (i < sizeof(buf) && (c = fgetc(output)) != EOF) {
608+
buf[i] = c;
609+
i++;
610+
}
611+
pclose(output);
612+
return *buf != '\0' && strstr(buf, "\"booted\":null") == NULL;
613+
#endif
614+
}
615+
589616
/**
590617
* XCCDF Processing fucntion
591618
* @param action OSCAP Action structure
@@ -596,6 +623,16 @@ int app_evaluate_xccdf(const struct oscap_action *action)
596623
struct xccdf_session *session = NULL;
597624

598625
int result = OSCAP_ERROR;
626+
627+
if (action->remediate && _system_is_in_bootc_mode()) {
628+
fprintf(stderr,
629+
"Detected running Image Mode operating system. OpenSCAP can't "
630+
"perform remediation of this system because majority of the "
631+
"system is read-only. Please apply remediation during bootable "
632+
"container image build using 'oscap-im' instead.");
633+
return result;
634+
}
635+
599636
#if defined(HAVE_SYSLOG_H)
600637
int priority = LOG_NOTICE;
601638

@@ -797,6 +834,14 @@ int app_xccdf_remediate(const struct oscap_action *action)
797834
{
798835
struct xccdf_session *session = NULL;
799836
int result = OSCAP_ERROR;
837+
if (_system_is_in_bootc_mode()) {
838+
fprintf(stderr,
839+
"Detected running Image Mode operating system. OpenSCAP can't "
840+
"perform remediation of this system because majority of the "
841+
"system is read-only. Please apply remediation during bootable "
842+
"container image build using 'oscap-im' instead.");
843+
return result;
844+
}
800845
session = xccdf_session_new(action->f_xccdf);
801846
if (session == NULL)
802847
goto cleanup;

0 commit comments

Comments
 (0)