int main(int ac, char **av) { int lc; char *msg; /*************************************************************** * 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(); /*************************************************************** * check looping state if -c option given ***************************************************************/ for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; /* * Call setgroups(2) */ TEST(SETGROUPS(ngrps, list)); /* check return code */ if (TEST_RETURN == -1) { TEST_ERROR_LOG(TEST_ERRNO); tst_resm(TFAIL, "setgroups(%d, list) Failed, errno=%d : %s", len, 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, "setgroups(%d, list) returned %ld", len, TEST_RETURN); } } } /*************************************************************** * cleanup and exit ***************************************************************/ cleanup(); tst_exit(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; int gidsetsize; /* total no. of groups */ char *test_desc; /* test specific error message */ if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); /* Perform setup for test */ setup(); /* set the expected errnos... */ TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; gidsetsize = NGROUPS; test_desc = "EFAULT"; /* * Call setgroups() to test condition * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0))); if (TEST_RETURN != -1) { tst_resm(TFAIL, "setgroups() returned %ld, " "expected -1, errno=%d", TEST_RETURN, exp_enos[0]); } else { TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO == exp_enos[0]) { tst_resm(TPASS, "setgroups() fails with expected " "error EFAULT errno:%d", TEST_ERRNO); } else { tst_resm(TFAIL, "setgroups() fails, %s, " "errno=%d, expected errno=%d", test_desc, TEST_ERRNO, exp_enos[0]); } } } cleanup(); tst_exit(); tst_exit(); }
int main(int ac, char **av) { int lc, i; int gidsetsize = 1; /* only one GID, the GID of TESTUSER */ int PASS_FLAG = 0; /* used for checking group array */ tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; /* * Call setgroups() to set supplimentary group IDs of * the calling super-user process to gid of TESTUSER. */ TEST(SETGROUPS(cleanup, gidsetsize, groups_list)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setgroups(%d, groups_list) Failed, " "errno=%d : %s", gidsetsize, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* * Call getgroups(2) to verify that * setgroups(2) successfully set the * supp. gids of TESTUSER. */ groups_list[0] = '\0'; if (GETGROUPS(cleanup, gidsetsize, groups_list) < 0) { tst_brkm(TFAIL, cleanup, "getgroups() Fails, " "error=%d", errno); } for (i = 0; i < NGROUPS; i++) { if (groups_list[i] == user_info->pw_gid) { tst_resm(TPASS, "Functionality of setgroups" "(%d, groups_list) successful", gidsetsize); PASS_FLAG = 1; } } if (PASS_FLAG == 0) { tst_resm(TFAIL, "Supplimentary gid %d not set " "for the process", user_info->pw_gid); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; int gidsetsize; /* total no. of groups */ char *test_desc; /* test specific error message */ tst_parse_opts(ac, av, NULL, NULL); /* Perform setup for test */ setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; gidsetsize = NGROUPS; test_desc = "EFAULT"; /* * Call setgroups() to test condition * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0))); if (TEST_RETURN != -1) { tst_resm(TFAIL, "setgroups() returned %ld, " "expected -1, errno=%d", TEST_RETURN, EFAULT); } else { if (TEST_ERRNO == EFAULT) { tst_resm(TPASS, "setgroups() fails with expected " "error EFAULT errno:%d", TEST_ERRNO); } else { tst_resm(TFAIL, "setgroups() fails, %s, " "errno=%d, expected errno=%d", test_desc, TEST_ERRNO, EFAULT); } } } cleanup(); tst_exit(); }
static void setup(void) { tst_require_root(); tst_sig(NOFORK, DEF_HANDLER, cleanup); TEST_PAUSE; /* * Get the IDs of all the groups of "root" * from /etc/group file */ ngroups = readgroups(groups); /* Setgroups is called by the login(1) process * if the testcase is executed via an ssh session this * testcase will fail. So execute setgroups() before executing * getgroups() */ if (SETGROUPS(cleanup, ngroups, groups) == -1) tst_brkm(TBROK | TERRNO, cleanup, "setgroups failed"); }
int main(int ac, char **av) { int lc; int gidsetsize; /* total no. of groups */ int i; char *test_desc; /* test specific error message */ int ngroups_max = sysconf(_SC_NGROUPS_MAX); /* max no. of groups in the current system */ tst_parse_opts(ac, av, NULL, NULL); groups_list = malloc(ngroups_max * sizeof(GID_T)); if (groups_list == NULL) { tst_brkm(TBROK, NULL, "malloc failed to alloc %zu errno " " %d ", ngroups_max * sizeof(GID_T), errno); } setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; for (i = 0; i < TST_TOTAL; i++) { if (Test_cases[i].setupfunc != NULL) { Test_cases[i].setupfunc(); } gidsetsize = ngroups_max + Test_cases[i].gsize_add; test_desc = Test_cases[i].desc; /* * Call setgroups() to test different test conditions * verify that it fails with -1 return value and * sets appropriate errno. */ TEST(SETGROUPS(cleanup, gidsetsize, groups_list)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "setgroups(%d) returned %ld, " "expected -1, errno=%d", gidsetsize, TEST_RETURN, Test_cases[i].exp_errno); continue; } if (TEST_ERRNO == Test_cases[i].exp_errno) { tst_resm(TPASS, "setgroups(%d) fails, %s, errno=%d", gidsetsize, test_desc, TEST_ERRNO); } else { tst_resm(TFAIL, "setgroups(%d) fails, %s, " "errno=%d, expected errno=%d", gidsetsize, test_desc, TEST_ERRNO, Test_cases[i].exp_errno); } } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc, i; /* loop counters */ char *msg; int gidsetsize = 1; /* only one GID, the GID of TESTUSER */ int PASS_FLAG = 0; /* used for checking group array */ /* Parse standard options given to run the test. */ 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++) { Tst_count = 0; /* * Call setgroups() to set supplimentary group IDs of * the calling super-user process to gid of TESTUSER. */ TEST(SETGROUPS(gidsetsize, groups_list)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "setgroups(%d, groups_list) Failed, " "errno=%d : %s", gidsetsize, TEST_ERRNO, strerror(TEST_ERRNO)); continue; } /* * Perform functional verification if test * executed without (-f) option. */ if (STD_FUNCTIONAL_TEST) { /* * Call getgroups(2) to verify that * setgroups(2) successfully set the * supp. gids of TESTUSER. */ groups_list[0] = '\0'; if (GETGROUPS(gidsetsize, groups_list) < 0) { tst_brkm(TFAIL, cleanup, "getgroups() Fails, " "error=%d", errno); } for (i = 0; i < NGROUPS; i++) { if (groups_list[i] == user_info->pw_gid) { tst_resm(TPASS, "Functionality of setgroups" "(%d, groups_list) successful", gidsetsize); PASS_FLAG = 1; } } if (PASS_FLAG == 0) { tst_resm(TFAIL, "Supplimentary gid %d not set " "for the process", user_info->pw_gid); } } else { tst_resm(TPASS, "call succeeded"); } } cleanup(); tst_exit(); tst_exit(); }