From: Martin R. <mr...@us...> - 2005-03-22 19:13:38
|
Update of /cvsroot/ltp/ltp/testcases/misc/selinux-testsuite/tests/ptrace In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27130/tests/ptrace Added Files: Makefile selinux_ptrace.c selinux_ptrace.sh selinux_ptrace_wait.sh Log Message: Initial release --- NEW FILE: selinux_ptrace.sh --- #!/bin/sh setup() { LTPTMP="/tmp/selinux" export TCID="setup" export TST_COUNT=0 SAVEPWD=${PWD} cd $LTPROOT/testcases/bin CURRENTDIR=. # Start the process to be traced. runcon -t test_ptrace_traced_t $CURRENTDIR/selinux_ptrace_wait.sh & PID=$! # Give the process a moment to initialize. sleep 1 } test01() { TCID="test01" TST_COUNT=1 RC=0 # Verify that the nottracer domain cannot attach to the process. # Should fail on the ptrace permission check. runcon -t test_ptrace_nottracer_t $CURRENTDIR/selinux_ptrace $PID RC=$? if [ $RC -ne 0 ] then echo "Test #1: ptrace passed." return 0 else echo "Test #1: ptrace failed." return 1 fi } test02() { TCID="test02" TST_COUNT=2 RC=0 # Verify that the tracer domain can trace to the process. runcon -t test_ptrace_tracer_t $CURRENTDIR/selinux_ptrace $PID RC=$? if [ $RC -eq 0 ] then echo "Test #2: ptrace passed." else echo "Test #2: ptrace failed." fi return $RC } cleanup() { # Kill the process. kill -s KILL $PID cd $SAVEPWD } # Function: main # # Description: - Execute all tests, exit with test status. # # Exit: - zero on success # - non-zero on failure. # RC=0 # Return value from setup, and test functions. setup || exit $RC test01 || exit $RC test02 || exit $RC cleanup exit 0 --- NEW FILE: Makefile --- TARGETS=$(patsubst %.c,%,$(wildcard *.c)) all: $(TARGETS) install: @set -e; for i in $(TARGETS); do ln -f $$i ../../../../bin/$$i ; done ln -f selinux_ptrace.sh ../../../../bin/ ln -f selinux_ptrace_wait.sh ../../../../bin/ clean: rm -f $(TARGETS) --- NEW FILE: selinux_ptrace_wait.sh --- #!/bin/sh # just loop while : do : done --- NEW FILE: selinux_ptrace.c --- #include<stdio.h> #include<stdlib.h> #include<sys/ptrace.h> int main(int argc,char **argv){ int rc; int pid; pid=atoi(argv[1]); rc=ptrace(PTRACE_ATTACH,pid,0,0); if(rc<0){ perror("PTRACE_ATTACH"); exit(1); } else{ wait(NULL); rc = ptrace(PTRACE_DETACH,pid,0,0); if (rc < 0) { perror("PTRACE_DETACH"); exit(1); } } exit(0); } |