Skip to content

Commit a253c73

Browse files
authored
Merge pull request #2233 from evgenyz/fix-bash-remediation-env-1.3
Inherit opscap environment when executing Bash remediations with `--remediate` option
2 parents 6a27cc1 + 9493420 commit a253c73

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/XCCDF_POLICY/xccdf_policy_remediate.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,8 @@ static inline int _xccdf_fix_execute(struct xccdf_rule_result *rr, struct xccdf_
464464
NULL
465465
};
466466

467-
char *const envp[2] = {
468-
"PATH=/bin:/sbin:/usr/bin:/usr/sbin",
469-
NULL
470-
};
471-
472-
execve(interpret, argvp, envp);
467+
// We are inheriting openscap environment
468+
execve(interpret, argvp, environ);
473469
/* Wow, execve returned. In this special case, we failed to execute the fix
474470
* and we return 0 from function. At least the following error message will
475471
* indicate the problem in xccdf:message. */

tests/API/XCCDF/unittests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ add_oscap_test("test_remediation_cdata.sh")
9292
add_oscap_test("test_remediation_subs_unresolved.sh")
9393
add_oscap_test("test_remediation_fix_without_system.sh")
9494
add_oscap_test("test_remediation_invalid_characters.sh")
95+
add_oscap_test("test_remediation_environment.sh")
9596
add_oscap_test("test_remediate_simple.sh")
9697
add_oscap_test("test_remediate_perl.sh")
9798
add_oscap_test("test_report_check_with_empty_selector.sh")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
. $builddir/tests/test_common.sh
3+
4+
set -e
5+
set -o pipefail
6+
7+
name=$(basename $0 .sh)
8+
result=$(mktemp -t ${name}.out.XXXXXX)
9+
10+
rm -f remediation.env
11+
12+
CANARY_EXPORTED="CANARY_EXPORTED_VALUE"
13+
export CANARY_EXPORTED
14+
CANARY_PROCESS="CANARY_PROCESS_VALUE" $OSCAP xccdf eval --remediate $srcdir/${name}.xccdf.xml || true
15+
16+
grep -q "${PATH}" remediation.env || die "PATH not found"
17+
grep -q "CANARY_EXPORTED_VALUE" remediation.env || die "CANARY_EXPORTED_VALUE not found"
18+
grep -q "CANARY_PROCESS_VALUE" remediation.env || die "CANARY_PROCESS_VALUE not found"
19+
20+
rm -f remediation.env
21+
rm $result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_moc.elpmaxe.www_benchmark_test">
3+
<status>accepted</status>
4+
<version>1.0</version>
5+
<Rule selected="true" id="xccdf_moc.elpmaxe.www_rule_1">
6+
<title>Write some environment variables</title>
7+
<fix system="urn:xccdf:fix:script:sh">
8+
echo "PATH=${PATH}" > remediation.env
9+
echo "CANARY_EXPORTED=${CANARY_EXPORTED}" >> remediation.env
10+
echo "CANARY_PROCESS=${CANARY_PROCESS}" >> remediation.env
11+
</fix>
12+
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
13+
<check-content-ref href="test_remediation_simple.oval.xml" name="oval:moc.elpmaxe.www:def:1"/>
14+
</check>
15+
</Rule>
16+
</Benchmark>

0 commit comments

Comments
 (0)