int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(SETUID(cleanup, ROOT_USER)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == EPERM) { tst_resm(TPASS, "setuid returned errno EPERM"); } else { tst_resm(TFAIL, "setuid returned unexpected errno - %d", TEST_ERRNO); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; TEST(SETUID(cleanup, ROOT_USER)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); continue; } if (TEST_ERRNO == EPERM) { tst_resm(TPASS, "setuid returned errno EPERM"); } else { tst_resm(TFAIL, "setuid returned unexpected errno - %d", TEST_ERRNO); } } cleanup(); tst_exit(); }
static void setup(void) { struct passwd *pw; uid_t uid; pw = SAFE_GETPWNAM("nobody"); uid = pw->pw_uid; UID16_CHECK(uid, setuid); /* Create test file */ SAFE_TOUCH(FILENAME, 0644, NULL); if (SETUID(uid) == -1) { tst_brk(TBROK, "setuid() failed to set the effective uid to %d", uid); } }
static void do_master_child(void) { int lc; int pid; int status; if (SETUID(NULL, ltpuser->pw_uid) == -1) { tst_brkm(TBROK, NULL, "setuid failed to set the effective uid to %d", ltpuser->pw_uid); } for (lc = 0; TEST_LOOPING(lc); lc++) { int tst_fd; tst_count = 0; TEST(tst_fd = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); close(tst_fd); } if (TEST_ERRNO == EACCES) { tst_resm(TPASS, "open returned errno EACCES"); } else { tst_resm(TFAIL, "open returned unexpected errno - %d", TEST_ERRNO); continue; } pid = FORK_OR_VFORK(); if (pid < 0) tst_brkm(TBROK, NULL, "Fork failed"); if (pid == 0) { int tst_fd2; /* Test to open the file in son process */ TEST(tst_fd2 = open(testfile, O_RDWR)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded unexpectedly"); close(tst_fd2); } if (TEST_ERRNO == EACCES) { tst_resm(TPASS, "open returned errno EACCES"); } else { tst_resm(TFAIL, "open returned unexpected errno - %d", TEST_ERRNO); } tst_exit(); } else { /* Wait for son completion */ waitpid(pid, &status, 0); if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) exit(WEXITSTATUS(status)); } } tst_exit(); }