From c8f70b8154d5782fea0556b3b324eaf036c3aa97 Mon Sep 17 00:00:00 2001 From: Erik van der Kouwe Date: Fri, 6 Aug 2010 12:33:32 +0000 Subject: [PATCH] Fix tests when run as root; use bin account but current directory --- test/run | 8 ++++++-- test/test17.c | 6 ------ test/test18.c | 7 ------- test/test19.c | 7 ------- test/test21.c | 6 ------ test/test25.c | 6 ------ test/test3.c | 6 ------ test/test6.c | 6 ------ 8 files changed, 6 insertions(+), 46 deletions(-) diff --git a/test/run b/test/run index 89f74bf4e..1470c523e 100755 --- a/test/run +++ b/test/run @@ -18,6 +18,10 @@ tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ sh1.sh sh2.sh" tests_no=`expr 0` +# Directory must be owned by bin +[ "$USER" != root ] || chown bin . + +# Count tests for i in `echo $tests`; do if [ -x ./test$i ]; then tests_no=`expr $tests_no + 1` @@ -36,8 +40,8 @@ do then total=`expr $total + 1` FAIL=0 - if [ $USER = root -a \( $i = 11 -o $i = 33 \) ] - then su - ast -c "cd `pwd`; ./test$i" || FAIL=1 + if [ "$USER" = root ] + then su - bin -c "cd `pwd`; ./test$i" || FAIL=1 else ./test$i || FAIL=1 fi if [ $FAIL -eq 0 ] diff --git a/test/test17.c b/test/test17.c index e24a6f5c4..0fbd6898a 100644 --- a/test/test17.c +++ b/test/test17.c @@ -129,12 +129,6 @@ char *argv[]; } sync(); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 17 cannot run as root; test aborted\n"); - exit(1); - } #define DIR "DIR17" system("rm -rf " DIR); diff --git a/test/test18.c b/test/test18.c index 080cb4185..8378d81a1 100644 --- a/test/test18.c +++ b/test/test18.c @@ -135,13 +135,6 @@ int main(int argc, char **argv) } } - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 18 cannot run as root; test aborted\n"); - exit(1); - } - #define DIR "DIR18" system("rm -rf " DIR); if(mkdir(DIR, 0755) != 0) { diff --git a/test/test19.c b/test/test19.c index e51f0b202..b0cad2bba 100644 --- a/test/test19.c +++ b/test/test19.c @@ -42,13 +42,6 @@ char *argv[]; m = (argc == 2 ? atoi(argv[1]) : 0xFFFF); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 19 cannot run as root; test aborted\n"); - exit(1); - } - system("rm -rf DIR_19; mkdir DIR_19"); chdir("DIR_19"); diff --git a/test/test21.c b/test/test21.c index 257382564..2a9b83285 100644 --- a/test/test21.c +++ b/test/test21.c @@ -48,12 +48,6 @@ char *argv[]; int i, m = 0xFFFF; sync(); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 21 cannot run as root; test aborted\n"); - exit(1); - } if (argc == 2) m = atoi(argv[1]); printf("Test 21 "); diff --git a/test/test25.c b/test/test25.c index ddcfd6198..d9d2bce6f 100644 --- a/test/test25.c +++ b/test/test25.c @@ -49,12 +49,6 @@ int main(int argc, char *argv[]) int i, m = 0xFFFF; sync(); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 25 cannot run as root; test aborted\n"); - exit(1); - } if (argc == 2) m = atoi(argv[1]); start(25); diff --git a/test/test3.c b/test/test3.c index 71a065464..a71ed5f9c 100644 --- a/test/test3.c +++ b/test/test3.c @@ -36,12 +36,6 @@ char *argv[]; sync(); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 3 cannot run as root; test aborted\n"); - exit(1); - } if (argc == 2) m = atoi(argv[1]); diff --git a/test/test6.c b/test/test6.c index 90f3839e1..9e8ba5f16 100644 --- a/test/test6.c +++ b/test/test6.c @@ -32,12 +32,6 @@ char *argv[]; int i, m = 0xFFFF; sync(); - if (geteuid() == 0 || getuid() == 0) { - realpath(argv[0], buffer); - execl("/usr/bin/su", "/usr/bin/su", "-", "ast", "-c", buffer, NULL); - printf("Test 6 cannot run as root; test aborted\n"); - exit(1); - } if (argc == 2) m = atoi(argv[1]);