/* * 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; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fname,"./tfile_%d",getpid()); do_file_setup(fname); bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX|MAP_ANONYMOUS, 0, 0); if (bad_addr == MAP_FAILED) { tst_brkm(TBROK, cleanup, "mmap failed"); } #if !defined(UCLINUX) TC[0].fd2 = bad_addr; TC[1].fd = bad_addr; #endif }
/* * setup() - performs all ONE TIME setup for this test. */ void setup() { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fname, "./tfile_%d", getpid()); sprintf(mname, "./rnfile_%d", getpid()); /* create the "old" file */ do_file_setup(fname); if (stat(fname, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat file %s" "in rename()", fname); } /* save the dev and inode */ olddev = buf1.st_dev; oldino = buf1.st_ino; /* link the "new" file to the "old" file */ if (link(fname, mname) == -1) { tst_brkm(TBROK, cleanup, "link from %s to %s failed!", fname, mname); } }
int main(int ac, char **av) { int lc; /* loop counter */ const 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 ***************************************************************/ for (lc=0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping. */ Tst_count=0; /* * Call rename(2) */ TEST(rename(fname, mname)); /* check return code */ if ( TEST_RETURN == -1 ) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "rename(%s, %s) Failed, errno=%d : %s", fname, mname, 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, "rename(%s, %s) returned %d", fname, mname, TEST_RETURN); } if (unlink(mname) == -1) { tst_resm(TWARN, "unlink(%s) Failed, errno=%d : %s", mname, errno, strerror(errno)); } do_file_setup(); } } /* End for TEST_LOOPING */ /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); return 0; } /* End main */
/* * setup2() - set up the files and directories for the tests */ void setup2() { /* create the old file */ do_file_setup(fname); if (stat(fname, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat file %s" "in rename()", fname); } /* save original file's dev and ino */ f_olddev = buf1.st_dev; f_oldino = buf1.st_ino; /* create another file */ do_file_setup(mname); /* create "old" directory */ if (mkdir(fdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir); } if (stat(fdir, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s" "in rename()", fdir); } d_olddev = buf1.st_dev; d_oldino = buf1.st_ino; /* create another directory */ if (mkdir(mdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir); } }
/* * 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; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fdir, "./tdir_%d", getpid()); sprintf(mdir, "./rndir_%d", getpid()); sprintf(tstfile, "%s/tstfile_%d", mdir, getpid()); /* create "old" directory */ if (mkdir(fdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir); /*NOTREACHED*/} if (stat(fdir, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s" "in rename()", fdir); /* NOTREACHED */ } /* save "old"'s dev and ino */ olddev = buf1.st_dev; oldino = buf1.st_ino; /* create another directory */ if (mkdir(mdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir); /*NOTREACHED*/} /* create a file under "new" directory */ do_file_setup(tstfile); if (stat(mdir, &buf2) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s " "in rename()", mdir); /* NOTREACHED */ } /* save "new"'s dev and ino */ olddev1 = buf2.st_dev; oldino1 = buf2.st_ino; }
/* * setup() - performs all ONE TIME setup for this test. */ void setup() { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fname, "./tfile_%d", getpid()); sprintf(mdir, "./rndir_%d", getpid()); sprintf(mname, "%s/rnfile_%d", mdir, getpid()); do_file_setup(fname); }
/* * 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; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fname,"./tfile_%d",getpid()); do_file_setup(fname); }
/*************************************************************** * setup() - performs all ONE TIME setup for this test. ***************************************************************/ void setup() { /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* make a temp directory and cd to it */ tst_tmpdir(); /* Pause if that option was specified */ TEST_PAUSE; sprintf(fname,"./tfile_%d",getpid()); sprintf(mname,"./rnfile_%d",getpid()); do_file_setup(); } /* End setup() */
/* * setup() - performs all ONE TIME setup for this test. */ void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(mdir, "./rndir_%d", getpid()); sprintf(fname, "./tfile_%d", getpid()); /* create "old" file */ do_file_setup(fname); if (stat(fname, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat file %s" "in rename()", fname); } /* save "old"'s dev and ino */ olddev = buf1.st_dev; oldino = buf1.st_ino; /* create another directory */ if (stat(mdir, &buf2) != -1) { tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir); } if (mkdir(mdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir); } if (stat(mdir, &buf2) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s " "in rename()", mdir); } /* save "new"'s dev and ino */ olddev1 = buf2.st_dev; oldino1 = buf2.st_ino; }
/* * set_condition - set up starting conditions for the individual tests */ void set_condition(int num) { switch(num) { case 1: /* set up for first test */ sprintf(tstdir1,"./tstdir1_%d",getpid()); sprintf(tstfile,"%s/tstfile_%d",tstdir1,getpid()); /* create a directory */ if (mkdir(tstdir1, PERMS) == -1) { tst_brkm(TBROK,cleanup,"mkdir(%s, %#o) Failed", tstdir1, PERMS); /*NOTREACHED*/ } /* create a file under tstdir1 */ do_file_setup(tstfile); break; case 2: create_longpath(); break; case 3: /* Initialize the test directory name */ sprintf(tstdir2, "NOSUCHADIR/tstdir2.%d", getpid()); break; case 4: /* Initialize the test directory name and file name */ sprintf(tstdir3, "%s/tstdir3", tstfile); /* create a file */ if (creat(tstfile, PERMS) == -1) { tst_brkm(TBROK, cleanup, "creat() failed"); /*NOTREACHED*/ } break; default: tst_brkm(TBROK, cleanup, "illegal setup case - %d", num); break; } }
/* * setup() - performs all ONE TIME setup for this test. */ void setup() { /* must run as root */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Must run this as root"); } tst_sig(FORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Create a temporary directory and make it current. */ tst_tmpdir(); umask(0); sprintf(fdir, "./tdir_%d", getpid()); sprintf(fname, "%s/tfile_%d", fdir, getpid()); sprintf(mname, "%s/rnfile_%d", fdir, getpid()); /* create a directory */ if (mkdir(fdir, PERMS) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir); } if (stat(fdir, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s", fdir); } /* set the sticky bit */ if (chmod(fdir, buf1.st_mode | S_ISVTX) != 0) { tst_brkm(TBROK, cleanup, "failed to set the S_ISVTX bit"); } /* create a file under fdir */ do_file_setup(fname); /* get nobody password file info */ nobody = my_getpwnam(user1name); }
/* * setup() - performs all ONE TIME setup for this test. */ void setup(void) { tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* Create a temporary directory and make it current. */ tst_tmpdir(); sprintf(fname, "./tfile_%d", getpid()); sprintf(mname, "./rnfile_%d", getpid()); sprintf(fdir, "./tdir_%d", getpid()); sprintf(mdir, "./rndir_%d", getpid()); /* create the "old" file */ do_file_setup(fname); if (stat(fname, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat file %s" "in setup()", fname); } f_olddev = buf1.st_dev; f_oldino = buf1.st_ino; /* create "old" directory */ if (mkdir(fdir, 00770) == -1) { tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir); } if (stat(fdir, &buf1) == -1) { tst_brkm(TBROK, cleanup, "failed to stat directory %s" "in setup()", fname); } d_olddev = buf1.st_dev; d_oldino = buf1.st_ino; }
int main(int ac, char **av) { int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ int rval; pid_t pid, pid1; int status; /* * 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 -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() #1 failed"); } if (pid == 0) { /* first child */ /* set to nobody */ rval = setreuid(nobody->pw_uid, nobody->pw_uid); if (rval < 0) { tst_resm(TWARN, "setreuid failed to " "to set the real uid to %d and " "effective uid to %d", nobody->pw_uid, nobody->pw_uid); perror("setreuid"); exit(1); } /* create the a directory with 0700 permits */ if (mkdir(fdir, PERMS) == -1) { tst_resm(TWARN, "mkdir(%s, %#o) Failed", fdir, PERMS); exit(1); } /* create "old" file under it */ do_file_setup(fname); exit(0); } /* wait for child to exit */ wait(&status); if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { tst_brkm(TBROK, cleanup, "First child failed to set " "up conditions for the test"); } if ((pid1 = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork() #2 failed"); } if (pid1 == 0) { /* second child */ /* set to bin */ if ((rval = seteuid(bin->pw_uid)) == -1) { tst_resm(TWARN, "seteuid() failed"); perror("setreuid"); exit(1); } /* create "new" directory */ if (mkdir(mdir, PERMS) == -1) { tst_resm(TWARN, "mkdir(%s, %#o) failed", mdir, PERMS); exit(1); } /* create the new file */ do_file_setup(mname); /* rename "old" to "new" */ TEST(rename(fname, mname)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != EACCES) { tst_resm(TFAIL, "Expected EACCES got %d", TEST_ERRNO); } else { tst_resm(TPASS, "rename() returned EACCES"); } /* set the process id back to root */ if (seteuid(0) == -1) { tst_resm(TWARN, "seteuid(0) failed"); exit(1); } /* clean up things in case we are looping */ if (unlink(fname) == -1) { tst_brkm(TBROK, cleanup, "unlink() #1 failed"); } if (unlink(mname) == -1) { tst_brkm(TBROK, cleanup, "unlink() #2 failed"); } if (rmdir(fdir) == -1) { tst_brkm(TBROK, cleanup, "rmdir() #1 failed"); } if (rmdir(mdir) == -1) { tst_brkm(TBROK, cleanup, "rmdir() #2 failed"); } } else { /* parent - let the second child carry on */ waitpid(pid1, &status, 0); if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) { exit(WEXITSTATUS(status)); } else { exit(0); } } } /* * cleanup and exit */ cleanup(); tst_exit(); }