From: Cyril H. <su...@li...> - 2013-10-22 17:51:12
|
The branch, master, has been updated via 705926d096f7a64c9d53efeb789288e25457d68f (commit) via de8b8db9324b78e62f79b4c7eca7dc1ed570425c (commit) via e0f8585542dc0cab1a31c8d6a3e0c92b5206bef4 (commit) from 1e5da030e9cdeb431d41e7eb84658d9c4a5b67e3 (commit) - Log ----------------------------------------------------------------- commit 705926d096f7a64c9d53efeb789288e25457d68f Author: Stanislav Kholmanskikh <sta...@or...> Date: Mon Oct 21 11:25:17 2013 +0400 syscalls/setregid02: fixes It was a bug that the testcase initially changed its uid/gid to 'nobody' user but after performing setregid() It waited for 'users' gid. Fixed this. Also added 16-bit version check and performed minor cleanup. Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit de8b8db9324b78e62f79b4c7eca7dc1ed570425c Author: Stanislav Kholmanskikh <sta...@or...> Date: Mon Oct 21 11:25:16 2013 +0400 syscalls/setregid{01, 03, 04}: 16-bit fixes and minor cleanup Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit e0f8585542dc0cab1a31c8d6a3e0c92b5206bef4 Author: Stanislav Kholmanskikh <sta...@or...> Date: Mon Oct 21 11:25:15 2013 +0400 syscalls/setreuid: 16-bit fixes and minor cleanup Signed-off-by: Stanislav Kholmanskikh <sta...@or...> ----------------------------------------------------------------------- Summary of changes: testcases/kernel/syscalls/setregid/setregid01.c | 146 +++--------------- testcases/kernel/syscalls/setregid/setregid02.c | 143 +++++------------ testcases/kernel/syscalls/setregid/setregid03.c | 186 ++++++++--------------- testcases/kernel/syscalls/setregid/setregid04.c | 142 +++++------------- testcases/kernel/syscalls/setreuid/setreuid01.c | 173 +++------------------ testcases/kernel/syscalls/setreuid/setreuid02.c | 162 +++++-------------- testcases/kernel/syscalls/setreuid/setreuid03.c | 187 +++++++---------------- testcases/kernel/syscalls/setreuid/setreuid04.c | 145 +++++------------- testcases/kernel/syscalls/setreuid/setreuid05.c | 191 +++++++---------------- testcases/kernel/syscalls/setreuid/setreuid06.c | 108 ++++--------- testcases/kernel/syscalls/setreuid/setreuid07.c | 124 ++++++--------- testcases/kernel/syscalls/utils/compat_16.h | 9 + 12 files changed, 466 insertions(+), 1250 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid01.c b/testcases/kernel/syscalls/setregid/setregid01.c index a24177d..dae17bf 100644 --- a/testcases/kernel/syscalls/setregid/setregid01.c +++ b/testcases/kernel/syscalls/setregid/setregid01.c @@ -29,104 +29,30 @@ * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ * + * Author: William Roske + * Co-pilot: Dave Fenner + */ + +/* + * Testcase to test the basic functionality of setregid(2) systemm call. */ -/* $Id: setregid01.c,v 1.6 2009/11/02 13:57:18 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : setregid01 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for setregid(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 5 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 05/13/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) setregid(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - * - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the setregid(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * setregid(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ #include <errno.h> #include <string.h> #include <signal.h> - #include <sys/types.h> #include "test.h" #include "usctest.h" +#include "compat_16.h" -void setup(); -void cleanup(); +static void setup(void); +static void cleanup(void); -char *TCID = "setregid01"; +TCID_DEFINE(setregid01); int TST_TOTAL = 5; -int exp_enos[] = { 0, 0 }; - -int gid, egid; /* current real and effective group id */ +static gid_t gid, egid; /* current real and effective group id */ int main(int ac, char **av) { @@ -138,9 +64,6 @@ int main(int ac, char **av) setup(); - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); - for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; @@ -150,12 +73,13 @@ int main(int ac, char **av) * Dont change either real or effective gid */ gid = getgid(); + GID16_CHECK(gid, setregid, cleanup); + egid = getegid(); + GID16_CHECK(egid, setregid, cleanup); - /* Call setregid(2) */ - TEST(setregid(-1, -1)); + TEST(SETREGID(cleanup, -1, -1)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, @@ -163,7 +87,6 @@ int main(int ac, char **av) TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setregid - Dont change either real or effective gid returned %ld", TEST_RETURN); @@ -175,10 +98,8 @@ int main(int ac, char **av) * change effective to effective gid */ - /* Call setregid(2) */ - TEST(setregid(-1, egid)); + TEST(SETREGID(cleanup, -1, egid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, @@ -186,7 +107,6 @@ int main(int ac, char **av) TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setregid - change effective to effective gid returned %ld", TEST_RETURN); @@ -198,10 +118,8 @@ int main(int ac, char **av) * change real to real gid */ - /* Call setregid(2) */ - TEST(setregid(gid, -1)); + TEST(SETREGID(cleanup, gid, -1)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, @@ -209,7 +127,6 @@ int main(int ac, char **av) TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setregid - change real to real gid returned %ld", TEST_RETURN); @@ -221,10 +138,8 @@ int main(int ac, char **av) * change effective to real gid */ - /* Call setregid(2) */ - TEST(setregid(-1, gid)); + TEST(SETREGID(cleanup, -1, gid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, @@ -232,7 +147,6 @@ int main(int ac, char **av) TEST_ERRNO, strerror(TEST_ERRNO)); } else { if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setregid - change effective to real gid returned %ld", TEST_RETURN); @@ -244,16 +158,13 @@ int main(int ac, char **av) * try to change real to current real */ - /* Call setregid(2) */ - TEST(setregid(gid, gid)); + TEST(SETREGID(cleanup, gid, gid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL | TTERRNO, "setregid failed"); } else { if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setregid return %ld", TEST_RETURN); } @@ -263,34 +174,19 @@ int main(int ac, char **av) cleanup(); tst_exit(); - tst_exit(); - } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; - /* make a temp dir and cd to it */ tst_tmpdir(); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; tst_rmdir(); diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index 349a494..e67a7df 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -15,74 +15,34 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Ported by John George */ /* - * NAME - * setregid02.c - * - * DESCRIPTION - * Test that setregid() fails and sets the proper errno values when a - * non-root user attemps to change the real or effective group id to a - * value other than the current gid or the current effective gid. - * - * ALGORITHM - * - * Setup: - * Setup signal handling - * Get user information. - * Pause for SIGUSER1 if option specified. - * Setup test values. - * Loop if the proper options are given. - * For each test set execute the system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given. - * - * USAGE: <for command-line> - * setregid02 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * This test must be ran as root. - * users must be a valid group. + * Test that setregid() fails and sets the proper errno values when a + * non-root user attemps to change the real or effective group id to a + * value other than the current gid or the current effective gid. */ +#include <errno.h> #include <pwd.h> #include <grp.h> #include <stdlib.h> #include <string.h> + #include "test.h" #include "usctest.h" -#include <errno.h> +#include "compat_16.h" -char *TCID = "setregid02"; -gid_t users_gr_gid, root_gr_gid, bin_gr_gid; -gid_t neg_one = -1; -int exp_enos[] = { EPERM, 0 }; +TCID_DEFINE(setregid02); -gid_t inval_user = (USHRT_MAX); -char nobody_uid[] = "nobody"; -struct passwd *nobody; +static gid_t neg_one = -1; -struct group users, root, bin; -struct passwd *nobody; +static gid_t inval_user = (USHRT_MAX); +static struct passwd *ltpuser; + +static struct group nobody, root, bin; /* * The following structure contains all test data. Each structure in the array @@ -98,28 +58,28 @@ struct test_data_t { char *test_msg; } test_data[] = { { - &neg_one, &root_gr_gid, EPERM, &users, &users, + &neg_one, &root.gr_gid, EPERM, &nobody, &nobody, "After setregid(-1, root),"}, { - &neg_one, &bin_gr_gid, EPERM, &users, &users, + &neg_one, &bin.gr_gid, EPERM, &nobody, &nobody, "After setregid(-1, bin)"}, { - &root_gr_gid, &neg_one, EPERM, &users, &users, + &root.gr_gid, &neg_one, EPERM, &nobody, &nobody, "After setregid(root,-1),"}, { - &bin_gr_gid, &neg_one, EPERM, &users, &users, + &bin.gr_gid, &neg_one, EPERM, &nobody, &nobody, "After setregid(bin, -1),"}, { - &root_gr_gid, &bin_gr_gid, EPERM, &users, &users, + &root.gr_gid, &bin.gr_gid, EPERM, &nobody, &nobody, "After setregid(root, bin)"}, { - &bin_gr_gid, &root_gr_gid, EPERM, &users, &users, + &bin.gr_gid, &root.gr_gid, EPERM, &nobody, &nobody, "After setregid(bin, root),"}, { - &inval_user, &neg_one, EINVAL, &users, &users, + &inval_user, &neg_one, EINVAL, &nobody, &nobody, "After setregid(invalid group, -1),"}, { -&neg_one, &inval_user, EINVAL, &users, &users, + &neg_one, &inval_user, EINVAL, &nobody, &nobody, "After setregid(-1, invalid group),"},}; int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); -void setup(void); -void cleanup(void); -void gid_verify(struct group *ru, struct group *eu, char *when); +static void setup(void); +static void cleanup(void); +static void gid_verify(struct group *ru, struct group *eu, char *when); int main(int ac, char **av) { @@ -134,12 +94,11 @@ int main(int ac, char **av) for (lc = 0; TEST_LOOPING(lc); lc++) { int i; - /* reset tst_count in case we are looping */ tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective group id */ - TEST(setregid(*test_data[i].real_gid, + TEST(SETREGID(cleanup, *test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { @@ -169,10 +128,6 @@ int main(int ac, char **av) *test_data[i].real_gid, *test_data[i].eff_gid, TEST_RETURN); } - /* - * Perform functional verification if test - * executed without (-f) option. - */ if (STD_FUNCTIONAL_TEST) { gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, @@ -184,15 +139,9 @@ int main(int ac, char **av) } cleanup(); tst_exit(); - tst_exit(); - } -/* - * setup() - * performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { struct group *junk; @@ -200,62 +149,50 @@ void setup(void) tst_sig(FORK, DEF_HANDLER, cleanup); - if ((nobody = getpwnam("nobody")) == NULL) { + ltpuser = getpwnam("nobody"); + if (ltpuser == NULL) tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed"); - } - if (setgid(nobody->pw_gid) == -1) { + if (setgid(ltpuser->pw_gid) == -1) { tst_brkm(TBROK | TERRNO, NULL, "setgid failed to set the effective gid to %d", - nobody->pw_gid); + ltpuser->pw_gid); } - if (setuid(nobody->pw_uid) == -1) { + if (setuid(ltpuser->pw_uid) == -1) { tst_brkm(TBROK | TERRNO, NULL, "setuid failed to to set the effective uid to %d", - nobody->pw_uid); + ltpuser->pw_uid); } - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); - #define GET_GID(group) do { \ junk = getgrnam(#group); \ if (junk == NULL) { \ tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", #group); \ } \ - group ## _gr_gid = junk->gr_gid;\ + GID16_CHECK(junk->gr_gid, setregid, NULL); \ + group = *(junk); \ } while (0) GET_GID(root); - GET_GID(users); + GET_GID(nobody); GET_GID(bin); - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -c option. - */ TEST_PAUSE; } -/* - * cleanup() - * performs all ONE TIME cleanup for this test at - * completion or premature exit - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; } void gid_verify(struct group *rg, struct group *eg, char *when) { if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { - tst_resm(TINFO, "ERROR: %s real gid = %d; effective gid = %d", + tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", when, getgid(), getegid()); tst_resm(TINFO, "Expected: real gid = %d; effective gid = %d", rg->gr_gid, eg->gr_gid); + } else { + tst_resm(TPASS, "real or effective gid was modified as expected"); } } diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c index b9a5311..1cbdd52 100644 --- a/testcases/kernel/syscalls/setregid/setregid03.c +++ b/testcases/kernel/syscalls/setregid/setregid03.c @@ -1,65 +1,25 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Ported by John George */ /* - * NAME - * setregid03.c - * - * DESCRIPTION - * Test setregid() when executed by a non-root user. - * - * ALGORITHM - * - * Setup: - * Setup signal handling - * Get user information. - * Pause for SIGUSER1 if option specified. - * Setup test values. - * Loop if the proper options are given. - * For each test set execute the system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given. - * - * USAGE: <for command-line> - * setregid03 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * This test must be ran as root. - * users, sys and bin must be valid groups. + * Test setregid() when executed by a non-root user. */ #include <errno.h> @@ -67,21 +27,19 @@ #include <stdlib.h> #include <pwd.h> #include <string.h> -#include "test.h" -#include "usctest.h" #include <sys/wait.h> -char *TCID = "setregid03"; -int fail = -1; -int pass = 0; -gid_t neg_one = -1; -int exp_enos[] = { 0 }; +#include "test.h" +#include "usctest.h" +#include "compat_16.h" -gid_t users_gr_gid, root_gr_gid, sys_gr_gid, bin_gr_gid; -uid_t nobody_pw_uid; +TCID_DEFINE(setregid03); +static int fail = -1; +static int pass; +static gid_t neg_one = -1; /* flag to tell parent if child passed or failed. */ -int flag = 0; +static int flag; struct group users, sys, root, bin; struct passwd nobody; @@ -99,33 +57,33 @@ struct test_data_t { char *test_msg; } test_data[] = { { - &sys_gr_gid, &bin_gr_gid, &pass, &sys, &bin, + &sys.gr_gid, &bin.gr_gid, &pass, &sys, &bin, "After setregid(sys, bin),"}, { - &neg_one, &sys_gr_gid, &pass, &sys, &sys, "After setregid(-1, sys)"}, + &neg_one, &sys.gr_gid, &pass, &sys, &sys, "After setregid(-1, sys)"}, { - &neg_one, &bin_gr_gid, &pass, &sys, &bin, "After setregid(-1, bin),"}, + &neg_one, &bin.gr_gid, &pass, &sys, &bin, "After setregid(-1, bin),"}, { - &bin_gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"}, + &bin.gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"}, { &neg_one, &neg_one, &pass, &bin, &bin, "After setregid(-1, -1),"}, { - &neg_one, &bin_gr_gid, &pass, &bin, &bin, "After setregid(-1, bin),"}, + &neg_one, &bin.gr_gid, &pass, &bin, &bin, "After setregid(-1, bin),"}, { - &bin_gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"}, + &bin.gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"}, { - &bin_gr_gid, &bin_gr_gid, &pass, &bin, &bin, + &bin.gr_gid, &bin.gr_gid, &pass, &bin, &bin, "After setregid(bin, bin),"}, { - &sys_gr_gid, &neg_one, &fail, &bin, &bin, "After setregid(sys, -1)"}, + &sys.gr_gid, &neg_one, &fail, &bin, &bin, "After setregid(sys, -1)"}, { - &neg_one, &sys_gr_gid, &fail, &bin, &bin, "After setregid(-1, sys)"}, + &neg_one, &sys.gr_gid, &fail, &bin, &bin, "After setregid(-1, sys)"}, { -&sys_gr_gid, &sys_gr_gid, &fail, &bin, &bin, + &sys.gr_gid, &sys.gr_gid, &fail, &bin, &bin, "After setregid(sys, sys)"},}; int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); -void setup(void); -void cleanup(void); -void gid_verify(struct group *ru, struct group *eu, char *when); +static void setup(void); +static void cleanup(void); +static void gid_verify(struct group *ru, struct group *eu, char *when); int main(int ac, char **av) { @@ -141,24 +99,25 @@ int main(int ac, char **av) pid_t pid; int status, i; - /* reset tst_count in case we are looping */ + pass = 0; + flag = 0; + tst_count = 0; /* set the appropriate ownership values */ - if (setregid(sys_gr_gid, bin_gr_gid) == -1) { + if (SETREGID(cleanup, sys.gr_gid, bin.gr_gid) == -1) tst_brkm(TBROK, NULL, "Initial setregid failed"); - } - if (seteuid(nobody_pw_uid) == -1) { + if (seteuid(nobody.pw_uid) == -1) tst_brkm(TBROK, NULL, "Initial seteuid failed"); - } + if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, NULL, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { gid_t test_ret; /* Set the real or effective group id */ - TEST(setregid(*test_data[i].real_gid, + TEST(SETREGID(NULL, *test_data[i].real_gid, *test_data[i].eff_gid)); test_ret = TEST_RETURN; @@ -202,10 +161,6 @@ int main(int ac, char **av) TEST_ERROR_LOG(TEST_ERRNO); } - /* - * Perform functional verification if test - * executed without (-f) option. - */ if (STD_FUNCTIONAL_TEST) { gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, @@ -225,65 +180,50 @@ int main(int ac, char **av) } cleanup(); tst_exit(); - tst_exit(); - } -/* - * setup() - * performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { + struct group *junk; + tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); - + if (getpwnam("nobody") == NULL) + tst_brkm(TBROK, NULL, "nobody must be a valid user."); nobody = *(getpwnam("nobody")); - nobody_pw_uid = nobody.pw_uid; - - root = *(getgrnam("root")); - root_gr_gid = root.gr_gid; - - users = *(getgrnam("users")); - users_gr_gid = users.gr_gid; - sys = *(getgrnam("sys")); - sys_gr_gid = sys.gr_gid; +#define GET_GID(group) do { \ + junk = getgrnam(#group); \ + if (junk == NULL) { \ + tst_brkm(TBROK, NULL, "%s must be a valid group", #group); \ + } \ + GID16_CHECK(junk->gr_gid, setregid, NULL); \ + group = *(junk); \ +} while (0) - bin = *(getgrnam("bin")); - bin_gr_gid = bin.gr_gid; + GET_GID(users); + GET_GID(sys); + GET_GID(bin); - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -c option. - */ TEST_PAUSE; } -/* - * cleanup() - * performs all ONE TIME cleanup for this test at - * completion or premature exit - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; } -void gid_verify(struct group *rg, struct group *eg, char *when) +static void gid_verify(struct group *rg, struct group *eg, char *when) { if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { - tst_resm(TINFO, "ERROR: %s real gid = %d; effective gid = %d", + tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", when, getgid(), getegid()); tst_resm(TINFO, "Expected: real gid = %d; effective gid = %d", rg->gr_gid, eg->gr_gid); flag = -1; + } else { + tst_resm(TPASS, "real or effective gid was modified as expected"); } } diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c index ee1348c..7b343e2 100644 --- a/testcases/kernel/syscalls/setregid/setregid04.c +++ b/testcases/kernel/syscalls/setregid/setregid04.c @@ -1,81 +1,42 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Ported by John George */ /* - * NAME - * setregid04.c - * - * DESCRIPTION - * Test setregid() when executed by root. - * - * ALGORITHM - * - * Setup: - * Setup signal handling - * Get user information. - * Pause for SIGUSER1 if option specified. - * Setup test values. - * Loop if the proper options are given. - * For each test set execute the system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given. - * - * USAGE: <for command-line> - * setregid04 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * This test must be ran as root. + * Test setregid() when executed by root. */ +#include <errno.h> #include <pwd.h> #include <grp.h> #include <stdlib.h> #include <string.h> + #include "test.h" #include "usctest.h" -#include <errno.h> +#include "compat_16.h" + +TCID_DEFINE(setregid04); -char *TCID = "setregid04"; -gid_t users_gr_gid, root_gr_gid, daemon_gr_gid, bin_gr_gid; -gid_t neg_one = -1; -int exp_enos[] = { 0 }; +static gid_t neg_one = -1; -/* Avoid clashing with daemon in unistd.h. */ -struct group users_gr, daemon_gr, root_gr, bin_gr; +static struct group users_gr, daemon_gr, root_gr, bin_gr; /* * The following structure contains all test data. Each structure in the array @@ -90,31 +51,31 @@ struct test_data_t { const char *test_msg; } test_data[] = { { - &root_gr_gid, &root_gr_gid, &root_gr, &root_gr, + &root_gr.gr_gid, &root_gr.gr_gid, &root_gr, &root_gr, "After setregid(root, root),"}, { - &users_gr_gid, &neg_one, &users_gr, &root_gr, + &users_gr.gr_gid, &neg_one, &users_gr, &root_gr, "After setregid(users, -1)"}, { - &root_gr_gid, &neg_one, &root_gr, &root_gr, + &root_gr.gr_gid, &neg_one, &root_gr, &root_gr, "After setregid(root,-1),"}, { &neg_one, &neg_one, &root_gr, &root_gr, "After setregid(-1, -1),"}, { - &neg_one, &root_gr_gid, &root_gr, &root_gr, + &neg_one, &root_gr.gr_gid, &root_gr, &root_gr, "After setregid(-1, root)"}, { - &root_gr_gid, &neg_one, &root_gr, &root_gr, + &root_gr.gr_gid, &neg_one, &root_gr, &root_gr, "After setregid(root, -1),"}, { - &daemon_gr_gid, &users_gr_gid, &daemon_gr, &users_gr, + &daemon_gr.gr_gid, &users_gr.gr_gid, &daemon_gr, &users_gr, "After setregid(daemon, users)"}, { &neg_one, &neg_one, &daemon_gr, &users_gr, "After setregid(-1, -1)"}, { - &neg_one, &users_gr_gid, &daemon_gr, &users_gr, + &neg_one, &users_gr.gr_gid, &daemon_gr, &users_gr, "After setregid(-1, users)"} }; int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); -void setup(void); -void cleanup(void); -void gid_verify(struct group *ru, struct group *eu, const char *when); +static void setup(void); +static void cleanup(void); +static void gid_verify(struct group *ru, struct group *eu, const char *when); int main(int ac, char **av) { @@ -129,12 +90,11 @@ int main(int ac, char **av) for (lc = 0; TEST_LOOPING(lc); lc++) { int i; - /* reset tst_count in case we are looping */ tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective group id */ - TEST(setregid(*test_data[i].real_gid, + TEST(SETREGID(cleanup, *test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { @@ -143,10 +103,6 @@ int main(int ac, char **av) *test_data[i].real_gid, *test_data[i].eff_gid); } else { - /* - * Perform functional verification if test - * executed without (-f) option. - */ if (STD_FUNCTIONAL_TEST) { gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, @@ -160,58 +116,34 @@ int main(int ac, char **av) cleanup(); tst_exit(); - tst_exit(); - } #define SAFE_GETGROUP(GROUPNAME) \ - if ((junk = getgrnam(#GROUPNAME)) == NULL) { \ + if (getgrnam(#GROUPNAME) == NULL) { \ tst_brkm(TBROK, NULL, "Couldn't find the `" #GROUPNAME "' group"); \ } \ - memcpy((void*) &GROUPNAME ## _gr, (const void*) junk, sizeof(struct group)); \ - GROUPNAME ## _gr_gid = GROUPNAME ## _gr.gr_gid + GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); -/* - * setup() - * performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { - struct group *junk; - tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); - SAFE_GETGROUP(root); SAFE_GETGROUP(users); SAFE_GETGROUP(daemon); SAFE_GETGROUP(bin); - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -c option. - */ TEST_PAUSE; } -/* - * cleanup() - * performs all ONE TIME cleanup for this test at - * completion or premature exit - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; } -void gid_verify(struct group *rg, struct group *eg, const char *when) +static void gid_verify(struct group *rg, struct group *eg, const char *when) { if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", diff --git a/testcases/kernel/syscalls/setreuid/setreuid01.c b/testcases/kernel/syscalls/setreuid/setreuid01.c index 1f54337..18b5ed0 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid01.c +++ b/testcases/kernel/syscalls/setreuid/setreuid01.c @@ -29,127 +29,41 @@ * * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ * + * Author: William Roske + * Co-pilot: Dave Fenner + */ + +/* + * Testcase to test the basic functionality of setreuid(2) system call. */ -/* $Id: setreuid01.c,v 1.6 2009/11/02 13:57:18 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : setreuid01 - * - * EXECUTED BY : anyone - * - * TEST TITLE : Basic test for setreuid(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 5 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 05/14/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) setreuid(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - * - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the setreuid(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * setreuid(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ #include <errno.h> #include <string.h> #include <signal.h> - #include <sys/types.h> #include "test.h" #include "usctest.h" +#include "compat_16.h" -void setup(); -void cleanup(); +static void setup(void); +static void cleanup(void); -char *TCID = "setreuid01"; +TCID_DEFINE(setreuid01); int TST_TOTAL = 5; -int exp_enos[] = { 0, 0 }; - -int ruid, euid; /* real and effective user ids */ +static uid_t ruid, euid; /* real and effective user ids */ int main(int ac, char **av) { int lc; char *msg; - /*************************************************************** - * parse standard options - ***************************************************************/ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); - /*************************************************************** - * perform global setup for test - ***************************************************************/ setup(); - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); - - /*************************************************************** - * check looping state if -c option given - ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; @@ -159,21 +73,19 @@ int main(int ac, char **av) * Don't change either real or effective uid */ ruid = getuid(); /* get real uid */ + UID16_CHECK(ruid, setreuid, cleanup); + euid = geteuid(); /* get effective uid */ + UID16_CHECK(euid, setreuid, cleanup); - /* Call setreuid(2) */ - TEST(setreuid(-1, -1)); + TEST(SETREUID(cleanup, -1, -1)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setreuid - Don't change either real or effective uid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { /* No Verification test, yet... */ tst_resm(TPASS, @@ -187,21 +99,15 @@ int main(int ac, char **av) * change effective to effective uid */ - /* Call setreuid(2) */ - TEST(setreuid(-1, euid)); + TEST(SETREUID(cleanup, -1, euid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setreuid - change effective to effective uid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setreuid - change effective to effective uid returned %ld", TEST_RETURN); @@ -213,21 +119,15 @@ int main(int ac, char **av) * change real to real uid */ - /* Call setreuid(2) */ - TEST(setreuid(ruid, -1)); + TEST(SETREUID(cleanup, ruid, -1)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setreuid - change real to real uid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setreuid - change real to real uid returned %ld", TEST_RETURN); @@ -239,21 +139,15 @@ int main(int ac, char **av) * change effective to real uid */ - /* Call setreuid(2) */ - TEST(setreuid(-1, ruid)); + TEST(SETREUID(cleanup, -1, ruid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setreuid - change effective to real uid failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setreuid - change effective to real uid returned %ld", TEST_RETURN); @@ -265,21 +159,15 @@ int main(int ac, char **av) * try to change real to current real */ - /* Call setreuid(2) */ - TEST(setreuid(ruid, ruid)); + TEST(SETREUID(cleanup, ruid, ruid)); - /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setreuid - try to change real to current real failed, errno=%d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); } else { - /*************************************************************** - * only perform functional verification if flag set (-f not given) - ***************************************************************/ if (STD_FUNCTIONAL_TEST) { - /* No Verification test, yet... */ tst_resm(TPASS, "setreuid - try to change real to current real returned %ld", TEST_RETURN); @@ -288,41 +176,22 @@ int main(int ac, char **av) } - /*************************************************************** - * cleanup and exit - ***************************************************************/ cleanup(); tst_exit(); - tst_exit(); - } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup() +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; - /* make a temp dir and cd to it */ tst_tmpdir(); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup() +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; tst_rmdir(); - } diff --git a/testcases/kernel/syscalls/setreuid/setreuid02.c b/testcases/kernel/syscalls/setreuid/setreuid02.c index 5fdd918..1263996 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid02.c +++ b/testcases/kernel/syscalls/setreuid/setreuid02.c @@ -1,87 +1,47 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Ported by John George */ /* - * NAME - * setreuid02.c - * - * DESCRIPTION - * Test setreuid() when executed by root. - * - * ALGORITHM - * - * Setup: - * Setup signal handling - * Get user information. - * Pause for SIGUSER1 if option specified. - * Setup test values. - * Loop if the proper options are given. - * For each test set execute the system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given. - * - * USAGE: <for command-line> - * setreuid02 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * This test must be ran as root. - * nobody, bin, and daemon must be valid users. + * Test setreuid() when executed by root. */ +#include <errno.h> #include <pwd.h> #include <stdlib.h> #include <string.h> + #include "test.h" #include "usctest.h" -#include <errno.h> +#include "compat_16.h" -char *TCID = "setreuid02"; -uid_t nobody_pw_uid, root_pw_uid, daemon_pw_uid, bin_pw_uid; -uid_t neg_one = -1; -int exp_enos[] = { 0 }; +TCID_DEFINE(setreuid02); -struct passwd nobody, daemonpw, root, bin; +static uid_t neg_one = -1; +static struct passwd nobody, daemonpw, root, bin; /* * The following structure contains all test data. Each structure in the array * is used for a separate test. The tests are executed in the for loop below. */ -struct test_data_t { +static struct test_data_t { uid_t *real_uid; uid_t *eff_uid; struct passwd *exp_real_usr; @@ -90,42 +50,39 @@ struct test_data_t { } test_data[] = { { &neg_one, &neg_one, &root, &root, "After setreuid(-1, -1),"}, { - &nobody_pw_uid, &neg_one, &nobody, &root, "After setreuid(nobody, -1)"}, + &nobody.pw_uid, &neg_one, &nobody, &root, "After setreuid(nobody, -1)"}, { - &root_pw_uid, &neg_one, &root, &root, "After setreuid(root,-1),"}, { - &neg_one, &daemon_pw_uid, &root, &daemonpw, + &root.pw_uid, &neg_one, &root, &root, "After setreuid(root,-1),"}, { + &neg_one, &daemonpw.pw_uid, &root, &daemonpw, "After setreuid(-1, daemon)"}, { - &neg_one, &root_pw_uid, &root, &root, "After setreuid(-1,root),"}, { - &bin_pw_uid, &neg_one, &bin, &root, "After setreuid(bin, -1)"}, { -&root_pw_uid, &neg_one, &root, &root, "After setreuid(-1, root)"},}; + &neg_one, &root.pw_uid, &root, &root, "After setreuid(-1,root),"}, { + &bin.pw_uid, &neg_one, &bin, &root, "After setreuid(bin, -1)"}, { +&root.pw_uid, &neg_one, &root, &root, "After setreuid(-1, root)"},}; int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); -void setup(void); -void cleanup(void); -void uid_verify(struct passwd *ru, struct passwd *eu, char *when); +static void setup(void); +static void cleanup(void); +static void uid_verify(struct passwd *ru, struct passwd *eu, char *when); int main(int ac, char **av) { int lc; char *msg; - 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); - } - setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i; - /* reset tst_count in case we are looping */ tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ - TEST(setreuid(*test_data[i].real_uid, + TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == -1) { @@ -134,10 +91,6 @@ int main(int ac, char **av) *test_data[i].real_uid, *test_data[i].eff_uid); } else { - /* - * Perform functional verification if test - * executed without (-f) option. - */ if (STD_FUNCTIONAL_TEST) { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, @@ -150,71 +103,44 @@ int main(int ac, char **av) } cleanup(); tst_exit(); - } -/* - * setup() - * performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { + tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); - if (getpwnam("nobody") == NULL) { + if (getpwnam("nobody") == NULL) tst_brkm(TBROK, NULL, "nobody must be a valid user."); - tst_exit(); - } - if (getpwnam("daemon") == NULL) { + if (getpwnam("daemon") == NULL) tst_brkm(TBROK, NULL, "daemon must be a valid user."); - tst_exit(); - } - /* Check that the test process id is root */ - if (geteuid() != 0) { - tst_brkm(TBROK, NULL, "Must be root for this test!"); - tst_exit(); - } - - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); + if (getpwnam("bin") == NULL) + tst_brkm(TBROK, NULL, "bin must be a valid user."); root = *(getpwnam("root")); - root_pw_uid = root.pw_uid; + UID16_CHECK(root.pw_uid, setreuid, cleanup); nobody = *(getpwnam("nobody")); - nobody_pw_uid = nobody.pw_uid; + UID16_CHECK(nobody.pw_uid, setreuid, cleanup); daemonpw = *(getpwnam("daemon")); - daemon_pw_uid = daemonpw.pw_uid; + UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup); bin = *(getpwnam("bin")); - bin_pw_uid = bin.pw_uid; + UID16_CHECK(bin.pw_uid, setreuid, cleanup); - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -c option. - */ TEST_PAUSE; } -/* - * cleanup() - * performs all ONE TIME cleanup for this test at - * completion or premature exit - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; - } -void uid_verify(struct passwd *ru, struct passwd *eu, char *when) +static void uid_verify(struct passwd *ru, struct passwd *eu, char *when) { if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) { tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d", diff --git a/testcases/kernel/syscalls/setreuid/setreuid03.c b/testcases/kernel/syscalls/setreuid/setreuid03.c index 5dcb1f6..1074e79 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid03.c +++ b/testcases/kernel/syscalls/setreuid/setreuid03.c @@ -1,94 +1,52 @@ /* * - * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) International Business Machines Corp., 2001 * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Ported by John George */ /* - * NAME - * setreuid03.c - * - * DESCRIPTION - * Test setreuid() when executed by an unpriviledged user. - * - * ALGORITHM - * - * Setup: - * Setup signal handling - * Get user information. - * Pause for SIGUSER1 if option specified. - * - * Setup test values. - * Loop if the proper options are given. - * For each test set execute the system call - * Check that we received the expected result. - * If setreuid failed as expected - * check that the correct errno value was set. - * otherwise - * Issue Pass message. - * Verify that the uid and euid values are still correct. - * Cleanup: - * Print errno log and/or timing stats if option given. - * - * USAGE: <for command-line> - * setreuid03 [-c n] [-f] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * This test must be run by nobody. + * Test setreuid() when executed by an unpriviledged user. */ +#include <errno.h> #include <pwd.h> #include <stdlib.h> + #include "test.h" #include "usctest.h" -#include <errno.h> +#include "compat_16.h" #define FAILED 1 -char *TCID = "setreuid03"; - -int fail = -1; -int pass = 0; -uid_t neg_one = -1; -int exp_enos[] = { EPERM, 0 }; +TCID_DEFINE(setreuid03); -uid_t root_pw_uid, nobody_pw_uid, bin_pw_uid; -char user1name[] = "nobody"; -char user2name[] = "bin"; -char rootname[] = "root"; +static int fail = -1; +static int pass; +static uid_t neg_one = -1; -struct passwd nobody, bin, root; +static struct passwd nobody, bin, root; /* * The following structure contains all test data. Each structure in the array * is used for a separate test. The tests are executed in the for loop below. */ -struct test_data_t { +static struct test_data_t { uid_t *real_uid; uid_t *eff_uid; int *exp_ret; @@ -97,63 +55,60 @@ struct test_data_t { char *test_msg; } test_data[] = { { - &nobody_pw_uid, &nobody_pw_uid, &pass, &nobody, &nobody, + &nobody.pw_uid, &nobody.pw_uid, &pass, &nobody, &nobody, "After setreuid(nobody, nobody),"}, { - &neg_one, &nobody_pw_uid, &pass, &nobody, &nobody, + &neg_one, &nobody.pw_uid, &pass, &nobody, &nobody, "After setreuid(-1, nobody),"}, { - &nobody_pw_uid, &neg_one, &pass, &nobody, &nobody, + &nobody.pw_uid, &neg_one, &pass, &nobody, &nobody, "After setreuid(nobody, -1),"}, { &neg_one, &neg_one, &pass, &nobody, &nobody, "After setreuid(-1, -1),"}, { - &neg_one, &root_pw_uid, &fail, &nobody, &nobody, + &neg_one, &root.pw_uid, &fail, &nobody, &nobody, "After setreuid(-1, root),"}, { - &root_pw_uid, &neg_one, &fail, &nobody, &nobody, + &root.pw_uid, &neg_one, &fail, &nobody, &nobody, "After setreuid(root, -1),"}, { - &root_pw_uid, &root_pw_uid, &fail, &nobody, &nobody, + &root.pw_uid, &root.pw_uid, &fail, &nobody, &nobody, "After setreuid(root, root),"}, { - &root_pw_uid, &nobody_pw_uid, &fail, &nobody, &nobody, + &root.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody, "After setreuid(root, nobody),"}, { - &root_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody, + &root.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody, "After setreuid(root, nobody),"}, { - &bin_pw_uid, &root_pw_uid, &fail, &nobody, &nobody, + &bin.pw_uid, &root.pw_uid, &fail, &nobody, &nobody, "After setreuid(bin, root),"}, { - &bin_pw_uid, &neg_one, &fail, &nobody, &nobody, + &bin.pw_uid, &neg_one, &fail, &nobody, &nobody, "After setreuid(bin, -1),"}, { - &bin_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody, + &bin.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody, "After setreuid(bin, bin,),"}, { - &bin_pw_uid, &nobody_pw_uid, &fail, &nobody, &nobody, + &bin.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody, "After setreuid(bin, nobody),"}, { -&nobody_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody, + &nobody.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody, "After setreuid(nobody, bin),"},}; int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]); -void setup(void); -void cleanup(void); -void uid_verify(struct passwd *, struct passwd *, char *); +static void setup(void); +static void cleanup(void); +static void uid_verify(struct passwd *, struct passwd *, char *); int main(int ac, char **av) { int lc; char *msg; - 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); - } - setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i; - /* reset tst_count in case we are looping */ tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ - TEST(setreuid(*test_data[i].real_uid, + TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { @@ -187,86 +142,56 @@ int main(int ac, char **av) if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); } - /* - * Perform functional verification if test - * executed without (-f) option. - */ if (STD_FUNCTIONAL_TEST) { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); + } else { + tst_resm(TINFO, "Call succeeded."); } } } cleanup(); tst_exit(); - } -/* - * setup() - * performs all ONE TIME setup for this test - */ -void setup(void) +static void setup(void) { + tst_require_root(NULL); tst_sig(FORK, DEF_HANDLER, cleanup); - if (getpwnam("nobody") == NULL) { + if (getpwnam("nobody") == NULL) tst_brkm(TBROK, NULL, "nobody must be a valid user."); - tst_exit(); - } - if (getpwnam("bin") == NULL) { + if (getpwnam("bin") == NULL) tst_brkm(TBROK, NULL, "bin must be a valid user."); - tst_exit(); - } - - /* set the expected errnos... */ - TEST_EXP_ENOS(exp_enos); root = *(getpwnam("root")); - root_pw_uid = root.pw_uid; + UID16_CHECK(root.pw_uid, setreuid, cleanup); nobody = *(getpwnam("nobody")); - nobody_pw_uid = nobody.pw_uid; + UID16_CHECK(nobody.pw_uid, setreuid, cleanup); bin = *(getpwnam("bin")); - bin_pw_uid = bin.pw_uid; + UID16_CHECK(bin.pw_uid, setreuid, cleanup); - /* Check that the test process id is nobody */ - if (geteuid() != nobody.pw_uid) { -/* tst_brkm(TBROK, NULL, "Must be nobody for this test!"); - tst_exit();*/ - setuid(nobody.pw_uid); - } + if (setuid(nobody.pw_uid) < 0) + tst_brkm(TBROK | TERRNO, NULL, "setuid() to nobody failed"); - /* Pause if that option was specified - * TEST_PAUSE contains the code to fork the test with the -c option. - */ TEST_PAUSE; } -/* - * cleanup() - * performs all ONE TIME cleanup for this test at - * completion or premature exit - */ -void cleanup(void) +static void cleanup(void) { - /* - * print timing stats if that option was specified. - * print errno log if that option was specified. - */ TEST_CLEANUP; - } -void uid_verify(struct passwd *ru, struct passwd *eu, char *when) +static void uid_verify(struct passwd *ru, struct passwd *eu, char *when) { if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) { - tst_resm(TINFO, "ERROR: %s real uid = %d; effective uid = %d", + tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d", when, getuid(), geteuid()); tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d", ru->pw_uid, eu->pw_uid); diff --git a/testcases/kernel/syscalls/setreuid/setreuid04.c b/testcases/kernel/syscalls/setreuid/setreuid04.c index 0396f05..3010fc5 100644 --- a/testcases/kernel/syscalls/setreuid/setreuid04.c +++ b/testcases/kernel/syscalls/setreuid/setreuid04.c @@ -1,83 +1,45 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * Copyright (c) International Business Machines Corp., 2001 + * This program is free software; you can redistribute it and/or m... [truncated message content] |