adamwill / rpms / openscap

Forked from rpms/openscap 3 years ago
Clone

Blame SOURCES/openscap-1.2.14-warning-by-default-PR-630.patch

4e2b27
From bb66711ed1151a5dfaa52a9ba4ad3658bdf546f7 Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Wed, 4 Jan 2017 16:41:31 -0500
4e2b27
Subject: [PATCH 1/9] Make WARNING the default verbosity level
4e2b27
4e2b27
---
4e2b27
 src/common/debug.c | 2 +-
4e2b27
 1 file changed, 1 insertion(+), 1 deletion(-)
4e2b27
4e2b27
diff --git a/src/common/debug.c b/src/common/debug.c
4e2b27
index bbcad4583..71d345a9d 100644
4e2b27
--- a/src/common/debug.c
4e2b27
+++ b/src/common/debug.c
4e2b27
@@ -85,7 +85,7 @@ oscap_verbosity_levels oscap_verbosity_level_from_cstr(const char *level_name)
4e2b27
 bool oscap_set_verbose(const char *verbosity_level, const char *filename, bool is_probe)
4e2b27
 {
4e2b27
 	if (verbosity_level == NULL) {
4e2b27
-		return true;
4e2b27
+		verbosity_level = "WARNING";
4e2b27
 	}
4e2b27
 	__debuglog_level = oscap_verbosity_level_from_cstr(verbosity_level);
4e2b27
 	if (__debuglog_level == DBG_UNKNOWN) {
4e2b27
4e2b27
From 54d66d5db6ab4e3fc24c05e239b7a4c474e3b20e Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Wed, 1 Feb 2017 13:24:47 -0500
4e2b27
Subject: [PATCH 3/9] Changed a warning about parsing without benchmark
4e2b27
 reference to info
4e2b27
4e2b27
It's not a serious warning and in many use-cases is expected.
4e2b27
---
4e2b27
 src/XCCDF/tailoring.c | 2 +-
4e2b27
 1 file changed, 1 insertion(+), 1 deletion(-)
4e2b27
4e2b27
diff --git a/src/XCCDF/tailoring.c b/src/XCCDF/tailoring.c
4e2b27
index dd2379e5f..4fe9e5d88 100644
4e2b27
--- a/src/XCCDF/tailoring.c
4e2b27
+++ b/src/XCCDF/tailoring.c
4e2b27
@@ -187,7 +187,7 @@ struct xccdf_tailoring *xccdf_tailoring_parse(xmlTextReaderPtr reader, struct xc
4e2b27
 		}
4e2b27
 		case XCCDFE_PROFILE: {
4e2b27
 			if (benchmark != NULL) {
4e2b27
-				dW("Parsing Tailoring Profiles without reference to Benchmark");
4e2b27
+				dI("Parsing Tailoring Profiles without reference to Benchmark");
4e2b27
 			}
4e2b27
 			struct xccdf_item *item = xccdf_profile_parse(reader, benchmark);
4e2b27
 			if (!xccdf_tailoring_add_profile(tailoring, XPROFILE(item))) {
4e2b27
4e2b27
From 3ef6685ae05007f7328b9284c0fcb22732b38f00 Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Wed, 1 Feb 2017 14:00:54 -0500
4e2b27
Subject: [PATCH 4/9] Filter expected permission errors from stderr in
4e2b27
 test_sysctl_probe_all.sh
4e2b27
4e2b27
---
4e2b27
 tests/probes/sysctl/test_sysctl_probe_all.sh | 2 ++
4e2b27
 1 file changed, 2 insertions(+)
4e2b27
4e2b27
diff --git a/tests/probes/sysctl/test_sysctl_probe_all.sh b/tests/probes/sysctl/test_sysctl_probe_all.sh
4e2b27
index 1b725231d..8e763ac37 100755
4e2b27
--- a/tests/probes/sysctl/test_sysctl_probe_all.sh
4e2b27
+++ b/tests/probes/sysctl/test_sysctl_probe_all.sh
4e2b27
@@ -28,6 +28,8 @@ grep unix-sys:name "$result" | sed -E 's;.*>(.*)<.*;\1;g' | sort > "$ourNames"
4e2b27
 
4e2b27
 diff "$sysctlNames" "$ourNames"
4e2b27
 
4e2b27
+# remove oscap error message related to permissions from stderr
4e2b27
+sed -i -E "/^E: lt-probe_sysctl: Can't read sysctl value from /d" "$stderr"
4e2b27
 [ ! -s $stderr ]
4e2b27
 
4e2b27
 rm $stderr $result $ourNames $sysctlNames
4e2b27
4e2b27
From 789486ee35410af0fc5739e2d68436470f2b3006 Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Wed, 1 Feb 2017 14:51:34 -0500
4e2b27
Subject: [PATCH 5/9] Filter out the expected error in sql57 probe test
4e2b27
4e2b27
---
4e2b27
 tests/probes/sql57/unsupported_engine.sh | 2 ++
4e2b27
 1 file changed, 2 insertions(+)
4e2b27
4e2b27
diff --git a/tests/probes/sql57/unsupported_engine.sh b/tests/probes/sql57/unsupported_engine.sh
4e2b27
index f90d6c8b7..6243cff35 100755
4e2b27
--- a/tests/probes/sql57/unsupported_engine.sh
4e2b27
+++ b/tests/probes/sql57/unsupported_engine.sh
4e2b27
@@ -10,6 +10,8 @@ echo "stderr file: $stderr"
4e2b27
 
4e2b27
 echo "Evaluating content."
4e2b27
 $OSCAP oval eval --results $result $srcdir/${name}.oval.xml 2> $stderr
4e2b27
+# filter out the expected error in stderr
4e2b27
+sed -i -E "/^E: lt-probe_sql57: DB engine not supported: sqlserver/d" "$stderr"
4e2b27
 [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
4e2b27
 echo "Validating results."
4e2b27
 #$OSCAP oval validate-xml --results --schematron $result
4e2b27
4e2b27
From cdff2e8504c19f473cbe3b1c64f56b99f13106af Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Wed, 8 Feb 2017 15:04:17 -0500
4e2b27
Subject: [PATCH 6/9] Do not output errors if check engine plugin auto-loading
4e2b27
 fails
4e2b27
4e2b27
If SCE is not installed it will fail in an expected way and it makes no
4e2b27
sense to clutter the error log with it. Explicit plugin loading via the
4e2b27
API will still fail with errors.
4e2b27
---
4e2b27
 src/XCCDF/public/xccdf_session.h              |  3 +++
4e2b27
 src/XCCDF/xccdf_session.c                     | 11 ++++++++---
4e2b27
 src/XCCDF_POLICY/check_engine_plugin.c        | 26 +++++++++++++++++---------
4e2b27
 src/XCCDF_POLICY/public/check_engine_plugin.h |  1 +
4e2b27
 utils/oscap.c                                 |  3 ++-
4e2b27
 5 files changed, 31 insertions(+), 13 deletions(-)
4e2b27
4e2b27
diff --git a/src/XCCDF/public/xccdf_session.h b/src/XCCDF/public/xccdf_session.h
4e2b27
index e1473aebe..2f1bf87c1 100644
4e2b27
--- a/src/XCCDF/public/xccdf_session.h
4e2b27
+++ b/src/XCCDF/public/xccdf_session.h
4e2b27
@@ -358,8 +358,11 @@ int xccdf_session_load_oval(struct xccdf_session *session);
4e2b27
  *
4e2b27
  * @memberof xccdf_session
4e2b27
  * @param session XCCDF Session
4e2b27
+ * @param plugin_name Name of the plugin to load
4e2b27
+ * @param quiet If true we will not output errors if loading fails
4e2b27
  * @returns zero on success
4e2b27
  */
4e2b27
+int xccdf_session_load_check_engine_plugin2(struct xccdf_session *session, const char* plugin_name, bool quiet);
4e2b27
 int xccdf_session_load_check_engine_plugin(struct xccdf_session *session, const char* plugin_name);
4e2b27
 
4e2b27
 /**
4e2b27
diff --git a/src/XCCDF/xccdf_session.c b/src/XCCDF/xccdf_session.c
4e2b27
index 3474e265e..60ea38bae 100644
4e2b27
--- a/src/XCCDF/xccdf_session.c
4e2b27
+++ b/src/XCCDF/xccdf_session.c
4e2b27
@@ -945,9 +945,9 @@ int xccdf_session_load_oval(struct xccdf_session *session)
4e2b27
 	return 0;
4e2b27
 }
4e2b27
 
4e2b27
-int xccdf_session_load_check_engine_plugin(struct xccdf_session *session, const char *plugin_name)
4e2b27
+int xccdf_session_load_check_engine_plugin2(struct xccdf_session *session, const char *plugin_name, bool quiet)
4e2b27
 {
4e2b27
-	struct check_engine_plugin_def *plugin = check_engine_plugin_load(plugin_name);
4e2b27
+	struct check_engine_plugin_def *plugin = check_engine_plugin_load2(plugin_name, quiet);
4e2b27
 
4e2b27
 	if (!plugin)
4e2b27
 		return -1; // error already set
4e2b27
@@ -964,6 +964,11 @@ int xccdf_session_load_check_engine_plugin(struct xccdf_session *session, const
4e2b27
 	}
4e2b27
 }
4e2b27
 
4e2b27
+int xccdf_session_load_check_engine_plugin(struct xccdf_session *session, const char *plugin_name)
4e2b27
+{
4e2b27
+	return xccdf_session_load_check_engine_plugin2(session, plugin_name, false);
4e2b27
+}
4e2b27
+
4e2b27
 int xccdf_session_load_check_engine_plugins(struct xccdf_session *session)
4e2b27
 {
4e2b27
 	xccdf_session_unload_check_engine_plugins(session);
4e2b27
@@ -973,7 +978,7 @@ int xccdf_session_load_check_engine_plugins(struct xccdf_session *session)
4e2b27
 	while (*known_plugins) {
4e2b27
 		// We do not report failure when a known plugin doesn't load properly, that's because they
4e2b27
 		// are optional and we don't know if it's not there or if it just failed to load.
4e2b27
-		if (xccdf_session_load_check_engine_plugin(session, *known_plugins) != 0)
4e2b27
+		if (xccdf_session_load_check_engine_plugin2(session, *known_plugins, true) != 0)
4e2b27
 			oscap_clearerr();
4e2b27
 
4e2b27
 		known_plugins++;
4e2b27
diff --git a/src/XCCDF_POLICY/check_engine_plugin.c b/src/XCCDF_POLICY/check_engine_plugin.c
4e2b27
index af9791a46..ea9e821b6 100644
4e2b27
--- a/src/XCCDF_POLICY/check_engine_plugin.c
4e2b27
+++ b/src/XCCDF_POLICY/check_engine_plugin.c
4e2b27
@@ -47,7 +47,7 @@ static void check_engine_plugin_def_free(struct check_engine_plugin_def *plugin)
4e2b27
 	oscap_free(plugin);
4e2b27
 }
4e2b27
 
4e2b27
-struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
+struct check_engine_plugin_def *check_engine_plugin_load2(const char* path, bool quiet)
4e2b27
 {
4e2b27
 	struct check_engine_plugin_def *ret = check_engine_plugin_def_new();
4e2b27
 
4e2b27
@@ -61,9 +61,10 @@ struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
 	if (!ret->module_handle) {
4e2b27
 		error = dlerror();
4e2b27
 
4e2b27
-		oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
-			"Failed to load extra check engine from '%s'. Details: '%s'.",
4e2b27
-			path, error);
4e2b27
+		if (!quiet)
4e2b27
+			oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
+				"Failed to load extra check engine from '%s'. Details: '%s'.",
4e2b27
+				path, error);
4e2b27
 
4e2b27
 		check_engine_plugin_def_free(ret);
4e2b27
 		return NULL;
4e2b27
@@ -73,9 +74,10 @@ struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
 	*(void **)(&entry_fn) = dlsym(ret->module_handle, STRINGIZE(OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRY));
4e2b27
 
4e2b27
 	if ((error = dlerror()) != NULL) {
4e2b27
-		oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
-			"Failed to retrieve module entry '%s' from loaded extra check engine '%s'. Details: '%s'.",
4e2b27
-			STRINGIZE(OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRY), path, error);
4e2b27
+		if (!quiet)
4e2b27
+			oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
+				"Failed to retrieve module entry '%s' from loaded extra check engine '%s'. Details: '%s'.",
4e2b27
+				STRINGIZE(OPENSCAP_CHECK_ENGINE_PLUGIN_ENTRY), path, error);
4e2b27
 
4e2b27
 		dlclose(ret->module_handle);
4e2b27
 		check_engine_plugin_def_free(ret);
4e2b27
@@ -83,8 +85,9 @@ struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
 	}
4e2b27
 
4e2b27
 	if ((*entry_fn)(ret) != 0) {
4e2b27
-		oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
-			"Failed to fill check_engine_plugin_def when loading check engine plugin '%s'.", path);
4e2b27
+		if (!quiet)
4e2b27
+			oscap_seterr(OSCAP_EFAMILY_GLIBC,
4e2b27
+				"Failed to fill check_engine_plugin_def when loading check engine plugin '%s'.", path);
4e2b27
 
4e2b27
 		dlclose(ret->module_handle);
4e2b27
 		check_engine_plugin_def_free(ret);
4e2b27
@@ -94,6 +97,11 @@ struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
 	return ret;
4e2b27
 }
4e2b27
 
4e2b27
+struct check_engine_plugin_def *check_engine_plugin_load(const char* path)
4e2b27
+{
4e2b27
+	return check_engine_plugin_load2(path, false);
4e2b27
+}
4e2b27
+
4e2b27
 void check_engine_plugin_unload(struct check_engine_plugin_def *plugin)
4e2b27
 {
4e2b27
 	if (!plugin->module_handle) {
4e2b27
diff --git a/src/XCCDF_POLICY/public/check_engine_plugin.h b/src/XCCDF_POLICY/public/check_engine_plugin.h
4e2b27
index 7878fe07f..4a992ae34 100644
4e2b27
--- a/src/XCCDF_POLICY/public/check_engine_plugin.h
4e2b27
+++ b/src/XCCDF_POLICY/public/check_engine_plugin.h
4e2b27
@@ -52,6 +52,7 @@ struct check_engine_plugin_def
4e2b27
 	const char *(*get_capabilities_fn)(void**);
4e2b27
 };
4e2b27
 
4e2b27
+struct check_engine_plugin_def *check_engine_plugin_load2(const char* path, bool quiet);
4e2b27
 struct check_engine_plugin_def *check_engine_plugin_load(const char* path);
4e2b27
 void check_engine_plugin_unload(struct check_engine_plugin_def *plugin);
4e2b27
 
4e2b27
diff --git a/utils/oscap.c b/utils/oscap.c
4e2b27
index 7396101a8..1e966540c 100644
4e2b27
--- a/utils/oscap.c
4e2b27
+++ b/utils/oscap.c
4e2b27
@@ -126,7 +126,8 @@ static int print_versions(const struct oscap_action *action)
4e2b27
 	const char * const *known_plugins = check_engine_plugin_get_known_plugins();
4e2b27
 	bool known_plugin_found = false;
4e2b27
 	while (*known_plugins) {
4e2b27
-		struct check_engine_plugin_def *plugin = check_engine_plugin_load(*known_plugins);
4e2b27
+		// try to load the plugin but output no errors if it fails (quiet=true)
4e2b27
+		struct check_engine_plugin_def *plugin = check_engine_plugin_load2(*known_plugins, true);
4e2b27
 		if (plugin) {
4e2b27
 			printf("%s (from %s)\n", check_engine_plugin_get_capabilities(plugin), *known_plugins);
4e2b27
 			check_engine_plugin_unload(plugin);
4e2b27
4e2b27
From 703c1045aedf1f826f007a01cf8b387b525c1d55 Mon Sep 17 00:00:00 2001
4e2b27
From: Martin Preisler <mpreisle@redhat.com>
4e2b27
Date: Thu, 9 Feb 2017 13:54:53 -0500
4e2b27
Subject: [PATCH 7/9] Filter out the expected warning in
4e2b27
 test_remediation_subs_unresolved
4e2b27
4e2b27
---
4e2b27
 tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh | 2 ++
4e2b27
 1 file changed, 2 insertions(+)
4e2b27
4e2b27
diff --git a/tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh b/tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh
4e2b27
index f48239d93..44ae2f772 100755
4e2b27
--- a/tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh
4e2b27
+++ b/tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh
4e2b27
@@ -35,6 +35,8 @@ assert_exists 1 '//score[text()="0.000000"]'
4e2b27
 ret=0
4e2b27
 $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?
4e2b27
 [ $ret -eq 2 ]
4e2b27
+# filter out the expected warning in stderr
4e2b27
+sed -i -E "/^W: oscap: The xccdf:rule-result\/xccdf:instance element was not found./d" "$stderr"
4e2b27
 [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
4e2b27
 
4e2b27
 $OSCAP xccdf validate-xml $result
4e2b27