Hi Garrett, Peng Haitao said the following on 2011-2-16 15:27: >> This is what the code currently looks like. I assume the same >> needs to be done for the other set*suid syscall testcases? > > setresuid and setreuid also need to be fixed at least. > Thanks. >
The following patch fix the cases of setresuid and setreuid. Signed-off-by: Peng Haitao <[email protected]> --- testcases/kernel/syscalls/setresuid/setresuid04.c | 71 +++++++++------------ testcases/kernel/syscalls/setreuid/setreuid07.c | 71 +++++++++------------ 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c index 13c7a8f..eef0d11 100644 --- a/testcases/kernel/syscalls/setresuid/setresuid04.c +++ b/testcases/kernel/syscalls/setresuid/setresuid04.c @@ -74,13 +74,8 @@ int main(int ac, char **av) int status; /* parse standard options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - - /* - * perform global setup for the test - */ setup(); TEST_EXP_ENOS(exp_enos); @@ -89,20 +84,16 @@ int main(int ac, char **av) if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); - if (pid == 0) { + if (pid == 0) do_master_child(); - } else { - waitpid(pid, &status, 0); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) - tst_resm(WEXITSTATUS(status), - "son process exits with error"); - } + if (waitpid(pid, &status, 0) == -1) + tst_resm(TBROK|TERRNO, "waitpid failed"); + if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) + tst_resm(TFAIL, "child process terminated abnormally"); cleanup(); tst_exit(); - tst_exit(); - } /* @@ -121,9 +112,8 @@ void do_master_child() Tst_count = 0; if (setresuid(0, ltpuser->pw_uid, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setresuid failed to set the euid to %d", - ltpuser->pw_uid); + perror("setfsuid failed"); + exit(1); } /* Test 1: Check the process with new uid cannot open the file @@ -132,16 +122,16 @@ void do_master_child() TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("open succeeded unexpectedly\n"); close(tst_fd); + exit(1); } if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); } else { - tst_resm(TFAIL, "open returned unexpected errno - %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } /* Test 2: Check a son process cannot open the file @@ -158,23 +148,26 @@ void do_master_child() TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("call succeeded unexpectedly\n"); close(tst_fd2); + exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); + exit(0); } else { - tst_resm(TFAIL, - "open returned unexpected errno - %d", - TEST_ERRNO); + printf("open failed unexpectedly\n"); + exit(1); } - continue; } else { /* Wait for son completion */ - waitpid(pid, &status, 0); + if(waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + exit(1); + } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } @@ -184,21 +177,21 @@ void do_master_child() */ Tst_count++; if (setresuid(0, 0, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setresuid failed to set the euid to 0"); + perror("setfsuid failed"); + exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { - tst_resm(TFAIL, "open returned unexpected errno %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } else { - tst_resm(TPASS, "open call succeeded"); + printf("open call succeeded\n"); close(tst_fd); } } + exit(0); } /* @@ -206,9 +199,7 @@ void do_master_child() */ void setup(void) { - if (geteuid() != 0) { - tst_brkm(TBROK, NULL, "Test must be run as root"); - } + tst_require_root(NULL); ltpuser = getpwnam(nobody_uid); @@ -242,4 +233,4 @@ void cleanup(void) tst_rmdir(); -} \ No newline at end of file +} diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c index 19025cd..69bb25f 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid07.c +++ b/testcases/kernel/syscalls/setreuid/setreuid07.c @@ -73,13 +73,8 @@ int main(int ac, char **av) int status; /* parse standard options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - - /* - * perform global setup for the test - */ setup(); TEST_EXP_ENOS(exp_enos); @@ -88,20 +83,16 @@ int main(int ac, char **av) if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); - if (pid == 0) { + if (pid == 0) do_master_child(); - } else { - waitpid(pid, &status, 0); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) - tst_resm(WEXITSTATUS(status), - "son process exits with error"); - } + if (waitpid(pid, &status, 0) == -1) + tst_resm(TBROK|TERRNO, "waitpid failed"); + if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) + tst_resm(TFAIL, "child process terminated abnormally"); cleanup(); tst_exit(); - tst_exit(); - } /* @@ -120,9 +111,8 @@ void do_master_child() Tst_count = 0; if (setreuid(0, ltpuser->pw_uid) == -1) { - tst_brkm(TBROK, cleanup, - "setreuid failed to set the euid to %d", - ltpuser->pw_uid); + perror("setfsuid failed"); + exit(1); } /* Test 1: Check the process with new uid cannot open the file @@ -131,16 +121,16 @@ void do_master_child() TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("open succeeded unexpectedly\n"); close(tst_fd); + exit(1); } if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); } else { - tst_resm(TFAIL, "open returned unexpected errno - %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } /* Test 2: Check a son process cannot open the file @@ -157,23 +147,26 @@ void do_master_child() TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("call succeeded unexpectedly\n"); close(tst_fd2); + exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); + exit(0); } else { - tst_resm(TFAIL, - "open returned unexpected errno - %d", - TEST_ERRNO); + printf("open failed unexpectedly\n"); + exit(1); } - continue; } else { /* Wait for son completion */ - waitpid(pid, &status, 0); + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + exit(1); + } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } @@ -183,21 +176,21 @@ void do_master_child() */ Tst_count++; if (setreuid(0, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setreuid failed to set the euid to 0"); + perror("setfsuid failed"); + exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { - tst_resm(TFAIL, "open returned unexpected errno %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } else { - tst_resm(TPASS, "open call succeeded"); + printf("open call succeeded\n"); close(tst_fd); } } + exit(0); } /* @@ -205,9 +198,7 @@ void do_master_child() */ void setup(void) { - if (geteuid() != 0) { - tst_brkm(TBROK, NULL, "Test must be run as root"); - } + tst_require_root(NULL); ltpuser = getpwnam(nobody_uid); @@ -241,4 +232,4 @@ void cleanup(void) tst_rmdir(); -} \ No newline at end of file +} -- 1.7.1 -- Best Regards, Peng Haitao
Signed-off-by: Peng Haitao <[email protected]> --- testcases/kernel/syscalls/setresuid/setresuid04.c | 71 +++++++++------------ testcases/kernel/syscalls/setreuid/setreuid07.c | 71 +++++++++------------ 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/testcases/kernel/syscalls/setresuid/setresuid04.c b/testcases/kernel/syscalls/setresuid/setresuid04.c index 13c7a8f..eef0d11 100644 --- a/testcases/kernel/syscalls/setresuid/setresuid04.c +++ b/testcases/kernel/syscalls/setresuid/setresuid04.c @@ -74,13 +74,8 @@ int main(int ac, char **av) int status; /* parse standard options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - - /* - * perform global setup for the test - */ setup(); TEST_EXP_ENOS(exp_enos); @@ -89,20 +84,16 @@ int main(int ac, char **av) if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); - if (pid == 0) { + if (pid == 0) do_master_child(); - } else { - waitpid(pid, &status, 0); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) - tst_resm(WEXITSTATUS(status), - "son process exits with error"); - } + if (waitpid(pid, &status, 0) == -1) + tst_resm(TBROK|TERRNO, "waitpid failed"); + if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) + tst_resm(TFAIL, "child process terminated abnormally"); cleanup(); tst_exit(); - tst_exit(); - } /* @@ -121,9 +112,8 @@ void do_master_child() Tst_count = 0; if (setresuid(0, ltpuser->pw_uid, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setresuid failed to set the euid to %d", - ltpuser->pw_uid); + perror("setfsuid failed"); + exit(1); } /* Test 1: Check the process with new uid cannot open the file @@ -132,16 +122,16 @@ void do_master_child() TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("open succeeded unexpectedly\n"); close(tst_fd); + exit(1); } if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); } else { - tst_resm(TFAIL, "open returned unexpected errno - %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } /* Test 2: Check a son process cannot open the file @@ -158,23 +148,26 @@ void do_master_child() TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("call succeeded unexpectedly\n"); close(tst_fd2); + exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); + exit(0); } else { - tst_resm(TFAIL, - "open returned unexpected errno - %d", - TEST_ERRNO); + printf("open failed unexpectedly\n"); + exit(1); } - continue; } else { /* Wait for son completion */ - waitpid(pid, &status, 0); + if(waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + exit(1); + } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } @@ -184,21 +177,21 @@ void do_master_child() */ Tst_count++; if (setresuid(0, 0, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setresuid failed to set the euid to 0"); + perror("setfsuid failed"); + exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { - tst_resm(TFAIL, "open returned unexpected errno %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } else { - tst_resm(TPASS, "open call succeeded"); + printf("open call succeeded\n"); close(tst_fd); } } + exit(0); } /* @@ -206,9 +199,7 @@ void do_master_child() */ void setup(void) { - if (geteuid() != 0) { - tst_brkm(TBROK, NULL, "Test must be run as root"); - } + tst_require_root(NULL); ltpuser = getpwnam(nobody_uid); @@ -242,4 +233,4 @@ void cleanup(void) tst_rmdir(); -} \ No newline at end of file +} diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c index 19025cd..69bb25f 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid07.c +++ b/testcases/kernel/syscalls/setreuid/setreuid07.c @@ -73,13 +73,8 @@ int main(int ac, char **av) int status; /* parse standard options */ - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { + if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - } - - /* - * perform global setup for the test - */ setup(); TEST_EXP_ENOS(exp_enos); @@ -88,20 +83,16 @@ int main(int ac, char **av) if (pid < 0) tst_brkm(TBROK, cleanup, "Fork failed"); - if (pid == 0) { + if (pid == 0) do_master_child(); - } else { - waitpid(pid, &status, 0); - if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) - tst_resm(WEXITSTATUS(status), - "son process exits with error"); - } + if (waitpid(pid, &status, 0) == -1) + tst_resm(TBROK|TERRNO, "waitpid failed"); + if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) + tst_resm(TFAIL, "child process terminated abnormally"); cleanup(); tst_exit(); - tst_exit(); - } /* @@ -120,9 +111,8 @@ void do_master_child() Tst_count = 0; if (setreuid(0, ltpuser->pw_uid) == -1) { - tst_brkm(TBROK, cleanup, - "setreuid failed to set the euid to %d", - ltpuser->pw_uid); + perror("setfsuid failed"); + exit(1); } /* Test 1: Check the process with new uid cannot open the file @@ -131,16 +121,16 @@ void do_master_child() TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("open succeeded unexpectedly\n"); close(tst_fd); + exit(1); } if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); } else { - tst_resm(TFAIL, "open returned unexpected errno - %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } /* Test 2: Check a son process cannot open the file @@ -157,23 +147,26 @@ void do_master_child() TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); + printf("call succeeded unexpectedly\n"); close(tst_fd2); + exit(1); } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EACCES) { - tst_resm(TPASS, "open returned errno EACCES"); + printf("open failed with EACCES as expected\n"); + exit(0); } else { - tst_resm(TFAIL, - "open returned unexpected errno - %d", - TEST_ERRNO); + printf("open failed unexpectedly\n"); + exit(1); } - continue; } else { /* Wait for son completion */ - waitpid(pid, &status, 0); + if (waitpid(pid, &status, 0) == -1) { + perror("waitpid failed"); + exit(1); + } if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } @@ -183,21 +176,21 @@ void do_master_child() */ Tst_count++; if (setreuid(0, 0) == -1) { - tst_brkm(TBROK, cleanup, - "setreuid failed to set the euid to 0"); + perror("setfsuid failed"); + exit(1); } TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN == -1) { - tst_resm(TFAIL, "open returned unexpected errno %d", - TEST_ERRNO); - continue; + perror("open failed unexpectedly"); + exit(1); } else { - tst_resm(TPASS, "open call succeeded"); + printf("open call succeeded\n"); close(tst_fd); } } + exit(0); } /* @@ -205,9 +198,7 @@ void do_master_child() */ void setup(void) { - if (geteuid() != 0) { - tst_brkm(TBROK, NULL, "Test must be run as root"); - } + tst_require_root(NULL); ltpuser = getpwnam(nobody_uid); @@ -241,4 +232,4 @@ void cleanup(void) tst_rmdir(); -} \ No newline at end of file +} -- 1.7.1
------------------------------------------------------------------------------ Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
