int main(int ac, char **av) { int lc; char *msg; uid_t uid; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); uid = 1; while (!getpwuid(uid)) uid++; UID16_CHECK(uid, setfsuid, cleanup); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(SETFSUID(cleanup, uid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setfsuid() failed unexpectedly"); continue; } if (!STD_FUNCTIONAL_TEST) { tst_resm(TPASS, "setfsuid() succeeded"); continue; } if (TEST_RETURN == uid) { tst_resm(TFAIL, "setfsuid() returned %ld, expected anything but %d", TEST_RETURN, uid); } else { tst_resm(TPASS, "setfsuid() returned expected value : " "%ld", TEST_RETURN); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; uid_t uid; tst_parse_opts(ac, av, NULL, NULL); setup(); uid = 1; while (!getpwuid(uid)) uid++; UID16_CHECK(uid, setfsuid, cleanup); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(SETFSUID(cleanup, uid)); if (TEST_RETURN == -1) { tst_resm(TFAIL | TTERRNO, "setfsuid() failed unexpectedly"); continue; } if (TEST_RETURN == uid) { tst_resm(TFAIL, "setfsuid() returned %ld, expected anything but %d", TEST_RETURN, uid); } else { tst_resm(TPASS, "setfsuid() returned expected value : " "%ld", TEST_RETURN); } } cleanup(); tst_exit(); }
static void do_master_child(void) { int pid; int status; if (SETFSUID(NULL, ltpuser->pw_uid) == -1) { perror("setfsuid failed"); exit(TFAIL); } /* Test 1: Check the process with new uid cannot open the file * with RDWR permissions. */ TEST(open(testfile, O_RDWR)); if (TEST_RETURN != -1) { close(TEST_RETURN); printf("open succeeded unexpectedly\n"); exit(TFAIL); } if (TEST_ERRNO == EACCES) { printf("open failed with EACCESS as expected\n"); } else { printf("open returned unexpected errno - %d\n", TEST_ERRNO); exit(TFAIL); } /* Test 2: Check a son process cannot open the file * with RDWR permissions. */ pid = FORK_OR_VFORK(); if (pid < 0) { perror("Fork failed"); exit(TFAIL); } if (pid == 0) { /* Test to open the file in son process */ TEST(open(testfile, O_RDWR)); if (TEST_RETURN != -1) { close(TEST_RETURN); printf("open succeeded unexpectedly\n"); exit(TFAIL); } if (TEST_ERRNO == EACCES) { printf("open failed with EACCESS as expected\n"); } else { printf("open returned unexpected errno - %d\n", TEST_ERRNO); exit(TFAIL); } } else { /* Wait for son completion */ if (waitpid(pid, &status, 0) == -1) { perror("waitpid failed"); exit(TFAIL); } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) exit(WEXITSTATUS(status)); } /* Test 3: Fallback to initial uid and check we can again open * the file with RDWR permissions. */ tst_count++; if (SETFSUID(NULL, 0) == -1) { perror("setfsuid failed"); exit(TFAIL); } TEST(open(testfile, O_RDWR)); if (TEST_RETURN == -1) { perror("open failed unexpectedly"); exit(TFAIL); } else { printf("open call succeeded\n"); close(TEST_RETURN); } exit(TPASS); }