From: Subrata <sub...@us...> - 2009-03-23 14:44:37
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/setuid In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14647/ltp/testcases/kernel/syscalls/setuid Modified Files: setuid01.c setuid02.c setuid03.c setuid04.c Log Message: Coding Syle Cleanups. Signed-Off-By: <mic...@pe...>. Index: setuid01.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/setuid/setuid01.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** setuid01.c 26 Feb 2009 12:16:39 -0000 1.3 --- setuid01.c 23 Mar 2009 13:36:04 -0000 1.4 *************** *** 66,70 **** * * OUTPUT SPECIFICATIONS ! * * DURATION * Terminates - with frequency and infinite modes. --- 66,70 ---- * * OUTPUT SPECIFICATIONS ! *$ * DURATION * Terminates - with frequency and infinite modes. *************** *** 122,208 **** void cleanup(); ! ! ! char *TCID="setuid01"; /* Test program identifier. */ ! int TST_TOTAL=1; /* Total number of test cases. */ extern int Tst_count; /* Test Case counter for tst_* routines */ ! int uid; /* current user id */ ! int ! main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ ! /*************************************************************** * parse standard options ***************************************************************/ ! if ( (msg=parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *) NULL ) { ! tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); ! tst_exit(); ! } /*************************************************************** * perform global setup for test ***************************************************************/ ! setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ ! for (lc=0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count=0; ! ! /* ! * TEST CASE: ! * Set the effective user ID to the current real uid ! */ ! uid=getuid(); ! /* Call setuid(2) */ ! TEST(setuid(uid)); ! /* check return code */ ! if ( TEST_RETURN == -1 ) { ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, "setuid - Set the effective user ID to the current 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, "setuid - Set the effective user ID to the current real uid returned %d", TEST_RETURN); ! } ! } ! ! } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ ! cleanup(); ! return 0; ! } /* End main */ /*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ ! void ! setup() { ! /* capture signals */ ! tst_sig(NOFORK, DEF_HANDLER, cleanup); ! ! /* Pause if that option was specified */ ! TEST_PAUSE; ! } /* End setup() */ /*************************************************************** --- 122,205 ---- void cleanup(); ! char *TCID = "setuid01"; /* Test program identifier. */ ! int TST_TOTAL = 1; /* Total number of test cases. */ extern int Tst_count; /* Test Case counter for tst_* routines */ ! int uid; /* current user id */ ! int main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ ! /*************************************************************** * parse standard options ***************************************************************/ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { ! tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); ! tst_exit(); ! } /*************************************************************** * perform global setup for test ***************************************************************/ ! setup(); /*************************************************************** * check looping state if -c option given ***************************************************************/ ! for (lc = 0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count = 0; ! /* ! * TEST CASE: ! * Set the effective user ID to the current real uid ! */ ! uid = getuid(); ! /* Call setuid(2) */ ! TEST(setuid(uid)); ! ! /* check return code */ ! if (TEST_RETURN == -1) { ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, ! "setuid - Set the effective user ID to the current 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, ! "setuid - Set the effective user ID to the current real uid returned %d", ! TEST_RETURN); ! } ! } ! } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ ! cleanup(); ! return 0; ! } /* End main */ /*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ ! void setup() { ! /* capture signals */ ! tst_sig(NOFORK, DEF_HANDLER, cleanup); + /* Pause if that option was specified */ + TEST_PAUSE; + } /* End setup() */ /*************************************************************** *************** *** 210,225 **** * completion or premature exit. ***************************************************************/ ! void ! cleanup() { ! /* ! * print timing stats if that option was specified. ! * print errno log if that option was specified. ! */ ! TEST_CLEANUP; ! ! /* exit with return code appropriate for results */ ! tst_exit(); ! } /* End cleanup() */ ! --- 207,219 ---- * completion or premature exit. ***************************************************************/ ! void cleanup() { ! /* ! * print timing stats if that option was specified. ! * print errno log if that option was specified. ! */ ! TEST_CLEANUP; + /* exit with return code appropriate for results */ + tst_exit(); + } /* End cleanup() */ Index: setuid04.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/setuid/setuid04.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** setuid04.c 26 Feb 2009 12:16:39 -0000 1.4 --- setuid04.c 23 Mar 2009 13:36:04 -0000 1.5 *************** *** 63,67 **** struct passwd *ltpuser; ! int exp_enos[] = {EACCES, 0}; int fd = -1; --- 63,67 ---- struct passwd *ltpuser; ! int exp_enos[] = { EACCES, 0 }; int fd = -1; *************** *** 73,84 **** { pid_t pid; ! char *msg; /* message returned from parse_opts */ int status; /* parse standard options */ ! if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); ! /*NOTREACHED*/ ! } /* --- 73,83 ---- { pid_t pid; ! char *msg; /* message returned from parse_opts */ int status; /* parse standard options */ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); ! /*NOTREACHED*/} /* *************** *** 95,109 **** 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"); } cleanup(); ! /*NOTREACHED*/ ! ! return 0; } --- 94,106 ---- 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"); } cleanup(); ! /*NOTREACHED*/ return 0; } *************** *** 113,117 **** void do_master_child() { ! int lc; /* loop counter */ int pid; int status; --- 110,114 ---- void do_master_child() { ! int lc; /* loop counter */ int pid; int status; *************** *** 161,174 **** TEST_ERROR_LOG(TEST_ERRNO); ! if (TEST_ERRNO == EACCES) { tst_resm(TPASS, "open returned errno EACCES"); } else { ! tst_resm(TFAIL, "open returned unexpected errno - %d", TEST_ERRNO); continue; } ! } ! else { /* Wait for son completion */ waitpid(pid, &status, 0); --- 158,171 ---- TEST_ERROR_LOG(TEST_ERRNO); ! if (TEST_ERRNO == EACCES) { tst_resm(TPASS, "open returned errno EACCES"); } else { ! tst_resm(TFAIL, ! "open returned unexpected errno - %d", TEST_ERRNO); continue; } ! } else { /* Wait for son completion */ waitpid(pid, &status, 0); *************** *** 182,191 **** * setup() - performs all ONE TIME setup for this test */ ! void ! setup(void) { ! if (geteuid() != 0) { ! tst_brkm(TBROK, tst_exit, "Test must be run as root"); ! } ltpuser = getpwnam(nobody_uid); --- 179,187 ---- * setup() - performs all ONE TIME setup for this test */ ! void setup(void) { ! if (geteuid() != 0) { ! tst_brkm(TBROK, tst_exit, "Test must be run as root"); ! } ltpuser = getpwnam(nobody_uid); *************** *** 209,216 **** * or premature exit */ ! void ! cleanup(void) { ! close (fd); unlink(testfile); --- 205,211 ---- * or premature exit */ ! void cleanup(void) { ! close(fd); unlink(testfile); Index: setuid03.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/setuid/setuid03.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** setuid03.c 26 Feb 2009 12:16:39 -0000 1.6 --- setuid03.c 23 Mar 2009 13:36:04 -0000 1.7 *************** *** 56,60 **** struct passwd *ltpuser; ! int exp_enos[] = {EPERM, 0}; void setup(void); --- 56,60 ---- struct passwd *ltpuser; ! int exp_enos[] = { EPERM, 0 }; void setup(void); *************** *** 63,74 **** int main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ /* parse standard options */ ! if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); ! /*NOTREACHED*/ ! } /* --- 63,73 ---- int main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ /* parse standard options */ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); ! /*NOTREACHED*/} /* *************** *** 103,108 **** cleanup(); ! /*NOTREACHED*/ ! return 0; } --- 102,106 ---- cleanup(); ! /*NOTREACHED*/ return 0; } *************** *** 110,128 **** * setup() - performs all ONE TIME setup for this test */ ! void ! setup(void) { /* Switch to nobody user for correct error code collection */ ! if (geteuid() != 0) { ! tst_brkm(TBROK, tst_exit, "Test must be run as root"); ! } ! ltpuser = getpwnam(nobody_uid); ! if (setuid(ltpuser->pw_uid) == -1) { ! tst_resm(TINFO, "setuid failed to " ! "to set the effective uid to %d", ! ltpuser->pw_uid); ! perror("setuid"); ! } ! /* capture signals */ --- 108,123 ---- * setup() - performs all ONE TIME setup for this test */ ! void setup(void) { /* Switch to nobody user for correct error code collection */ ! if (geteuid() != 0) { ! tst_brkm(TBROK, tst_exit, "Test must be run as root"); ! } ! ltpuser = getpwnam(nobody_uid); ! if (setuid(ltpuser->pw_uid) == -1) { ! tst_resm(TINFO, "setuid failed to " ! "to set the effective uid to %d", ltpuser->pw_uid); ! perror("setuid"); ! } /* capture signals */ *************** *** 139,144 **** * or premature exit */ ! void ! cleanup(void) { /* --- 134,138 ---- * or premature exit */ ! void cleanup(void) { /* Index: setuid02.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/setuid/setuid02.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** setuid02.c 26 Feb 2009 12:16:39 -0000 1.4 --- setuid02.c 23 Mar 2009 13:36:04 -0000 1.5 *************** *** 67,71 **** * * OUTPUT SPECIFICATIONS ! * * DURATION * Terminates - with frequency and infinite modes. --- 67,71 ---- * * OUTPUT SPECIFICATIONS ! *$ * DURATION * Terminates - with frequency and infinite modes. *************** *** 122,220 **** void cleanup(); ! ! ! char *TCID="setuid02"; /* Test program identifier. */ ! int TST_TOTAL=1; /* Total number of test cases. */ extern int Tst_count; /* Test Case counter for tst_* routines */ ! int exp_enos[]={0, 0}; /* Zero terminated list of expected errnos */ ! ! int uid; /* current user id */ ! int ! main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ ! /*************************************************************** * parse standard options ***************************************************************/ ! if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) ! tst_brkm(TBROK, cleanup, "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 ***************************************************************/ ! uid=getuid(); ! for (lc=0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count=0; ! ! /* ! * TEST CASE: ! * Set the effective user ID to the current real uid ! */ ! /* Call setuid(2) */ ! TEST(setuid(uid)); ! /* check return code */ ! if ( TEST_RETURN == -1 ) { ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, "setuid - Set the effective user ID to the current 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, "setuid - Set the effective user ID to the current real uid returned %d", TEST_RETURN); ! } ! } ! ! } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ ! cleanup(); ! return 0; ! } /* End main */ /*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ ! void ! setup() { ! /* capture signals */ ! tst_sig(NOFORK, DEF_HANDLER, cleanup); ! ! /* Pause if that option was specified */ ! TEST_PAUSE; ! /* make a temp dir and cd to it */ ! tst_tmpdir(); ! /* must be root */ ! if ( geteuid() != 0 ) ! tst_brkm(TBROK, cleanup, "Must be root for this test!"); ! } /* End setup() */ /*************************************************************** --- 122,215 ---- void cleanup(); ! char *TCID = "setuid02"; /* Test program identifier. */ ! int TST_TOTAL = 1; /* Total number of test cases. */ extern int Tst_count; /* Test Case counter for tst_* routines */ ! int exp_enos[] = { 0, 0 }; /* Zero terminated list of expected errnos */ + int uid; /* current user id */ ! int main(int ac, char **av) { ! int lc; /* loop counter */ ! char *msg; /* message returned from parse_opts */ ! /*************************************************************** * parse standard options ***************************************************************/ ! if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) ! tst_brkm(TBROK, cleanup, "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 ***************************************************************/ ! uid = getuid(); ! for (lc = 0; TEST_LOOPING(lc); lc++) { ! /* reset Tst_count in case we are looping. */ ! Tst_count = 0; ! /* ! * TEST CASE: ! * Set the effective user ID to the current real uid ! */ ! /* Call setuid(2) */ ! TEST(setuid(uid)); ! /* check return code */ ! if (TEST_RETURN == -1) { ! TEST_ERROR_LOG(TEST_ERRNO); ! tst_resm(TFAIL, ! "setuid - Set the effective user ID to the current 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, ! "setuid - Set the effective user ID to the current real uid returned %d", ! TEST_RETURN); ! } ! } ! } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ ! cleanup(); ! return 0; ! } /* End main */ /*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ ! void setup() { ! /* capture signals */ ! tst_sig(NOFORK, DEF_HANDLER, cleanup); ! /* Pause if that option was specified */ ! TEST_PAUSE; ! /* make a temp dir and cd to it */ ! tst_tmpdir(); + /* must be root */ + if (geteuid() != 0) + tst_brkm(TBROK, cleanup, "Must be root for this test!"); + } /* End setup() */ /*************************************************************** *************** *** 222,240 **** * completion or premature exit. ***************************************************************/ ! void ! cleanup() { ! /* ! * print timing stats if that option was specified. ! * print errno log if that option was specified. ! */ ! TEST_CLEANUP; ! ! /* remove files and temp dir */ ! tst_rmdir(); ! ! /* exit with return code appropriate for results */ ! tst_exit(); ! } /* End cleanup() */ --- 217,232 ---- * completion or premature exit. ***************************************************************/ ! void cleanup() { ! /* ! * print timing stats if that option was specified. ! * print errno log if that option was specified. ! */ ! TEST_CLEANUP; + /* remove files and temp dir */ + tst_rmdir(); + /* exit with return code appropriate for results */ + tst_exit(); + } /* End cleanup() */ |