@@ -362,6 +362,7 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
362
362
{
363
363
struct sce_parameters * parameters = (struct sce_parameters * )usr ;
364
364
const char * xccdf_directory = parameters -> xccdf_directory ;
365
+ bool use_sce_wrapper = false; // use osca-run-sce-script ?
365
366
366
367
char * tmp_href = oscap_sprintf ("%s/%s" , xccdf_directory , href );
367
368
@@ -381,27 +382,26 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
381
382
382
383
if (access (tmp_href , F_OK | X_OK ))
383
384
{
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 use." , tmp_href );
389
388
}
390
389
391
390
// all the result codes are shifted by 100, because otherwise syntax errors in scripts
392
391
// or even their nonexistence would cause XCCDF_RESULT_PASS to be the result
393
392
394
- char * argvp [1 + 1 ] = {
393
+ char * argvp [3 ] = {
394
+ tmp_href ,
395
395
tmp_href ,
396
396
NULL
397
397
};
398
-
398
+ dI ( "arvp[0] = %s" , argvp [ 0 ]);
399
399
// bound values in KEY=VALUE form, ready to be passed as environment variables
400
400
char * * env_values = malloc (10 * sizeof (char * ));
401
401
size_t env_value_count = 10 ;
402
402
const size_t index_of_first_env_value_not_compiled_in = 10 ;
403
403
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" ;
405
405
406
406
env_values [1 ] = "XCCDF_RESULT_PASS=101" ;
407
407
env_values [2 ] = "XCCDF_RESULT_FAIL=102" ;
@@ -491,7 +491,7 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
491
491
env_values [env_value_count ] = env_operator_entry ;
492
492
env_value_count ++ ;
493
493
}
494
-
494
+ dI ( "debug0 .." );
495
495
env_values = realloc (env_values , (env_value_count + 1 ) * sizeof (char * ));
496
496
env_values [env_value_count ] = NULL ;
497
497
@@ -508,27 +508,30 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
508
508
// FIXME: We definitely want to impose security restrictions in the forked child process in the future.
509
509
// This would prevent scripts from writing to files or deleting them.
510
510
511
+ dI ("debug1 .." );
512
+
511
513
int fork_result = fork ();
512
514
if (fork_result >= 0 )
513
515
{
514
516
// fork successful
515
517
516
518
if (fork_result == 0 )
517
519
{
520
+ dI ("debug2 .." );
518
521
// we won't read from the pipes, so close the reading fd
519
522
close (stdout_pipefd [0 ]);
520
523
close (stderr_pipefd [0 ]);
521
-
524
+ dI ( "debug2.1 .." );
522
525
// forward stdout and stderr to our custom opened pipes
523
- dup2 (stdout_pipefd [1 ], fileno (stdout ));
524
- dup2 (stderr_pipefd [1 ], fileno (stderr ));
525
-
526
+ // dup2(stdout_pipefd[1], fileno(stdout));
527
+ // dup2(stderr_pipefd[1], fileno(stderr));
528
+ dI ( "debug2.2 .." );
526
529
// we duplicated the file descriptors twice, we can close the original
527
530
// ones now, stdout and stderr will be closed properly after the execved
528
531
// script/executable finishes
529
532
close (stdout_pipefd [1 ]);
530
533
close (stderr_pipefd [1 ]);
531
-
534
+ dI ( "debug3 .." );
532
535
// before we execute the script, lets make sure we get SIGTERM when
533
536
// oscap is killed, crashes or otherwise terminates
534
537
#ifdef PR_SET_PDEATHSIG
@@ -539,7 +542,13 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
539
542
#endif
540
543
541
544
// we are the child process
542
- execve (tmp_href , argvp , env_values );
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 );
543
552
544
553
free_env_values (env_values , index_of_first_env_value_not_compiled_in , env_value_count );
545
554
0 commit comments