int main(int ac, char **av) { int lc; const char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); flag = 0; for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid, status; tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN != -1) { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); flag = -1; } 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."); } } exit(flag); } else { /* parent */ waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "test failed within " "child process."); } } } cleanup(); tst_exit(); }
static void daemon_switch_user(const uid_t uid, const char *user) { if ((setuid(uid) == -1) || !uid_verify(uid)) { VLOG_FATAL("%s: fail to switch user to %s, aborting", pidfile, user); } }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid; /* reset tst_count in case we are looping */ tst_count = 0; /* set the appropriate ownership values */ if (setresuid(nobody_pw_uid, bin_pw_uid, nobody_pw_uid) == -1) { tst_brkm(TFAIL, cleanup, "Initial setresuid failed"); } if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real, effective or saved user id */ TEST(SETRESUID(NULL, *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN != -1) { tst_resm(TPASS, "setresuid(%d, %d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); } else { tst_resm(TFAIL, "setresuid(%d, %d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); flag = -1; } uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].exp_sav_usr, test_data[i].test_msg); } exit(flag); } else { /* parent */ tst_record_childstatus(cleanup, pid); } } cleanup(); tst_exit(); }
static void daemon_switch_user(const uid_t real, const uid_t effective, const uid_t saved, const char *user) { if ((setresuid(real, effective, saved) == -1) || !uid_verify(real, effective, saved)) { VLOG_FATAL("%s: fail to switch user to %s, aborting", pidfile, user); } }
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(); /*NOTREACHED*/ } /* Perform global setup for test */ setup(); /* check looping state if -i option is given */ 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_data[i].eff_uid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TBROK, "setreuid(%d, %d) failed", 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, test_data[i].test_msg); } else { tst_resm(TPASS, "Call succeeded."); } } } } cleanup(); /*NOTREACHED*/ return(0); }
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(); 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, effective or user id */ TEST(setresuid(*test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setresuid(%d, %d, %d) failed", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_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, test_data[i].exp_sav_usr, test_data[i].test_msg); } else { tst_resm(TPASS, "Call succeeded."); } } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; const char *msg; 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, effective or user id */ TEST(setresuid(*test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setresuid(%d, %d, %d) failed", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); } else { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].exp_sav_usr, test_data[i].test_msg); } } } cleanup(); tst_exit(); }
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(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i; tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TBROK, "setreuid(%d, %d) failed", *test_data[i].real_uid, *test_data[i].eff_uid); } else { 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(TPASS, "Call succeeded."); } } } } 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++) { int i; /* reset tst_count in case we are looping */ tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real, effective or user id */ TEST(SETRESUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setresuid(%d, %d, %d) failed", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); } else { uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].exp_sav_usr, test_data[i].test_msg); } } } cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc; char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid, status; /* reset Tst_count in case we are looping */ Tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(setreuid(*test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { if (TEST_RETURN == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setreuid(%d, %d) " "did not set errno " "value as expected.", *test_data[i]. real_uid, *test_data[i]. eff_uid); flag = -1; continue; } tst_resm(TPASS, "setreuid(%d, %d) " "failed as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); flag = -1; } 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); } } exit(flag); } else { /* parent */ waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "test failed within " "child process."); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; /* message returned from parse_opts */ int status; /* parse standard options */ 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, pid; /* reset Tst_count in case we are looping */ Tst_count = 0; /* set the appropriate ownership values */ if (setresuid(nobody_pw_uid, bin_pw_uid, nobody_pw_uid) == -1) { tst_brkm(TFAIL, cleanup, "Initial setresuid failed"); } if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real, effective or saved user id */ TEST(setresuid(*test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid)); if (TEST_RETURN != -1) { tst_resm(TPASS, "setresuid(%d, %d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); } else { tst_resm(TFAIL, "setresuid(%d, %d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid, *test_data[i].sav_uid); flag = -1; } /* * 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].exp_sav_usr, test_data[i].test_msg); } else { tst_resm(TINFO, "Call succeeded."); } } exit(flag); } else { /* parent */ waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "test failed within " "child process."); } } } cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc; const char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); pass = 0; for (lc = 0; TEST_LOOPING(lc); lc++) { int i, pid; tst_count = 0; if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective user id */ TEST(SETREUID(cleanup, *test_data[i].real_uid, *test_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { if (TEST_RETURN == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setreuid(%d, %d) " "did not set errno " "value as expected.", *test_data [i].real_uid, *test_data [i].eff_uid); continue; } tst_resm(TPASS, "setreuid(%d, %d) " "failed as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); } uid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } tst_exit(); } else { /* parent */ tst_record_childstatus(cleanup, pid); } } cleanup(); tst_exit(); }
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(); 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_data[i].eff_uid)); if (TEST_RETURN == *test_data[i].exp_ret) { if (TEST_RETURN == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setreuid(%d, %d) " "did not set errno " "value as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); continue; } tst_resm(TPASS, "setreuid(%d, %d) " "failed as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } else { tst_resm(TPASS, "setreuid(%d, %d) " "succeeded as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } } else { tst_resm(TFAIL, "setreuid(%d, %d) " "did not return as expected.", *test_data[i].real_uid, *test_data[i].eff_uid); } 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); } } } cleanup(); tst_exit(); }