Skip to content

Commit 5015ade

Browse files
authored
Merge pull request #1418 from DominiqueDevinci/contrib_sce
Fix #528 - Eval SCE script when /tmp is in mode noexec
2 parents 30e1931 + fef1619 commit 5015ade

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

src/SCE/sce_engine.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
362362
{
363363
struct sce_parameters* parameters = (struct sce_parameters*)usr;
364364
const char* xccdf_directory = parameters->xccdf_directory;
365+
bool use_sce_wrapper = false; // use osca-run-sce-script ?
365366

366367
char* tmp_href = oscap_sprintf("%s/%s", xccdf_directory, href);
367368

@@ -381,27 +382,26 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
381382

382383
if (access(tmp_href, F_OK | X_OK))
383384
{
384-
// again, only to provide helpful error message
385-
oscap_seterr(OSCAP_EFAMILY_SCE, "SCE has found script file '%s' at '%s' "
386-
"but it isn't executable!", href, tmp_href);
387-
free(tmp_href);
388-
return XCCDF_RESULT_ERROR;
385+
// use the sce wrapper if it's not possible to acquire +x rights
386+
use_sce_wrapper = true;
387+
dI("%s isn't executable, oscap-run-sce-script will be used.", tmp_href);
389388
}
390389

391390
// all the result codes are shifted by 100, because otherwise syntax errors in scripts
392391
// or even their nonexistence would cause XCCDF_RESULT_PASS to be the result
393392

394-
char* argvp[1 + 1] = {
393+
char* argvp[3] = {
395394
tmp_href,
396-
NULL
395+
tmp_href, // the second tmp_href is added in case we use the wrapper (oscap-run-sce-script)
396+
NULL // which need the path of the script to eval as first parameter.
397397
};
398398

399399
// bound values in KEY=VALUE form, ready to be passed as environment variables
400400
char ** env_values = malloc(10 * sizeof(char * ));
401401
size_t env_value_count = 10;
402402
const size_t index_of_first_env_value_not_compiled_in = 10;
403403

404-
env_values[0] = "PATH=/bin:/sbin:/usr/bin:/usr/sbin";
404+
env_values[0] = "PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin";
405405

406406
env_values[1] = "XCCDF_RESULT_PASS=101";
407407
env_values[2] = "XCCDF_RESULT_FAIL=102";
@@ -539,7 +539,11 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
539539
#endif
540540

541541
// we are the child process
542-
execve(tmp_href, argvp, env_values);
542+
543+
if(use_sce_wrapper)
544+
execvpe("oscap-run-sce-script", argvp, env_values);
545+
else
546+
execve(tmp_href, argvp, env_values);
543547

544548
free_env_values(env_values, index_of_first_env_value_not_compiled_in, env_value_count);
545549

utils/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
install(PROGRAMS "oscap-run-sce-script"
2+
DESTINATION ${CMAKE_INSTALL_BINDIR}
3+
)
4+
15
if(ENABLE_OSCAP_UTIL)
26
file(GLOB UTILS_SOURCES "*.c")
37
if(HAVE_GETOPT_H)

utils/oscap-run-sce-script

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
#
3+
# Authors:
4+
# Dominique Blaze <[email protected]>
5+
#
6+
# use by oscap for evaluate a SCE file when +x rights are missing
7+
8+
if [ ! -z $1 ] && [ -f $1 ]
9+
then
10+
# file exists. first check if shebang is here
11+
12+
firstline=$(head -n1 $1)
13+
if [ ${firstline:0:2} = "#!" ]
14+
then # it's a shebang
15+
cmd=${firstline:2} # remove the begin (#!)
16+
cmd=${cmd##*( )} # trim whitespaces
17+
eval $cmd $1 > /dev/stdout
18+
else # no shebang, trying bash by default ...
19+
/usr/bin/env bash $1 > /dev/stdout
20+
fi
21+
22+
else
23+
echo "Script file not found: $1" > /dev/stderr
24+
fi

0 commit comments

Comments
 (0)