|
|
8b65ee |
From df7b06ffaab9f593ae672182a43e43b145fc7739 Mon Sep 17 00:00:00 2001
|
|
|
8b65ee |
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
|
|
|
8b65ee |
Date: Tue, 13 Nov 2018 11:15:17 +0100
|
|
|
8b65ee |
Subject: [PATCH] Fix trailing whitespaces in Ansible Playbooks
|
|
|
8b65ee |
|
|
|
8b65ee |
Code which generates Ansible remediations updated to:
|
|
|
8b65ee |
* remove trailing whitespaces from the Ansible remediation lines,
|
|
|
8b65ee |
* not indent empty Ansible remediation lines.
|
|
|
8b65ee |
These issues were found by `ansible-lint`. Also trailing whitespaces
|
|
|
8b65ee |
got removed from the generated remediation headers.
|
|
|
8b65ee |
---
|
|
|
8b65ee |
src/XCCDF_POLICY/xccdf_policy_remediate.c | 38 ++++++++++++++++-------
|
|
|
8b65ee |
1 file changed, 27 insertions(+), 11 deletions(-)
|
|
|
8b65ee |
|
|
|
8b65ee |
diff --git a/src/XCCDF_POLICY/xccdf_policy_remediate.c b/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
8b65ee |
index acf2c11951..344ff68859 100644
|
|
|
8b65ee |
--- a/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
8b65ee |
+++ b/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
8b65ee |
@@ -22,7 +22,8 @@
|
|
|
8b65ee |
#endif
|
|
|
8b65ee |
|
|
|
8b65ee |
#include <string.h>
|
|
|
8b65ee |
+#include <ctype.h>
|
|
|
8b65ee |
#include <errno.h>
|
|
|
8b65ee |
#include <sys/stat.h>
|
|
|
8b65ee |
#include <sys/wait.h>
|
|
|
8b65ee |
#include <unistd.h>
|
|
|
8b65ee |
@@ -103,6 +104,7 @@ static int _write_remediation_to_fd_and_free(int output_fd, const char* template
|
|
|
8b65ee |
|
|
|
8b65ee |
char *current = text;
|
|
|
8b65ee |
char *next_delim = NULL;
|
|
|
8b65ee |
+ char *end = NULL;
|
|
|
8b65ee |
|
|
|
8b65ee |
do {
|
|
|
8b65ee |
next_delim = strchr(current, delim);
|
|
|
8b65ee |
@@ -110,17 +112,27 @@ static int _write_remediation_to_fd_and_free(int output_fd, const char* template
|
|
|
8b65ee |
*next_delim = '\0';
|
|
|
8b65ee |
}
|
|
|
8b65ee |
|
|
|
8b65ee |
- // write indentation
|
|
|
8b65ee |
- if (_write_text_to_fd(output_fd, indentation) != 0) {
|
|
|
8b65ee |
- free(text);
|
|
|
8b65ee |
- return 1;
|
|
|
8b65ee |
+ // remove all trailing whitespaces
|
|
|
8b65ee |
+ end = current + strlen(current) - 1;
|
|
|
8b65ee |
+ while (isspace(*end)) {
|
|
|
8b65ee |
+ *end = '\0';
|
|
|
8b65ee |
+ if (end == current)
|
|
|
8b65ee |
+ break;
|
|
|
8b65ee |
+ end--;
|
|
|
8b65ee |
}
|
|
|
8b65ee |
|
|
|
8b65ee |
- // write rest of line
|
|
|
8b65ee |
- if (_write_text_to_fd(output_fd, current) != 0) {
|
|
|
8b65ee |
- free(text);
|
|
|
8b65ee |
- return 1;
|
|
|
8b65ee |
+ if (strlen(current) != 0) {
|
|
|
8b65ee |
+ // write indentation
|
|
|
8b65ee |
+ if (_write_text_to_fd(output_fd, indentation) != 0) {
|
|
|
8b65ee |
+ free(text);
|
|
|
8b65ee |
+ return 1;
|
|
|
8b65ee |
+ }
|
|
|
8b65ee |
+ if (_write_text_to_fd(output_fd, current) != 0) {
|
|
|
8b65ee |
+ free(text);
|
|
|
8b65ee |
+ return 1;
|
|
|
8b65ee |
+ }
|
|
|
8b65ee |
}
|
|
|
8b65ee |
+
|
|
|
8b65ee |
if (_write_text_to_fd(output_fd, "\n") != 0) {
|
|
|
8b65ee |
free(text);
|
|
|
8b65ee |
return 1;
|
|
|
8b65ee |
@@ -130,8 +142,12 @@ static int _write_remediation_to_fd_and_free(int output_fd, const char* template
|
|
|
8b65ee |
// text is NULL terminated to this is guaranteed to point to valid memory
|
|
|
8b65ee |
current = next_delim + 1;
|
|
|
8b65ee |
}
|
|
|
8b65ee |
+ } while (next_delim != NULL);
|
|
|
8b65ee |
+
|
|
|
8b65ee |
+ if (_write_text_to_fd(output_fd, "\n") != 0) {
|
|
|
8b65ee |
+ free(text);
|
|
|
8b65ee |
+ return 1;
|
|
|
8b65ee |
}
|
|
|
8b65ee |
- while (next_delim != NULL);
|
|
|
8b65ee |
|
|
|
8b65ee |
free(text);
|
|
|
8b65ee |
return 0;
|
|
|
8b65ee |
@@ -852,7 +868,7 @@ static int _write_script_header_to_fd(struct xccdf_policy *policy, struct xccdf_
|
|
|
8b65ee |
"# Benchmark Version: %s\n#\n"
|
|
|
8b65ee |
"# XCCDF Version: %s\n#\n"
|
|
|
8b65ee |
"# This file was generated by OpenSCAP %s using:\n"
|
|
|
8b65ee |
- "# $ oscap xccdf generate fix --profile %s%s%s xccdf-file.xml \n#\n"
|
|
|
8b65ee |
+ "# $ oscap xccdf generate fix --profile %s%s%s xccdf-file.xml\n#\n"
|
|
|
8b65ee |
"# This script is generated from an OpenSCAP profile without preliminary evaluation.\n"
|
|
|
8b65ee |
"# It attempts to fix every selected rule, even if the system is already compliant.\n"
|
|
|
8b65ee |
"#\n"
|
|
|
8b65ee |
@@ -881,7 +897,7 @@ static int _write_script_header_to_fd(struct xccdf_policy *policy, struct xccdf_
|
|
|
8b65ee |
"# Evaluation Start Time: %s\n"
|
|
|
8b65ee |
"# Evaluation End Time: %s\n#\n"
|
|
|
8b65ee |
"# This file was generated by OpenSCAP %s using:\n"
|
|
|
8b65ee |
- "# $ oscap xccdf generate fix --result-id %s%s%s xccdf-results.xml \n#\n"
|
|
|
8b65ee |
+ "# $ oscap xccdf generate fix --result-id %s%s%s xccdf-results.xml\n#\n"
|
|
|
8b65ee |
"# This script is generated from the results of a profile evaluation.\n"
|
|
|
8b65ee |
"# It attempts to remediate all issues from the selected rules that failed the test.\n"
|
|
|
8b65ee |
"#\n"
|