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 group id */ TEST(SETREGID(cleanup, *test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test_data[i].exp_errno) { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } else if (TEST_ERRNO == test_data[0].exp_errno) { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } else { tst_resm(TFAIL, "setregid(%d, %d) " "failed (%d) but did not set the " "expected errno (%d).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_ERRNO, test_data[i].exp_errno); } } else { tst_resm(TFAIL, "setregid(%d, %d) " "did not fail (ret: %ld) as expected (ret: -1).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_RETURN); } if (STD_FUNCTIONAL_TEST) { gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } else { tst_resm(TINFO, "Call succeeded."); } } } cleanup(); tst_exit(); }
static void daemon_switch_group(gid_t gid) { if ((setgid(gid) == -1) || !gid_verify(gid)) { VLOG_FATAL("%s: fail to switch group to gid as %d, aborting", pidfile, gid); } }
static void daemon_switch_group(gid_t real, gid_t effective, gid_t saved) { if ((setresgid(real, effective, saved) == -1) || !gid_verify(real, effective, saved)) { VLOG_FATAL("%s: failed to switch group to gid as %d, aborting", pidfile, gid); } }
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; tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { /* Set the real or effective group id */ TEST(SETREGID(NULL, *test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { if (TEST_ERRNO == test_data[i].exp_errno) { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } else { tst_resm(TFAIL, "setregid(%d, %d) " "failed (%d) but did not set the " "expected errno (%d).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_ERRNO, test_data[i].exp_errno); } } else { tst_resm(TFAIL, "setregid(%d, %d) " "did not fail (ret: %ld) as expected (ret: -1).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_RETURN); } gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } } 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 group id */ TEST(setregid(*test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TBROK, "setregid(%d, %d) failed", *test_data[i].real_gid, *test_data[i].eff_gid); } else { /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { gid_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(); tst_exit(); }
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 pid, status, i; /* reset Tst_count in case we are looping */ Tst_count = 0; /* set the appropriate ownership values */ if (setregid(sys_gr_gid, bin_gr_gid) == -1) { tst_brkm(TBROK, cleanup, "Initial setregid failed"); /*NOTREACHED*/} if (seteuid(nobody_pw_uid) == -1) { tst_brkm(TBROK, cleanup, "Initial seteuid failed"); /*NOTREACHED*/} if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "fork failed"); /*NOTREACHED*/} else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { gid_t test_ret; /* Set the real or effective group id */ TEST(setregid(*test_data[i].real_gid, *test_data[i].eff_gid)); test_ret = TEST_RETURN; if (test_ret == *test_data[i].exp_ret) { if (test_ret == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setregid(%d, %d) " "did not set errno " "value as expected.", *test_data[i]. real_gid, *test_data[i]. eff_gid); fail = -1; continue; } else { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i]. real_gid, *test_data[i]. eff_gid); } } else { tst_resm(TPASS, "setregid(%d, %d) " "succeeded as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } } else { tst_resm(TFAIL, "setregid(%d, %d) " "did not return as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); flag = -1; } if (test_ret == -1) { TEST_ERROR_LOG(TEST_ERRNO); } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { gid_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(); /*NOTREACHED*/ return 0; }
int main(int ac, char **av) { int lc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { pid_t pid; int status, i; pass = 0; flag = 0; tst_count = 0; /* set the appropriate ownership values */ if (SETREGID(NULL, sys.gr_gid, bin.gr_gid) == -1) tst_brkm(TBROK, NULL, "Initial setregid failed"); if (seteuid(nobody.pw_uid) == -1) tst_brkm(TBROK, NULL, "Initial seteuid failed"); if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, NULL, "fork failed"); } else if (pid == 0) { /* child */ for (i = 0; i < TST_TOTAL; i++) { gid_t test_ret; /* Set the real or effective group id */ TEST(SETREGID(NULL, *test_data[i].real_gid, *test_data[i].eff_gid)); test_ret = TEST_RETURN; if (test_ret == *test_data[i].exp_ret) { if (test_ret == neg_one) { if (TEST_ERRNO != EPERM) { tst_resm(TFAIL, "setregid(%d, %d) " "did not set errno " "value as expected.", *test_data [i].real_gid, *test_data [i].eff_gid); fail = -1; continue; } else { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data [i].real_gid, *test_data [i].eff_gid); } } else { tst_resm(TPASS, "setregid(%d, %d) " "succeeded as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } } else { tst_resm(TFAIL, "setregid(%d, %d) " "did not return as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); flag = -1; } if (test_ret == -1) { } gid_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."); } } } tst_exit(); }
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 group id */ TEST(setregid(*test_data[i].real_gid, *test_data[i].eff_gid)); if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == test_data[i].exp_errno) { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } else if (TEST_ERRNO == test_data[0].exp_errno) { tst_resm(TPASS, "setregid(%d, %d) " "failed as expected.", *test_data[i].real_gid, *test_data[i].eff_gid); } else { tst_resm(TFAIL, "setregid(%d, %d) " "failed (%d) but did not set the " "expected errno (%d).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_ERRNO, test_data[i].exp_errno); } } else { tst_resm(TFAIL, "setregid(%d, %d) " "did not fail (ret: %ld) as expected (ret: -1).", *test_data[i].real_gid, *test_data[i].eff_gid, TEST_RETURN); } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, test_data[i].test_msg); } else { tst_resm(TINFO, "Call succeeded."); } } } cleanup(); /*NOTREACHED*/ return 0; }