Skip to content

Commit 1769c0b

Browse files
use execvpe to found oscap-run-sce-script
1 parent 7f23880 commit 1769c0b

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/SCE/sce_engine.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
392392

393393
char* argvp[3] = {
394394
tmp_href,
395-
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
};
398-
dI("arvp[0] = %s", argvp[0]);
398+
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;
@@ -491,7 +491,7 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
491491
env_values[env_value_count] = env_operator_entry;
492492
env_value_count++;
493493
}
494-
dI("debug0 ..");
494+
495495
env_values = realloc(env_values, (env_value_count + 1) * sizeof(char*));
496496
env_values[env_value_count] = NULL;
497497

@@ -507,8 +507,6 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
507507

508508
// FIXME: We definitely want to impose security restrictions in the forked child process in the future.
509509
// This would prevent scripts from writing to files or deleting them.
510-
511-
dI("debug1 ..");
512510

513511
int fork_result = fork();
514512
if (fork_result >= 0)
@@ -517,21 +515,21 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
517515

518516
if (fork_result == 0)
519517
{
520-
dI("debug2 ..");
518+
521519
// we won't read from the pipes, so close the reading fd
522520
close(stdout_pipefd[0]);
523521
close(stderr_pipefd[0]);
524-
dI("debug2.1 ..");
522+
525523
// forward stdout and stderr to our custom opened pipes
526-
//dup2(stdout_pipefd[1], fileno(stdout));
527-
//dup2(stderr_pipefd[1], fileno(stderr));
528-
dI("debug2.2 ..");
524+
dup2(stdout_pipefd[1], fileno(stdout));
525+
dup2(stderr_pipefd[1], fileno(stderr));
526+
529527
// we duplicated the file descriptors twice, we can close the original
530528
// ones now, stdout and stderr will be closed properly after the execved
531529
// script/executable finishes
532530
close(stdout_pipefd[1]);
533531
close(stderr_pipefd[1]);
534-
dI("debug3 ..");
532+
535533
// before we execute the script, lets make sure we get SIGTERM when
536534
// oscap is killed, crashes or otherwise terminates
537535
#ifdef PR_SET_PDEATHSIG
@@ -542,14 +540,14 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
542540
#endif
543541

544542
// we are the child process
545-
dI("argvp[0<] = %s", argvp[0]);
546-
dI("env<(0 %s", env_values[0]);
547-
548-
if(use_sce_wrapper)
549-
execvp("oscap-run-sce-script", argvp, env_values);
550-
else
551-
execve(tmp_href, argvp, env_values);
552543

544+
if(use_sce_wrapper) {
545+
dI("Eval sce script using oscap-run-sce-script because %s isn't +x", tmp_href);
546+
execvpe("oscap-run-sce-script", argvp, env_values);
547+
} else {
548+
execve(tmp_href, argvp, env_values);
549+
}
550+
553551
free_env_values(env_values, index_of_first_env_value_not_compiled_in, env_value_count);
554552

555553
// no need to check the return value of execve, if it returned at all we are in trouble

0 commit comments

Comments
 (0)